Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated to reference new docs

  • Loading branch information...
commit 9b85cd84459ffaa4d56bf34e045dc496275cc9a9 1 parent 033dee7
Dallon Feldner dallonf authored
2  bin/createtemplate/public/index.html
View
@@ -7,6 +7,6 @@
<body>
<h1>Welcome to Deployd!</h1>
<p>You've just created a Deployd app. You can add front-end files in the <code>public</code> folder.</p>
- <p>If you're new to Deployd, have a look at the <a href="http://deployd.com/docs">Getting Started Guide</a> or <a href="http://deployd.com/docs/tutorials/hello-world.html">Hello World Tutorial<a>.</p>
+ <p>If you're new to Deployd, have a look at the <a href="http://docs.deployd.com/docs/getting-started/what-is-deployd.md">Getting Started Guide</a> or <a href="http://docs.deployd.com/docs/getting-started/your-first-api.md">Hello World Tutorial<a>.</p>
</body>
</html>
11 docs/about.md
View
@@ -1,11 +0,0 @@
-# About Deployd
-
-We call Deployd a **resource server**. A resource server is not a library, but a complete server that works out of the box, and can be customized to fit the needs of your app by adding resources. Resources are ready-made components that live at a URL and provide functionality to your client app.
-
-An example of a resource is a data collection. You only have to define the properties and types of objects, and the server will validate the data. You will also be able to create your own custom resources and install custom resources from other developers. (we're built on Node.js, so custom resources will take the form of node modules).
-
-## Install
-
- - [Download](http://www.deployd.com/download.html) the OSX installer (13.8mb).
- - [Download](http://www.deployd.com/download.html) the Windows installer (13.8mb).
-
75 docs/deploy.md
View
@@ -1,75 +0,0 @@
-# Deploying Your App
-
-When you want to share your app with the world, you can use Deployd's beta hosting service to host it online in seconds.
-
-*Note: this service is heavily in development and will change drastically in the future*
-
-In your Deployd app folder, type the command:
-
- dpd deploy [subdomain]
-
-If you do not provide a subdomain, it will automatically use the app's folder name.
-
-*Note: if you recieve a "not allowed" error, it means that the subdomain you requested is in use by another app and you don't have the credentials to push to it. In that case, you choose another subdomain.*
-
-When it is done, you can access your app at `[subdomain].deploydapp.com`.
-
-## Accessing Your App's Dashboard
-
-To access your app's dashboard (for example, to add data), you can go to `[subdomain].deploydapp.com/dashboard` or type `dpd remote`. The Dashboard will prompt you for a key, type `dpd showkey` to print this key to the console and paste it into the box.
-
-## Working with collaborators
-
-To provide additional collaborators access to push new versions and access the dashboard, you can copy the `deployments.json` and `keys.json` files out of your app's `.dpd` directory and give them to your collaborators. Your collaborators can then paste these files in their own `.dpd` directory and use the `deploy`, `remote`, and `showkey` commands.
-
-# On your own server
-
-You can also deploy your app on your server, or on a cloud hosting service such as EC2 or Heroku. The server must support [Node.js](http://nodejs.org/).
-
-Deployd also requires a [MongoDB](http://www.mongodb.org/) database, which can be hosted on the same server or externally.
-
-If you have root shell access on the deployment server, you can install Deployd on it using the command `npm install -g deployd`.
-Otherwise, you will need to install Deployd as a dependency of your app itself using `npm install deployd` in the root directory of your app.
-
-You can use the `dpd` CLI to run your server; this will start up an instance of MongoDB automatically, using the "data" folder. (Requires MongoDB installed on the server)
-
-## Dashboard Accesss
-To set up the dashboard on your server, type `dpd keygen` on your server's command line to create a remote access key. Type `dpd showkey` to get the key; you should store this somewhere secure.
-
-You can then go to the `/dashboard` route on the server and type in that key to gain access.
-
-## Server Script
-
-For more control, you can create a simple script to run the server. Here's an example:
-
- // index.js
- var deployd = require('deployd');
-
- var server = deployd({
- port: process.env.PORT || 5000,
- env: 'production',
- db: {
- host: 'my.mongo.host',
- port: 27105,
- name: 'my-db',
- credentials: {
- username: 'username',
- password: 'password'
- }
- }
- });
-
- server.listen();
-
- server.on('listening', function() {
- console.log("Server is listening");
- });
-
- server.on('error', function(err) {
- console.error(err);
- process.nextTick(function() { // Give the server a chance to return an error
- process.exit();
- });
- });
-
-*Note:* Some hosts do not support WebSockets, so `dpd.on()` may not work correctly on certain deployments.
32 docs/examples.md
View
@@ -1,32 +0,0 @@
-# Example Apps
-
-These demo apps are just a taste of what you can do with Deployd. Browse their source code to see how they work.
-
-## Poll Demo
-
-![Poll Demo](http://deployd.com/img/examples/poll.png)
-
-A simple survey app. You can vote in it and change your response, and other users will see the bar graph update immediately. Download the source to see how to aggregate data in real time.
-
-<a class="btn btn-primary" target="_blank" href="http://poll2.deploydapp.com"><i class="icon-white icon-eye-open"></i> View Online</a>
-<a class="btn btn-primary" target="_blank" href="/downloads/examples/poll.zip"><i class="icon-white icon-download"></i> Download Source</a>
-
-## Users Demo
-
-![Users Demo](http://deployd.com/img/examples/users.png)
-
-A simple messaging app. Register, login in, and post messages for other users to see. Download the source to see how to simply add user authentication to your app.
-
-<a class="btn btn-primary" target="_blank" href="http://users.deploydapp.com/login.html"><i class="icon-white icon-eye-open"></i> View Online</a>
-<a class="btn btn-primary" target="_blank" href="/downloads/examples/users.zip"><i class="icon-white icon-download"></i> Download Source</a>
-
-## Trivia Demo
-
-![Trivia Demo](http://deployd.com/img/examples/trivia.png)
-
-A multiple-choice trivia game. See how much you know about JavaScript, and how much everybody else knows! Download the source to see how to add secure gamification to your app.
-
-*Note: There's only three questions right now! Help us out by posting your favorite JavaScript quirks on the [community page](http://deployd.com/community.html)*
-
-<a class="btn btn-primary" target="_blank" href="http://trivia.deploydapp.com"><i class="icon-white icon-eye-open"></i> View Online</a>
-<a class="btn btn-primary" target="_blank" href="/downloads/examples/trivia.zip"><i class="icon-white icon-download"></i> Download Source</a>
91 docs/index.md
View
@@ -1,91 +0,0 @@
-# Deployd Guide
-
-Deployd is a new way of building data-driven backends for web apps. Ready-made, configurable *Resources* add common functionality to a Deployd backend, which can be further customized with JavaScript *Events*.
-
-# Getting Started
-
-Create an app by running:
-
- $ dpd create hello
- $ cd hello
- $ dpd
- dpd>
-
-The `dpd>` you see after starting Deployd is a REPL for interacting with the server as it's running.
-
-You will probably use the following commands frequently:
-
-- `open` - Opens your app (`http://localhost:2403` by default) in your default browser
-- `dashboard` - Opens your app's Deployd dashboard (`http://localhost:2403/dashboard` by default) in your default browser
-
-To open your app or dashboard immediately after creating an app, put a `--open`/`-o` or `--dashboard`/`-d` flag on `dpd create`:
-
- dpd create hello -d
- dpd>
-
-# dpd Command
-
-The `dpd` command line tool has some options that you can specify when you run it:
-
-- `dpd -p [port]` - Runs the Deployd server on a specific port. Default is `2403`.
-- `dpd -d` - Runs the Deployd server and immediately runs the `dashboard` command
-- `dpd -o` - Runs the Deployd server and immediately runs the `open` command
-- `dpd -V` - Outputs the current version of the Deployd server.
-- `dpd -h` - Lists the available options in more detail
-
-If you used the Mac or Windows installer, double-clicking on an `app.dpd` file will have the same effect as `dpd -d` - it will start your app and open the dashboard.
-
-# Dashboard
-
-The dashboard is a simple UI that you'll use to create and manage your Deployd backend. You can get to the dashboard by opening `/dashboard` (eg. `http://localhost:2403/dashboard`) in a browser.
-
-The sidebar of the Dashboard lists the Resources that you have in your app. A resource is a feature that you can add to your app's backend.
-
-![Dashboard](/img/docs/dashboard.png)
-
-## Managing Resources
-
-Click on the "+" button on the sidebar to add a resource.
-
-The following resource types are available:
-
-- [Collection](/docs/resources/collection.html)
-- [User Collection](/docs/resources/user-collection.html)
-
-From the main view of the dashboard, you can delete and rename resources by clicking on the arrow next to it.'
-
-![Dashboard](/img/docs/dashboard-detail.png)
-
-# Files
-
-Deployd serves static files from its `public` folder. This folder is created when you run `dpd create`. These files will be served with the appropriate cache headers (`Last-Modified` and `Etag`) so browsers will cache them.
-
-Deployd will automatically serve an `index.html` file as the default file in a directory.
-
-# Dpd.js
-
-The Deployd client library (`dpd.js`) can optionally be included in your web app to simplify backend requests. Include it with this script tag in your `<head>` or `<body>`:
-
- <script type="text/javascript" src="/dpd.js" />
-
-This will include a `dpd` object that can be used to make HTTP requests:
-
- dpd.mycollection.post({some: 'value'}, function(result, error) {
- //Makes a POST request to /my-collection
- });
-
- dpd.mycollection.get({some: 'query'}, function(result, error) {
- //Makes a GET request to /my-collection?some=query
- });
-
-See the [Dpd.js Reference](/docs/reference/dpdjs.html) for more details.
-
-# More Information
-
-- [Community discussion](/community.html)
-- [Github project](https://github.com/deployd/deployd)
-- [Issue tracker](https://github.com/deployd/deployd/issues)
-- [Deployd blog](http://deployd.tumblr.com/)
-- [@deploydapp](https://twitter.com/#!/deploydapp)
-
-
89 docs/module-api/collection.md
View
@@ -1,89 +0,0 @@
-# Collection
-
-Collections provide a proxy between http and a `Store`. They validate incoming requests, execute event scripts for `get`, `post`, `put`, `delete`, and `validate`. If all event scripts execute without error (or `cancel()`ing) the request is proxied to the collection's `Store`.
-
-## Class: Collection
-
-A `Collection` inherits from `Resource`. Any constructor that inherits from `Collection` must include its own `Collection.external` prototype object.
-
-Example inheriting from `Collection`:
-
- var Collection = require('deployd/lib/resources/collection');
- var util = require('util');
-
- function MyCollection(name, options) {
- Collection.apply(this, arguments);
- }
- MyCollection.external = Collection.external;
-
- util.inherits(MyCollection, Collection);
-
-## collection.store
-
-* {Store}
-
-The backing persistence abstraction layer. Supports saving and reading data from a database. See `Store` for more info (/lib/db.js).
-
-## collection.validate(body, create)
-
-Validate the request `body` against the `Collection` `properties`
-and return an object containing any `errors`.
-
-* body {Object}
-
-The object to validate
-
-* create {Boolean}
-
-Should validate a new object being created
-
-* return errors {Object}
-
-## collection.sanitize(body)
-
-Sanitize the request `body` against the `collection.properties`
-and return an object containing only properties that exist in the
-`collection.config.properties` object.
-
-* body {Object}
-* return sanitized {Object}
-
-## collection.sanitizeQuery(query)
-
-Sanitize the request `query` against the `collection.properties`
-and return an object containing only properties that exist in the
-`collection.properties` object.
-
-* query {Object}
-* return sanitizedQuery {Object}
-
-## collection.parseId(ctx)
-
-Parse the `ctx.url` for an id. Override this change how an object's id is parsed out of a url.
-
-* ctx {Context}
-
-## collection.find(ctx, fn)
-
-Find all the objects in a collection that match the given `ctx.query`. Then execute a `get` event script, if one exists, using each object found. Finally call `fn(err)` passing an `error` if one occurred.
-
-* ctx {Context}
-* fn(err)
-
-## collection.remove(ctx, fn)
-
-Execute a `delete` event script, if one exists, using each object found. Then remove a single object that matches the `ctx.query.id`. Finally call `fn(err)` passing an `error` if one occurred.
-
-* ctx {Context}
-* fn(err)
-
-## collection.save(ctx, fn)
-
-First execute a `validate` event script if one exists. If the event does not error, try to save the `ctx.body` into the store. If `ctx.body.id` exists, perform an `update` and execute the `put` event script. Otherwise perform an `insert` and execute the `post` event script. Finally call `fn(err)` passing an `error` if one occurred.
-
-* ctx {Context}
-* fn(err)
-
-
-
-
46 docs/module-api/context.md
View
@@ -1,46 +0,0 @@
-# Context
-
-Contexts are a thin abstraction between http requests, `Resource`s, and `Script`s. They provide utility methods to simplify interacting with node's [http.ServerRequest](http://nodejs.org/api/http.html#http_class_http_serverrequest) and [http.ServerResponse](http://nodejs.org/api/http.html#http_class_http_serverresponse) objects.
-
-A `Context` is built from a request and response and passed to a matching `Resource` by the `Router`. This might originate from an external http request or a call to an **internal client** from a `Script`.
-
-## Mock Contexts
-
-Contexts may be created without a real request and response such as during an internal request using the `dpd` object. See: `internalClient` for more info.
-
-## Class: Context
-
- var Context = require('deployd/lib/context');
- var ctx = new Context(resource, req, res, server);
-
-### ctx.done(err, result)
-
-Continuous callback sugar for easily calling `res.end()`. Conforms to the idiomatic callback signature for most node APIs. It can be passed directly to most APIs that require a callback in node.
-
- fs.readFile('bar.txt', ctx.done);
-
-* `err` {Error | Object}
-
-An error if one occured during handling of the `ctx`. Otherwise it should be `null`.
-
-* `result` {Object}
-
-The result of executing the `ctx`. This should be a `typeof` object and serialize-able as JSON.
-
-### ctx.body
-
-* {Object}
-
-The body of the request if sent as `application/json` or `application/x-www-form-urlencoded`.
-
-### ctx.query
-
-* {Object}
-
-The query string of the request serialized as an `Object`. Supports both `?key=value` as well as `?{"key":"value"}`.
-
-### ctx.method
-
-* {Object}
-
-An alias to the request's method.
0  docs/module-api/db.md
View
No changes.
74 docs/module-api/internal-client.md
View
@@ -1,74 +0,0 @@
-# Internal Client
-
-The `internal-client` module is responsible for building a server-side version of **dpd.js**. It is intended for use in `Script`s but can be used by resources to access other resources' REST APIs.
-
-*Note: As in dpd.js, the callback for an internal client request recieves the arguments `(data, err)`, which is different than the Node convention of `(err, data)`. This is for a better experience in writings `Script`s and events.*
-
-## internalClient.build(server, [session], [stack])
-
- var internalClient = require('deployd/lib/internal-client');
- var dpd = internalClient.build(server);
-
- dpd.todos.get(function(data, err) {
- // Do something...
- });
-
-* `server` {Server}
-
-The Deployd server to build a client for.
-
-* `session` {Session} *(optional)*
-
-The `Session` object on the current request.
-
-* `stack` {Array} *(optional)*
-
-Used internally to prevent recursive calls to resources.
-
-## Mock context
-
-In order to make requests on resources within the Deployd server, `internal-client` creates mock `req` and `res` objects. These objects are not Streams and cannot be treated exactly like the standard `http.ServerRequest` and `http.ServerResponse` objects in Node, but they imitate their interfaces with the following properties:
-
-### req
-
-* `url` {String}
-
-The URL of the request, i.e. "/hello"
-
-* `method` {String}
-
-The method of the request, i.e. "GET", "POST"
-
-* `query` {Object}
-
-The query object.
-
-* `body` {Object}
-
-The body of the request.
-
-* `session` {Session}
-
-The current session, if any.
-
-* `internal` {Boolean}
-
-Always equal to `true` to indicate an internal request and a mock `req` object.
-
-### res
-
-* `statusCode` {Number}
-
-Set this to a standard HTTP response code.
-
-* `setHeader()` {Function}
-
-No-op.
-
-* `end(data)` {Function}
-
-Returns data to the internal client call. If `data` is JSON, it will be parsed into an object, otherwise it will simply be passed as a string. If the `res.statusCode` is not 200 or 204, `data` will be passed as an error.
-
-* `internal` {Boolean}
-
-Always equal to `true` to indicate an internal request and a mock `res` object.
0  docs/module-api/keys.md
View
No changes.
213 docs/module-api/resource.md
View
@@ -1,213 +0,0 @@
-# Resource
-
-Resources provide a way to handle http requests at a root url. They must implement a `handle(ctx, next)` method that either handles a request or calls `next()` to give the request back to the router.
-
-Resources can also be attributed with meta-data to allow the dashboard to dynamically render an editor gui for configuring a resource instance.
-
-## Events / Scripts
-
-A `Resource` can execute `Script`s during the handling of an http request when certain events occur. This allows users of the resource to inject logic during specific events during an http request without having to extend the resource or create their own.
-
-For example, the `Collection` resource executes the *get.js* event script when it retrieves each object from its store. If a *get.js* file exists in the instance folder of a resource (eg. `/my-project/resources/my-collection/get.js`), it will be pulled in by the resource and exposed as `myResource.scripts.get`.
-
-## Class: Resource
-
-A `Resource` inherits from `EventEmitter`. The following events are available.
-
- - `changed` after a resource config has changed
- - `deleted` after a resource config has been deleted
-
-Inheriting from Resource:
-
- var Resource = require('deployd/lib/resource')
- , util = require('util');
-
- function MyResource(name, options) {
- // run the parent constructor
- // before using any properties/methods
- Resource.apply(this, arguments);
- }
- util.inherits(MyResource, Resource);
- module.exports = MyResource;
-
-* `name` {String}
-
-The name of the resource.
-
-* `options` {Object}
-
- - `configPath` the project relative path to the resource instance
- - `path` the base path a resource should handle
- - `db` *(optional)* the database a resource will use for persistence
- - `config` the instance configuration object
- - `server` the server object
-
-The following resource would respond with a file at the url `/my-file.html`.
-
- function MyFileResource(name, options) {
- Resource.apply(this, arguments);
-
- this.on('changed', function(config) {
- console.log('MyFileResource changed', config);
- });
- }
- util.inherits(MyFileResource, Resource);
-
- MyFileResource.prototype.handle = function (ctx, next) {
- if (ctx.url === '/my-file.html') {
- fs.createReadStream('my-file.html').pipe(ctx.res);
- } else {
- next();
- }
- }
-
-## Overriding Behavior
-
-Certain method's on a `Resource` prototype are called by the runtime. Their default behavior should be overriden to define an inherited `Resources` behavior.
-
-## resource.handle(ctx, next)
-
-Handle an incoming request. This gets called by the router.
-Call `next()` if the resource cannot handle the request.
-Otherwise call `cxt.done(err, res)` when the resource
-is ready to respond.
-
-* ctx {Context}
-
-The http context created by the `Router`. This provides an abstraction between the actual request and response. A `Resource` should call `ctx.done` or pipe to `ctx.res` if it can handle a request. Otherwise it should call `next()`.
-
-Override the handle method to return a string:
-
- function MyResource(settings) {
- Resource.apply(this, arguments);
- }
- util.inherits(MyResource, Resource);
-
- MyResource.prototype.handle = function (ctx, next) {
- // respond with the file contents (or an error if one occurs)
- fs.readFile('myfile.txt', ctx.done);
- }
-
-## resource.load(fn)
-
-Load any dependencies and call `fn(err)` with any errors that occur. This is automatically called by the runtime to support asynchronous construction of a resource (such as loading files). If this method is overridden the super method must be called to support loading of the `MyResource.events` array.
-
-## External Prototype
-
-This is a special type of prototype object that is used to build the `dpd` object. Each function on the `Resource.external` prototype `Object` are exposed externally in two places
-
- 1. To the generated `dpd.js` browser JavaScript client
- 2. To the `Context.dpd` object generated for inter-resource calls
-
-Here is an example of a simple resource that exposes a method on the external prototype.
-
-`/my-project/node_modules/example.js`
-
- var util = require('util');
- var Resource = require('deployd/lib/resource');
- function Example(name, options) {
- Resource.apply(this, arguments);
- }
- util.inherits(Example, Resource);
-
- Example.external = {};
-
- Example.external.hello = function(options, ctx, fn) {
- console.log(options.msg); // 'hello world'
- }
-
-When the `hello()` method is called a context does not need to be provided as the `dpd` object is built with a context. A callback may be provided which will be executed with results of `fn(err, result)`.
-
-`/my-project/public/hello.js`
-
- dpd.example.hello({msg: 'hello world'});
-
-`/my-project/resources/other-resource/get.js`
-
- dpd.example.hello({msg: 'hello world'});
-
-## Resource.events
-
-* {Array}
-
-If a `Resource` constructor includes an array of events, it will try to load the scripts in its instance folder (eg. `/my-project/resources/my-resource/get.js`) using `resource.loadScripts(eventNames, fn)`.
-
- MyResource.events = ['get'];
-
-This will be available to each instance of this resource.
-
-`/my-project/node_modules/my-resource.js`
-
- MyResource.prototype.handle = function(ctx, next) {
- if(this.events && this.events.get) {
- var domain = {
- say: function(msg) {
- console.log(msg); // 'hello world'
- }
- }
- this.events.get.run(ctx, domain, ctx.done);
- }
- }
-
-`/my-project/resources/my-resource/get.js`
-
- say('hello world');
-
-## Custom Dashboard
-
-A resource can describe the dependencies of a fully custom dashboard editor ui. This will be passed to the dashboard during rendering to create a custom ui.
-
-This example creates a custom dashboard for the `Collection` resource. It automatically includes pages, and separate scripts.
-
- Collection.dashboard = {
- path: path.join(__dirname, 'dashboard')
- , pages: ['Properties', 'Data', 'Events', 'API']
- , scripts: [
- '/js/ui.js'
- , '/js/util.js'
- ]
- }
-
-* `path` {String}
-
-The absolute path to this resource's dashboard
-
-* `pages` {Array} *(optional)*
-
-An array of pages to appear in the sidebar. If this is not provided, the only page available will be "Config" (and "Events", if `MyResource.events` is set).
-
-The dashboard will load content from `[current-page].html` and `js/[current-page].js`.
-
-*Note: The "Config" page will load from `index.html` and `js/index.js`.*
-
-*Note: `events.html` is optional - if not provided, the dashboard will load a default event editor.*
-
-* `scripts` {Array} *(optional)*
-
-An array of extra JavaScript files to load with the dashboard pages.
-
-## Basic Dashboard
-
-In cases where a custom ui is not practical, a resource can describe the setting to render for a basic dashboard. The following example would render a single textbox.
-
- Proxy.basicDashboard = {
- settings: [{
- name: "remote"
- , type: "text"
- , description: "The remote server to proxy to."
- }]
- }
-
-The `settings` object is an array of objects with these properties:
-
-* `name` {String}
-
-The name of the property in your config object. Make sure this is something easily accessible through JavaScript, i.e. `maxItems` rather than "Maximum Amount of Items".
-
-* `type` {String}
-
-The type of field to render in the dashboard. Supported options are `text`, `textarea`, `number`, and `checkbox`.
-
-* `description` {String}
-
-Text to appear beneath the property in the dashboard.
0  docs/module-api/router.md
View
No changes.
89 docs/module-api/script.md
View
@@ -1,89 +0,0 @@
-# Script
-
-A `Script` provides a mechanism to run JavaScript source in a sandbox. A `Script` is executed with a `Context` and a `domain` object using [the node vm module](http://nodejs.org/api/vm.html). Each `Script` runs independently. They do not share any scope (including global scope), nor do they share state with other scripts.
-
-## Async Mode
-
-Scripts can be run in an **async mode**. This mode is triggered when a `Script` is `run(ctx, domain, fn)` with a callback (`fn`). When run in this mode a `Script` will try scrub all functions in the domain for operations that require a callback. If a callback is required, the function is re-written to count the callbacks completion and notify the script. When all pending callbacks are complete the script is considered finished.
-
-## Async Errors
-
-If a script is run with a callback (in **async mode**), any error will emit an internal `error` event. This will stop the execution of the script and pass the error to the script's callback.
-
-## Class: Script
-
- var Script = require('deployd/lib/script');
- var script = new Script('hello()', 'hello.js');
-
-A `Script`'s source is compiled when its constructor is called. It can be `run()` many times with independent `Context`s and `domain`s.
-
-## script.run(ctx, domain, [fn])
-
-* ctx {Context}
-
-A `Context` with a `session`, `query`, `req` and `res`.
-
-* domain {Object}
-
-An `Object` containing functions to be injected into the `Script`s sandbox. This will override any existing functions or objects in the `Script`s sandbox / global scope.
-
-This example `domain` provides a log function to a script.
-
- var script = new Script('log("hello world")');
- var context = {};
- var domain = {};
- var msg;
-
- domain.log = function(str) {
- console.log(msg = str);
- }
-
- script.run(ctx, domain, function(err) {
- console.log(msg); // 'hello world'
- });
-
-* fn(err) *optional*
-
-If a callback is provided the script will be run in **async mode**. The callback will receive any error even if the error occurs asynchronously. Otherwise it will be called without any arguments when the script is finished executing (see: async mode).
-
- var s = new Script('setTimeout(function() { throw "test err" }, 22)');
-
- // give the script access to setTimeout
- var domain = {setTimeout: setTimeout};
-
- s.run({}, domain, function (e) {
- console.log(e); // test err
- });
-
-## Script.load(path, fn)
-
-* path {String}
-
-* fn(err, script)
-
-Load a new `script` at the given file `path`. Callback with an error if one occured or a new `Script` loaded from the contents of the file.
-
-## Default Domain
-
-Scripts are executed with a default sandbox and set of domain functions. These are functions that every `Script` needs. The following are available to every `Script`. These can be overridden by passing a value such as `{cancel: ...}` in a `domain`.
-
-### cancel(msg, status)
-
-Throws an error that immediately stops the execution of a context and calls the callback passed to `script.run()` passing the error as the first argument.
-
-### emit([collection], [query], event, data)
-
- Stability: will change in 0.7
-
-Emits an `event` to all sessions. Can be passed an optional `UserCollection` and `query` to emit the event to only the users in the collection that match the query.
-
-### Sandbox
-
-The default sandbox or global object in a `Script` comes with several other properties:
-
- - `me` - the current user if one exists on the `Context`
- - `this` - an empty object if not overridden by the `domain`
- - `internal` - a boolean property, true if this request has been initiated by another script
- - `isRoot` - a boolean property, true if this request is authenticated as root (from the dashboard or a custom script)
- - `query` - the current `Context`'s query
- - `console` - support for `console.log()` and other `console` methods
66 docs/module-api/server.md
View
@@ -1,66 +0,0 @@
-# Server
-
-Each deployd instance uses a single server to manage IO as well as tie together resources. Deployd's `Server` extends node's `http.Server`. A `Server` is created with an options object that tells deployd what port to serve on and which database to connect to.
-
-## Class: Server
-
-Servers are created when calling the deployd exported function.
-
- var deployd = require('deployd')
- , options = {port: 3000}
- , server = deployd(options);
-
-* `options` {Object}
-
- - port {Number} - the port to listen on
- - db {Object} - the database to connect to
- - port {Number} - the port of the database server
- - host {String} - the ip or domain of the database server
- - name {String} - the name of the database
- - credentials {Object} - credentials for the server
- - username {String}
- - password {String}
- - env {String} - the environment to run in.
-
-*Note:* If `options.env` is "development", the dashboard will not require authentication and configuration will not be cached. Make sure to change this to "production" or something similar when deploying.
-
-## Server.listen([port], [host])
-
-Load any configuration and start listening for incoming connections.
-
- var dpd = require('deployd')
- , server = dpd()
-
- dpd.listen();
- dpd.on('listening', function() {
- console.log(server.options.port); // 2403
- });
-
-## Server.createStore(namespace)
-
-Create a new `Store` for persisting data using the database info that was passed to the server when it was created.
-
- // Create a new server
- var server = new Server({port: 3000, db: {host: 'localhost', port: 27015, name: 'my-db'}});
-
- // Attach a store to the server
- var todos = server.createStore('todos');
-
- // Use the store to CRUD data
- todos.insert({name: 'go to the store', done: true}, ...); // see `Store` for more info
-
-## Server.sockets
-
-The **socket.io** sockets `Manager` object ([view source](https://github.com/LearnBoost/socket.io/blob/master/lib/manager.js)).
-
-## Server.sessions
-
-The server's `SessionStore`.
-
-## Server.router
-
-The server's `Router`.
-
-## Server.resources
-
-An `Array` of the server's resource instances. These a built from the config and type loaders.
0  docs/module-api/session.md
View
No changes.
0  docs/module-api/user-collection.md
View
No changes.
77 docs/reference/advanced-queries.md
View
@@ -1,77 +0,0 @@
-# Advanced Queries
-
-When querying a [Collection](../resources/collection.md), you can use special commands to create a more advanced query.
-
-Deployd supports all of [MongoDB's conditional operators](http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-ConditionalOperators); only the common operators and Deployd's custom commands are documented here.
-
-When using an advanced query in REST, you must pass JSON as the query string, for example:
-
- GET /posts?{"likes": {"$gt": 10}}
-
-If you are using dpd.js, this will be handled automatically.
-
-
-## Comparison ($gt, $lt, $gte, $lte)
-
-Compares a Number property to a given value.
-
-- `$gt` - Greater than
-- `$lt` - Less than
-- `$gte` - Greater than or equal to
-- `$lte` - Less than or equal to
-
- //Finds all posts with more than 10 likes
- {
- likes: {$gt: 10}
- }
-
-## $ne (Not Equal)
-
-The `$ne` command lets you choose a value to exclude.
-
- // Get all posts except those posted by Bob
- {
- author: {$ne: "Bob"}
- }
-
-## $in
-
-The `$in` command allows you to specify an array of possible matches.
-
- // Get articles in the "food", "business", and "technology" categories
- {
- category: {$in: ["food", "business", "technology"]}
- }
-
-# Query commands
-
-Query commands apply to the entire query, not just a single property.
-
-## $sort
-
-The `$sort` command allows you to order your results by the value of a property. The value can be 1 for ascending sort (lowest first; A-Z, 0-10) or -1 for descending (highest first; Z-A, 10-0)
-
- // Sort posts by likes, descending
- {
- $sort: {likes: -1}
- }
-
-## $limit
-
-The `$limit` command allows you to limit the amount of objects that are returned from a query. This is commonly used for paging, along with `$skip`.
-
- // Return the top 10 scores
- {
- $sort: {score: -1}
- $limit: 10
- }
-
-## $skip
-
-The `$skip` command allows you to exclude a given number of the first objects returned from a query. This is commonly used for paging, along with `$limit`.
-
- // Return the third page of posts, with 10 posts per page
- {
- $skip: 20
- $limit: 10
- }
213 docs/reference/collection-events.md
View
@@ -1,213 +0,0 @@
-# Collection Events Reference
-
-Events allow you to add custom logic to your Collection using JavaScript. Deployd is compatible with ECMAScript 5, so you can use functional-style programming, such as `forEach()`, `map()`, and `filter()`.
-
-### this
-
-The current object is represented as `this`. You can always read its properties. Modifying its properties in an `On Get` request will change the result that the client recieves, while modifying its properties in an `On Post`, `On Put`, or `On Validate` will change the value in the database.
-
- // Example: On Validate
- // If a property is too long, truncate it
- if (this.message.length > 140) {
- this.message = this.message.substring(0, 137) + '...';
- }
-
-*Note*: In some cases, the meaning of `this` will change to something less useful inside of a function. If you are using functional programming (i.e. `Array.forEach()`), you may need to bind another variable to `this`:
-
- // Won't work - sum gets set to 0
- this.sum = 0;
- this.targets.forEach(function(t) {
- this.sum += t.points;
- });
-
-<!--seperate-->
-
- //Works as expected
- var self = this;
-
- this.sum = 0;
- this.targets.forEach(function(t) {
- self.sum += t.points;
- });
-
-### me
-
-The currently logged in User from a User Collection. `undefined` if no user is logged in.
-
- // Example: On Post
- // Save the creator's information
- if (me) {
- this.creatorId = me.id;
- this.creatorName = me.name;
- }
-### query
-
-The query string object. On a specific query (i.e. `/posts/a59551a90be9abd8`), this includes an `id` property.
-
- // Example: On Get
- // Don't show the body of a post in a general query
- if (!query.id) {
- hide(this.body);
- }
-
-### cancel()
-
- cancel(message, [statusCode])
-
-Stops the current request with the provided error message and HTTP status code. Status code defaults to `400`. Commonly used for security and authorization.
-
- // Example: On Post
- // Don't allow non-admins to create items
- if (!me.admin) {
- cancel("You are not authorized to do that", 401);
- }
-
-### error()
-
- error(key, message)
-
-Adds an error message to an `errors` object in the response. Cancels the request, but continues running the event so it can to collect multiple errors to display to the user. Commonly used for validation.
-
- // Example: On Validate
- // Don't allow certain words
- // Returns response {"errors": {"name": "Contains forbidden words"}}
- if (!this.name.match(/(foo|bar)/)) {
- error('name', "Contains forbidden words");
- }
-
-### hide()
-
- hide(property)
-
-Hides a property from the response.
-
- // Example: On Get
- // Don't show private information
- if (!me || me.id !== this.creatorId) {
- hide('secret');
- }
-
-### protect()
-
- protect(property)
-
-Prevents a property from being updated.
-
- // Example: On Put
- // Protect a property
- protect('createdDate');
-
-
-### changed()
-
- changed(property)
-
-Returns whether a property has been updated.
-
- // Example: On Put
- // Validate the title when it changes
- if(changed('title') && this.title.length < 5) {
- error('title', 'must be over 5 characters');
- }
-
-### previous
-
-An `Object` containing the previous values of the item to be updated.
-
- // Example: On Put
- if(this.votes < previous.votes) {
- emit('votes have decreased');
- }
-
-### emit()
-
- emit([userCollection, query], event, [data])
-
-Emits a realtime event to the client
-You can use `userCollection` and `query` parameters to limit the event broadcast to specific users.
-
- // Example: On Put
- // Alert the owner that their post has been modified
- if (me.id !== this.creatorId) {
- emit(dpd.users, {id: this.creatorId}, 'postModified', this);
- }
-
-<!--seperate-->
-
- // Example: On Post
- // Alert clients that a new post has been created
- emit('postCreated', this);
-
-In the front end:
-
- // Listen for new posts
- dpd.on('postCreated', function(post) {
- //do something...
- });
-
-See the [Dpd.js Reference](/docs/reference/dpdjs.html#docs-realtime) for details on how to listen for events.
-
-### dpd
-
-The entire [dpd.js](/docs/reference/dpdjs.html) library, except for `dpd.on()`, is available from events. It will also properly bind `this` in callbacks.
-
- // Example: On Get
- // If specific query, get comments
- dpd.comments.get({postId: this.id}, function(results) {
- this.comments = results;
- });
-
-<!--seperate-->
-
- // Example: On Delete
- // Log item elsewhere
- dpd.archived.post(this);
-
-Dpd.js will prevent recursive queries. This works by returning `null` from a `dpd` function call that has already been called further up in the stack.
-
- // Example: On Get /recursive
- // Call self
- dpd.recursive.get(function(results) {
- if (results) this.recursive = results;
- });
-
-<!--seperate-->
-
- // GET /recursive
- {
- "id": "a59551a90be9abd8",
- "recursive": [
- {
- "id": "a59551a90be9abd8"
- }
- ]
- }
-
-
-### internal
-
-Equal to true if this request has been sent by another script.
-
- // Example: On GET /posts
- // Posts with a parent are invisible, but are counted by their parent
- if (this.parentId && !internal) cancel();
-
- dpd.posts.get({parentId: this.id}, function(posts) {
- this.childPosts = posts.length;
- });
-
-### isRoot
-
-Equal to true if this request has been authenticated as root (has the `dpd-ssh-key` header with the appropriate key)
-
- // Example: On PUT /users
- // Protect reputation property - should only be calculated by a custom script.
-
- if (!isRoot) protect('reputation');
-
-
-### console.log()
-
- console.log([arguments]...)
-
-Logs the values provided to the command line. Useful for debugging.
91 docs/reference/dpdjs.md
View
@@ -1,91 +0,0 @@
-# dpd.js
-
-The Deployd client library (`dpd.js`) can optionally be included in your web app to simplify backend requests. Include it with this script tag in your `<head>` or `<body>`:
-
- <script type="text/javascript" src="/dpd.js" />
-
-This will include a `dpd` object that contains all of the resources on the server. For example, if your app contains a `/my-objects` and a `/users` resource, you would use `dpd.myobjects` and `dpd.users` to access their APIs.
-Alternatively, you can use `dpd` as a function, such as `dpd('my-objects')` or `dpd('users')`, but this will not populate any resource-specific helper functions.
-
-# Realtime
-
- dpd.on(event, fn)
-
-Listens for an event coming from the server.
-
-* `event` - The name of the event to listen for
-* `fn` - Callback `function(eventData)`. Called every time the event is received.
-
-<!--seperate-->
-
- // Listen for a new post
- dpd.on('postCreated', function(post) {
- //do something
- });
-
-In your Collection Events:
-
- // On Post
- emit('postCreated', this);
-
-See the [Collection Event Reference](/docs/reference/collection-events.html#docs-emit) for details on how to send events with the `emit()` function.
-
-# Generic Resource APIs
-
-**Note**: These APIs are designed to work with any resource, so some features may be unavailable depending on the resource. Use resource-specific documentation to learn how to use their APIs.
-
-### get()
-
- dpd.[resource].get([func], [path], [query], fn)
-
-Makes a GET HTTP request at the URL `/<resource>/<func>/<path>`, using the `query` object as the query string if provided.
-
-- `func` - A special RPC identifier, i.e. `/me`.
-- `path` - An idenitifier for a particular object, usually the id
-- `query` - An object defining the querystring. If the object is complex, it will be serialized as JSON.
-- `fn` - Callback `function(result, error)`.
-
-### post()
-
- dpd.[resource].post([path], [query], body, fn)
-
-Makes a POST HTTP request at the URL `/<resource>/<path>`, using the `query` object as the query string if provided and `body` as the request body.
-
-- `path` - An idenitifier for a particular object, usually the id
-- `query` - An object defining the querystring. If the object is complex, it will be serialized as JSON.
-- `body` - The body of the request; will be serialized as JSON as sent with `Content-Type: application/json` header.
-- `fn` - Callback `function(result, error)`.
-
-### put()
-
- dpd.[resource].put([path], [query], body, fn)
-
-Makes a PUT HTTP request at the URL `/<resource>/<path>`, using the `query` object as the query string if provided and `body` as the request body.
-
-- `path` - An idenitifier for a particular object, usually the id
-- `query` - An object defining the querystring. If the object is complex, it will be serialized as JSON and passed as the `q` parameter.
-- `body` - The body of the request; will be serialized as JSON as sent with `Content-Type: application/json` header.
-- `fn` - Callback `function(result, error)`.
-
-### del()
-
- dpd.[resource].del([path], [query], fn)
-
-Makes a DELETE HTTP request at the URL `/<resource>/<path>`, using the `query` object as the query string if provided.
-
-- `path` - An idenitifier for a particular object, usually the id
-- `query` - An object defining the querystring. If the object is complex, it will be serialized as JSON and passed as the `q` parameter.
-- `fn` - Callback `function(result, error)`.
-
-
-### exec()
-
- dpd.[resource].exec(func, [path], [body], fn)
-
-Makes an RPC-style POST HTTP request at the URL `/<resource>/<func>/<path>`. Useful for functions that don't make sense in REST-style APIs, such as `/users/login`.
-
-- `func` - The name of the RPC to call
-- `path` - An idenitifier for a particular object, usually the id
-- `body` - The body of the request; will be serialized as JSON as sent with `Content-Type: application/json` header.
-- `fn` - Callback `function(result, error)`.
-
58 docs/reference/modifiers.md
View
@@ -1,58 +0,0 @@
-# Update Modifiers
-
-When updating an object in a [Collection](/docs/resources/collection.html), you can use special modifier commands to more granularly change property values.
-
-## $inc
-
-The `$inc` command increments the value of a given Number property.
-
- // Give a player 5 points
- {
- score: {$inc: 5}
- }
-
-## $push
-
-The `$push` command adds a value to an Array property.
-
- // Add a follower to a user by storing their id.
- {
- followers: {$push: 'a59551a90be9abd8'}
- }
-
-*Note: This will work even on an undefined property*
-
-## $pushAll
-
-The `$pushAll` command adds multiple values to an Array property.
-
- // Add mentions of users
- {
- mentions: {
- $pushAll: ['a59551a90be9abd8', 'd0be45d1445d3809']
- }
- }
-
-*Note: This will work even on an undefined property*
-
-## $pull
-
-The `$pull` command removes a value from an Array property.
-
- // Remove a user from followers
- {
- followers: {$pull: 'a59551a90be9abd8'}
- }
-
-*Note: If there is more than one matching value in the Array, this will remove all of them*
-
-## $pullAll
-
-The `$pullAll` command removes multiple values from an Array property.
-
- // Remove multiple users
- {
- followers: {$pullAll: ['a59551a90be9abd8', 'd0be45d1445d3809']}
- }
-
-*Note: This will remove all of matching values from the Array*
185 docs/resources/collection.md
View
@@ -1,185 +0,0 @@
-# Collection
-
-The Collection resource allows clients to save, update, delete, and query data of a given type.
-
-## Properties
-
-![Properties editor](/img/docs/collection-properties.png)
-
-Properties in a Collection describe the objects that it can store.
-Every Collection has an `id` property that cannot be removed. This property is automatically generated when you create an object and serves as a unique identifier.
-
-You can add these types of properties to a Collection:
-
-- `String` - Acts like a JavaScript string
-- `Number` - Stores numeric values, including floating points.
-- `Boolean` - Either true or false. (To avoid confusion, Deployd will consider null or undefined to be false)
-- `Object` - Stores any JSON object. Used for storing arbitrary data on an object without needing to validate schema.
-- `Array` - Stores an array of any type.
-
-*Deprecated* Any property can be marked as "Required". This will cause an error message if the property is null or undefined when an object is created.
-
-## Events
-
-Events allow you to add custom logic to your Collection. Events are written in JavaScript, see the [Collection Events Reference](/docs/reference/collection-events.html) for details on the API.
-
-These events are available for scripting:
-
-### On Get
-
-Called whenever an object is loaded from the server. Commonly used to hide properties, restrict access to private objects, and calculate dynamic values.
-
- // Example On Get: Hide Secret Properties
- if (!me || me.id !== this.creatorId) {
- hide('secret');
- }
-
-<!--seperate-->
-
- // Example On Get: Load A Post's Comments
- dpd.comments.get({postId: this.id}, function(comments) {
- this.comments = comments;
- });
-
-*Note: When a list of objects is loaded, `On Get` will run once for each object in the list. Calling `cancel()` in this case will remove the object from the list, rather than cancelling the entire request.*
-
-
-### On Validate
-
-Called whenever an object's values change, including when it is first created. Commonly used to validate property values and calculate certain dynamic values (i.e. last modified time).
-
- // Example On Validate: Enforce a max length
- if (this.body.length > 100) {
- error('body', "Cannot be more than 100 characters");
- }
-
-<!--seperate-->
-
- // Example On Validate: Normalize an @handle
- if (this.handle.indexOf('@') !== 0) {
- this.handle = '@' + this.handle;
- }
-
-*Note: `On Post` or `On Put` will execute after `On Validate`, unless `cancel()` or `error()` is called*
-
-
-### On Post
-
-Called when an object is created. Commonly used to prevent unauthorized creation and save data relevant to the creation of an object, such as its creator.
-
- // Example On Post: Save the date created
- this.createdDate = new Date();
-
-<!--seperate-->
-
- // Example On Post: Prevent unauthorized users from posting
- if (!me) {
- cancel("You must be logged in", 401);
- }
-
-
-### On Put
-
-Called when an object is updated. Commonly used to restrict editing access to certain roles, or to protect certain properties from editing.
-
- // Example On Put: Protect readonly/automatic properties
- protect('createdDate');
- protect('creatorId')
-
-### On Delete
-
-Called when an object is deleted. Commonly used to prevent unauthorized deletion.
-
- // Example On Delete: Prevent non-admins from deleting
- if (!me || me.role !== 'admin') {
- cancel("You must be an admin to delete this", 401);
- }
-
-## API
-
-A Collection allows clients to interact with it over a REST interface, as well as with the `dpd.js` library.
-
-### Listing Data
-
-**REST Example**
-
- GET /todos
-
-**dpd.js Example**
-
- // Get all todos
- dpd.todos.get(function(results, error) {
- //Do something
- });
-
-### Querying Data
-
-Filters results by the property values specified.
-
-**REST Example**
-
- GET /todos?category=red
-
-**dpd.js Example**
-
- // Get all todos that are in the red category
- dpd.todos.get({category: 'red'}, function(results, error) {
- //Do something
- });
-
-*Note: for Array properties, this acts as a "contains" operation. For example, the above query would also match `category` value of `["blue", "red", "orange"]`.*
-
-Use the [Advanced Query commands](/docs/reference/advanced-queries.html) for more control over the results.
-
-### Creating an Object
-
-**REST Example**
-
- POST /todos
- {"title": "Walk the dog", "category": "red"}
-
-**dpd.js Example**
-
- dpd.todos.post({title: 'Walk the dog'}, function(result, error) {
- //Do something
- });
-
-### Getting a Single Object
-
-**REST Example**
-
- GET /todos/add1ad66465e6890
-
-**dpd.js Example**
-
- dpd.todos.get('add1ad66465e6890', function(result, error)) {
- //Do something
- });
-
-### Updating an Object
-
-You do not need to provide all properties for an object. Deployd will only update the properties you provide.
-You can use [Update Modifiers](/docs/reference/modifiers.html) for atomic updates such as incrementing Number properties and adding to Array properties.
-
-**REST Example**
-
- PUT /todos/add1ad66465e6890
- {"title": "Bathe the cat"}
-
-**dpd.js Example**
-
- dpd.todos.put('add1ad66465e6890', {title: "Bathe the cat"}, function(result, error)) {
- //Do something
- });
-
-### Deleting an Object
-
-**REST Example**
-
- DELETE /todos/add1ad66465e6890
-
-**dpd.js Example**
-
- dpd.todos.del('add1ad66465e6890', function(result, error)) {
- //Do something
- });
217 docs/resources/custom-resources.md
View
@@ -1,217 +0,0 @@
-# Custom Resources
-
-A resource is a node module that deployd mounts at a given url and handles HTTP requests. Deployd comes bundled with two resources: [Collection](collection.html) and [UserCollection](user-collection.html). You can create your own custom resources by extending the `Resource` constructor and implementing a `handle()` method. Here is an example of a simple custom resource:
-
- var Resource = require('deployd/lib/resource')
- , util = require('util');
-
- function Hello(options) {
- Resource.apply(this, arguments);
- }
- util.inherits(Hello, Resource);
- module.exports = Hello;
-
- Hello.prototype.handle = function (ctx, next) {
- if(ctx.req && ctx.req.method !== 'GET') return next();
-
- ctx.done(null, {hello: 'world'});
- }
-
-This resource will respond to every GET request with: `{"hello": "world"}`.
-
-## Loading / File Structure
-
-Deployd looks for custom resources in your project's `node_modules` folder. Any node module that exports a constructor that inherits from `Resource` will be loaded and made available in the dashboard.
-
-Heres an example project structure:
-
- - my-project
- - app.dpd
- - resources
- - data
- - node_modules
- - hello.js
- - my-module
- - index.js
- - README.md
- - package.json
- - node_modules
- - foo-module
- - foo.js
-
-Resources can be a single file (eg. hello.js) or a folder with a `package.json` and its own `node_modules` folder. Resources are just regular node modules.
-
-## Dashboard
-
-If your custom resource type is properly installed in your app, you should see it in the Create Resource menu in the dashboard. To customize its appearance in this menu, use the following properties:
-
- // The resource type's name as it appears in the dashboard.
- // If this is not set, it will appear with its constructor
- // name ('Hello' in this case)
- Hello.label = 'Hello World';
-
- // The default path suggested to users creating a resource.
- // If this is not set, it will use the constructor's name
- // in lowercase. ('/hello' in this case).
- Hello.defaultPath = '/hello-world';
-
-By default, the dashboard will provide a JSON editor to configure this resource. For a more customized experience, you can set specific properties to be edited:
-
- Hello.basicDashboard = {
- settings: [{
- name: 'propertyName',
- type: 'text',
- description: "This description appears below the text field"
- }, {
- name: 'longTextProperty',
- type: 'textarea'
- }, {
- name: 'numericProperty',
- type: 'number'
- }, {
- name: 'booleanProperty',
- type: 'checkbox'
- }]
- };
-
-![Basic Dashboard](/img/docs/basic-dashboard.png)
-
-## Context
-
-Resources must implement a `handle(ctx, next)` method. This method is passed a `Context` during HTTP requests. The resource can either handle this context and call `ctx.done(err, obj)` with an error or result JSON object or call `next()` to give the context back to the router. If a resource calls `next()` the router might find another match for the resource, or respond with a `404`.
-
-A context comes with several useful properties to make HTTP easy.
-
- - **query** the requests query as an object
- - **body** the requests body as JSON if it exists
- - **session** the current user's session if one exists
- - **dpd** the internal interface for interacting with other resources
-
-## Script
-
-To make your `Resource` reusable, you can expose hooks to execute scripts when a resource is handling a request. A `Script` runs JavaScript in an isolated context. It interfaces with the current request through a `domain` which is passed to a `Script` to run.
-
-For example, in the `Collection` resource, custom logic is injected through hooks called **event scripts**. These are short scripts that are executed in their own context. They do not share a scope or state with any other scripts. In an **event script** the global object contains a set of **domain functions**. These functions, such as `hide()`, `error()`, and `protect()` operate on the context. In the case of a `Collection` they interact with the item that is being retrieved or saved, the `ctx.body`.
-
-A common type of `Script` is an event. The following example resource loads an event.
-
-my-resource.js:
-
- var Resource = require('deployd/lib/resource');
- var Script = require('deployd/lib/script');
- var fs = require('fs');
- var util = require('util');
-
- var MyResource = function () {
- Resource.apply(this, arguments);
- }
- util.inherits(MyResource, Resource);
-
- MyResource.events = ["get"]; // Registers events to be loaded. Also makes them editable in the dashboard
-
- MyResource.prototype.handle = function (ctx) {
- var value;
-
- var domain = {
- send: function(msg) {
- value = msg;
- },
- };
-
- this.events.get.run(ctx, domain, function() {
- ctx.done(null, value);
- });
- }
-
-get.js:
-
- send({hello: 'world'});
-
-GET /my-resource response:
-
- {
- "hello": "world"
- }
-
-## Custom Dashboard
-
-To create a fully customized editor for your resource, set the "dashboard" property:
-
- Hello.dashboard = {
- path: __dirname + '/dashboard', //The absolute path to your front-end files
- pages: ["Credentials", "Events", "API"], // Optional; these pages will appear on the sidebar.
- scripts: [
- '/js/lib/backbone.js', //relative paths to extra JavaScript files you would like to load
- '/js/lib/jquery-ui.js'
- ]
- };
-
-This will load your resources' editor from the dashboard path. It will load the following files:
-
- - `[current-page].html`
- - `js/[current-page].js`
- - `style.css`
-
-The default page is `index`; the `config` page will also redirect to `index`.
-
-The `config` or `index` page will load the basic dashboard if no `index.html` file is provided.
-The `events` page will load the default event editor if no `events.html` file is provided.
-
-To embed the event editor in your dashboard, include this empty div:
-
- <div id="event-editor" class="default-editor"></div>
-
-For styling, the dashboard uses a reskinned version of [Twitter Bootstrap 2.0.2](http://twitter.github.com/bootstrap/).
-
-The dashboard provides several JavaScript libraries by default:
-
-- [jQuery 1.7.2](http://jquery.com/)
-- [jquery.cookie](https://github.com/carhartl/jquery-cookie/)
-- [Underscore 1.3.3](http://underscorejs.org/)
-- [Twitter Bootstrap 2.0.2](http://twitter.github.com/bootstrap/javascript.html)
-- [UIKit](http://visionmedia.github.com/uikit/)
-- [Ace Editor](https://github.com/ajaxorg/ace) (noconflict version)
- - JavaScript mode
- - JSON mode
- - Custom theme for the Dashboard (`ace/theme/deployd`)
-- [Google Code Prettify](http://code.google.com/p/google-code-prettify/)
-- dpd.js
- - *Note:* all dpd.js requests will be sent as root, which gives special priveleges, such as ignoring `cancel()` in events.
-
-Within the dashboard, a `Context` object is available:
-
- //Automatically generated by Deployd:
- window.Context = {
- resourceId: '/hello', // The id of the current resource
- resourceType: 'Hello', // The type of the current resource
- page: 'properties', // The current page, in multi page editors
- basicDashboard: {} // The configuration of the basic dashboard - not ordinarily useful
- };
-
-You can use this to query the current resource:
-
- dpd(Context.resourceId).get(function(result, err) {
- //Do something
- });
-
-In the dashboard, you also have access to the special `__resources` resource, which lets you update your app's configuration files:
-
- // Get the config for the current resource
- dpd('__resources').get(Context.resourceId, function(result, err) {
- //Do something
- });
-
- // Set a property for the current resource
- dpd('__resources').put(Context.resourceId, {someProperty: true}, function(result, err) {
- //Do something
- });
-
- // Set all properties for the current resource, deleting any that are not provided
- dpd('__resources').put(Context.resourceId, {someProperty: true, $setAll: true}, function(result, err) {
- //Do something
- });
-
- // Save another file, which will be loaded by the resource
- dpd('__resources').post(Context.resourceId + '/content.md', {value: "# Hello World!"}, function(result, err)) {
- //Do something
- });
63 docs/resources/user-collection.md
View
@@ -1,63 +0,0 @@
-# User Collection
-
-A User Collection extends a [Collection](/docs/resources/collection.html), adding the functionality needed to authenticate users with your app.
-
-## Properties
-
-User Collections can have the same properties as a Collection, with two additional non-removable properties:
-
-- `username` - The user's identifier; must be unique.
-- `password` - A write-only, encrypted password
-
-## API
-
-User Collections add three new methods to the standard Collection API:
-
-### Logging in
-
-Log in a user with their username and password. If successful, the browser will save a secure cookie for their session. This request responds with the session details:
-
- {
- "id": "s0446b993caaad577a..." //Session id - usually not needed
- "path": "/users" // The path of the User Collection - useful if you have different types of users.
- "uid": "ec54ad870eaca95f" //The id of the user
- }
-
-**REST Example**
-
- POST /users/login
- {"username": "test@test.com", "password": "1234"}
-
-**dpd.js Example**
-
- dpd.users.login({'username': 'test@test.com', 'password': '1234'}, function(result, error) {
- //Do something
- });
-
-### Logging out
-
-Logging out will remove the session cookie on the browser and destroy the current session. It does not return a result.
-
-**REST Example**
-
- POST /users/logout
-
-**dpd.js Example**
-
- dpd.users.logout(function(result, error) {
- //Do something
- });
-
-### Getting the current user
-
-Returns the user that is logged in.
-
-**REST Example**
-
- GET /users/me
-
-**dpd.js Example**
-
- dpd.users.me(function(result, errors) {
- //Do something
- });
205 docs/tutorials/comments-1.md
View
@@ -1,205 +0,0 @@
-# Building a Comments app
-
-In this tutorial, you'll see how to create a simple app from the ground up in Deployd. This tutorial assumes a working knowledge of jQuery. It doesn't assume any knowledge of Deployd, but it's recommended to read the [Hello World](hello-world.md) tutorial if you haven't already.
-
-## Getting started
-
-Create a new app in the command line:
-
- $ dpd create comments
- $ cd comments
-
-Using your text editor of choice, replace the default `index.html` file in the `public` folder:
-
- <!DOCTYPE html>
- <html>
- <head>
- <title>Deployd Tutorial</title>
- <style type="text/css">
- body { font-size: 16pt; }
- .container { width: 960px; margin-left: auto; margin-right: auto; }
- form { border: #cccccc 1px solid; padding: 20px; margin-bottom: 10px; -moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; }
- .form-element { margin-bottom: 10px; }
- #refresh-btn { margin-bottom: 20px; }
- .comment { padding: 10px; margin-bottom: 10px; border-bottom: #cccccc 1px solid; }
- .comment .links { float: right; }
- .comment .links a { margin-left: 10px; }
- .comment .author { font-style: italic; }
- </style>
- </head>
- <body>
- <div class="container">
- <div id="comments">
- </div>
- <form id="comment-form">
- <div class="form-element">
- <label for="name">Name: </label>
- <input type="text" id="name" name="name" />
- </div>
- <div class="form-element">
- <textarea id="comment" name="comment" rows="5" cols="50">
- </textarea>
- </div>
- <div class="form-element">
- <button type="submit">Add New Comment</button>
- </div>
- </form>
- </div>
-
- <script src="http://code.jquery.com/jquery-latest.min.js"></script>
- <script type="text/javascript" src="script.js"></script>
- </body>
- </html>
-
-Also add a file `script.js` and paste this code:
-
- $(document).ready(function() {
-
- $('#comment-form').submit(function() {
- //Get the data from the form
- var name = $('#name').val();
- var comment = $('#comment').val();
-
- //Clear the form elements
- $('#name').val('');
- $('#comment').val('');
-
- addComment({
- name: name,
- comment: comment
- });
-
- return false;
- });
-
- function addComment(comment) {
- $('<div class="comment">')
- .append('<div class="author">Posted by: ' + comment.name + '</div>')
- .append('<p>' + comment.comment + '</p>')
- .appendTo('#comments');
- }
-
- });
-
-Run the app:
-
- $ dpd --open
- dpd>
-
-The `open` command will automatically open `http://localhost:2403` in your browser.
-
-![App Preview](/img/tutorials/comments-app-preview.png)
-
-This basic app asks for a name and message body to post a comment. Take a moment to read the code and see how it works.
-
-Next, we'll add a Deployd backend to this app, so that users can interact with each other and post comments.
-
-## Creating a backend
-
-Open the dashboard by by typing `dashboard` into the `dpd>` prompt.
-
-1. Create a new Collection Resource and call it `/comments`.
-2. On the Properties editor, add two "string" properties called `name` and `comment`.
-3. In the Data editor, add a couple of comments so you can start testing right away.
-
-That's all you have to do in the backend for now!
-
-## Integrating in the frontend
-
-In `index.html`, add the following script reference in between jQuery and `script.js` (near line 37):
-
- <script type="text/javascript" src="/dpd.js"></script>
-
-This will add a reference to [dpd.js](/docs/reference/dpdjs.html), a simple library dynamically built specifically for your app's backend. Dpd.js will automatically detect what resources you have added to your app and add them to the `dpd` object. Each resource object has asynchronous functions to communicate with your Deployd app.
-
-In `script.js`, add a `loadComments()` function inside of `$(document).ready`:
-
- function loadComments() {
- dpd.comments.get(function(comments, error) { //Use dpd.js to send a request to the backend
- $('#comments').empty(); //Empty the list
- comments.forEach(function(comment) { //Loop through the result
- addComment(comment); //Add it to the DOM.
- });
- });
- }
-
-And call it when the page loads:
-
- $(document).ready(function() {
-
- loadComments();
-
- //...
-
- });
-
-If you run the app now, you should see the comments that you created in the Dashboard.
-
-The `get` function that makes this work sends an HTTP `GET` request to `/comments`, and returns an array of objects in the resource. There's nothing magical hapenning in dpd.js; you can use standard AJAX or HTTP requests if you prefer, or if you're not working in JavaScript (i.e. mobile apps)
-
-**Note**: If you haven't used AJAX much, note that all dpd.js functions are *asynchronous* and don't directly return a value.
-
- //Won't work:
- var comments = dpd.comments.get();
-
-This means that your JavaScript will continue to execute and respond to user input while data is loading, which will make your app feel much faster to your users.
-
-## Saving data
-
-Notice that any comments you add through the app's form are still gone when you refresh. Let's make the form save comments to the database.
-
-Delete these lines from `script.js` (near line 10, depending on where you put your `loadComments()` function):
-
- //Clear the form elements
- $('#name').val('');
- $('#comment').val('');
-
- addComment({
- name: name,
- comment: comment
- });
-
-And replace them with:
-
- dpd.comments.post({
- name: name,
- comment: comment
- }, function(comment, error) {
- if (error) return showError(error);
-
- addComment(comment);
- $('#name').val('');
- $('#comment').val('');
- });
-
-Add a utility function at the very top of `script.js` to alert any errors we get:
-
- function showError(error) {
- var message = "An error occured";
- if (error.message) {
- message = error.message;
- } else if (error.errors) {
- var errors = error.errors;
- message = "";
- Object.keys(errors).forEach(function(k) {
- message += k + ": " + errors[k] + "\n";
- });
- }
-
- alert(message);
- }
-
-An `error` object can include either a `message` property or an `errors` object containing validation errors.
-
-If you load the page now, you should be able to submit a comment that appears even after you refresh.
-
-## Conclusion
-
-In this tutorial, you saw how to create a simple app in Deployd. In the next part (coming soon), you'll see how to secure this app with Events.
-
-The source code for this chapter includes a few extra features. If you're feeling adventurous, try adding them yourself:
-
-- A refresh button that reloads the comments without refreshing the page
-- Edit and Delete links next to each comment. Hint: use the `put()` and `del()` functions from dpd.js.
-
-<a class="btn btn-primary" href="http://deployd.com/downloads/tutorials/dpd-comments-1.zip"><i class="icon-white icon-download"></i> Download Source</a>
99 docs/tutorials/hello-world.md
View
@@ -1,99 +0,0 @@
-# Hello World
-
-In this tutorial, you'll get a taste of how to use Deployd by creating a simple backend.
-
-## Creating an app
-
-Start out by creating a Deployd app. Open a command line in a directory of your choice and type:
-
- $ dpd create hello -d
-
-This will create your first Deployd app in a folder called `hello` and open up the Deployd *Dashboard*. If you open up the folder and look at the contents, you'll see the following files and folders:
-
- - `.dpd` is an internal folder that contains housekeeping information.
- - `data` contains your app's database.
- - `public` contains all of the static web assets that you'd like to host.
- - `resources` contains your application's resource configuration.
- - `app.dpd` is your app's settings.
-
-## Dashboard
-
-The Dashboard is where you will create the *resources* that make up your app's backend. A resource is essentially a feature that your frontend needs to access.
-
-This new app doesn't contain any resources yet, so add one now by clicking on "Resources +" and choosing Collection. Click "Create" (leave it at its default name of `my-objects`).
-
-![Dashboard](http://deployd.com/img/tutorials/hello-world-dashboard.png)
-
-You have just added your first resource to Deployd!
-
-## Collections
-
-The dashboard should open up the Collection Property editor.
-
-![Properties](http://deployd.com/img/tutorials/hello-world-properties.png)
-
-This is where you define the objects that you want to store in this Collection. For now, make sure `string` is selected as the type and enter `name` as the property. Click "Add". This means that every object stored in the `my-objects` collection will have a `name` property.
-
-Click on "Data" in the sidebar. This will open up the Collection Data editor. Type "World" in the `name` field and click "Add". Now the `my-objects` collection has an object in it.
-
-Let's see how this will look to your app's frontend code. Open up a new browser tab and navigate to `http://localhost:2403/my-objects`. (If your browser tries to download it as a file, open it with any text editor.) You should see something like this (your "id" will be different):
-
- [
- {
- "name":"World",
- "id":"a59551a90be9abd8"
- }
- ]
-
-This is a JSON array of objects. If you add another object to the collection, it will look like this:
-
- [
- {
- "name":"World",
- "id":"a59551a90be9abd8"
- }, {
- "name":"Joe",
- "id":"d0be45d1445d3809"
- }
- ]
-
-If you copy one of the ids and put it at the end of the URL (i.e. `/my-objects/a59551a90be9abd8`), you will see just that object:
-
- {
- "name":"World",
- "id":"a59551a90be9abd8"
- }
-
-Collections allow you to access data on the backend with very little setup.
-
-## Events
-
-Go back to the Dashboard and click on the "Events" link in the sidebar. Select the "On Get" tab and type the following JavaScript:
-
- this.greeting = "Hello, " + this.name + "!";
-
-If you check the data again, you will see that value set on the objects:
-
- [
- {
- "name":"World","id":"a59551a90be9abd8",
- "greeting":"Hello, World!"
- }, {
- "name":"Joe",
- "id":"d0be45d1445d3809",
- "greeting":"Hello, Joe!"
- }
- ]
-
-Events allow you to customize the behavior of data in a collection with simple JavaScript.
-
-## Next Steps
-
-This was just a quick tour through Deployd. To learn more:
-
-- If you have an application that can send raw HTTP requests, you could try to save data using POST and PUT verbs. Make sure to add a `Content-Type: application/json` header.
-- Check out the API link on the sidebar and see how to access this data from your frontend JavaScript. Try building a simple app in the `public` folder.
-- Check out [the community](/community.html) and ask questions about Deployd.
-- Start reading the [Comments App](/docs/tutorials/comments-1.html) tutorial to see how to make a full app
-
-<a class="btn btn-primary" href="http://deployd.com/downloads/tutorials/dpd-hello-world.zip"><i class="icon-white icon-download"></i> Download Source</a>
18 lib/resources/collection/dashboard/api.html
View
@@ -25,35 +25,35 @@
</tr>
<tbody>
<tr>
- <td><a href="http://www.deployd.com/docs/resources/collection.html#docs-listing-data" target="_blank">Listing data</a></td>
+ <td><a href="http://docs.deployd.com/docs/collections/reference/http.md#s-Listing Data-1286" target="_blank">Listing data</a></td>
<td>GET</td>
<td><a href="<%- '/' + resourceData.id %>" target="_blank"><%- '/' + resourceData.id %></a></td>
<td><em>Nothing</em></td>
<td>An array of objects</td>
</tr>
<tr>
- <td><a href="http://www.deployd.com/docs/resources/collection.html#docs-creating-an-object" target="_blank">Creating an object</a></td>
+ <td><a href="http://docs.deployd.com/docs/collections/reference/http.md#s-Creating an Object-1286" target="_blank">Creating an object</a></td>
<td>POST</td>
<td><%- '/' + resourceData.id %></td>
<td>A single object</td>
<td>The saved object (or errors)</td>
</tr>
<tr>
- <td><a href="http://www.deployd.com/docs/resources/collection.html#docs-getting-a-single-object" target="_blank">Getting an object</a></td>
+ <td><a href="http://docs.deployd.com/docs/collections/reference/http.md#s-Getting a Specific Object-1286" target="_blank">Getting an object</a></td>
<td>GET</td>
<td><%- '/' + resourceData.id %>/&lt;id&gt;</td>
<td><em>Nothing</em></td>
<td>A single object</td>
</tr>
<tr>
- <td><a href="http://www.deployd.com/docs/resources/collection.html#docs-updating-an-object" target="_blank">Updating an object</a></td>
+ <td><a href="http://docs.deployd.com/docs/collections/reference/http.md#s-Updating an Object-1286" target="_blank">Updating an object</a></td>
<td>PUT</td>
<td><%- '/' + resourceData.id %>/&lt;id&gt;</td>
<td>A single object</td>
<td>The saved object (or errors)</td>
</tr>
<tr>
- <td><a href="http://www.deployd.com/docs/resources/collection.html#docs-deleting-an-object" target="_blank">Deleting an object</a></td>
+ <td><a href="http://docs.deployd.com/docs/collections/reference/http.md#s-Deleting an Object-1286" target="_blank">Deleting an object</a></td>
<td>DELETE</td>
<td><%- '/' + resourceData.id %>/&lt;id&gt;</td>
<td>A single object</td>
@@ -61,21 +61,21 @@
</tr>
<% if (resourceData.type === 'UserCollection') { %>
<tr>
- <td><a href="http://www.deployd.com/docs/resources/user-collection.html#docs-logging-in" target="_blank">Logging in</a></td>
+ <td><a href="http://docs.deployd.com/docs/users/authenticating-users.md#s-Logging in-2026" target="_blank">Logging in</a></td>
<td>POST</td>
<td><%- '/' + resourceData.id %>/login</td>
<td><code>username</code> and <code>password</code> of user</td>
<td>The user, plus session cookie (or error)</td>
</tr>
<tr>
- <td><a href="http://www.deployd.com/docs/resources/user-collection.html#docs-logging-out" target="_blank">Logging out</a></td>
+ <td><a href="http://docs.deployd.com/docs/users/authenticating-users.md#s-Logging out" target="_blank">Logging out</a></td>
<td>POST</td>
<td><%- '/' + resourceData.id %>/logout</td>
<td><em>Nothing</em></td>
<td><em>Nothing</em></td>
</tr>
<tr>
- <td><a href="http://www.deployd.com/docs/resources/user-collection.html#docs-getting-the-current-user" target="_blank">Getting the current user</a></td>
+ <td><a href="http://docs.deployd.com/docs/users/authenticating-users.md#s-Getting the current user" target="_blank">Getting the current user</a></td>
<td>GET</td>
<td><a href="<%- '/' + resourceData.id %>/me" target="_blank"><%- '/' + resourceData.id %>/me</a></td>
<td><em>Nothing</em></td>
@@ -88,7 +88,7 @@
</div>
<div id="js-examples" class="tab-pane">
- <p>Deployd generates a browser JavaScript api for easily accessing data from the <code><%= '/' + resourceData.id %></code> collection. To use it you first need to include the generated script.</p>
+ <p>Deployd generates a <a href="http://docs.deployd.com/docs/collections/reference/dpd-js.md">browser JavaScript API</a> for easily accessing data from the <code><%= '/' + resourceData.id %></code> collection. To use it you first need to include the generated script.</p>
<pre class="prettyprint code">&lt;script src="dpd.js"&gt;&lt;/script&gt;</pre>
2  lib/resources/collection/dashboard/events.html
View
@@ -4,7 +4,7 @@
<div id="events-panel" class="well stacked">
<h3 class="clearfix">
Events
- <a class="pull-right header-link" target="_blank" href="http://www.deployd.com/docs/reference/collection-events.html">Documentation</a>
+ <a class="pull-right header-link" target="_blank" href="http://docs.deployd.com/docs/collections/adding-logic.md">Documentation</a>
</h3>
<div id="event-editor" class="default-editor">
Please sign in to comment.
Something went wrong with that request. Please try again.