eggjs / tegg Goto Github PK
View Code? Open in Web Editor NEWStrong Type framework with eggjs.
License: MIT License
Strong Type framework with eggjs.
License: MIT License
octet-stream 怎么支持前端传输的octet-stream类型的数据,tegg怎么获取并保存
octet-stream 怎么支持前端传输的octet-stream类型的数据,tegg怎么获取并保存
18.0.0
3.12.0
3.12.0
3.12.0
A TODO comment in indicates that the 'diff' functionality is missing. This issue tracks the implementation of this functionality as discussed in PR #192 and the specific comment #192 (comment).
Please ensure to review the context of the PR and the discussion to understand the requirements and expectations for this implementation.
目前这个项目是什么状态?可用于生产环境了吗?
我这边的使用场景是:
redis地址需要动态获取,因此需要请求接口获取配置,于是自定义redis插件,初始化之前发起异步请求。
egg-redis的配置,我在demo上是瞎写的,不过不用关心,报此类错误可以忽略,关键是加了await后还走不到这一步。
演示步骤如下:
1.下方的demo仓库,我是稍微改造了官方的eggjs-redis插件:
改动点在: app/plugins/egg-redis/lib/redis.js
2.插件配置如下(通过path指向插件):
3.Service层注入redis插件如下:
4.加了await后,npm run dev,报错如下:
ERROR 73152 framework.EggPrototypeNotFound: Object redis not found in LOAD_UNIT:foo [ https://eggjs.org/zh-cn/faq/TEGG_EGG_PROTO_NOT_FOUND ]
......................................................................
......................................................................
......................................................................
code: TEGG_EGG_PROTO_NOT_FOUND
serialNumber: EGG_PROTO_NOT_FOUND
errorContext: ""
奇怪:
1、加await处的代码报错捕获不到,感觉一加await就像跳过了当前的执行。
2、axios、app.curl试了都不行。
3、只要去掉await,非同步执行都ok。
麻烦大佬们帮看看,非常感谢~~
https://github.com/yinshanhu/eggjs-addSingleton-asyncFunction-error.git
v18.12.1
3.5.2
无
window11
tegg-orm-decorator 和 sequelize怎么一起使用
tegg-orm-decorator 和 sequelize怎么一起使用
v14.18.1
v3.5.2
3.6.3
windows10
Middleware decorator cannot make case sensitive routing.
It seems that getEggObject
will get wrong ObjectMap after Middleware decorator.
eggObjectMap Map(3) {
'LOAD_UNIT:tegg-app-controller:PROTO:853:middlewareController' => Map(1) { },
'LOAD_UNIT:multiModuleService:PROTO:851:appService' => Map(1) {},
'LOAD_UNIT:multi-module-repo:PROTO:850:appRepo' => Map(1) {}
}
proto.id: LOAD_UNIT:tegg-app-controller:PROTO:857:viewController
Provide a mini GitHub repository which can reproduce the issue.
Usenpm init egg --type=simple bug
then upload to your GitHub
add following into plugin/controller/test/http/middleware.test.ts
it('method Middleware should not work', async () => {
app.mockCsrf();
await app.httpRequest()
.get('/Middleware/Method')
.expect(200)
.expect('hello, view');
});
Steps to reproduce the behavior:
@HTTPController({
path: '/middleware',
})
@Middleware(countMw)
export class MiddlewareController {
@Inject()
appService: AppService;
@HTTPMethod({
method: HTTPMethodEnum.GET,
path: '/global',
})
async global() {
return {};
}
@HTTPMethod({
method: HTTPMethodEnum.GET,
path: '/method',
})
@Middleware(logMwFactory('use middleware'))
async middleware() {
return {};
}
}
add a viewController to match other paths
@HTTPController()
export class ViewController {
@HTTPMethod({
method: HTTPMethodEnum.GET,
path: '/*',
})
async get() {
return 'hello, view';
}
}
/Middleware/Method
,response 500 server errorExpected behavior
/*
and response 'hello, view'There's a TODO comment in the method of the class, indicating the need for implementing index left matching. This enhancement is related to the Data Access Layer (DAL) features introduced in PR #192.
The specific TODO can be found in the diff for .
This issue was requested to be opened by @fengmk2 in the PR discussion: #192 (comment)
使用 cnpmcore + tegg 开发,cnpmcore v3.38.2, tegg v3.12.0 版本,原本没有问题,升级到 v3.29.0 后启动报错 framework.EggPrototypeNotFound: Object searchAdapter not found in LOAD_UNIT:cnpmcoreRepository
;
锁版本 tegg 相关包锁在 3.12.0,cnpmcore v3.38.2,报错 nodejs.ERR_PACKAGE_PATH_NOT_EXPORTEDError: [egg-core] load file: /Users/xxx/demo/node_modules/@eggjs/tegg-orm-plugin/app.js, error: Package subpath './src/setup_hooks' is not defined by "exports" in /Users/xxx/demo/node_modules/leoric/package.json
;
查看 cnpmcore 依赖后,发现 "@eggjs/tegg": "^3.12.0",所以会安装依赖 3.12.0 3.29.0,这两个版本不兼容吗?
无
18.19.0
3.29.0
cnpmcore, 3.38.2
macOS 13.5.2 (22G91)
tegg
里面如何使用 egg-redis
中间件我使用这种方式可以 log
出值 redies.get('foo')
的值
但是会有两个问题
ctx.app.redis
ts 会提示 类型“Application”上不存在属性“redis”还想咨询一下,除过readme 还有其他的tegg的文档吗
async index(@Context() ctx: EggContext) {
try {
// @ts-ignore
const data = await ctx.app.redis.get('foo');
console.log(data);
return 'hello word';
} catch (err) {
console.log(err);
return 'hello word error';
}
}
config.redis = {
client: {
port: 6379, // Redis port
host: '127.0.0.1', // Redis host
password: 'my_react_admin_app',
db: 0,
},
};
redis: {
enable: true,
package: 'egg-redis',
},
请使用
npm init egg --type=simple bug
创建,并上传到你的 GitHub 仓库
1.使用的是eggjs框架,egg-redis不符合我的使用场景,于是通过addSingleton注册了自己的插件,名称为:‘redis’。确认注册是成功的。
2.代码里使用时,注入的方式:
import type { Redis } from 'ioredis';
@Inject()
private readonly redis: Redis;
3、报错:
framework.EggPrototypeNotFound: Object redis not found in LOAD_UNIT:......................................非关键信息省略..........
code: TEGG_EGG_PROTO_NOT_FOUND
serialNumber: EGG_PROTO_NOT_FOUND
还请大佬帮忙解答。
无
v18.14.1
3.5.2
1
window11
使用 pkg
直接报错
ERROR 27855 nodejs.Error: unknown type of module reference config: {"pkg":"cnpmcore/common"}
at Function.readModuleReferenceFromModuleJson (/Users/xxx/github/hello-tegg/node_modules/@eggjs/tegg-common-util/src/ModuleConfig.ts:85:15)
at Function.readModuleReference (/Users/xxx/github/hello-tegg/node_modules/@eggjs/tegg-common-util/src/ModuleConfig.ts:62:19)
README 文档:
v18.16.0
3.7.0
cnpmcore, 3.20.2
macOS 13.3.1 (22E261)
实现控制器拦截器注解。对类或者类方法的执行进行拦截。类似于nestjs
中的守卫
比如现在有些控制器接口有控制访问权限。我直接可以加上一个@Auth(AuthInterceptor) 注解。在AuthInterceptor里面实现自己的拦截逻辑
https://github.com/apache/rocketmq-clients Node.js client is ready.
能够看到官网的文档。
我用按照官网的教程,选择了TS版本示例,结果发送和官网的文档没有任何对应关系。。。
目前是靠约定 init 函数名称来实现的,应用开发者会踩坑,也很难避免应用层会使用到 init 这个同名方法。
想想可以直接import进来直接用,但是我看cnpmcore里可以导入 @model() 注解下的导入,我自己按下面代码测试就注入后对象的方法
controller代码如下:
import { Inject, HTTPController, HTTPMethod, HTTPMethodEnum } from '@eggjs/tegg';
import type { UserService } from '../service/UserService';
@HTTPController({
path: '/',
})
export class HomeController {
@Inject()
private readonly userService: typeof UserService;
@HTTPMethod({
method: HTTPMethodEnum.GET,
path: '/',
})
async index() {
this.userService.find();
return 'hello egg';
}
}
service代码如下:
import { AccessLevel, SingletonProto } from '@eggjs/tegg';
@SingletonProto({
accessLevel: AccessLevel.PUBLIC
})
export class UserService {
static find() {
console.log('find');
}
}
16.17.0
^3.5.2
"@eggjs/tegg-aop-plugin": "^3.5.2",
macOs 14.2 (23C64)
现在的HTTPMethod 虽然足够满足业务需求,但是不够简练,是否能提供 常用的 Get,Post等方法的修饰器
@Controller('/')
export class HomeController {
@Get('/')
async home() {
return 'Hello tegg!';
}
}
顺带补充,能否提供修改全局route的前缀 ,类似于在配置文件提供
export default config={
tegg:{
root:"/hello"
}
}
1、我在项目里面extend/context.ts里面,按照redmine文档,写了一个扩展属性
`
import { Session } from '@xx/eos'
const SESSION_HELPER = Symbol('context#sessionHelper');
export default {
/**
* sessionHelper
*/
get sessionHelper() {
if (!this[SESSION_HELPER]) {
this[SESSION_HELPER] = new Session(2)
}
return this[SESSION_HELPER];
},
};`
2、 在项目运行的时候会报如下错误:
`2023-12-13 20:52:43,219 ERROR 41983 nodejs.TypeError: Cannot read property 'protoImplType' of undefined
at Function.createProto (/Users/xxx/Work/docker/bytehubs-eos/node_modules/.store/@eggjs[email protected]/node_modules/@eggjs/tegg-metadata/src/factory/EggPrototypeCreatorFactory.ts:39:57)
at AppLoadUnit.init (/Users/xxx/Work/docker/bytehubs-eos/node_modules/.store/@eggjs[email protected]/node_modules/@eggjs/tegg-plugin/lib/AppLoadUnit.ts:53:55)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async Function.createLoadUnit (/Users/xxx/Work/docker/bytehubs-eos/node_modules/.store/@eggjs[email protected]/node_modules/@eggjs/tegg-metadata/src/factory/LoadUnitFactory.ts:33:7)
at async EggModuleLoader.loadApp (/Users/xxx/Work/docker/bytehubs-eos/node_modules/.store/@eggjs[email protected]/node_modules/@eggjs/tegg-plugin/lib/EggModuleLoader.ts:15:22)
at async EggModuleLoader.load (/Users/xxx/Work/docker/bytehubs-eos/node_modules/.store/@eggjs[email protected]/node_modules/@eggjs/tegg-plugin/lib/EggModuleLoader.ts:50:5)
at async ModuleHandler.init (/Users/xxx/Work/docker/bytehubs-eos/node_modules/.store/@eggjs[email protected]/node_modules/@eggjs/tegg-plugin/lib/ModuleHandler.ts:31:7)
at async App.didLoad (/Users/xxx/Work/docker/bytehubs-eos/node_modules/.store/@eggjs[email protected]/node_modules/@eggjs/tegg-plugin/app.ts:50:5)
pid: 41983`
无
v14.19.1
3.28.2
"dependencies": { "@eggjs/tegg": "^3.28.1", "@eggjs/tegg-aop-plugin": "^3.5.2", "@eggjs/tegg-config": "^3.2.3", "@eggjs/tegg-controller-plugin": "^3.5.2", "@eggjs/tegg-eventbus-plugin": "^3.5.2", "@eggjs/tegg-plugin": "^3.5.2", "@eggjs/tegg-schedule-plugin": "^3.5.2", "egg": "^3.15.0", "egg-scripts": "^2.17.0", "egg-tracer": "^2.0.0", "glob": "^10.3.10", "lodash": "^4.17.21" },
mac
Nodejs的require.resolve不支持windows格式的路径地址
tegg/core/common-util/src/ModuleConfig.ts
Line 75 in 2c683c3
requier.resolve("cnpmcore\\common\\package.json")
会解析失败
需要统一转换成linux的路径格式,如:
requier.resolve("cnpmcore/common/package.json")
tegg/core/common-util/src/ModuleConfig.ts
Line 75 in 2c683c3
18.12.0
3.8.0
tegg-common-util
Windows11
是否可以引入 https://github.com/xiekw2010/egg-typebox-validate 成为默认的 validate 插件,之前的 egg-validate 在 ts 下其实不太满足。
cc @xiekw2010
我希望给出使用simple创建js项目再切换ts,和使用tegg的相同点和不同点。
为什么官网没有给出相关的说明?只看readme没看出个所以然来,希望有个与官网文档类似的指导。
我的困惑是,现在推荐使用tegg还是这个方式?
https://www.eggjs.org/zh-CN/tutorials/typescript#%E6%8E%A7%E5%88%B6%E5%99%A8controller
参照: 提供更加简单化请求方法的修饰器的讨论
为了方便区分Controller
,RestController
,HttpController
,RpcControlle
需要单独划分命名空间以方便归类。 将HttpController和简化后的Controller将会被划分到
http namespace, RestController 会被划分到rest namespace,RpcControlle
会被划分到 rpc namespace。
以下将通过import
的形式具体描述:
import {Controller, HttpController} from '@eggjs/tegg/http';
import {RestController} from '@eggjs/tegg/rest';
import {RpcController} from '@eggjs/tegg/rpc';
config新增baseRoot能力
tegg:{
baseRoot:string
}
通过这个字段可以全局调整路由根路径
//config.default.ts
tegg:{
baseRoot:'/tegg'
}
//controller/fruitController.ts
@RestController('/api/v1')
//or Controller('/api/v1')
class Fruit {
// GET /api/v1/
@List
home() {
}
}
此时路径会被修正到‘/tegg/api/v1'’
所有的方法入参暂定为继承自HttpController:
Controller(path?: string, protoName?: string, controllerName?: string);
新的Http Method
会跟 HTTPMethodEnum
的枚举保持一致,包含 GET
,POST
,PUT
,DELETE
,PATCH
,OPTIONS
,HEAD
所有的方法入参暂时定为继承自HTTPMethod,以GET为例:
Get(path?: string, priority?: number)
与HTTPMethod不同的是Get第一个入参为可选,如果Get的path
入参为空时, 可以通过检索Handler Function 名称自动匹配路径。 下面以GET为例:
@Controller('/api/v1')
class Fruit {
// GET /api/v1/hello
@Get()
hello() {
}
}
以下方代码为例子,如果要处理当前Controller的跟路径,请使用Get('/')
@Controller('/api/v1')
class Fruit {
// GET /api/v1/
@Get('/')
home() {
}
}
与常规HttpController不同,RestController将自动携带 Hypermedia,
API,即返回结果中提供链接,连向其他API方法,使得用户不查文档,也知道下一步应该做什么。
比如访问 https://api.github.com/ 即可获得所有api 访问api.github.com/user,然后就得到了下面结果。
{
"message": "Requires authentication",
"documentation_url": "https://docs.github.com/rest/reference/users#get-the-authenticated-user"
}
配置baseRoot对RestController的会产生影响,通过这个字段可以全局调整RESTful根路径。
//config.default.ts
tegg:{
baseRoot:'/tegg'
}
此时会将rest默认的/api
前缀覆盖为/tegg
//config.default.ts
tegg:{
baseRoot:'/'
}
此时会将rest默认的/api
前缀覆盖为/
@RestController继承自HttpController,但是与Controller不同,如果path为缺省会根据当前的class name 并以复数的形式自动补全,会在当前根目录自动生成Hypermedia API。
type RestControllerOptions {
docURL?:string,
version?:string,
protoName?: string,
controllerName?: string,
}
@RestController(path?: string, options?: RestControllerOptions)
以下方代码为例子,我们没有填写任何参数并且没有配置baseRoot
字段,那么就会指向/api/v1/fruits
@RestController()
class Fruit {
// GET /api/v1/fruit/apple
@List
apple() {}
}
下面我们假设进行请求
$ GET /api/v1/fruits
# 我们会得到
{
"apple": "/api/v1/fruits/apple"
"documentation_url": "/doc/v1/fruit"
}
$GET /api/v1
# 我们会得到
{
"fruit": "/api/v1/fruits"
"documentation_url": "/doc/v1"
}
基于Get 请求增加,额外的业务能力
@Query
支持取出单条数据
@Query()
foo(id:string):Promise <Foo> {}
@List
支持取出所有数据,默认遵从RESTful风格支持常见参数过滤(可能需要配合ORM的能力)
1.支持 ?limit=10:指定返回记录的数量
2.支持 ?offset=10:指定返回记录的开始位置。
3.支持 ?page=2&per_page=100:指定第几页,以及每页的记录数。 4.根据函数的入参可以进行横向扩展,比如需要支持搜索
@List()
listFoo(keyword:string):Promise<Array<Foo>> {}
剩余业务能力支持待补充
待调查: 主要调查方向GRPC, JSONRPC
装饰器的文档有更全面的吗,目前的文档感觉好少,不知道怎么写啊...
当我下载完tegg相关插件后,运行项目,本地启动太慢,希望官方解决
无
18.0.0
3.12.0
3.12.0
3.12.0
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.