Skip to content

Apply a series of promise-returning transform functions on an object stream

License

Notifications You must be signed in to change notification settings

stream-utils/streaming-object-transform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

streaming-object-transform

NPM version Build status Test coverage Dependency Status License Downloads

Apply a series of promise-returning transform functions on an object stream.

const transform = require('streaming-object-transform')([
  obj => {
    // sort object alphabetically
    return require('deep-object-sort')(obj)
  },
  async => {
    // asynchronously populate the user
    if (obj.user_id) obj.user = await Users.getById(obj.user_id)
    return obj
  }
])

app.use((req, res, next) => {
  res.setHeader('Content-Type', 'application/json')
  db.query({})
    .stream()
    .on('error', next)
    .pipe(transform())
    .on('error', next)
    .pipe(require('JSONStream').stringify())
    .on('error', next)
    .pipe(res)
})

About

Apply a series of promise-returning transform functions on an object stream

Resources

License

Stars

Watchers

Forks

Packages

No packages published