1.3.0 • Published 4 years ago

denormalized-invariants v1.3.0

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

Maintain invariants

The goal of this module is to help maintain invariants in a set of databases. This is typically used to enforce business rules inside a database or between databases.

Specifically it is targeted at CouchDB.

{invariant,DenormalizedDB} = require 'denormalized-invariants'

class Business
  @Subscription: ({type}) -> type is 'subscription'

  constructor: (db_uri) ->
    @db = new DenormalizedDB db_uri

    invariant 'A subscription document should have a panel link', @db, (S) =>
      S
      .filter Business.Subscription
      .map (doc) =>
        url = "#{panel}/s/#{doc.s}"

        return if doc.panel?.url is url
        doc.panel ?= {}
        doc.panel.url = url
        await @db.put doc
        return

    invariant.start()
    return

These are called invariants because the goal of the operative part of the invariant is to attempt to maintain its textual description.

1.3.0

4 years ago

1.2.0

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago