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.
Here is a random assortment of code in coffeescript:
@key "title" length: 3...24@key "description" max: 140task = title: "Work that needs to be done"description: "This is some important work"priority:10tasksave# orTaskcreatetitle: "Clean carpet"description: "Clean the carpets, they're gross"priority: 4task = TaskfindOnetitle: "This is my title"taskon "load"consolelogtaskget"priority" # 10taskon "update"#called when someone updates this tasktaskon "delete"#called when someone deletes this task#this runs any time priority changestaskget "priority"consolelogval # 10taskget "priority"consolelogkey # priorityconsolelogval # 10# this binds tasks get to views set bindingtaskget "priority"viewset# this binds all propertiestaskget viewsettaskset "key"valuetaskset key: valuekey2: val2# mongodb style queries, if it"s supported by mongo, we should support it (not# true atm!)tasks = Taskfindpriority: $lt: 10taskson "load"# called when the tasks have been loaded from the datasourcetaskson "insert"# 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 criteriataskson "remove"# 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
You can find the API here: xcoderzach.github.com/liveDocument
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.
@requireScope = true@allowScope ownerId:
To run the tests you need an instance of mongo running on the default port. Then just run the following.
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.
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.
Ideas, feature requests, bug reports, etc are very welcome.
- 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
- Zach Smith @xcoderzach
- Eugene Butler @EButlerIV
- Chad Seibert @omegakoder
Licensed under MIT (see LICENSE file)