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 🙏

© 2024 – Pkg Stats / Ryan Hefner

exmd

v1.0.38

Published

```exmd```的核心代码, 包含的功能有: 1. ```startProject``` 启动项目 2. ```BaseModel``` model基类 3. ```migrate``` 数据库表转model 4. ```asyncdb``` model转数据库表 5. ```renderRequestType``` controller方法的请求配置 - 配置请求 - 配置swagger及swagger中的参数和返回参数描述 6. ```handleClientAdapter``` 持久层

Downloads

85

Readme

exmd

exmd的核心代码, 包含的功能有:

  1. startProject 启动项目
  2. BaseModel model基类
  3. migrate 数据库表转model
  4. asyncdb model转数据库表
  5. renderRequestType controller方法的请求配置
  • 配置请求
  • 配置swagger及swagger中的参数和返回参数描述
  1. handleClientAdapter 持久层适配器,它能指定数据源,对数据源中的表对应的model操作
  2. ResultVo 返回的结果集合
  3. AuthController 内置的登录注册controller
  4. UploadController 内置的文件上传控制器

数据源配置 目前只支持postgresql数据库,后续将会扩展

module.exports = {
  // 数据库1
  postgresql1: {
    type: 'postgresql',
    data: {
      user: 'bserverx',
      database: 'bserver',
      password: 'bserverx123',
      host: 'localhost',
      port: '5432',
      poolSize: 5,
      poolIdleTimeout: 30000,
      reapIntervalMillis: 10000
    }
  }
}

启动项目

startProject({
  /**
   * 是否开启调试模式
   * 调试模式将会打印sql
   * 调试模式下不会发送邮件
   */
  isDebugger: true,
  /**
   * api地址路由配置
   */
  router,
  /**
   * 数据源
   */
  Datasource,
  /**
   * 用户model
   */
  authUserModel: UserModel,
  /**
   * 登录注册使用的数据源对应key
   */
  authDataSourceKey: 'postgresql1',
  /**
   * 注册邮箱使用的内容模板
   * 没有配置将会使用默认模板
   * @param {*} code 
   * @returns 
   */
  authEmailContent: (code) => {
    return `
      <p>您好:</p>
      <p>您的验证码是:<strong style="color:orangered;">${code}</strong></p>
      <p>嘿嘿</p>
    `
  },
  /**
   * 登录注册验证码超时时间
   */
  authEmailCodeMaxTime: '1minute', 
  // 一个邮箱最多允许绑定多少个用户
  authEmailBindUserMax: 3,
  // token生成私钥
  authPrivateKey: 'abc123',
  // hour/minute/second
  authTokenTime: '1minute',
  /**
   * 发邮件库,
   * 目前只支持 tencenmail
   */
  emailLib: 'tencenmail',
  /**
   * 邮箱配置
   */
  emailConfig,
  /**
   * 返回数据的结果集合模板
   */
  ResultVo,
  // swagger的路径配置
  swaggerUrl: '/swagger/data',
  // 文件上传的保存路径
  uploadBaseUrl: '/Users/wujianfei/test-upload-files',
  /**
   * 文件上传模块划分, 必须传
   * 上传的文件路径:基础路径下 文件名称: [模块名称_时间戳],
   * 比如default下的文件名称:
   * test1_1657007903331.mp4
   */
  uploadFileDirectorys: [{
    name: 'test1'
  }, {
    name: 'default'
  }],
  // 文件限制配置
  uploadLimits: {
    fileSize: 10 * 1024 * 1024 * 1024
  }
})

文件上传和登录模块使用 可参考提供的后端模板项目中的路由,看注释即可

const { AuthController, UploadController } = require('exmd')
const router = [
  {
    url: '/bserve/',
    controller: UploadController
  },
  {
    url: '/bserve/',
    controller: AuthController
  }
  ...自己定义的controller
]

ResultVo 可以根据该ResultVo自定义

/**
 * 返回实体类
 * @param {*} params 
 */
function ResultVo(params) {
  const { status, data, message } = params
  if (status === undefined) {
    throw new Error('status is undefined')
  }
  if (data === undefined && message === undefined) {
    throw new Error('both and data are undefined')
  }
  return {
    status,
    data,
    message
  }
}
ResultVo.prototype.swaggerDescription = {
  status: '状态 0正常',
  data: '',
  message: '异常信息'
}
module.exports = ResultVo

UserModel 可以根据该model自定义模板放到models目录下

const { BaseModel } = require('exmd')
const fieldsMap = {
  id: {
    type: 'uuid',
    length: 16,
    lengthvar: -1,
    notnull: true,
    comment: null,
    isPrimary: true,
    pk_name: 'omuser_pkey'
  },
  username: {
    type: 'text',
    length: -1,
    lengthvar: -1,
    notnull: true,
    comment: null
  },
  password: {
    type: 'text',
    length: -1,
    lengthvar: -1,
    notnull: true,
    comment: null
  },
  email: {
    type: 'text',
    length: -1,
    lengthvar: -1,
    notnull: true,
    comment: null
  },
  fullName: {
    type: 'text',
    length: -1,
    lengthvar: -1,
    notnull: true,
    comment: null
  },
  isactive: {
    type: 'int4',
    length: 4,
    lengthvar: -1,
    notnull: true,
    comment: null
  },
  realname: {
    type: 'text',
    length: -1,
    lengthvar: -1,
    notnull: false,
    comment: null
  }
}

function omuser() {
  const vm = this
  BaseModel.apply(vm, arguments)
  vm.fields = fieldsMap
  vm.tableName = 'omuser'
}

;(function () {
  const TempFun = function () {}
  TempFun.prototype = BaseModel.prototype
  omuser.prototype = new TempFun()
})()

module.exports = omuser

构建

npm run build

提交所有代码

npm run push:all

发布

npm run publish:exmd
npm run publish:aux

源码仓库已提交申请中,请耐心等待