How to use data-point - 4 common examples

To help you get started, we’ve selected a few data-point examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ViacomInc / data-point / packages / data-point / examples / middleware-exit-chain.js View on Github external
dp.use("before", (acc, next) => {
  console.log("Entity model:MyModel is being called");
  next();
});

dp.use("before", (acc, next) => {
  console.log("hijacking");
  next(null, "hijacked");
});

dp.use("before", (acc, next) => {
  console.log("never got here");
  next();
});

const MyModel = DataPoint.Model("MyModel", {
  value: () => {
    // this will not be executed because the entity was hijacked
    console.log("processing");
    return "hello";
  }
});

dp.resolve(MyModel, true)
  // console output:
  // Entity model:MyModel is being called
  // hijacking
  .then(value => {
    assert.strictEqual(value, "hijacked");
  });
github ViacomInc / data-point / packages / data-point / examples / middleware-exit-chain.js View on Github external
/* eslint-disable no-console */
const assert = require("assert");
// eslint-disable-next-line import/no-extraneous-dependencies
const DataPoint = require("data-point");

const dp = DataPoint.create();

dp.use("before", (acc, next) => {
  console.log("Entity model:MyModel is being called");
  next();
});

dp.use("before", (acc, next) => {
  console.log("hijacking");
  next(null, "hijacked");
});

dp.use("before", (acc, next) => {
  console.log("never got here");
  next();
});
github ViacomInc / data-point / packages / data-point / examples / trace.js View on Github external
const PersonRequest = Request("PersonRequest", {
  url: "https://swapi.co/api/people/{value}/"
});

const PersonModel = Model("PersonModel", {
  value: {
    name: "$name",
    birthYear: "$birth_year"
  }
});

const options = {
  trace: false // <-- set to true to enable tracing, a file will be created
};

const dataPoint = DataPoint.create();

dataPoint.transform([PersonRequest, PersonModel], 1, options).then(() => {
  /*
    a file with the name data-point-trace-.json will
    be created.

    File follows the structure of:

    {
      "id": "1",
      "reducer": {
        "type": "ReducerList",
        "reducers": [...]
      },
      "hrtime": [
        405103,
github ViacomInc / data-point / packages / data-point-service / examples / express-cache-stale-while-revalidate-registered-entity.js View on Github external
const express = require("express");
const DataPoint = require("data-point");
const DataPointService = require("../lib");

const Model = DataPoint.Model("HelloWorld", {
  value: (input, acc) => {
    const person = acc.locals.query.person;
    if (!person) {
      throw new Error(
        'Url query parameter "person" is missing. Try appending ?person=Darek at the end of the URL'
      );
    }
    return `Hello ${person}!!`;
  },
  params: {
    cache: {
      ttl: "30s",
      staleWhileRevalidate: "3m"
    }
  }
});

data-point

Data Processing and Transformation Utility

Apache-2.0
Latest version published 5 years ago

Package Health Score

56 / 100
Full package analysis

Popular data-point functions