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

apaas-request

v0.1.9

Published

the is aPaaS custom component request tools library

Downloads

18

Readme

apaas-request

apaas-request 是一个前端工具库,主要用于 aPaaS 低代码平台组建开发的请求相关的操作

封装了一些自定义组件的常用方法。不常用的也没有剔除,并附带上面,使用者依旧可以使用原生的方法。

  • 亲民:设想使用 axios 的写法使用请求
  • 简便:安装一个包覆盖 aPaaS 所有前端所包含的 skd
  • 一统:请求方式与 node 端服务相同。链式调用。

2.5 更新暴露出 application 对标 云函数的 application

由于组建的请求 SDK 不能完全覆盖云函数的 SDK,所以在使用的时候,请根据 ts 方法暴露出的方法改变。使用是跟云函数 SDK 一致的

  • application.data.object

    • limit
    • select
    • where 使用 application.operator
      • contain
      • eq
      • neq
      • isAnyOf
    • find
    • findOne
    • findStream
  • application.metadata.object

    • getField
    • getFields
  • application.flow.execute

  • application.function().invoke()

简单对比。优势在我

以前需要安装

npm i  @byted-apaas/data  @byted-apaas/flow @byted-apaas/i18n @byted-apaas/global-variable @byted-apaas/function

现在需要安装

npm i apaas-request

以前使用的方法。

import {
  batchUpdateRecords,
  createRecord,
  datasetsDescribe,
  datasetsFieldsDescribe,
  deleteRecord,
  downloadFile,
  objectDescribe,
  searchObjectsDescribe,
  searchRecords,
  uploadFile,
} from "@byted-apaas/data";

// 光一个 data 的 api 就这么多并且各种方法的传递参数又不一致。

searchObjectsDescribe("xxx");

现在使用的方法

import trequest from "trequest";
// 优雅,实在是太优雅了
trequest.oaxios.get({ apiName: "xxx", params: { xxx: "xxx" } });

yes is future

拦截器概念

import { OAxios } from "trequest";
// 设置请求拦截器
OAxios.request.use(
  (params) => {
    // TODO: 处理请求参数,比如:给每个参数都加上一个 page_size 。
    console.log(params);
  },
  (err) => {
    console.log(err);
  }
);

// 设置响应拦截器
OAxios.response.use(
  (response) => {
    // TODO: 处理响应回来的数据,比如:解构一些参数拿到
    console.log(response);
  },
  (err) => {
    console.log(err);
  }
);

// 请求封装
export const OAxios = ({ method, apiName, params }) => {
  return OAxios[method]?.({
    apiName,
    params: {
      ...params,
      field: ["number"],
    },
  });
};

// 使用
OAxios({
  method: "get",
  apiName: "object_vl8kepdgoka",
  params: {
    fields: ["number"],
  },
}).then((res) => {
  console.log("success", res);
});

单个拦截器

如果没有设置方法对应的请求,默认是使用到当前实例的请求都会经过改拦截器,很多地方我们并不需要这样,所以有单个拦截器的诞生。

import { flow } from "trequest";

const config = { apiName };

const successResponse = (response) => {
  let data = response.data.issue;
  data = schemaValueHandler(data); // 这个方法你可自行处理自己的逻辑
  return data;
};

const errorResponse = (err) => {
  console.log("err", err);
  return err;
};

const interceptor = flow.response.use(
  { ...config, handler: successResponse },
  { ...config, handler: errorResponse }
);

// 删除拦截器的两种方式
flow.response.eject(successResponse, errorResponse);
flow.response.eject(interceptor);

使用手册

使用此库依旧需要基础知识铺垫,主要是参数的了解。比如:@byted-apaas/data 的 api 传递参数。 这个库只是基于这些上面做了一个统一的封装。

OAxios 参数介绍。

所有的 data 字段类型都以原生的对象为基准。如果不清楚可查看 官方文档

get 方法

get 中,封装了三个对象方法

  1. searchRecords 怎么通过 get 使用呢?

使用: 传入 apiName 和参数 params 即可。

  1. objectDescribe 怎么通过 get 使用呢?

使用:在调用 get 方法的时候,在 config 参数中携带,isDescribe: true 这个字段,调用的就是 objectDescribe 了。

  • apiName: 必填,对象 apiName。

  • 参数(params):params 参数中,只需传入 fields。

  • 配置(config): config.isDescribe = true;设置为 objectDescribe

  1. downloadFile 怎么通过 get 使用呢?

使用:在调用 get 方法的时候,在 params 参数中携带,token:'xxx' 这个。

  • apiName: 可不填

  • 参数(params):

    1. token 必填,剩余参数都会传入到对应的选项中。
    2. onProgress,用于接收进度。
    3. name 文件名称

这里需要花点笔墨来说一下,调用下载的时候,给封装成了一个 Promise ,而这个 Promise 返回的结果是对象。这个对象有个 result 的字段,result 也是一个 promise,这个 promise 就是最后返回的数据。为什么会这样,因为这个 api 方法调用就会返回一些操作方法,供开发者使用,而成功的结果是一个回调函数,等成功之后调用回调,所以 result 的 promise 是在等回调成功。

post

在 post 请求中封装了 uploadFile、createRecord

post 接受一个对象, 对象里面 apiName data options。

  1. uploadFile 上传文件
  • apiName 必填
  • data 必须为 File 类型否则校验不过
  • options 可选,是原本 uploadFile 的配置
  1. createRecord 创建记录
  • apiName 必填
  • data 可以为对象,可以为数组
  • options 不填

patch 方法

封装了 batchUpdateRecords 更新方法

传入一个对象 apiName data

  1. batchUpdateRecords 更新记录
  • apiName 必填
  • data 数组

delete 方法

封装了 deleteRecord 删除方法

传入一个对象 apiName data

  1. deleteRecord 删除记录
  • apiName 必填
  • data 是一个对象里面需要 recordId 字段

flow 参数介绍。

所有的 params 字段类型都以原生的对象为基准。如果不清楚可查看 官方文档

-- 标识为官方文档参数类型

get 的用法

封装了 getExecutionList、getExecutionInfo、getExecutionParams

传入的参数 apiName、params

  1. getExecutionList 获取流程列表
  • apiName 必填
  • params --
  1. getExecutionInfo 获取执行流程信息
  • apiName 必填 number 类型
  1. getExecutionParams 获取流程参数
  • apiName 必填

post 的用法

封装了 startExecution

传入的参数 apiName、params

  1. startExecution 调用流程
  • apiName 必填
  • params --

delete 方法

封装了 revokeExecution

传入的参数 apiName、reason

  1. revokeExecution
  • apiName 必填
  • reason --

func 的删除介绍

所有的 params 字段类型都以原生的对象为基准。如果不清楚可查看 官方文档

需要开启允许前端调用

  1. invokeFunction
  • apiName 必填
  • params --

Other 方法介绍

trans 方法

trans.localegetCurrentLocale 的返回值 trans.i18n 传入一个对象, 对象的类型, 在使用的时候只需要拿到

// a.ts 定义
 const languageType =  {
    key:{
      zh_CN:"干得好,伙计",
      en_US:"god job man",
    }
  }
  export const language = trans.i18n(languageType)
  // b.ts 使用
 <div>{language.key}</div>

globalVar 方法

用法跟原生的一样。这里不做多展示,请查看文档。 getVar -- getDescribe --

项目所涉及到的包。

  • "@byted-apaas/data",
  • "@byted-apaas/flow",
  • "@byted-apaas/i18n",
  • "@byted-apaas/global-variable",
  • "@byted-apaas/function",
  • "lodash.isequal",