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

@forchange/ams

v0.2.1

Published

接口管理、数据mock 一体化服务

Downloads

68

Readme

ams

api 和 mock 一体化服务

特点

  • 定义元数据
  • 生成接口实例
  • 可视化展示

快速开始

安装 node 环境

$ brew install node

安装 ams 服务

$ npm install -g @forchange/ams

初始化

$ ams init
$ cd <输入的文件名>

安装 mock 服务

$ npm install @forchange/mock --save

启动

$ ams

现在,访问 http://0.0.0.0:3839 查看

术语描述

| 名 称 | 解 释 | | :------: | :--------------: | | model | 元数据 | | api | 数据整合配置 | | data | 数据 | | traverse | 复杂数据数量配置 | | rules | 自定义规则 | | flow | 数据联动标识 |

如何使用

示例目录结构

ams
├── api                          // api 数据
│   └── welcome
│       └── forchange#get.ts
├── model                        // model 数据
│   └── welcome
│       └── forchange#get.ts
├── config.json                  // 模块配置文件
└── .amsrc                       // 配置文件

接口定义

规则

  • 一个接口一个文件
  • 文件路径即路由和方法

示例

路由:/ambassador/courses/:id/:pay 方法:GET

ams
├── api
│   └── ambassador
│       └── courses
│           └── :id
│               └── :pay#get.js

编写 api

新建

$ ams create <文件路径>  [-m <method>] -api

参数列表

| 参 数 | 解 释 | 类型 | 示 例 | | :---------: | :-------------------------: | :------: | :------------------------: | | title | 接口名 | string | '这是一个示例标题' | | description | 接口描述 | string | '这是对示例标题对一个解释' | | model | 模 型 | boolean | true | | data | 数 据 | object | | | traverse | 定义 model 中复杂数据的数量 | object | | | rules | 内部规则 | object | | | flow | 数据联动 | [object] | |

title

api 接口标题

description

api 接口描述

data

api 中定义的数据,将会覆盖 model 中的 data 数据定义 👉 参考

对于 data 字段, 我们在定义式不支持复杂的函数形式

traverse

定义 model 中复杂数据的数量

rules

内部规则 👉 参考

flow

接口联动 👉 参考

示例

export default {
  title: "这是一个标题",

  description: "welcome to use ams",

  data: {
    welcome: {
      userInfo: {
        __rule__: "@list",
        params: {
          payload: {
              name: "@name",
          }
        }
      }
    }
  }

  traverse: {
    "data.welcome.userInfo.params": {
      number: 3
    }
  },

  rules: {
    a: function() {
      return 1;
    }
  },

  flow: [
    {
      route: "/aaa/bb/cc",
      method: "post",
      data: {
        forchange: "welcome"
      }
    }
  ]
};

编写 model

新建

$ ams create <文件路径> -model

参数

| 参 数 | 解 释 | 类 型 | | :------: | :----------: | :-------: | | namespace | 模块名 | | | Request | 配置请求参数 | interface | | Response | 配置相应参数 | interface |

data 定义

数据定义 👉 参考

注解说明

我们通过 namespace 字段来定义模块 我们将通过注释的方式来对字段进行注解 RequestResponse 两个字段都将原封不动的进行数据展示 你可以通过注释获取每个字段所代表的含义

示例

namespace Forchange {
  interface Request {
    header: {
      // header 参数
    };
    query: {
      // query 参数
    };
  }

  interface Response {
    message: "hello forchange"; // message 字段(来自 model 中 data 字段
  }
}

即该接口模块名为 Forchange

编写描述信息

编写模块标题

定义

我们将 model 文件中 namespace 定义的字段视作 模块。(如果没有 model 文件,我们会将路径对第一层 path 视作模块名) 你可以在 config.json 文件中的 model 字段下对 模块 进行释义。

示例

{
  "model": {
    "Welcome": "这是welcome模块"
  }
}

配置 .amsrc

如果你不需要配置文件,可跳过。

新建

在当前文件夹下新建 .amsrc 文件

参数

| 参 数 | 解 释 | 示 例 | | :---: | :-------: | :-------: | | host | ip | '0.0.0.0' | | port | ams 端口 | 3839 | | mport | mock 端口 | 3838 |

示例

module.exports = {
  host: "0.0.0.0",
  port: 3839,
  mport: 3838
};

命令

常用指令

Usage
  create <path> [-m <method>] [-api] [-model]
      path           路径
      -m, --method   method of create file
      -api           create api file
      -model         create model file

  init               快速开始

  -h, --host         host of ams
  -p, --port         port of ams
  -l, --label        label of ams
  -m, --mport       port of mock
  -c, --config       use config of .amsrc

Options:
  --help             Show help
  -v, --version      Show version info

Examples:
  ams init
  ams

启动 mock 服务

$ ams [-c <.amsrc path>]

新建文件

同时新建 api 和 model 文件

$ ams create <path> [-m <method>]

新建 api 文件

$ ams create <path> [-m <method>] -api

新建 model 文件

$ ams create <path> [-m <method>] -model