Code Monkey home page Code Monkey logo

pipeline-xml-processing-js-redis's Introduction

XML Processing in JS with REDIS

This project shows an example pipeline for processing, transformation, and storage of XML datasets.

Stack:

  1. Docker
  2. REDIS Database for data storage
  3. NodeJS + Pure JS
  4. xml2js

Software design

Configuring XML key extraction and transformation

src/index.js#EXPORT_CONFIG defines a transformation configuration for keys in an XML dataset. The type is: {[xmlKeyName: string]: (data: any) => any}.

const EXPORT_CONFIG = {
  'subdomains': (data) => {
    return [['subdomains', data.flatMap(s => s.subdomain)]]
  },
  'cookies': (data) => {
    return data.flatMap(s => s.cookie).map(cookie => {
      const {name, host} = cookie['$']
      const val = cookie["_"]
      const key = `cookie:${name}:${host}`
      return [key, val]
    })
  }
}

Database access during test, dev, and prod

src/database.js defines DB_Prod and DB_Debug classes that share the same interface IDatabase. DB_Prod accesses a local REDIS database. DB_Debug access an in-memory database.

Switching between dev & prod DB environments is handled automatically by setting the NODE_ENV environment variable. This allows the project to be quickly deployed in test, dev, or prod environments.

Unit testable functions

Functions in this project can be easily unit tested because most complex dependencies are given as arguments. Example: To test the src/index.js#exportToRedis function a developer can pass an object matches the IDatabase interface instead of mocking the DB module using jest.mock.

pipeline-xml-processing-js-redis's People

Contributors

mk5med avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.