Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sails

Package Overview
Dependencies
Maintainers
1
Versions
236
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sails - npm Package Compare versions

Comparing version 0.7.0 to 0.7.1

4

bin/sails.js

@@ -149,2 +149,6 @@ #!/usr/bin/env node

},
scripts: {
test: 'mocha -b',
start: 'node app.js'
},
main: 'app.js',

@@ -151,0 +155,0 @@ repository: '',

2

lib/assets.js

@@ -66,3 +66,3 @@ var rigging = require('rigging');

// Get all template files in rigging sequence
var templateFiles = rigging.ls(sails.config.rigging.sequence,/\.ejs$/);
var templateFiles = rigging.ls(sails.config.rigging.sequence, new RegExp('\\.'+sails.config.viewEngine));
_.each(templateFiles,function(filepath) {

@@ -69,0 +69,0 @@ html += require('fs').readFileSync(filepath,'utf8') + "\n";

@@ -41,2 +41,3 @@ ////////////////////////////////////////////////////////////

var util = require('sails-util');
sails.util = util;

@@ -43,0 +44,0 @@ // Internal dependencies

@@ -24,18 +24,34 @@ exports.definition = function(modelName) {

findAll: function(req, res) {
// Normalize WHERE parameter
var where = applyFilter(req.param("sails_filter"), req.param('where') || req.param('search'));
// If WHERE is a string, try to interpret it as JSON
if (_.isString(where)) {
where = sails.parseJSON(where);
}
// If other params are specified, assume they represent attributes to be searched on in the model
var params;
if (!where) {
params = _.extend(req.query || {}, req.params || {}, req.body || {});
params = applyFilter(req.param("sails_filter"),params);
// Remove undefined params
params = sails.util.objReject(params, function (param) {
return _.isUndefined(param);
});
where = params;
}
// Build options object
var options = {
limit: req.param('limit') || undefined,
offset: req.param('skip') || req.param('offset') || undefined,
order: req.param('order') || undefined
skip: req.param('skip') || req.param('offset') || undefined,
sort: req.param('sort') || req.param('order') || undefined,
where: where || undefined
};
// TODO: instead of ?search, allow search by attribute
// Respond to queries
var finding;
var query = req.param('where') || req.param('search');
var where = Model.filter(query);
if(query) {
finding = Model.findAllLike(where, options);
}
// No WHERE criteria was specified, find all
else finding = Model.findAll(options);
var finding = Model.findAll(options);

@@ -57,4 +73,5 @@ finding.done(function afterFound(err, models) {

var params = _.extend(req.query || {}, req.params || {}, req.body || {});
params = applyFilter(req.param("sails_filter"),params);
Model.create(Model.filter(params)).done(function(err, model) {
Model.create(params).done(function(err, model) {
if(err) return res.send(err, 500);

@@ -81,2 +98,3 @@

var params = _.extend(req.query || {}, req.params || {}, req.body || {});
params = applyFilter(req.param("sails_filter"),params);

@@ -89,8 +107,6 @@ var id = req.param('id');

});
console.log("id:", id);
console.log("params:", Model.filter(params));
console.log("identity:", Model.identity);
Model.update({
id: id
}, Model.filter(params), function(err, model) {
}, params, function(err, model) {
if(err) return res.send(err, 500);

@@ -124,3 +140,3 @@ if(!model) return res.send('Model cannot be found.', 500);

Model.destroy(id, Model.filter(params)).done(function(err) {
Model.destroy(id, params).done(function(err) {
if(err) return res.send(err, 500);

@@ -141,2 +157,41 @@

};
};
};
// If "sails_filter" is explicitly enabled, filter the parameters
// (really useful for when a client's view-model is bundled in the same object as its api model)
// (e.g. Mast or Backbone.js)
function applyFilter (sails_filter, data) {
if (!data || !_.isObject(data)) return data;
// Always remove the params which sails automatically includes
delete data['action'];
delete data['entity'];
delete data['controller'];
// If the 'sails_filter' param is set,
// remove the attributes which are not in the model
// (but leave 'where', 'limit', 'skip', and 'sort' alone)
if (sails_filter) return _.extend({
where: data.where,
limit: data.limit,
sort: data.sort,
skip: data.skip
}, Model.filter(data));
else return data;
}
// Attempt to parse JSON
// If the parse fails, return the error object
// If JSON is falsey, return null
// (this is so that it will be ignored if not specified)
sails.parseJSON = function (json) {
if (!_.isString(json)) return null;
try {
return JSON.parse(json);
}
catch (e) {
return e;
}
};

@@ -6,2 +6,6 @@ {

{
"name": "Mike McNeil",
"email": "mike@balderdash.co"
},
{
"name": "Balderdash Design Co.",

@@ -17,6 +21,10 @@ "email": "dev@balderdash.co"

"email": "brad@techpines.com"
},
{
"name": "Curtis Lacy",
"email": "curtis.lacy@ldengine.com"
}
],
"version": "0.7.0",
"description": "Realtime MVC framework for Node.JS with support for Socket.io (built on Express)",
"version": "0.7.1",
"description": "API-driven framework for building realtime apps, using MVC conventions (based on Express and Socket.io)",
"homepage": "http://sailsjs.com",

@@ -26,6 +34,7 @@ "keywords": [

"mvc",
"sockets",
"socket.io",
"websockets",
"restful",
"API",
"auth",
"socket.io",
"rails",

@@ -48,3 +57,3 @@ "orm",

"dependencies": {
"waterline": "~0.1.04",
"waterline": "~0.1.6-0",
"express": "= 2.5.11",

@@ -81,4 +90,4 @@ "socket.io": "= 0.9.6",

"engines": {
"node": ">= 0.6.4"
"node": ">= 0.8.1"
}
}

@@ -1,2 +0,2 @@

![sails.jpg](http://i.imgur.com/o0Qsp.jpg)
![image_devInTub@2x.png](http://i.imgur.com/Tj9Nk.png)

@@ -6,3 +6,151 @@ # Sails

## Features
# Installation
To install the latest stable release with the command-line tool:
```sh
sudo npm -g install sails
```
# Creating a New Sails Project
Create a new app
```sh
# Create the app
sails new testProject
```
Lift Sails
```sh
# cd into the new folder
cd testProject
# Fire up the server
sails lift
```
The default port for Sails is 1337. At this point if you visit <a href="http://localhost:1337/">http://localhost:1337/</a> You will see
the default index.html page. Now, let's get Sails to tell us Hello.
# Hello, Sails!
To get Sails to say "Hello World!", you need only to define one controller with an action and define
one route. Lets start with the controller.
```sh
sails generate controller hello index
```
This will generate a file called `HelloController.js` in your app's `api/controllers` directory with one action, `index()`.
Now let's edit that action to send back the string `'Hello World!'`.
```javascript
var HelloController = {
index: function(req, res) {
res.send('Hello World!');
}
}
exports = HelloController;
```
After you have added that, you will want to remove the default index.html page that shows at the
start of your application.
```sh
rm ui/public/index.html
```
We want the application to display this hello response when a request for the root "/" route
comes in. Go into the **/config/routes.js** file. Here you can manually define these mappings,
and here we will do so. Change the file to look like this.
```javascript
var routes = {
'/': {
controller: 'hello',
action: 'index'
}
}
module.exports = routes;
```
As you will see when working more with Sails, one great feature is that by default, you do not have
to define incoming routes to controller actions. This is talked more about in the
<a href="https://github.com/balderdashy/sails/wiki/Routing">Routing page</a> of this wiki.
Finally, restart the server by going to your node terminal and pressing control+c. Then enter the
following.
```sh
sails lift
```
Now when you visit <a href="http://localhost:1337/">http://localhost:1337/</a> your browser should say **'Hello World!'**.
# Creating a Model
Creating a model is very easy with the command line tool. You can even define attributes and their
type by adding arguments at the end of the command. To generate a User model, enter the following:
```
sails generate model User
```
You will see that this creates a user model at **/api/model/User.js**. Let's give her a name-- try uncommenting the name attribute so it looks more or less like this:
```javascript
var User = {
attributes : {
name: 'STRING'
}
};
module.exports = User;
```
# What's Better Than Scaffolding? How About a free JSON API?
Sails API scaffolding is nothing like Rails scaffolding. HTML scaffolds just don't make sense for
modern web apps! Instead, Sails automatically builds a RESTful JSON API for your models. Best of
all, it supports HTTP _and_ WebSockets! By default for every controller you create, you get the
basic CRUD operations created automatically.
For instance, after generating the User model above, if you visit `http://localhost:1337/user/create`, you'll see:
```json
{
"createdAt": "2013-01-10T01:33:19.105Z",
"updatedAt": "2013-01-10T01:33:19.105Z",
"id": 1
}
```
That's it! You just created a model in the database! You can also `find`, `update`, and `destroy` users:
```
# List of all users
http://localhost:1337/user
# Find the user with id 1
http://localhost:1337/user/1
# Create a new user
http://localhost:1337/user/create?name=Fisslewick
(or send an HTTP POST to http://localhost:1337/user)
# Update the name of the user with id 1
http://localhost:1337/user/update/1?name=Gordo
(or send an HTTP PUT to http://localhost:1337/user/1)
# Destroy the user with id 1
http://localhost:1337/user/destroy/1
(or send an HTTP DELETE to http://localhost:1337/user/1)
```
## Additional Features
Sails does a few things other Node.js MVC frameworks can't do:

@@ -19,34 +167,24 @@ - Automatically generated JSON API for manipulating models means you don't have to write any backend code to build simple database apps

To learn more, check out the documentation here:
https://github.com/balderdashy/sails/wiki/_pages
Installation
Dependencies and Compatibility
--
To install the latest stable release:
```
npm install sails
```
Tested with node 0.8.1
Sails is built on the rock-solid foundations of ExpressJS and Socket.io.
Or to install with the command line tool: ```sudo npm install -g sails```
> NOTE: Sails is currently in open beta-- but lots of folks (including us) are using it in production today.
> If you're planning on using Sails in a production environment, make sure you lock down your dependency in your project's package.json file.
> (The next version of the Sails command-line tool does this for you, but it's not released yet.)
> We're on the cusp of a major release which will introduce support for a new ORM, Waterline.
Getting Started
--
If you installed Sails with the command line tool above, the following command will generate a new Sails project, ```nameOfNewApp/```, in the current directory:
```sails nameOfNewApp```
Then run the app:
```
cd nameOfNewApp
node app.js
```
Example
![icon_circlechart@2x.png](http://i.imgur.com/hXc06.png)
Demo
--
#### Live demo
*Try it in two browser windows*

@@ -56,20 +194,17 @@

<!--
#### Code
https://github.com/balderdashy/sails-example
-->
### Philosophy
Like other MVC frameworks, Sails espouses a same convention-over-configuration philosophy and emphasis on developer happiness, but takes it a step further. Like Node.js, using Sails means your app is written entirely in JavaScript, the language you or your team is already using to build the frontend portion of your web or mobile web app. This cuts development to a fraction of the time.
We've used Sails to build production-ready, realtime apps in a matter of weeks. In the past, that would have taken us months!
### Performance
Since Sails is written in Node.js, your servers reap the performance benefits of an event-driven, asynchronous architecture. (http://venturebeat.com/2011/08/16/linkedin-node/)
Dependencies and Compatibility
--
Tested with node 0.8.1
Sails is built on the rock-solid foundations of ExpressJS and Socket.io.
![icon_circleheart@2x.png](http://i.imgur.com/liHPV.png)
## Who Built This?

@@ -82,2 +217,9 @@

![icon_circlelightbulb@2x.png](http://i.imgur.com/eOFXn.png)
License

@@ -88,2 +230,3 @@ --

The MIT License (MIT)

@@ -90,0 +233,0 @@ --

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc