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

jason-server

v3.0.0

Published

自动创建服务器,实现事务等。。。极速方便mysql+ express

Downloads

350

Readme

#自动创建生成 服务器(express+mysql)---将要废弃不再维护,更好更多方案将在jason-core-api出现(未完) ##特点

  1. 自动创建服务,自带mysql服务器连接 方便
  2. 自动注入了表的增删改查(如user表)
 findAllUser({filter:{...}})
 findOneUser({filter:{...}})
 createUser({id:...,name:...})
 updateUser({user:{name:...},filter:{id:...}})
 upsertUser({name:...,id:...})//存在id为修改否则为新增
 deleteUser({filter})
 countUser(filter)//计数统计,一般用于分页列表

其中filter为过滤条件如:(支持多层嵌套)

{name:'sss',age:89...}// name =’sss‘ and age=89...
{name_ne:'sss',age_gt: 89}//name =’sss‘ and age>89
{name_ne:'sss',age_gte: 89}//name =’sss‘ and age>=89
{name_like:'sss%',age_lt:89}//name like ’sss‘ and age<89
{name_like:'sss%',age_lte:89}//name like ’sss‘ and age<=89
{name_notLike:'%sss'}//name not like ’sss‘ 
{name_in:['sss']}//name in [’sss‘] 
{name_notIn:['sss']}//name not in [’sss‘ ]
{
  AND:[
    {name:'99'},
    {id_ne:'1111'},
    ...
  ]
 }// name='99' and id != '1111'...
 {
  OR:[
    {name:'99'},
    {id_ne:'1111'},
    ...
  ]
 }//name ='99' or id != '1111'...

等等... ##用法文档 1.在根目录下创建.env.js文件

export default {
    IGORE_TOKEN_FUN: ['login', 'getCurrentUser' , 'sendIdentifyCode', 'uploadImg'],//不需token校验的接口,2.0.20版本已经不需要,但兼容
    SET_TOKEN_FUN: ['login'],//设置token的api接口
    MODEL_DIR: `${__dirname}/model`,//表目录
    API_DIR: `${__dirname}/biz`,//自定义接口目录
    ENV: {
        PORT: 5001,
        URL: 'http://localhost'
    },//服务器配置
    DB_ENV: {
        host: 'localhost',
        user: 'root',
        database: 'job',
        password: 'root',
        port: 3306,
        multipleStatements: true
    }//mysql 配置
}

2.在根目录下创建 表文件目录 model,在目录下创建表文件 Account.type.sql

type Account {
    id: ID!,
    mobile: String,
    password: String,
    lastLoginTime: DateTime,
    loginTimes: Int
}//目前支持类型 ID! String Bool Int Decimal Date DateTimeq七种类型

3.在根目录创建自定义接口目录 biz 在biz中创建自定义接口文件如 password.biz.js 自定义接口如下

import {injectable, apiService, transaction, ignoreCheckToken} from 'jason-server'
//登录
export const login = apiService(
    injectable(['findOneAccount', 'findOneUser', 'findOneToken', 'createToken', 'updateToken', 'updateAccount']),
    transaction(true),
    ignoreCheckToken(true)//此接口不开启token 校验
)(async ({findOneAccount, findOneUser, findOneToken, createToken, updateToken, updateAccount}, {mobile, password}) => {

    const account = await  findOneAccount({mobile, password: hasMd5(password)});
    if (!account) return {error: '账号不存在或密码错误'};
    const accountId = account.id;
    const user = await  findOneUser({accountId});
    if (!user) return {error: '用户不存在'}
    await updateAccount({account: {lastLoginTime: formatDateTime(new Date())}, filter: {id: accountId}})
    let token = await  findOneToken({accountId}) || await  createToken({accountId});
    await updateToken({token, filter: {id: token.id}});

    return {user, accountId, tokenId: token.id}
})
login 接口
injectable:引入其他接口,包括自定义和系统自定义
transaction: 是否注入事务处理

#创建服务

import 'babel-polyfill'
import {autoCreateServer} from 'jason-server'

export const setParamsMiddleWare = (req, res, next) => {
    //根据实际情况写此方法
    const params = req.body.params||{};
    const token = req.body.tokenId;
    const url = req.url;
    const urls = url.split('/');
    
    const funName = urls[urls.length - 1].split('.do')[0];
    req.funName = funName;
    req.token = token;
    req.params = params;
    
    next()
}

//核心
export default autoCreateServer({
    setParamsMiddleWare,
    customMiddlewares:[]
})
funName: 接口名//必填
params:接口参数//必填
setParamsMiddleWare:注入token 用户参数等信息//必须
customMiddlewares: 用于自定义中间件//非必须

##版本历史信息 2.0.19 ........ 1.添加api ignoreCheckToken(true) 不开启token校验,默认所有findOne,findAll,count都不校验, 2.不允许自定义api以 findAll findOne count create update upsert 开头 2.0.18 ........ 修改配置文件,适应ip + token校验 2.0.8 ........ 添加据库自动创建表( 删除原表) 2.0.4 ........ 修改不需事务处理bug。 1.0.0 ........ 优化自动注入接口,添加自定义model计数接口如: countUser({filter:{....}})。