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

dwh-fetch

v1.7.0

Published

fetching data from DigiWEB devices

Downloads

72

Readme

Typescript service for Digitronic Dwh interface

Usage

yarn add dwh-fetch

Start coding!

Features

  • fetch DigiWEB variables as strings, or integers or as arrays
  • map results of DigiWeb variables to objects using the @Expression decorator

Importing library

import DwhFetch from 'dwh-fetch'

Examples

const dwh = new DwhFetch();

// fetch a simple variable to promise
dwh.fetchString('##000187').then(value => console.log(value));

(async () => {
// or with await ...
  const value = await dwh.fetchString('##000187');
})();
const dwh = new DwhFetch();

(async () => {

  // fetch as Number to convert the result to number before returning
  const aNumber = await dwh.fetchNumber('##000187');
  const isNumber = aNumber instanceof Number; // true

})();
const dwh = new DwhFetch();

(async () => {

  // fetch as Number to convert the result to number before returning
  const result = await dwh.fetch(['##A', '##B']);
  console.log(result.accessRights); //current accessRights from the request
  console.log(result.lines[0].success); //boolean indicates that request has been successful processed or not
  console.log(result.lines[0].value); //value of ##A or errorCode if success is false
  console.log(result.lines[1].success); //boolean indicates that request has been successful processed or not
  console.log(result.lines[1].value); //value of ##B or errorCode if success is false

})();

It's also possible to map values to objects and convert the results directly

interface Test {
  timer: number;
  firmware: string;
}

const expressions: ExpressionDefinitions<Test> = {
  timer: Expression.integer('##000187'),
  firmware: Expression.string('#$000199')
};
(async () => {
  const dwhFetch = new DwhFetch();
  const values: Test = await fetchExpressions(dwhFetch, expressions);
  console.log(values);
})();

This is also possible with array like expressions and using G= requests

import {
  Expression,
  ExpressionDefinitions,
  fetchExpressions,
  fetchIndexed
} from '../fetch-indexed';
import { DwhFetch } from '../dwh-fetch';

interface Test {
  num: number;
  str: string;
}

const expressions: ExpressionDefinitions<Test> = {
  num: Expression.integer('##Module[##X].num'),
  str: Expression.string('##Module[##X].str')
};
(async () => {
  const dwhFetch = new DwhFetch();
  const values: Test[] = await fetchIndexed(dwhFetch, '##Module.Count', expressions);
  console.log(values);
})();

This is also possible with multiple ExpressionDefinitions in one call

    //expression store holds all the requests that should be sent in one request
    const store = new ExpressionStore();
    // add the first expressions. Note that this won't resolve util fetchExpressionStore has been called and awaited
    const first = store.add({
      a: Expression.string('#$str[$(index)]'),
      b: Expression.integer('##num[$(index)]'),
    });
    // add the first expressions. Note that this won't resolve util fetchExpressionStore has been called and awaited
    const second = store.add({
      c: Expression.string('#$str'),
      d: Expression.integer('##num'),
      e: Expression.string('#$str'),
    });
    // fetch data from dwh
    await fetchExpressionStore(dwhFetch, store);
    // now the promises from the expressionstore can be awaited
    console.log(await first); // { a: 'str', b: 7 }
    console.log(await second); // { c: 'str', d: 7, e: 'str' }