Commit 3adc8625 authored by Alex Clavelle's avatar Alex Clavelle
Browse files

initial

parents
(WIP)_ Typescript definitions for the [sails.js](https://github.com/balderdashy/sails) web framework.
Overview:
sails.js is a node.js mvc web framework. The two main pieces of a sails app are the Models, and Controllers. The views can be interchanged between multiple view engines. They aren't sails specific so don't require any type mappings.
requirements:
Requires the express,bluebird, and socket.io type mappings(for now_)
Controllers:
Each controller action is passed two parameters,an express request object, and an express response object. The request and response objects have been extended by the sails framework to add custom functionality. The main controller type definitions are for the extensions to the request and response objects.
Models:
A sails Model is a static class with methods like create, update, and find which correspond to operations on the database. These operations return Records.
Records: A record corresponds to a single row in the database.
Usage:
todo, check the tests
Mappings:
todo, check the code
///<reference path="../node/node.d.ts"/>
declare module Express{
export interface Request{
params :{
all():Object;
}
}
export interface Response{
view(route:string);
}
export interface Application{}
}
declare module Sails{
export interface Model{
attributes:Object;
create(params:Object):WaterlinePromise<QueryResult>;
create(params:Array<Object>):WaterlinePromise<QueryResult>;
create(params:Object,cb:(err:Error,created:QueryResult)=>void):void;
create(params:Array<Object>,cb:(err:Error,created:Array<QueryResult>)=>void):void;
find():QueryBuilder;
find(params:Object):QueryBuilder;
find(params:Object):WaterlinePromise<Array<QueryResult>>;
findOne(criteria:Object):WaterlinePromise<QueryResult>;
count(criteria:Object):WaterlinePromise<number>;
count(criteria:Array<Object>):WaterlinePromise<number>;
count(criteria:string):WaterlinePromise<number>;
count(criteria:number):WaterlinePromise<number>;
count(criteria:Object,cb:(err:Error,found:number)=>void);
count(criteria:Array<Object>,cb:(err:Error,found:number)=>void);
count(criteria:string,cb:(err:Error,found:number)=>void);
count(criteria:number,cb:(err:Error,found:number)=>void);
destroy(criteria:Object):WaterlinePromise<Array<Record>>;
destroy(criteria:Array<Object>):WaterlinePromise<Array<Record>>;
destroy(criteria:string):WaterlinePromise<Array<Record>>;
destroy(criteria:number):WaterlinePromise<Array<Record>>;
destroy(criteria:Object,cb:(err:Error,deleted:Array<Record>)=>void):void;
destroy(criteria:Array<Object>,cb:(err:Error,deleted:Array<Record>)=>void):void;
destroy(criteria:string,cb:(err:Error,deleted:Array<Record>)=>void):void;
destroy(criteria:number,cb:(err:Error,deleted:Array<Record>)=>void):void;
update(criteria:Object,changes:Object):WaterlinePromise<Array<QueryResult>>;
update(criteria:Array<Object>,changes:Object):WaterlinePromise<Array<QueryResult>>;
update(criteria:string,changes:Object):WaterlinePromise<Array<QueryResult>>;
update(criteria:number,changes:Object):WaterlinePromise<Array<QueryResult>>;
update(criteria:Object,changes:Array<Object>):WaterlinePromise<Array<QueryResult>>;
update(criteria:Array<Object>,changes:Array<Object>):WaterlinePromise<Array<QueryResult>>;
update(criteria:string,changes:Array<Object>):WaterlinePromise<Array<QueryResult>>;
update(criteria:number,changes:Array<Object>):WaterlinePromise<Array<QueryResult>>;
update(criteria:Object,changes:Array<Object>,cb:(err:Error,updated:Array<QueryResult>)=>void):void;
update(criteria:Array<Object>,changes:Array<Object>,cb:(err:Error,updated:Array<QueryResult>)=>void):void;
update(criteria:string,changes:Array<Object>,cb:(err:Error,updated:Array<QueryResult>)=>void):void;
update(criteria:number,changes:Array<Object>,cb:(err:Error,updated:Array<QueryResult>)=>void):void;
query(sqlQuery:string,cb:(err:Error,results:Array<Record>)=>void);
native(cb:(err:Error,collection:Model)=>void);
stream(criteria:Object,writeEnd:Object):NodeJS.WritableStream;
stream(criteria:Array<Object>,writeEnd:Object):NodeJS.WritableStream;
stream(criteria:string,writeEnd:Object):NodeJS.WritableStream;
stream(criteria:number,writeEnd:Object):NodeJS.WritableStream;
stream(criteria:Object,writeEnd:Object):Error;
stream(criteria:Array<Object>,writeEnd:Object):Error;
stream(criteria:string,writeEnd:Object):Error;
stream(criteria:number,writeEnd:Object):Error;
}
export class WaterlinePromise<T> extends Promise<T>{
exec(cb:(err:Error,results:Array<QueryResult>)=>void);
exec(cb:(err:Error,result:QueryResult)=>void);
}
export class Record{
id:number;
createdAt:Date;
updatedAt:Date;
}
export class QueryResult extends Record{
destroy():Promise<Array<Sails.QueryResult>>;
toJSON():Object;
}
export class QueryBuilder extends Promise<any>{
exec(cb:(error:any,results:Array<QueryResult>)=>void);
where(condition:Object):QueryBuilder;
limit(lim:number):QueryBuilder;
skip(num:number):QueryBuilder;
sort(criteria:string):QueryBuilder;
populate(association:string):QueryBuilder;
populate(association:string,filter:Object):QueryBuilder;
}
export interface Controller{
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment