0.0.0 • Published 6 years ago

hashbag v0.0.0

Weekly downloads
4
License
-
Repository
github
Last release
6 years ago

hashbag

Specialized Callbags validated through schemas and hashes.

Install

npm i hashbag

Usage

A hashbag is a Callbag + a JSON Schema.

Observables are paired with the JSON schemas:

fromHashbag({
  source: Callbag,
  schema: JSONSchema
})

This gives you a callbag producing:

{
  found: Date,
  source: SHA256,
  data: *
}

Callbag sinks that are made for these objects (a.k.a. Hashbag sinks) can identify the structures of data using these hashes, and whether or not it's something it should handle.

  • Know the data follows the schema represented by the hash. Safely access properties, assume types and values, and recreate schemas for whatever reason.
  • Catalog functions by the hashes they handle. This goes across framework, storage, and language bariers.
  • Simply validate data against a schema.

fromHashbag(hashbag, validate)

Create a Callbag observable from { source, schema }, where source is the Callbag producing the data, and schema is a JSON Schema used for establishing a hash of the structure and optionally validing.

const { pipe, forEach } = require('callbag-basics')
const { fromHashbag } = require('hashbag')
const { clientStream, clientSchema } = require('./my-client')

pipe(
  fromHasbag({
    schema: clientSchema,
    source: clientStream('john doe', 'hunter2')
  }),
  forEach(record => {
    if (record.source !== '...some SHA256 hash...') return r
    console.log(record.data.title)
  })
)

See callbag-basics .merge for a way to merge the output of observables. Also callbag-couchdb for a simple way to save the output.