npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

dinegg

v3.12.1

Published

egg framework dinegg.

Readme

dinegg

dinegg framework is base eggjs, use typescript develop.

QuickStart

$ npm install
$ npm test

publish your framework to npm, then change app's framework config:

// {app_root}/index.js
{
  "name": "my-project",
  "egg": {
    "framework": "dinegg"
  }
}

v3.3.0

添加多进程直连socket通讯机制逻辑

v3 breaking change

  • dinegg v3 使用最新 3.0 的 egg,由于 egg3 最低支持 node 14.20,因此使用 dinegg v3 也不再兼容低版本 node,当前推荐使用 16/18
  • sequelize 使用最新版的 6.0 版本
  • dinegg v3 强烈不建议在 service 中访问 ctx 上的属性,所有的 http 入参(body,params,query,header)等,都建议只在 controller 中获取。响应也只能在 controller 中返回统一对象。然后显示传递参数给到service,也就是说将service作为业务逻辑方法库,提供明确的入参出参。不直接访问ctx
  • controller和service等在modules和原egg中可同时声明,但二者最终会合并,如果出现相同目录,将被覆盖,覆盖方式:modules优先

使用 modules 封装业务逻辑代码在同一个目录下

  • 将 service、controller、middleware 等文件放在同一个目录,类似 nest 的模块组织程序结构。
  • 文件名以这些单词结尾,如 a.service.ts

使用指南:

  • 文件放置在 app/modules 目录下,以模块划分目录。如 app/modules/user/login.service.ts
  • 配置 config.modules 可以设置哪些模块导出(可控制哪些用哪些不用)。注意这里同时最好同步设置 ets 相关配置,这样代码提示也就不会有未导出的模块功能。
  • breking: 控制器定义必须以.controller.ts 结尾,在原 egg 定义的,第一层目录就必须与 module 的配置导出名一致才能引用到。
  • 注意,由于使用的.controller.ts 这种后缀,对原 egg 的控制器加载会有影响,原 egg 需同样后缀,且,如果使用了模块导出,原 egg 也必须外部套一层模块名目录。
//支持的文件
**/*.service.ts
**/*.controller.ts
**/router.ts
task/*.ts
schedule/*.ts
app.ts
agent.ts
// 配置文件
config.modules = {
  imports: ["mod_user","cat"],//配置需要使用的模块
  enable:true,//此属性配置用于开启module。开启后必须遵从本文档指南撰写代码,否则将和egg原来的方式造成冲突。
};

// tshelper.js
require('dinegg/lib/tshelper')([moduleName1,mod2])
  • 使用
//service
this.ctx.service.
//controller
app.controller.
//schedule 定时任务,从模块目录下的task/或者schedule/目录读取任务文件。只匹配模块下的第一层目录。*/task/task1.ts 和 */schedule/task2.ts

permission 权限控制

  • 装饰器@permission

装饰器可以从 controllerDecorator 和 serviceDecorator 导入,效果一致!

// controller.ts
import { permission, get } from "dinegg/decorator";

class Controller {
	@get("/api/abc")
	@permission(["abc:bcd"])
	async method() {}
}
  • 权限控制类实现及使用
// 自定义权限控制实现类
import { AbstractPermissionAccessControl } from "egg";

export default class RoleAccessControl2 extends AbstractPermissionAccessControl {
	async main() {
		const userRole = this.ctx.request.query.myRole;
		console.log("userRole", userRole);
		if (this.permId.includes(userRole)) {
			return true;
		} else {
			throw new Error(`抱歉,您没有权限!需要的权限:${this.permId.toString()}`);
		}
	}
}

// app.ts 在app.ts中绑定后即可使用。在控制器或service的方法上绑定装饰器,如果验证权限失败会抛出错误。
import { Application, IBoot } from "egg";
import PermissionAccessControl from "./PermissionAccessControl";
// import * as path from "path"

export default class AppInit implements IBoot {
	private readonly app: Application;

	constructor(_app: Application) {
		this.app = _app;
		this.app.PermissionAccessControl = PermissionAccessControl;
	}

	async willReady() {}
}

cache 内存缓存简单实现 map 接口

  • this.app.cache.set()

  • this.app.cache.get()

  • this.app.cache.remove()

  • this.app.cache.clear()

  • 使用方式 dts 声明

/**
 * 添加一个缓存
 *
 * @param {string} key 字段key,注意不能重复
 * @param {*} value
 * @param {number} seconds 缓存时间,按s为单位 默认20s
 * @memberof AppCache
 */
set(key: string, value: any, expire: number = 20): boolean;
/**
 * 获取缓存
 *
 * @template T
 * @param {string} key
 * @return {*}  {(T | null)}
 * @memberof AppCache
 */
get<T extends any>(key: string): T | null;
remove(key: string): boolean;
delete(key: string): boolean;
/** 移除已过期的key value */
removeExpired(): boolean;
/** 重置整个map为新的,原来的放弃,被垃圾回收 */
reset(): void;
/** 重置整个map为新的,原来的放弃,被垃圾回收 */
clear(): void;

dineggApiClient 进程直连通讯

egg多进程默认使用ipc在agent与app之间通讯,这是需要通过node默认的cluster机制,由master中转来实现的。 dinegg参考egg官方文档,实现了一套直连通讯机制接口

Questions & Suggestions

Please open an issue here.