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

xform-uploader

v1.0.0

Published

Parse an xform and attachments and upload to an odk-aggregate server or osm-p2p + hyperdrive.

Downloads

12

Readme

xform-uploader

Parse a set of XForms and attachments, and upload them to an odk-aggregate server or osm-p2p + hyperdrive.

Example

var uploader = new Uploader()

uploader.add([
  xmlFile1,
  attachment1,
  attachment2,
  xmlFile2,
  attachment4,
  attachment5
], function (err) {
  console.log(uploader.state())
})

// output:
{
  forms: [
    {
      data: parsedFormAsGeoJSON,
      uploaded: 0 // 0-1 progress uploaded, 1 === upload complete
      attachments: [
        {
          filename: 'originalFilename.jpg',
          mediaId: '1231421531.jpg', // not set on attachments until after upload
          blob: attachment1,
          uploaded: 1
        }, {
          filename: 'originalFilename2.jpg',
          mediaId: null,
          blob: attachment2,
          uploaded: 0
        }
      ]
    }
  ],
  missingAttachments: [
    // A form references this media, but the media itself has not been provided.
    'originalFilename3.jpg'
  ],
  orphanAttachments: [
    // This media was provided, but no form references it.
    'otherFilename.png'
  ]
}

// fires every time the internal state changes
uploader.on('change', function () { console.log(uploader.state()) })

uploader.upload({
  observationUpload: 'http://localhost:4001/obs/create',
  mediaUpload: 'http://localhost:4002/media/jpg'
})

API

var Uploader = require('xform-uploader')
var uploader = new Uploader()

uploader.add(files, done)

Add an array of Files to the uploader. Once complete, the callback done will be called with the form function (err).

uploader.state()

Synchronously return the instantaneous state of the Uploader as an object. It will have the following structure:

{
  forms: [
    {
      data: parsedFormAsGeoJSON,
      uploaded: 0 // 0-1 progress uploaded, 1 === upload complete
      attachments: [
        {
          filename: 'originalFilename.jpg',
          mediaId: '1231421531', // or 'null' until uploaded
          blob: attachment1,
          uploaded: 1
        }, {
          filename: 'originalFilename2.jpg',
          mediaId: null,
          blob: attachment2,
          uploaded: 0
        }
      ]
    }
  ],
  missingAttachments: [
    // A form references this media, but the media itself has not been provided.
    'originalFilename3.jpg'
  ],
  orphanAttachments: [
    // This media was provided, but no form references it.
    'otherFilename.png'
  ]
}

uploader.on('change', function () { ... })

This event is emitted whenever the public-facing state of the Uploader has changed.

uploader.upload(servers, done)

Upload the forms and their attachments to various servers.

servers is an object. Currently the following keys are accepted:

  • observationsUrl: an HTTP URL of a POST endpoint to receive the osm observation data that each form represents.
  • mediaUrl: an HTTP URL of a POST endpoint to receive the media data that each attachment represents.

Inner Modules

This module contains two inner modules: FormSet and XFormSet, which are more general purpose and may useful outside of the context of the outer module, which is just a small amount of glue code.

License

ISC