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

ts-api-core

v1.3.0

Published

Nodejs api framework core

Downloads

47

Readme

TS-API-Core SDK

一、简介

SDK 是适用于 Node.js ,基于 express 的轻量级 API 框架内核。 主要特点是可以采用传统的基于 Controller 方式和特色的基于 RouteConfig 方式开发 API 接口。 而 RouteConfig 方式的 API 接口开发具有文档即接口的特点,也正是本 SDK 所推荐的方式。

ToDo

  • [x] 基本框架
    • [x] 常用工具类
      • [x] Utils
      • [x] UtilsDB
      • [x] PackageLoader
      • [x] 数据库日志基础类
      • [x] MySQL 分布式锁
      • [x] 数据字段驼峰转化 Helper
      • [x] 数据模型转化 ModelHelper
      • [x] 本地内存高速数据缓存 LocalCache
    • [x] RouteConfig 引擎
      • [x] Raw 请求引擎 Wrapper
      • [x] 自定义 Wrapper 执行引擎
      • [x] GraphQL 执行引擎
      • [x] SQL 执行引擎
    • [x] Contoller 引擎
    • [x] 在线 api 接口文档
      • [x] 文档输出
      • [x] 在线查看
      • [x] UI css 自定义
    • [x] MySQL 集成
      • [x] DBConnectionManager 数据库连接池管理 (支持多数据库的管理)
      • [x] DBManager 数据库管理器
      • [x] DBScript 工具类
      • [x] Context 集成
      • [x] Wrapper 集成
      • [x] SQL 日志
    • [x] 三方数据源集成
      • [x] Redis 缓存 CacheAccess
        • [x] get, set, remove, exist, getSet, search, setNX
      • [x] Http 集成 HttpAccess
      • [x] 阿里云 oss 集成 OssAccess
        • [x] move, remove, upload, uploadStream, uploadUrlDownload, uploadBuffer, getFileList
      • [x] RabbitMQ 消息队列集成 RabbitMQAccess
        • [x] 订阅和消费
        • [x] 消息发送
      • [ ] 其它
    • [x] Web Server
    • [x] 后台服务 BackupServer
    • [x] MVC
      • [x] 可配置的自动扫描加载
      • [x] 依赖注入
      • [x] Ioc容器
      • [x] 参数校验
        • [x] integer
        • [x] length
        • [x] mobile
        • [x] pick
        • [x] required
    • [x] 日志模块
      • [x] api 日志
      • [x] 系统日志
      • [x] SQL 脚本日志
    • [ ] JWT 集成
    • [ ] 在线接口管理后台
      • [ ] 登录
      • [ ] 动态管理接口
  • [ ] Demo
  • [ ] SDK 文档
  • [ ] 其它 ??

1.1 推荐的项目结构

doc 项目文档
src 源代码
    controller 接口控制器目录
        ...
    model 数据模型定义目录
        ...
    route 接口路由配置目录
        ...
    server 后台服务目录
        ...
    service 数据业务服务目录(数据库操作)
        ...
    wrapper 接口业务实现目录
        ...
    app.ts 应用入口
    config.ts 程序配置管理
    consts.ts 全局常量定义
Dockerfile
package.json
README.md
tsconfig.json
tsconfig.eslint.json

1.2 使用示例

app.ts

启用服务的示例

import { App } from 'ts-api-core'

App.initialize("TS WEB 服务", {
  server: {
    port: Number(process.env.EXPOSE_PORT ?? 8080),
    controller: [],
    allowHeader: ["token"],
    // logger: new MysqlApiLogger(),
    loadOpts: { loadDir: [ "./route", "./controller" ] }
  },
  entitys: [],
  config: {
    ossConfig: Config.ossConfig,
    dbConfig: Config.dbConfig,
    rabbitmqConfig: Config.rabbitmqConfig,
    // modelHelperConfig: new ModelHumpConfig(),
    apiTimeOut: Config.API_TIME_OUT,
    loadOpts: { loadDir: ["./wrapper"] }
  }
})

1.3 自定义 Route 请求类型

1.3.1 添加 Route 请求类型

/**
 * 自定义请求处理 Wrapper
 */
class TestCustomWrapper extends BaseRouteRawWrapper {
  async executeRequest(
    context: RequestContext
  ): Promise<WrapperResult<any | undefined>> {
    return new WrapperResult({
      query: context.req.query,
      body: context.req.body,
      params: context.req.params
    })
  }
}

/**
 * 自定义 Route 请求 Controller
 */
@Service('custom')
export class TestCustomController extends BaseRouteRawController {
  protected canExecuteWrapper(context: RequestContext): boolean {
    return true
  }

  protected getWrapper(context: RequestContext): RawWrapper {
    return new TestCustomeWrapper(context)
  }
}

1.3.2 使用示例

@Route("/demo")
export class CustomRouteConfig implements RouteConfig {
 name = '自定义请求类型测试';
 data(): any {
    return this.routers
 }
 
 private readonly routers: RequestData[] = [
 {
  name: "test",
  path: "/custom/req/type",
  methed: RequestMethod.GET,
  type: 'custom',
  query: [],
  resp: {},
  config: {}
 }]
 
}
请求示例
GET http://127.0.0.1:8080/demo/custom/req/type?id=123456
响应示例
{
    "code":0,
    "data":{
        "query":{
            "id":"123456"
        },
        "body":{},
        "params":{}
    },
    "reqId":"c8ba894927c5461991da8d0d1875a9a9"
}

二、调试说明

链接到全局

将本项目链接到全局:

npm link

与调试项目建立链接

在调试项目中与本项目建立链接:

npm link ts-api-core

这时候你修改了本项目原文件里内容时,在调试项目里调试时也会跟着变。

三、发布说明

配置目标仓库

不配置会使用默认的仓库(npmjs)。

npm config set registry https://registry.npmjs.org

登录

添加用户和登录,输入命令后按提示输入用户名和密码、emial。

npm adduser
npm login

发布

// 先编译
npm run build
// 发布
cd dist
npm publish
// 发布到指定仓库
npm publish --registry https://npm.xxx.com/