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

LiveDocument

v0.0.1

Published

A Realtime Isomorphic ODM for MongoDB

Downloads

2

Readme

LiveDocument v0.0.0

LiveDocument is an client/server isopmorphic ODM. The goal of LiveDocument is to provide a seamless way to interact with a mongodb database on the client, without duplication of effort writing both a client side and a server side models.

LiveDocument also provides real-time updates out of the box. After you query something from the database, LiveDocument notifies you of any documents that are created, updated, or deleted and match your criteria. If you ask for a single document, any changes made to that document will automatically be pushed to you.

Table of Contents

Examples

Here is a random assortment of code in coffeescript:

class Task extends LiveDocument
  @key "title", { length: [3...24] }
  @key "description", { max: 140 }

task = new Task({title: "Work that needs to be done", description: "This is some important work", priority:10})
task.save()

# or 

Task.create({title: "Clean carpet", description: "Clean the carpets, they're gross", priority: 4})

task = Task.findOne({title: "This is my title"})

task.on "load", (tasks) ->
  console.log(task.get("priority")) # 10

task.on "update", (task) ->
  #called when someone updates this task

task.on "delete", (task) ->
  #called when someone deletes this task

#this runs any time priority changes
task.get "priority" (val) ->
  console.log(val) # 10

task.get "priority" (key, val) ->
  console.log(key) # priority
  console.log(val) # 10
# this binds tasks get to views set binding
task.get "priority", view.set
# this binds all properties
task.get view.set

task.set "key", value
task.set {key: value, key2: val2}

# mongodb style queries, if it"s supported by mongo, we should support it (not
# true atm!)

tasks = Task.find({priority: {$lt: 10}})

tasks.on "load", (tasks) ->
  # called when the tasks have been loaded from the datasource

tasks.on "insert", (tasks) ->
  # called when a document is created that matches the criteria
  # or an existing document is updated in such a way that it
  # now matches the criteria

tasks.on "remove", (tasks) ->
  # called when a document is deleted that matches the criteria
  # or an document is updated in such a way that it no longer
  # matches the criteria

Motivation

API

You can find the API here: xcoderzach.github.com/liveDocument

Experimental API (Warning, these method probably DON'T EXIST OR WORK

.allowScope()

Since we don't want a malicious user to be able to query every post on our social network. Which would essentially be a DoS attack, since it would grab EVERY post and authorize them ALL. That's where allowScope comes in handy.

The allowScope method won't allow any queries which don't have they keys defined in allowScope.

class Post extends LiveDocument
  @requireScope = true
  @allowScope { ownerId: } 

Tests

To run the tests you need an instance of mongo running on the default port. Then just run the following.

mocha test/*.coffee

Validation

Model validation happens on both the client and the server when possible. Input is validated on the client first if possible, to provide a responsive user experience. The model is then validated again on the server, in order to catch people bypassing client side validation, as well as doing validations that can only happen on the server, such as checking if an email address is taken.

####Error Messages

Validations do not give you error messages. They do not allow you to set error messages. Error messages belong in the view.

All of the declarative LiveDocument class methods, return this, allowing you to chain them together.

Contributing

Ideas, feature requests, bug reports, etc are very welcome.

####TODO Before it's releaseable

  • make it able to run by itself, as a connect middleware
  • has many associations should be embedded documents or normal assocs
  • get rid of coffeescript tests
  • documentation

Contributors

  • Zach Smith @xcoderzach
  • Eugene Butler @EButlerIV
  • Chad Seibert @omegakoder

License

Licensed under MIT (see LICENSE file)