-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from mmdapl/feat/code
feat: 初始化模块,增加文档和配置
- Loading branch information
Showing
54 changed files
with
14,811 additions
and
6,337 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
logs/ | ||
node_modules/ | ||
package-lock.json | ||
coverage/ | ||
.idea/ | ||
run/ | ||
.DS_Store | ||
typings/ | ||
.vscode | ||
/**/.DS_Store | ||
/.vscode/ | ||
/.vscode | ||
dist/ | ||
*/jsconfig.json | ||
*/.turbo/ | ||
.husky | ||
/**/jsconfig.json | ||
/**/**/.nuxt/ | ||
/**/.nuxt/ | ||
/.turbo/ | ||
**/.turbo/ | ||
**/**/.output/ | ||
**/.output/ | ||
**/node_modules | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# @142vip/egg-axios | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
{ | ||
"name": "@142vip/egg-axios" | ||
"name": "@142vip/egg-axios", | ||
"private": false, | ||
"description": "公众号搜:储凡", | ||
"keywords": ["公众号搜:储凡"], | ||
"author": "mmdapl <[email protected]>", | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# @142vip/egg-grpc-client | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
{ | ||
"name": "@142vip/egg-grpc-client" | ||
"name": "@142vip/egg-grpc-client", | ||
"private": false, | ||
"description": "公众号搜:储凡", | ||
"keywords": ["公众号搜:储凡"], | ||
"author": "mmdapl <[email protected]>", | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# @142vip/egg-grpc-server | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
{ | ||
"name": "@142vip/egg-grpc-server" | ||
"name": "@142vip/egg-grpc-server", | ||
"private": false, | ||
"description": "公众号搜:储凡", | ||
"keywords": ["公众号搜:储凡"], | ||
"author": "mmdapl <[email protected]>", | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# @142vip/egg | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "@142vip/egg", | ||
"private": false, | ||
"description": "公众号搜:储凡", | ||
"keywords": ["公众号搜:储凡"], | ||
"author": "mmdapl <[email protected]>", | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# @142vip/egg-sequelize | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
{ | ||
"name": "@142vip/egg-sequelize" | ||
"name": "@142vip/egg-sequelize", | ||
"private": false, | ||
"description": "公众号搜:储凡", | ||
"keywords": ["公众号搜:储凡"], | ||
"author": "mmdapl <[email protected]>", | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# @142vip/egg-swagger | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
{ | ||
"name": "@142vip/egg-swagger" | ||
"name": "@142vip/egg-swagger", | ||
"private": false, | ||
"description": "公众号搜:储凡", | ||
"keywords": ["公众号搜:储凡"], | ||
"author": "mmdapl <[email protected]>", | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# @142vip/egg | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
{ | ||
"name": "@142vip/egg" | ||
"name": "@142vip/egg", | ||
"private": false, | ||
"description": "公众号搜:储凡", | ||
"keywords": ["公众号搜:储凡"], | ||
"author": "mmdapl <[email protected]>", | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# @142vip/fairy-cli | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './src' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,15 @@ | ||
{ | ||
"name": "@142vip/fairy-cli" | ||
"name": "@142vip/fairy-cli", | ||
"private": false, | ||
"main": "index.d.ts", | ||
"description": "公众号搜:储凡、fairy-cli", | ||
"keywords": ["公众号搜:储凡"], | ||
"scripts": { | ||
"build": "tsc" | ||
}, | ||
"devDependencies": { | ||
"shelljs": "^0.8.5" | ||
}, | ||
"author": "mmdapl <[email protected]>", | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* 脚本执行器,执行shell命令 | ||
*/ | ||
import {join} from "path"; | ||
import {exec,exit} from 'shelljs' | ||
|
||
|
||
const cwd = join(__dirname, '..') | ||
process.env.PATH = `${join(cwd, 'node_modules', '.bin')}:${process.env.PATH}` | ||
|
||
/** | ||
* 监听进程 | ||
* - 退出进程 | ||
*/ | ||
process.on('exit', () => { | ||
exit() | ||
}) | ||
|
||
|
||
/** | ||
* 执行shell指令 | ||
*/ | ||
export async function execShell(commands: string | string[]):Promise<void>{ | ||
let runCommands:string[] = [] | ||
if (typeof commands === 'string') { | ||
runCommands.push(commands) | ||
} | ||
|
||
// 批量执行 | ||
if (Array.isArray(commands)) { | ||
runCommands = commands | ||
} | ||
|
||
for (let index = 0; index < runCommands.length; index++) { | ||
const command = runCommands[index] | ||
const count = index + 1 | ||
console.log(`step${count}:\n${command} \nstep${count}(start): === `) | ||
// await syncExec(command) | ||
const execResult = await exec(command) | ||
// 打印输出结果 | ||
console.log(execResult.stdout); | ||
console.log(`step${count}(ending): === \n`) | ||
// 指令异常,不执行后续指令,非0退出 | ||
if (execResult.code !== 0) { | ||
exit(1) | ||
break; | ||
} | ||
} | ||
} | ||
|
||
|
||
exports.execShell = async commands => { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './exec' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": "src", | ||
"outDir": "dist", | ||
"target": "es2018" | ||
}, | ||
"exclude": [ | ||
"dist", | ||
"node_modules", | ||
"test" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# @142vip/nest-redis | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './src' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "@142vip/nest-redis", | ||
"private": false, | ||
"description": "公众号搜:储凡", | ||
"keywords": ["公众号搜:储凡"], | ||
"author": "mmdapl <[email protected]>", | ||
"license": "MIT" | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": "src", | ||
"outDir": "dist", | ||
"target": "es2018" | ||
}, | ||
"exclude": [ | ||
"dist", | ||
"node_modules", | ||
"test" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# @142vip/nest-redis | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './src' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "@142vip/nest-redis", | ||
"private": false, | ||
"description": "公众号搜:储凡", | ||
"keywords": [ | ||
"公众号搜:储凡" | ||
], | ||
|
||
"author": "mmdapl <[email protected]>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@142vip/nest": "workspace:*", | ||
"@nestjs/typeorm": "^10.0.2", | ||
"mysql2": "^3.10.1", | ||
"typeorm": "^0.3.20" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import {EntityManager} from "typeorm"; | ||
import {InjectEntityManager} from "@nestjs/typeorm"; | ||
|
||
export class BaseDBService{ | ||
@InjectEntityManager() | ||
public readonly entityManager: EntityManager | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/nest-typeorm/src/core/custom-repository.decorator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { SetMetadata } from '@nestjs/common' | ||
import {TYPEORM_CUSTOM_REPOSITORY} from "./typeorm.constant"; | ||
|
||
|
||
/** | ||
* 自定义Repo装饰器 | ||
* @param entity | ||
*/ | ||
export function CustomRepository(entity: new (...args: any) => any): ClassDecorator { | ||
return SetMetadata(TYPEORM_CUSTOM_REPOSITORY, entity) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const TYPEORM_CUSTOM_REPOSITORY = 'TYPEORM_CUSTOM_REPOSITORY' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import type { DynamicModule, Provider } from '@nestjs/common' | ||
import { | ||
TypeOrmModule, | ||
TypeOrmModuleOptions, | ||
getDataSourceToken, | ||
getRepositoryToken, | ||
} from '@nestjs/typeorm' | ||
import type { | ||
TypeOrmModuleAsyncOptions, | ||
} from '@nestjs/typeorm/dist/interfaces/typeorm-options.interface' | ||
import type { DataSource } from 'typeorm' | ||
import {TYPEORM_CUSTOM_REPOSITORY} from "./typeorm.constant"; | ||
|
||
type EntitiesOrRepositories = (new (...args: any) => any)[] | ||
|
||
// types.setTypeParser(types.builtins.INT8, val => Number.parseInt(val, 10)) | ||
// types.setTypeParser(types.builtins.NUMERIC, val => Number.parseFloat(val)) | ||
|
||
export class TypeormModule { | ||
public static forFeature(entitiesOrRepositories: EntitiesOrRepositories, token?: string): DynamicModule { | ||
const providers: Provider[] = [] | ||
|
||
const entities = entitiesOrRepositories.map((Repository) => { | ||
const entity = Reflect.getMetadata(TYPEORM_CUSTOM_REPOSITORY, Repository) | ||
if (entity) { | ||
providers.push({ | ||
provide: getRepositoryToken(Repository, token), | ||
useFactory: (dataSource: DataSource) => { | ||
const baseRepo = dataSource.getRepository(entity) | ||
return new Repository( | ||
baseRepo.target, | ||
baseRepo.manager, | ||
baseRepo.queryRunner, | ||
) | ||
}, | ||
inject: [getDataSourceToken(token)], | ||
}) | ||
return entity | ||
} | ||
return Repository | ||
}) | ||
|
||
const forFeature = TypeOrmModule.forFeature(entities, token) | ||
|
||
return { | ||
module: TypeormModule, | ||
providers, | ||
imports: [forFeature], | ||
exports: [...providers, forFeature], | ||
global: true, | ||
} | ||
} | ||
|
||
public static forRoot(options: TypeOrmModuleOptions): DynamicModule { | ||
return { | ||
module: TypeormModule, | ||
providers: [], | ||
exports: [], | ||
imports: [TypeOrmModule.forRoot(options)], | ||
global: true, | ||
} | ||
} | ||
|
||
public static forRootAsync(options: TypeOrmModuleAsyncOptions): DynamicModule { | ||
return { | ||
module: TypeormModule, | ||
providers: [], | ||
exports: [], | ||
imports: [TypeOrmModule.forRootAsync(options)], | ||
global: true, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './core/base.service' | ||
export * from './core/typeorm.module' | ||
export * from './core/custom-repository.decorator' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": "src", | ||
"outDir": "dist", | ||
"target": "es2018" | ||
}, | ||
"exclude": [ | ||
"dist", | ||
"node_modules", | ||
"test" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# @142vip/nest | ||
|
||
|
||
|
||
## 参考资料 | ||
|
||
- 官方文档:<https://docs.nestjs.com/> | ||
- 中文文档:<> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './src' |
Oops, something went wrong.