1.7.0 • Published 1 year ago

dwh-fetch v1.7.0

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

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' }
1.7.0

1 year ago

1.6.0

1 year ago

1.5.3

2 years ago

1.5.2

2 years ago

1.5.1

2 years ago

1.4.2

2 years ago

1.5.0

2 years ago

1.4.1

2 years ago

1.4.0

3 years ago

1.3.6

3 years ago

1.3.4

3 years ago

1.3.3

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.9

3 years ago

1.2.8

3 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.0

3 years ago

1.1.9

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.2.4

3 years ago

1.1.5

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.1.3

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.1.2

3 years ago

1.0.0

4 years ago