Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@e2fyi/streams

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@e2fyi/streams

Nodejs stream library for various use cases: e.g. Auto-tagging object streams, streaming to mongoDb via mongoose models, etc.

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@e2fyi/streams

GitHub release Build Status Coverage Status Known Vulnerabilities styled with prettier

This NodeJS library provides custom NodeJS streams for specific use cases.

Currently, the following streams are available:

ChangeLog

  • v1.0.0: new streams: DocumentTagger, MongooseStream.

Quick start

Using CommonJS module

// importing DocumentTagger and MongooseStream
const {DocumentTagger, MongooseStream} = require('@e2fyi/streams');

API reference

The API documentation is also available at https://e2fyi.github.io/streams.

@e2fyi/streams

@e2fyi/streams.DocumentTagger ⇐ stream.Transform

Transform Object stream (objectMode=true) to tag with an autoIncrement id. An object or function can be optionally provided to mutate each object in the stream.

Kind: static class of @e2fyi/streams
Extends: stream.Transform
Emits: filtered

new DocumentTagger(opts)

Create a new DocumentTagger stream.

ParamTypeDescription
optsDocumentTaggerSettingsSettings for the stream.

Example

const docTagger = new DocumentTagger({autoIncrement: 'id', mutate: { project: 'test' }});
someReadableStreamFromArray([{text: 'abc'}, {text: 'efg'}])
  .pipe(docTagger)
  .pipe(process.stdout);
// stdout >
// {"text": "abc", "id": 0, "project": "test"}
// {"text": "efg", "id": 1, "project": "test"}

@e2fyi/streams.MongooseStream ⇐ stream.Transform

A custom NodeJS Transform stream to mongo via mongoose.

Kind: static class of @e2fyi/streams
Extends: stream.Transform
Emits: mongoose-bulk-write

new MongooseStream(opts)

Create a Transform stream which bulkWrite to mongo based on the itemWaterMark. model (mongoose Model) is a required field.

ParamTypeDescription
optsMongooseStreamSettingsConfiguration for MongoStream. Default value for itemWaterMark is 50.

Example

var stream2mongo = new MongooseStream({mode: SomeMongooseModel});
someReadableStreamFromArray([{text: 'abc'}, {text: 'efg'}])
  .pipe(stream2mongo) // writes to mongo (while stream are also passthrough)
  .pipe(response); // stream same results back to some request

@e2fyi/streams.DocumentTaggerSettings : Object

Settings for DocumentTagger.

Kind: static typedef of @e2fyi/streams
Properties

NameTypeDescription
autoIncrementStringThe auto-increment field to tag onto the stream object.
ignoreNonObjectBooleanIf true, no errors will be emitted when the chunk in the stream cannot be parsed into Object.
readableObjectModeBooleanIf true, Object will be emitted from the stream, otherwise a String or Buffer representation or will emitted instead.
objectModeBooleanIf true, Object will be emitted from the stream, otherwise a String or Buffer representation or will emitted instead. Overwrites writableObjectMode.
filterfunctionFunction to filter the objects in the stream. Return true to keep the object.
mutatefunction | ObjectFunction or Object to mutate the stream. If an Object is provided, each stream object will be mutated with the Object.assign(streamObj, mutateObj).

@e2fyi/streams.MongooseStreamSettings : Object

Settings for MongooseStream.

Kind: static typedef of @e2fyi/streams
Properties

NameTypeDefaultDescription
itemWaterMarkNumber50The number of item collected before writing to mongodb.
passThroughBooleanIf false nothing will be emitted from the stream.
modelmongoose.Modelmongoose Model.

Development

Unit testing

npm test

Build documentation

npm run build

Keywords

FAQs

Package last updated on 14 Dec 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc