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

ws-process

v0.3.46

Published

Process Management for Web Socket Client

Downloads

180

Readme

ws-process

Call REST API

Process management for Web Socket Client

Each process will be running parallelly.

Requests in a process will be running sequently.

import { newProcess } from "ws-process";

// Basic usage skeleton
const promise = newProcess()
  .newRequest()
  .newRequest()
  .start();

promise
  .then(result=>{})
  .catch((err)=>{})
/*
.start() returns a Promise instance.
When the all requests belong to process are finished, it resolve with following:
*/
result = {
  data: {
	  isLast: true,
	  processID,
	  jsonResponse,
	  cbData
	},
  dispatch,
  getState,
  processFinished: true,
  processID
}

Sample

// To query a production order
dispatch(
  getOrder(
    { orderID },
    {
      afterSucceed: () => {
        history.push(`/prodconfirm/order/${orderID}`);
      }
    }
  )
);

// getOrder - an action creator for the thunk which is the middleware of redux
/*
  newProcess()
    arguments:
      Process ID: String without space
      Options: {
        appIsBusy = true(default)
      }
        Options are provided to "beforeEachProcess", "afterEachProcess" which are interceptors.
*/
const getOrder = (params, callback) => {
  return (dispatch, getState) => {
    const promise = newProcess("productionOrder")
      .newRequest({
        requestHandler: reqOrder,
        params,
        responseHandler: resOrder,
        callback
      })
      .start();
  };
};
/*
  params: Provided to 'request' function
*/

const reqOrder = ({ params }) => {
  return (dispatch, getState) => {
    return {
      version: "20190625",
      action: "requestodata",
      subAction: "getProductionOrder",
      description: "Fetch production order data from ByDesign",
      httpMethod: "GET",
      headers: {}, // headers could be ignored, authentication will be added in ws-process package,
      // Attributes in 'headers' will overwrite the attributes defined in ws-process package
      url: dispatch(
        convURL.custom("productionorder/ProductionOrderCollection", {
          $expand: ["ProductionLot/ProductionLotMaterialOutput"].join(","),
          $filter: [escape("ID eq '" + params.orderID + "'")]
        })
      )
      /* convURL has following methods
        .custom() - Returns url with process.env.REACT_APP_BYD_CUSTOM_ODATA_PATH,
        .report() or .reportCC() - Returns url with process.env.REACT_APP_BYD_REPORT_ODATA_PATH,
        .reportANA() - Returns url with process.env.REACT_APP_BYD_REPORT_ODATA_PATH_ANA,
        .datasource() - Returns url with process.env.REACT_APP_BYD_DATASOURCE_ODATA_PATH;
      */
      /* Default query parameters:
        sap-language: currentUser.lang || "en"
        $format: "json",
        $inlinecount: "allpages"
      */
    };
  };
};

// resOrder - An action creator for thunk the middleware of redux
/*
  arguments:
    
    @isLast: SAP Odata would split response if the data size exceeds the limit(?), so isLast is used for determine if the response is last.
    
    @jsonResponse: Response data as json format
  
  return:
    array - [boolean,data for callback]

    If no data for callback function need to be transferred, then it could return only boolean value, not array.
    If no callback function is provided, then 'return' could be ignored.
*/
function resOrder({ isLast, jsonResponse }) {
  return (dispatch, getState) => {
    const body = jsonResponse.body;
    const results = body.d.results;
    const count = parseInt(body.d.__count);

    if (count > 0) {
      dispatch(getProductionOrder(results));
      return [true];
    } else {
      dispatch(addError(["None of order is fetched"]));
      return [false];
    }
  };
}
  • callback functions: optional

    • afterSucceed(cbData): function - optional

      If response handler returns true or [true, <callback data>], then invoke afterSucceed and always.

    • afterFailed(cbData): function - optional

      If response handler returns false or [true, <callback data>], then invoke afterFailed and always.

    • always(cbData): function - optional

      Whatever returned by response handler, if always callback function is provided, it will run anyway for the specific request.

    callback functions will be invoked by the result of response handler.

Call REST API

url: The URL of REST API, if no domain is included, the API Hub domain will be used.

method: The HTTP Method

description: The text represented on Loading Dialog

params: The query string parameters

data: The body of request

newProcess("get master data")
  .newRequest({
    requestHandler: () => () => {
      return {
        url: "/master",
        method: "GET",
        description: "get vendor list",
        params: {
          type: "vendor"
        }
      };
    },
    responseHandler: ({ isFirst, isLast, jsonResponse }) => {
      return dispatch => {
        const body = jsonResponse.body;

        return [false];
      };
    },
    callback: {
      afterSucceed: () => {},
      afterFailed: () => {},
      always: () => {}
    }
  })
  .start();