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

extract-source-cases-migration

v1.3.1

Published

Extract inlined source case information into dedicated person documents.

Downloads

8

Readme

extract-source-cases-migration

Extract inlined source case information into dedicated person documents.

Build Status

Usage

CLI

npm install -g extract-source-cases-migration
extract-source-cases http://localhost:5984/persons

Extracted source cases will be aggregated by default. Disable it with the --allow-duplicates alias -A option:

extract-source-cases -A http://localhost:5984/persons

Node

var migrate = require('extract-source-cases-migration')

var contact =
  { _id: '00ae40fe-7b6f-4cea-df66-e00b59713944'
  , _rev: '8-3a99b57d89647c15056dfb6a0ae9eb77'
  , doc_type: 'person'
  , version: '0.0.0'
  , contact:
    { sourceCases:
      [
        { id: 'qz0255'
        , name: 'John aka J. Doe'
        , lastContactDate: '2012-03-29T12:22:41.761Z'
        , phone: '01123 2345678'
        , exposures: [ 'objects' ]
        , relative:
          { name: ''
          , phone: '0112 334455'
          }
        }
      ]
    }
  }

var docs = migrate(contact)

This will produce the following data structure for docs:

[
  // first doc is the updated contact

  { _id: '00ae40fe-7b6f-4cea-df66-e00b59713944'
  , _rev: '8-3a99b57d89647c15056dfb6a0ae9eb77'
  , doc_type: 'person'
  , version: '1.16.0'
  , contact:
    { sourceCases:
      [
        { personId: 'fdbe63ec2cf62e484922c6f4203b5695'
        , lastContactDate: '2012-03-29T12:22:41.761Z'
        , exposures: [ 'objects' ]
        }
      ]
    }
  , changeLog:
    [
      { user: 'extract-source-cases-migration'
      , timestamp: 1422613414251
      , rev: '8-3a99b57d89647c15056dfb6a0ae9eb77'
      }
    ]
  }
,
  // remaining docs are the extracted cases

  { _id: 'fdbe63ec2cf62e484922c6f4203b5695'
  , doc_type: 'person'
  , version: '1.16.0'
  , createdDate: '2015-03-11T10:45:14.715Z' // now
  , surname: 'Doe'
  , otherNames: 'John aka J.'
  , phoneNumber: '01123 2345678'
  , relative:
    { name: ''
    , phone: '0112 334455'
    }
  , case:
    { id: 'qz0255'
    , status: 'unknown'
    }
  , sources:
    [
      { type: 'migration'
      , name: 'extract-source-cases-migration'
      , origin: '00ae40fe-7b6f-4cea-df66-e00b59713944/contact/source-cases/0'
      , timestamp: 1422613414251
      }
    ]
  }
]

Passing an aggregator object to each function call will create and reference a single doc for inline source cases that have matching id and name.

var docs = []
  , aggregator = {}

docs.concat(migrate(contact1, aggregator))
docs.concat(migrate(contact2, aggregator))

Testing

Run the tests with

npm test

TODO

  • extract and merge cases without id and matching(?) name