├── .gitignore ├── CHANGELOG.md ├── CONTRIBUTING.md ├── CONTRIBUTORS.md ├── LICENSE ├── PULL_REQUEST_TEMPLATE.md ├── README.md ├── bower.json ├── dist ├── rest.js ├── rest.min.js ├── rest.node.js ├── rest.polyfill.js └── rest.polyfill.min.js ├── docs ├── 1.1.0 │ ├── Element.html │ ├── Factory.html │ ├── Rest.html │ ├── Rest_Config.html │ ├── fonts │ │ ├── OpenSans-Bold-webfont.eot │ │ ├── OpenSans-Bold-webfont.svg │ │ ├── OpenSans-Bold-webfont.woff │ │ ├── OpenSans-BoldItalic-webfont.eot │ │ ├── OpenSans-BoldItalic-webfont.svg │ │ ├── OpenSans-BoldItalic-webfont.woff │ │ ├── OpenSans-Italic-webfont.eot │ │ ├── OpenSans-Italic-webfont.svg │ │ ├── OpenSans-Italic-webfont.woff │ │ ├── OpenSans-Light-webfont.eot │ │ ├── OpenSans-Light-webfont.svg │ │ ├── OpenSans-Light-webfont.woff │ │ ├── OpenSans-LightItalic-webfont.eot │ │ ├── OpenSans-LightItalic-webfont.svg │ │ ├── OpenSans-LightItalic-webfont.woff │ │ ├── OpenSans-Regular-webfont.eot │ │ ├── OpenSans-Regular-webfont.svg │ │ └── OpenSans-Regular-webfont.woff │ ├── index.html │ ├── rest.js.html │ ├── scripts │ │ ├── linenumber.js │ │ └── prettify │ │ │ ├── Apache-License-2.0.txt │ │ │ ├── lang-css.js │ │ │ └── prettify.js │ └── styles │ │ ├── jsdoc-default.css │ │ ├── prettify-jsdoc.css │ │ └── prettify-tomorrow.css ├── 1.1.1 │ ├── Element.html │ ├── Factory.html │ ├── Rest.html │ ├── Rest_Config.html │ ├── element.js.html │ ├── factory.js.html │ ├── fonts │ │ ├── OpenSans-Bold-webfont.eot │ │ ├── OpenSans-Bold-webfont.svg │ │ ├── OpenSans-Bold-webfont.woff │ │ ├── OpenSans-BoldItalic-webfont.eot │ │ ├── OpenSans-BoldItalic-webfont.svg │ │ ├── OpenSans-BoldItalic-webfont.woff │ │ ├── OpenSans-Italic-webfont.eot │ │ ├── OpenSans-Italic-webfont.svg │ │ ├── OpenSans-Italic-webfont.woff │ │ ├── OpenSans-Light-webfont.eot │ │ ├── OpenSans-Light-webfont.svg │ │ ├── OpenSans-Light-webfont.woff │ │ ├── OpenSans-LightItalic-webfont.eot │ │ ├── OpenSans-LightItalic-webfont.svg │ │ ├── OpenSans-LightItalic-webfont.woff │ │ ├── OpenSans-Regular-webfont.eot │ │ ├── OpenSans-Regular-webfont.svg │ │ └── OpenSans-Regular-webfont.woff │ ├── index.html │ ├── rest.js.html │ ├── scripts │ │ ├── linenumber.js │ │ └── prettify │ │ │ ├── Apache-License-2.0.txt │ │ │ ├── lang-css.js │ │ │ └── prettify.js │ └── styles │ │ ├── jsdoc-default.css │ │ ├── prettify-jsdoc.css │ │ └── prettify-tomorrow.css ├── CNAME ├── _config.yml ├── _layouts │ └── default.html ├── conf.json ├── images │ └── logo.png ├── index-old.html ├── index.md ├── latest │ ├── index.md │ └── index.template.md └── stylesheets │ ├── github-light.css │ ├── main.css │ ├── normalize.css │ └── stylesheet.css ├── package.json ├── scripts ├── build.sh └── release.sh ├── src ├── element.js ├── factory.js └── rest.js ├── test ├── config.js ├── config.local.js ├── data.js └── test.js └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | ### OSX ### 2 | *.DS_Store 3 | .AppleDouble 4 | .LSOverride 5 | 6 | # Icon must end with two \r 7 | Icon 8 | 9 | 10 | # Thumbnails 11 | ._* 12 | 13 | # Files that might appear in the root of a volume 14 | .DocumentRevisions-V100 15 | .fseventsd 16 | .Spotlight-V100 17 | .TemporaryItems 18 | .Trashes 19 | .VolumeIcon.icns 20 | .com.apple.timemachine.donotpresent 21 | 22 | # Directories potentially created on remote AFP share 23 | .AppleDB 24 | .AppleDesktop 25 | Network Trash Folder 26 | Temporary Items 27 | .apdisk 28 | 29 | ### Node ### 30 | # Logs 31 | logs 32 | *.log 33 | npm-debug.log* 34 | 35 | # Runtime data 36 | pids 37 | *.pid 38 | *.seed 39 | 40 | # Directory for instrumented libs generated by jscoverage/JSCover 41 | lib-cov 42 | 43 | # Coverage directory used by tools like istanbul 44 | coverage 45 | 46 | # nyc test coverage 47 | .nyc_output 48 | 49 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 50 | .grunts 51 | 52 | # node-waf configuration 53 | .lock-wscript 54 | 55 | # Compiled binary addons (http://nodejs.org/api/addons.html) 56 | build/Release 57 | 58 | # Dependency directories 59 | node_modules 60 | jspm_packages 61 | 62 | # Optional npm cache directory 63 | .npm 64 | 65 | # Optional REPL history 66 | .node_repl_history 67 | 68 | coverage -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | #CHANGELOG 2 | 3 | ## Unreleased 4 | 5 | ## 1.1.0 - 2017-02-15 6 | 7 | ### Fixed 8 | Fixed the elementTransformer not working correctly when passed a function 9 | 10 | ### Added 11 | Added the option for `Element.get()` to pass a route and/or params 12 | 13 | ## 1.1.0 - 2017-02-10 14 | 15 | ***BREAKING***: Added collection transformer as option for `Rest.factory` 16 | This change will break backwards compatibility for anything using `Rest.factory` as the method signature has changed. 17 | 18 | ### Added 19 | Added new default options to the config 20 | - Default parameters 21 | Added `xhr` parameter to response interceptors 22 | Added request interceptors 23 | Added `post` and `customPOST` on `Rest.factory` 24 | 25 | ### Fixed 26 | Fixes to the build script: 27 | - Already minified Babel polyfill is being added to the already minified dist file, rather than adding the polyfill and minifying both 28 | - Now correctly clears the dist folder 29 | 30 | ## 1.0.2 - 2016-08-31 31 | Updated to possibly work with Node. This will _not_ work without an `XMLHttpRequest` polyfill for Node 32 | 33 | ## 1.0.1 - 2016-06-14 34 | Fixed problem with only resolving 200s. Oops. 35 | Added test coverage for said status code problem. 36 | Now includes (optionally) polyfill and minified versions 37 | 38 | ## 1.0.0 - 2016-06-13 39 | Initial release 40 | 41 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Thanks for taking the time to contribute to this project. 4 | 5 | ## Bug Reports 6 | If you think you've found a bug, please first search [the issues list](https://github.com/daviesgeek/restjs/issues) before opening an issue. 7 | 8 | ### Writing A Bug Report 9 | 10 | If you haven't found an existing issue, take some time to follow some simple guidelines for writing the issue: 11 | 12 | - Use a **clear and descriptive title** for the issue. 13 | - If possible use [this Plunker **template**](http://plnkr.co/edit/s02mNeQfE8pLv07t4JJQ) to show the problem. Or, submit a failing unit test (Read about [how to run tests](https://github.com/daviesgeek/restjs/blob/master/README.md#tests)). 14 | - **Describe** how you encountered the bug with as much detail as possible. For instance, make sure you include OS and browser versions, as well as code snippets to demonstrate the issue. 15 | 16 | ## Pull Requests 17 | 18 | If you'd like to submit a pull request, there are a couple more things to add: 19 | 20 | - All changes not in a release will be made on [the `dev` branch](https://github.com/daviesgeek/restjs/tree/dev) 21 | - Please make sure you update surrounding comments in the code you changed. All comments are written in [JSDoc](http://usejsdoc.org/) format. PRs will not be merged in without valid JSDoc comments (run `npm run docs` to confirm & to rebuild the docs). 22 | - Please add a note under "Unreleased" in [CHANGELOG.md](https://github.com/daviesgeek/restjs/blob/master/CHANGELOG.md) to note your changes (see the comments in the changelog for more details) 23 | - Make sure unit tests aren't failing. 24 | - If you added functionality, please add test coverage to verify the expected behavior of new features. 25 | - Don't update the dist folder in your PR. Leave that for the release stage 26 | - Add yourself to CONTRIBUTORS.md 27 | 28 | ### Coding Conventions 29 | 30 | - Run `npm run lint` to lint your code. 31 | - No trailing whitespace. 32 | - Indent using two spaces (not tabs; soft tabs). 33 | - Always have a space before an opening bracket: 34 | 35 | ```js 36 | if(thing == true){} // Not like this 37 | 38 | if(thing == true) { // Like this! 39 | // Thing is true! Woohoo!! 40 | } 41 | 42 | for(var key in object) { // and this! 43 | // Monkey, donkey, pinkey, hockey, turkey…oh wait, not those kinds of keys? 44 | } 45 | ``` 46 | 47 | - Similarly, always put a space between operators: 48 | 49 | ```js 50 | 51 | // Nasty! 52 | let sum = 1+foo+bar+73 53 | 54 | // Much better! 55 | let sum = 1 + foo + bar + 72 56 | ``` 57 | 58 | - Omit brackets on single line-if statements for cleaner code: 59 | 60 | ```js 61 | if(thing == true) 62 | console.log('thing is true!') 63 | else 64 | console.log('thing is false!') 65 | 66 | ``` 67 | 68 | - No need to elimate commas in lists: 69 | 70 | ```js 71 | 72 | let doctors = { 73 | "Capaldi": "Peter", 74 | "Smith": "Matt", 75 | "Tennant": "David", 76 | "Eccleston": "Christopher", // leave the trailing comma here; 77 | // it makes it easier to rearrange lists, and you don't have to worry about adding or removing the comma! 78 | } 79 | 80 | ``` -------------------------------------------------------------------------------- /CONTRIBUTORS.md: -------------------------------------------------------------------------------- 1 | # Contributions to RestJS 2 | 3 | ## Creator & Maintainer 4 | - Matthew Davies (https://daviesgeek.com) 5 | 6 | ## Contributors 7 | 8 | (in chronological order) 9 | 10 | No one yet. :cry: Submit a pull request so this list fills up! 11 | 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Matthew Davies 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | # Status 2 | ***READY/IN DEVELOPMENT/HOLD*** 3 | 4 | ### Description 5 | A few lines detailing the changes made and a summary of the PR's goal 6 | 7 | ## Related Issues and Branches 8 | 9 | (If needed) list related issues, branches or other PRs here 10 | 11 | ## Todos: 12 | 13 | - [ ] Update comments 14 | - [ ] Pass tests 15 | - [ ] Write new tests (if necessary) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RestJS 2 | 3 | [![CircleCI](https://circleci.com/gh/daviesgeek/restjs/tree/master.svg?style=svg)](https://circleci.com/gh/daviesgeek/restjs/tree/master) 4 | 5 | [![Sauce Labs Build Status](https://saucelabs.com/buildstatus/restjs)](https://saucelabs.com/beta/builds/a8c23c04d25448f2b4098bb6d2ca75d8) 6 | 7 | 8 | RestJS is somewhat based off [Restangular](https://github.com/mgonto/restangular). It is an “ORM” style library for consuming REST APIs on the frontend. 9 | 10 | This is very much still a 1.0 version, so expect breaking changes and feature updates. It's also only really been tested in Chrome on OS X and PhantomJS, so it definitely needs more browser testing. 11 | 12 | If you'd like, fill out [this form](http://goo.gl/forms/K3noZAe0MX1j8OjT2) to receive an invite to Slack. 13 | 14 | ## Installing 15 | 16 | Install using [Bower](http://bower.io): 17 | 18 | ```js 19 | bower install restjs 20 | ``` 21 | 22 | By default, the non-minified, non-polyfill version is set as [the `main` property](https://github.com/bower/spec/blob/master/json.md#main) for the Bower package. The polyfill version includes [the Babel polyfill](https://babeljs.io/docs/usage/polyfill/) in the source. Depending on what you're doing, you might need the polyfill to be included. Here's a quick example of how to use the polyfill version instead: 23 | 24 | ```js 25 | { 26 | "overrides": { 27 | "restjs": { 28 | "main": [ 29 | "dist/rest.polyfill.js" 30 | ] 31 | } 32 | } 33 | } 34 | ``` 35 | 36 | Other options include the minified version ([`dist/rest.min.js`](https://github.com/daviesgeek/restjs/blob/master/dist/rest.min.js)), the Node version ([`dist/rest.node.js`](https://github.com/daviesgeek/restjs/blob/master/dist/rest.min.js): includes an export statement for ES6 modules), and the polyfill & minified version ([`dist/rest.polyfill.min.js`](https://github.com/daviesgeek/restjs/blob/master/dist/rest.polyfill.min.js)) 37 | 38 | ## Usage 39 | 40 | ### The 10 second version 41 | 42 | ```js 43 | 44 | // Create a model factory 45 | let Doctor = Rest.factory('doctors') 46 | 47 | // Create a new element, passing in the object as the first argument 48 | let doctor = Doctor.create({id: 11, first: "Matt", last: "Smith"}) 49 | 50 | // Save it! 51 | doctor.post() 52 | 53 | // Update something 54 | doctor.name = "Matthew" 55 | doctor.patch() 56 | 57 | // Get a list of users 58 | Doctor.getList().then(function(doctors) { 59 | // Do something with the array 60 | }) 61 | ``` 62 | 63 | ### Config 64 | 65 | Configuration can be set using `Rest.Config.set()`: 66 | 67 | ```js 68 | Rest.Config.set({baseUrl: 'https://restjs.js.org'}) 69 | ``` 70 | ##### `baseUrl`: String 71 | The base URL for requests. I.e, if the `baseUrl` is set to `http://google.com`, all requests will be prefixed with `http://google.com` 72 | 73 | ##### `defaultParams`: Object 74 | The default parameters for requests. Can be overriden by specific requests 75 | 76 | ##### `fields`: Object 77 | Custom fields that RestJS uses to pick up on properties needed. 78 | 79 | ######      `id`: String 80 |      The property that RestJS should use as the id. This will be used for subsequent requests, such as DELETE, PUT or PATCH requests: `//` 81 | 82 | ##### `headers`: String[String[]] 83 | An array of headers to send for the request. The headers must be an array, with each element containing an array, with the first element being the header name and the second the header value. 84 | 85 | ```js 86 | 87 | Rest.Config.set( 88 | { 89 | headers: [ 90 | ['X-Requested-With': 'RestJ'] 91 | ] 92 | } 93 | ) 94 | 95 | ``` 96 | 97 | See [`XMLHttpRequest.setRequestHeader()`](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/setRequestHeader) 98 | 99 | ##### `responseType`: String 100 | The type of the response. See [`XMLHttpRequest.responseType`](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseType) 101 | 102 | ##### `timeout`: Integer 103 | The timeout setting for XHR requests. See [`XMLHttpRequest.timeout`](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/timeout) 104 | 105 | ##### `withCredentials`: Boolean 106 | whether to send CORS credentials with the request or not. See [`XMLHttpRequest.withCredentials`](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials) 107 | 108 | ## Development 109 | 110 | Run `npm install` to install all the build tools. `src/rest.js` contains all the source code. Run `npm run build` to run [Babel](https://babeljs.io/) to compile for the browser. 111 | 112 | ### Tests 113 | 114 | RestJS uses [Karma](https://karma-runner.github.io), [Mocha](https://mochajs.org/), and [Chai](http://chaijs.com/) for running tests. 115 | Run local tests with `npm run unit`. Running `npm run test` will first lint the files, then run all the tests on Sauce Labs using [karma-sauce-launcher](https://github.com/karma-runner/karma-sauce-launcher). 116 | 117 | ### Docs 118 | 119 | All docs are written using the [JSDoc](http://usejsdoc.org/) syntax. 120 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "restjs", 3 | "description": "An 'ORM' style library for consuming RESTful APIs on the frontend", 4 | "main": "dist/rest.js", 5 | "authors": [ 6 | "Matthew Davies (http://daviesgeek.com)" 7 | ], 8 | "license": "MIT", 9 | "keywords": [ 10 | "orm", 11 | "rest" 12 | ], 13 | "moduleType": [ 14 | "amd", 15 | "es6", 16 | "globals", 17 | "node", 18 | "yui" 19 | ], 20 | "homepage": "http://github.com/daviesgeek/restjs", 21 | "ignore": [ 22 | "**/.*", 23 | "node_modules", 24 | "bower_components", 25 | "test", 26 | "tests" 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /dist/rest.min.js: -------------------------------------------------------------------------------- 1 | "use strict";var _typeof=typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol==="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};var Element={};Element.get=function(){var e=_typeof(arguments[0])==="object"?arguments[0]:arguments[1]||{};var t=typeof arguments[0]==="string"?arguments[0]:null;var n=this.route+("/"+this[this.config.fields.id]);if(t){n+="/"+t}return Rest._makeRequest(this.config,"GET",n,e,this.factory,null)};Element.post=function(e){return Rest._makeRequest(this.config,"POST",this.route+(this.fromServer?"/"+this[this.config.fields.id]:""),e,this.factory,this)};Element.patch=function(){var e=Rest._findBodyAndParams(arguments,this),t=e.body,n=e.params;return Rest._makeRequest(this.config,"PATCH",this.route+("/"+this[this.config.fields.id]),n,this.factory,t)};Element.put=function(e){return Rest._makeRequest(this.config,"PUT",this.route+("/"+this[this.config.fields.id]),e,this.factory,this)};var Factory=function e(){};Factory.create=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var n=Object.create(Element,{route:{configurable:false,enumerable:false,value:this.route},fromServer:{configurable:true,enumerable:false,value:t},config:{configurable:false,enumerable:false,value:this.config},factory:{configurable:false,enumerable:false,value:this}});var r=_typeof(this.elementTransformer)=="object"?this.elementTransformer:{};Object.assign(n,e,r);if(typeof this.elementTransformer=="function")n=this.elementTransformer(n);return n};Factory.getList=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};return Rest._makeRequest(this.config,"GET",this.route,e,this,null)};Factory.get=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};return Rest._makeRequest(this.config,"GET",this.route+("/"+e),t,this,null)};Factory.post=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};return Rest._makeRequest(this.config,"POST",this.route,t,this,e)};Factory.customPOST=function(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:"";var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};return Rest._makeRequest(this.config,"POST",this.route+("/"+e),n,this,t)};"use strict";var Rest={};Rest.Config={baseUrl:"",defaultParams:{},fields:{id:"id"},headers:[],responseType:"json"};Rest.Config.set=function(e){Object.assign(Rest.Config,e)};Rest._responseInterceptors=[];Rest.addResponseInterceptor=function(e){Rest._responseInterceptors.push(e)};Rest._responseExtractors=[];Rest.addResponseExtractor=function(e){Rest._responseExtractors.push(e)};Rest._requestInterceptors=[];Rest.addRequestInterceptor=function(e){Rest._requestInterceptors.push(e)};Rest.factory=function(e,t,n,r){var s=arguments.length>4&&arguments[4]!==undefined?arguments[4]:null;var o=Object.create(Factory,{route:{configurable:false,enumerable:false,value:e.replace(/^\/|\/$/g,"")},config:{configurable:false,enumerable:false,value:s||Rest.Config},elementTransformer:{configurable:false,enumerable:false,value:n},collectionTransformer:{configurable:false,enumerable:false,value:r}});var i=(typeof t==="undefined"?"undefined":_typeof(t))=="object"?t:{};Object.assign(o,i);if(typeof t=="function")o=t(o);return o};Rest._makeRequest=function(e,t,n){var r=arguments.length>3&&arguments[3]!==undefined?arguments[3]:{};var s=arguments[4];var o=arguments[5];var i=new Promise(function(i,a){var f=new XMLHttpRequest;if("timeout"in e)f.timeout=e.timeout;f.withCredentials=e.withCredentials;f.responseType=e.responseType;f.onreadystatechange=function(){var t=f.response;if(f.readyState==XMLHttpRequest.DONE){Rest._responseInterceptors.forEach(function(e){e(t,f.responseType,n,f.responseURL,a,f)});Rest._responseExtractors.forEach(function(e){t=e(t)});if(f.status<200||f.status>299)return a({data:t,xhr:f});if(t&&Object.keys(t).length)i(Rest._restify(t,s,e));else i(null)}};r=Object.assign({},Rest.Config.defaultParams,r);var u={route:n,params:r,body:o};Rest._requestInterceptors.forEach(function(e){u=e(u,f)});f.open(t,Rest._createUrl(u.route,u.params),true);f.setRequestHeader("Content-type","application/json");e.headers.forEach(function(e){f.setRequestHeader(e[0],e[1])});if(u.body&&f.responseType=="json")return f.send(JSON.stringify(u.body));else if(u.body)return f.send(u.body);else return f.send()});return i};Rest._createUrl=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var n=Rest.Config.baseUrl.replace(/\/+$/,"");var r=Object.keys(t).reduce(function(e,n){e.push(n+"="+encodeURIComponent(t[n]));return e},[]).join("&");return n+"/"+e+(r?"?"+r:"")};Rest._restify=function(e,t,n){if(Array.isArray(e)){if(typeof t.collectionTransformer=="function")t.collectionTransformer(e);var r=e.reduce(function(e,r){e.push(Rest._restify(r,t,n));return e},[]);if(_typeof(t.collectionTransformer)=="object")Object.assign(r,t.collectionTransformer);return r}return t.create.call(t,e,true)};Rest._findBodyAndParams=function(e,t){var n={},r=void 0;if(e[0]instanceof Array){e[0].forEach(function(e){n[e]=t[e]});r=e[1]||{}}else if(_typeof(e[0])=="object"){n=e[0];r=e[1]||{}}else if(typeof e[0]=="string"){for(var s=0;s 2 | 3 | 4 | 5 | JSDoc: Class: Config 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Class: Config

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 |
30 | 31 |

32 | Rest#Config

33 | 34 | 35 |
36 | 37 |
38 |
39 | 40 | 41 | 42 | 43 | 44 |

new Config()

45 | 46 | 47 | 48 | 49 | 50 |
51 |

The default configuration options

52 |
53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 |
Properties:
67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 105 | 106 | 107 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 134 | 135 | 136 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 163 | 164 | 165 | 170 | 171 | 172 | 173 | 174 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 240 | 241 | 242 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 269 | 270 | 271 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 298 | 299 | 300 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 329 | 330 | 331 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 |
NameTypeAttributesDescription
baseUrl 98 | 99 | 100 | String 101 | 102 | 103 | 104 | 108 | 109 | 110 | 111 |

The base URL for requests. I.e, if the baseUrl is set to http://google.com, all requests will be prefixed with http://google.com

defaultParams 127 | 128 | 129 | Object 130 | 131 | 132 | 133 | 137 | 138 | 139 | 140 |

The default parameters for requests. Can be overriden by specific requests

fields 156 | 157 | 158 | Object 159 | 160 | 161 | 162 | 166 | 167 | 168 | 169 |

The special fields used to determine url (and later, header) information

175 |
Properties
176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 |
NameTypeDescription
id 203 | 204 | 205 | Object 206 | 207 | 208 | 209 |

The property that RestJS should use as the id. This will be used for subsequent requests, such as DELETE, PUT or PATCH requests: <baseUrl>/<resource>/<id field>

221 | 222 |
headers 233 | 234 | 235 | Array.<Array.<String>> 236 | 237 | 238 | 239 | 243 | 244 | 245 | 246 |

The default headers for requests, defaults to an empty array, expected elements: [String, String]

responseType 262 | 263 | 264 | String 265 | 266 | 267 | 268 | 272 | 273 | 274 | 275 |

The response type for the request. See the docs for XMLHttpRequest.responseType

timeout 291 | 292 | 293 | number 294 | 295 | 296 | 297 | 301 | 302 | <optional>
303 | 304 | 305 | 306 |

The XHR timeout. See the docs for XMLHttpRequest.timeout

withCredentials 322 | 323 | 324 | boolean 325 | 326 | 327 | 328 | 332 | 333 | <optional>
334 | 335 | 336 | 337 |

Whether to send CORS credentials with the request or not. See the docs for XMLHttpRequest.withCredentials

348 | 349 | 350 | 351 | 352 |
353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 |
Source:
380 |
383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 |
391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 |
409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 |

Methods

424 | 425 | 426 | 427 | 428 | 429 | 430 |

(static) Rest.Config.set(config)

431 | 432 | 433 | 434 | 435 | 436 |
437 |

Sets a given config to the configuration object

438 |
439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 |
Parameters:
449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 |
NameTypeDescription
config 477 | 478 | 479 | Object 480 | 481 | 482 | 483 |

The specified config

495 | 496 | 497 | 498 | 499 | 500 | 501 |
502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 |
Source:
529 |
532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 |
540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 |
Example
556 | 557 |
Rest.Config.set({baseUrl: 'https://restjs.js.org'})
558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 |
568 | 569 |
570 | 571 | 572 | 573 | 574 |
575 | 576 | 579 | 580 |
581 | 582 |
583 | Documentation generated by JSDoc 3.4.3 on Fri Feb 10 2017 14:19:07 GMT-0800 (PST) 584 |
585 | 586 | 587 | 588 | 589 | -------------------------------------------------------------------------------- /docs/1.1.0/fonts/OpenSans-Bold-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daviesgeek/restjs/9bbe8713a62f511920d64da796adf4e1a615cfb6/docs/1.1.0/fonts/OpenSans-Bold-webfont.eot -------------------------------------------------------------------------------- /docs/1.1.0/fonts/OpenSans-Bold-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daviesgeek/restjs/9bbe8713a62f511920d64da796adf4e1a615cfb6/docs/1.1.0/fonts/OpenSans-Bold-webfont.woff -------------------------------------------------------------------------------- /docs/1.1.0/fonts/OpenSans-BoldItalic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daviesgeek/restjs/9bbe8713a62f511920d64da796adf4e1a615cfb6/docs/1.1.0/fonts/OpenSans-BoldItalic-webfont.eot -------------------------------------------------------------------------------- /docs/1.1.0/fonts/OpenSans-BoldItalic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daviesgeek/restjs/9bbe8713a62f511920d64da796adf4e1a615cfb6/docs/1.1.0/fonts/OpenSans-BoldItalic-webfont.woff -------------------------------------------------------------------------------- /docs/1.1.0/fonts/OpenSans-Italic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daviesgeek/restjs/9bbe8713a62f511920d64da796adf4e1a615cfb6/docs/1.1.0/fonts/OpenSans-Italic-webfont.eot -------------------------------------------------------------------------------- /docs/1.1.0/fonts/OpenSans-Italic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daviesgeek/restjs/9bbe8713a62f511920d64da796adf4e1a615cfb6/docs/1.1.0/fonts/OpenSans-Italic-webfont.woff -------------------------------------------------------------------------------- /docs/1.1.0/fonts/OpenSans-Light-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daviesgeek/restjs/9bbe8713a62f511920d64da796adf4e1a615cfb6/docs/1.1.0/fonts/OpenSans-Light-webfont.eot -------------------------------------------------------------------------------- /docs/1.1.0/fonts/OpenSans-Light-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daviesgeek/restjs/9bbe8713a62f511920d64da796adf4e1a615cfb6/docs/1.1.0/fonts/OpenSans-Light-webfont.woff -------------------------------------------------------------------------------- /docs/1.1.0/fonts/OpenSans-LightItalic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daviesgeek/restjs/9bbe8713a62f511920d64da796adf4e1a615cfb6/docs/1.1.0/fonts/OpenSans-LightItalic-webfont.eot -------------------------------------------------------------------------------- /docs/1.1.0/fonts/OpenSans-LightItalic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daviesgeek/restjs/9bbe8713a62f511920d64da796adf4e1a615cfb6/docs/1.1.0/fonts/OpenSans-LightItalic-webfont.woff -------------------------------------------------------------------------------- /docs/1.1.0/fonts/OpenSans-Regular-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daviesgeek/restjs/9bbe8713a62f511920d64da796adf4e1a615cfb6/docs/1.1.0/fonts/OpenSans-Regular-webfont.eot -------------------------------------------------------------------------------- /docs/1.1.0/fonts/OpenSans-Regular-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daviesgeek/restjs/9bbe8713a62f511920d64da796adf4e1a615cfb6/docs/1.1.0/fonts/OpenSans-Regular-webfont.woff -------------------------------------------------------------------------------- /docs/1.1.0/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Home 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Home

21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |

restjs 1.1.0

30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 |
46 |

RestJS

CircleCI

47 |

Sauce Test Status

48 |

RestJS is somewhat based off Restangular. It is an “ORM” style library for consuming REST APIs on the frontend.

49 |

This is very much still a 1.0 version, so expect breaking changes and feature updates. It's also only really been tested in Chrome on OS X and PhantomJS, so it definitely needs more browser testing.

50 |

If you'd like, fill out this form to receive an invite to Slack.

51 |

Installing

Install using Bower:

52 |
bower install restjs

By default, the non-minified, non-polyfill version is set as the main property for the Bower package. The polyfill version includes the Babel polyfill in the source. Depending on what you're doing, you might need the polyfill to be included. Here's a quick example of how to use the polyfill version instead:

53 |
{
 54 |   "overrides": {
 55 |     "restjs": {
 56 |       "main": [
 57 |         "dist/rest.polyfill.js"
 58 |       ]
 59 |     }
 60 |   }
 61 | }

Other options include the minified version (dist/rest.min.js), the Node version (dist/rest.node.js: includes an export statement for ES6 modules), and the polyfill & minified version (dist/rest.polyfill.min.js)

62 |

Usage

The 10 second version


 63 | // Create a model factory
 64 | let Doctor = Rest.factory('doctors')
 65 | 
 66 | // Create a new element, passing in the object as the first argument
 67 | let doctor = Doctor.create({id: 11, first: "Matt", last: "Smith"})
 68 | 
 69 | // Save it!
 70 | doctor.post()
 71 | 
 72 | // Update something
 73 | doctor.name = "Matthew"
 74 | doctor.patch()
 75 | 
 76 | // Get a list of users
 77 | Doctor.getList().then(function(doctors) {
 78 |   // Do something with the array
 79 | })

Config

Configuration can be set using Rest.Config.set():

80 |
Rest.Config.set({baseUrl: 'https://restjs.js.org'})
baseUrl: String

The base URL for requests. I.e, if the baseUrl is set to http://google.com, all requests will be prefixed with http://google.com

81 |
defaultParams: Object

The default parameters for requests. Can be overriden by specific requests

82 |
fields: Object

Custom fields that RestJS uses to pick up on properties needed.

83 |
     id: String

     The property that RestJS should use as the id. This will be used for subsequent requests, such as DELETE, PUT or PATCH requests: <baseUrl>/<resource>/<id field>

84 |
headers: String[String[]]

An array of headers to send for the request. The headers must be an array, with each element containing an array, with the first element being the header name and the second the header value.

85 |

 86 | Rest.Config.set(
 87 |   {
 88 |     headers: [
 89 |       ['X-Requested-With': 'RestJ']
 90 |     ]
 91 |   }
 92 | )

See XMLHttpRequest.setRequestHeader()

93 |
responseType: String

The type of the response. See XMLHttpRequest.responseType

94 |
timeout: Integer

The timeout setting for XHR requests. See XMLHttpRequest.timeout

95 |
withCredentials: Boolean

whether to send CORS credentials with the request or not. See XMLHttpRequest.withCredentials

96 |

Development

Run npm install to install all the build tools. src/rest.js contains all the source code. Run npm run build to run Babel to compile for the browser.

97 |

Tests

RestJS uses Karma, Mocha, and Chai for running tests. 98 | Run local tests with npm run unit. Running npm run test will first lint the files, then run all the tests on Sauce Labs using karma-sauce-launcher.

99 |

Docs

All docs are written using the JSDoc syntax.

100 |
101 | 102 | 103 | 104 | 105 | 106 | 107 |
108 | 109 | 112 | 113 |
114 | 115 |
116 | Documentation generated by JSDoc 3.4.3 on Fri Feb 10 2017 14:19:07 GMT-0800 (PST) 117 |
118 | 119 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /docs/1.1.0/scripts/linenumber.js: -------------------------------------------------------------------------------- 1 | /*global document */ 2 | (function() { 3 | var source = document.getElementsByClassName('prettyprint source linenums'); 4 | var i = 0; 5 | var lineNumber = 0; 6 | var lineId; 7 | var lines; 8 | var totalLines; 9 | var anchorHash; 10 | 11 | if (source && source[0]) { 12 | anchorHash = document.location.hash.substring(1); 13 | lines = source[0].getElementsByTagName('li'); 14 | totalLines = lines.length; 15 | 16 | for (; i < totalLines; i++) { 17 | lineNumber++; 18 | lineId = 'line' + lineNumber; 19 | lines[i].id = lineId; 20 | if (lineId === anchorHash) { 21 | lines[i].className += ' selected'; 22 | } 23 | } 24 | } 25 | })(); 26 | -------------------------------------------------------------------------------- /docs/1.1.0/scripts/prettify/Apache-License-2.0.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /docs/1.1.0/scripts/prettify/lang-css.js: -------------------------------------------------------------------------------- 1 | PR.registerLangHandler(PR.createSimpleLexer([["pln",/^[\t\n\f\r ]+/,null," \t\r\n "]],[["str",/^"(?:[^\n\f\r"\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*"/,null],["str",/^'(?:[^\n\f\r'\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*'/,null],["lang-css-str",/^url\(([^"')]*)\)/i],["kwd",/^(?:url|rgb|!important|@import|@page|@media|@charset|inherit)(?=[^\w-]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*)\s*:/i],["com",/^\/\*[^*]*\*+(?:[^*/][^*]*\*+)*\//],["com", 2 | /^(?:<\!--|--\>)/],["lit",/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],["lit",/^#[\da-f]{3,6}/i],["pln",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i],["pun",/^[^\s\w"']+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[["kwd",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[["str",/^[^"')]+/]]),["css-str"]); 3 | -------------------------------------------------------------------------------- /docs/1.1.0/scripts/prettify/prettify.js: -------------------------------------------------------------------------------- 1 | var q=null;window.PR_SHOULD_USE_CONTINUATION=!0; 2 | (function(){function L(a){function m(a){var f=a.charCodeAt(0);if(f!==92)return f;var b=a.charAt(1);return(f=r[b])?f:"0"<=b&&b<="7"?parseInt(a.substring(1),8):b==="u"||b==="x"?parseInt(a.substring(2),16):a.charCodeAt(1)}function e(a){if(a<32)return(a<16?"\\x0":"\\x")+a.toString(16);a=String.fromCharCode(a);if(a==="\\"||a==="-"||a==="["||a==="]")a="\\"+a;return a}function h(a){for(var f=a.substring(1,a.length-1).match(/\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\[0-3][0-7]{0,2}|\\[0-7]{1,2}|\\[\S\s]|[^\\]/g),a= 3 | [],b=[],o=f[0]==="^",c=o?1:0,i=f.length;c122||(d<65||j>90||b.push([Math.max(65,j)|32,Math.min(d,90)|32]),d<97||j>122||b.push([Math.max(97,j)&-33,Math.min(d,122)&-33]))}}b.sort(function(a,f){return a[0]-f[0]||f[1]-a[1]});f=[];j=[NaN,NaN];for(c=0;ci[0]&&(i[1]+1>i[0]&&b.push("-"),b.push(e(i[1])));b.push("]");return b.join("")}function y(a){for(var f=a.source.match(/\[(?:[^\\\]]|\\[\S\s])*]|\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\\d+|\\[^\dux]|\(\?[!:=]|[()^]|[^()[\\^]+/g),b=f.length,d=[],c=0,i=0;c=2&&a==="["?f[c]=h(j):a!=="\\"&&(f[c]=j.replace(/[A-Za-z]/g,function(a){a=a.charCodeAt(0);return"["+String.fromCharCode(a&-33,a|32)+"]"}));return f.join("")}for(var t=0,s=!1,l=!1,p=0,d=a.length;p=5&&"lang-"===b.substring(0,5))&&!(o&&typeof o[1]==="string"))c=!1,b="src";c||(r[f]=b)}i=d;d+=f.length;if(c){c=o[1];var j=f.indexOf(c),k=j+c.length;o[2]&&(k=f.length-o[2].length,j=k-c.length);b=b.substring(5);B(l+i,f.substring(0,j),e,p);B(l+i+j,c,C(b,c),p);B(l+i+k,f.substring(k),e,p)}else p.push(l+i,b)}a.e=p}var h={},y;(function(){for(var e=a.concat(m), 9 | l=[],p={},d=0,g=e.length;d=0;)h[n.charAt(k)]=r;r=r[1];n=""+r;p.hasOwnProperty(n)||(l.push(r),p[n]=q)}l.push(/[\S\s]/);y=L(l)})();var t=m.length;return e}function u(a){var m=[],e=[];a.tripleQuotedStrings?m.push(["str",/^(?:'''(?:[^'\\]|\\[\S\s]|''?(?=[^']))*(?:'''|$)|"""(?:[^"\\]|\\[\S\s]|""?(?=[^"]))*(?:"""|$)|'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$))/,q,"'\""]):a.multiLineStrings?m.push(["str",/^(?:'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$)|`(?:[^\\`]|\\[\S\s])*(?:`|$))/, 10 | q,"'\"`"]):m.push(["str",/^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(?:"|$))/,q,"\"'"]);a.verbatimStrings&&e.push(["str",/^@"(?:[^"]|"")*(?:"|$)/,q]);var h=a.hashComments;h&&(a.cStyleComments?(h>1?m.push(["com",/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,q,"#"]):m.push(["com",/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\n\r]*)/,q,"#"]),e.push(["str",/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,q])):m.push(["com",/^#[^\n\r]*/, 11 | q,"#"]));a.cStyleComments&&(e.push(["com",/^\/\/[^\n\r]*/,q]),e.push(["com",/^\/\*[\S\s]*?(?:\*\/|$)/,q]));a.regexLiterals&&e.push(["lang-regex",/^(?:^^\.?|[!+-]|!=|!==|#|%|%=|&|&&|&&=|&=|\(|\*|\*=|\+=|,|-=|->|\/|\/=|:|::|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|[?@[^]|\^=|\^\^|\^\^=|{|\||\|=|\|\||\|\|=|~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\s*(\/(?=[^*/])(?:[^/[\\]|\\[\S\s]|\[(?:[^\\\]]|\\[\S\s])*(?:]|$))+\/)/]);(h=a.types)&&e.push(["typ",h]);a=(""+a.keywords).replace(/^ | $/g, 12 | "");a.length&&e.push(["kwd",RegExp("^(?:"+a.replace(/[\s,]+/g,"|")+")\\b"),q]);m.push(["pln",/^\s+/,q," \r\n\t\xa0"]);e.push(["lit",/^@[$_a-z][\w$@]*/i,q],["typ",/^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/,q],["pln",/^[$_a-z][\w$@]*/i,q],["lit",/^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i,q,"0123456789"],["pln",/^\\[\S\s]?/,q],["pun",/^.[^\s\w"-$'./@\\`]*/,q]);return x(m,e)}function D(a,m){function e(a){switch(a.nodeType){case 1:if(k.test(a.className))break;if("BR"===a.nodeName)h(a), 13 | a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)e(a);break;case 3:case 4:if(p){var b=a.nodeValue,d=b.match(t);if(d){var c=b.substring(0,d.index);a.nodeValue=c;(b=b.substring(d.index+d[0].length))&&a.parentNode.insertBefore(s.createTextNode(b),a.nextSibling);h(a);c||a.parentNode.removeChild(a)}}}}function h(a){function b(a,d){var e=d?a.cloneNode(!1):a,f=a.parentNode;if(f){var f=b(f,1),g=a.nextSibling;f.appendChild(e);for(var h=g;h;h=g)g=h.nextSibling,f.appendChild(h)}return e} 14 | for(;!a.nextSibling;)if(a=a.parentNode,!a)return;for(var a=b(a.nextSibling,0),e;(e=a.parentNode)&&e.nodeType===1;)a=e;d.push(a)}var k=/(?:^|\s)nocode(?:\s|$)/,t=/\r\n?|\n/,s=a.ownerDocument,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=s.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);for(l=s.createElement("LI");a.firstChild;)l.appendChild(a.firstChild);for(var d=[l],g=0;g=0;){var h=m[e];A.hasOwnProperty(h)?window.console&&console.warn("cannot override language handler %s",h):A[h]=a}}function C(a,m){if(!a||!A.hasOwnProperty(a))a=/^\s*=o&&(h+=2);e>=c&&(a+=2)}}catch(w){"console"in window&&console.log(w&&w.stack?w.stack:w)}}var v=["break,continue,do,else,for,if,return,while"],w=[[v,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"], 18 | "catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],F=[w,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"],G=[w,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"], 19 | H=[G,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"],w=[w,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"],I=[v,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"], 20 | J=[v,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"],v=[v,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"],K=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/,N=/\S/,O=u({keywords:[F,H,w,"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END"+ 21 | I,J,v],hashComments:!0,cStyleComments:!0,multiLineStrings:!0,regexLiterals:!0}),A={};k(O,["default-code"]);k(x([],[["pln",/^[^]*(?:>|$)/],["com",/^<\!--[\S\s]*?(?:--\>|$)/],["lang-",/^<\?([\S\s]+?)(?:\?>|$)/],["lang-",/^<%([\S\s]+?)(?:%>|$)/],["pun",/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\S\s]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\S\s]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\S\s]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]), 22 | ["default-markup","htm","html","mxml","xhtml","xml","xsl"]);k(x([["pln",/^\s+/,q," \t\r\n"],["atv",/^(?:"[^"]*"?|'[^']*'?)/,q,"\"'"]],[["tag",/^^<\/?[a-z](?:[\w-.:]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^\s"'>]*(?:[^\s"'/>]|\/(?=\s)))/],["pun",/^[/<->]+/],["lang-js",/^on\w+\s*=\s*"([^"]+)"/i],["lang-js",/^on\w+\s*=\s*'([^']+)'/i],["lang-js",/^on\w+\s*=\s*([^\s"'>]+)/i],["lang-css",/^style\s*=\s*"([^"]+)"/i],["lang-css",/^style\s*=\s*'([^']+)'/i],["lang-css", 23 | /^style\s*=\s*([^\s"'>]+)/i]]),["in.tag"]);k(x([],[["atv",/^[\S\s]+/]]),["uq.val"]);k(u({keywords:F,hashComments:!0,cStyleComments:!0,types:K}),["c","cc","cpp","cxx","cyc","m"]);k(u({keywords:"null,true,false"}),["json"]);k(u({keywords:H,hashComments:!0,cStyleComments:!0,verbatimStrings:!0,types:K}),["cs"]);k(u({keywords:G,cStyleComments:!0}),["java"]);k(u({keywords:v,hashComments:!0,multiLineStrings:!0}),["bsh","csh","sh"]);k(u({keywords:I,hashComments:!0,multiLineStrings:!0,tripleQuotedStrings:!0}), 24 | ["cv","py"]);k(u({keywords:"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["perl","pl","pm"]);k(u({keywords:J,hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["rb"]);k(u({keywords:w,cStyleComments:!0,regexLiterals:!0}),["js"]);k(u({keywords:"all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes", 25 | hashComments:3,cStyleComments:!0,multilineStrings:!0,tripleQuotedStrings:!0,regexLiterals:!0}),["coffee"]);k(x([],[["str",/^[\S\s]+/]]),["regex"]);window.prettyPrintOne=function(a,m,e){var h=document.createElement("PRE");h.innerHTML=a;e&&D(h,e);E({g:m,i:e,h:h});return h.innerHTML};window.prettyPrint=function(a){function m(){for(var e=window.PR_SHOULD_USE_CONTINUATION?l.now()+250:Infinity;p=0){var k=k.match(g),f,b;if(b= 26 | !k){b=n;for(var o=void 0,c=b.firstChild;c;c=c.nextSibling)var i=c.nodeType,o=i===1?o?b:c:i===3?N.test(c.nodeValue)?b:o:o;b=(f=o===b?void 0:o)&&"CODE"===f.tagName}b&&(k=f.className.match(g));k&&(k=k[1]);b=!1;for(o=n.parentNode;o;o=o.parentNode)if((o.tagName==="pre"||o.tagName==="code"||o.tagName==="xmp")&&o.className&&o.className.indexOf("prettyprint")>=0){b=!0;break}b||((b=(b=n.className.match(/\blinenums\b(?::(\d+))?/))?b[1]&&b[1].length?+b[1]:!0:!1)&&D(n,b),d={g:k,h:n,i:b},E(d))}}p th:last-child { border-right: 1px solid #ddd; } 220 | 221 | .ancestors { color: #999; } 222 | .ancestors a 223 | { 224 | color: #999 !important; 225 | text-decoration: none; 226 | } 227 | 228 | .clear 229 | { 230 | clear: both; 231 | } 232 | 233 | .important 234 | { 235 | font-weight: bold; 236 | color: #950B02; 237 | } 238 | 239 | .yes-def { 240 | text-indent: -1000px; 241 | } 242 | 243 | .type-signature { 244 | color: #aaa; 245 | } 246 | 247 | .name, .signature { 248 | font-family: Consolas, Monaco, 'Andale Mono', monospace; 249 | } 250 | 251 | .details { margin-top: 14px; border-left: 2px solid #DDD; } 252 | .details dt { width: 120px; float: left; padding-left: 10px; padding-top: 6px; } 253 | .details dd { margin-left: 70px; } 254 | .details ul { margin: 0; } 255 | .details ul { list-style-type: none; } 256 | .details li { margin-left: 30px; padding-top: 6px; } 257 | .details pre.prettyprint { margin: 0 } 258 | .details .object-value { padding-top: 0; } 259 | 260 | .description { 261 | margin-bottom: 1em; 262 | margin-top: 1em; 263 | } 264 | 265 | .code-caption 266 | { 267 | font-style: italic; 268 | font-size: 107%; 269 | margin: 0; 270 | } 271 | 272 | .prettyprint 273 | { 274 | border: 1px solid #ddd; 275 | width: 80%; 276 | overflow: auto; 277 | } 278 | 279 | .prettyprint.source { 280 | width: inherit; 281 | } 282 | 283 | .prettyprint code 284 | { 285 | font-size: 100%; 286 | line-height: 18px; 287 | display: block; 288 | padding: 4px 12px; 289 | margin: 0; 290 | background-color: #fff; 291 | color: #4D4E53; 292 | } 293 | 294 | .prettyprint code span.line 295 | { 296 | display: inline-block; 297 | } 298 | 299 | .prettyprint.linenums 300 | { 301 | padding-left: 70px; 302 | -webkit-user-select: none; 303 | -moz-user-select: none; 304 | -ms-user-select: none; 305 | user-select: none; 306 | } 307 | 308 | .prettyprint.linenums ol 309 | { 310 | padding-left: 0; 311 | } 312 | 313 | .prettyprint.linenums li 314 | { 315 | border-left: 3px #ddd solid; 316 | } 317 | 318 | .prettyprint.linenums li.selected, 319 | .prettyprint.linenums li.selected * 320 | { 321 | background-color: lightyellow; 322 | } 323 | 324 | .prettyprint.linenums li * 325 | { 326 | -webkit-user-select: text; 327 | -moz-user-select: text; 328 | -ms-user-select: text; 329 | user-select: text; 330 | } 331 | 332 | .params .name, .props .name, .name code { 333 | color: #4D4E53; 334 | font-family: Consolas, Monaco, 'Andale Mono', monospace; 335 | font-size: 100%; 336 | } 337 | 338 | .params td.description > p:first-child, 339 | .props td.description > p:first-child 340 | { 341 | margin-top: 0; 342 | padding-top: 0; 343 | } 344 | 345 | .params td.description > p:last-child, 346 | .props td.description > p:last-child 347 | { 348 | margin-bottom: 0; 349 | padding-bottom: 0; 350 | } 351 | 352 | .disabled { 353 | color: #454545; 354 | } 355 | -------------------------------------------------------------------------------- /docs/1.1.0/styles/prettify-jsdoc.css: -------------------------------------------------------------------------------- 1 | /* JSDoc prettify.js theme */ 2 | 3 | /* plain text */ 4 | .pln { 5 | color: #000000; 6 | font-weight: normal; 7 | font-style: normal; 8 | } 9 | 10 | /* string content */ 11 | .str { 12 | color: #006400; 13 | font-weight: normal; 14 | font-style: normal; 15 | } 16 | 17 | /* a keyword */ 18 | .kwd { 19 | color: #000000; 20 | font-weight: bold; 21 | font-style: normal; 22 | } 23 | 24 | /* a comment */ 25 | .com { 26 | font-weight: normal; 27 | font-style: italic; 28 | } 29 | 30 | /* a type name */ 31 | .typ { 32 | color: #000000; 33 | font-weight: normal; 34 | font-style: normal; 35 | } 36 | 37 | /* a literal value */ 38 | .lit { 39 | color: #006400; 40 | font-weight: normal; 41 | font-style: normal; 42 | } 43 | 44 | /* punctuation */ 45 | .pun { 46 | color: #000000; 47 | font-weight: bold; 48 | font-style: normal; 49 | } 50 | 51 | /* lisp open bracket */ 52 | .opn { 53 | color: #000000; 54 | font-weight: bold; 55 | font-style: normal; 56 | } 57 | 58 | /* lisp close bracket */ 59 | .clo { 60 | color: #000000; 61 | font-weight: bold; 62 | font-style: normal; 63 | } 64 | 65 | /* a markup tag name */ 66 | .tag { 67 | color: #006400; 68 | font-weight: normal; 69 | font-style: normal; 70 | } 71 | 72 | /* a markup attribute name */ 73 | .atn { 74 | color: #006400; 75 | font-weight: normal; 76 | font-style: normal; 77 | } 78 | 79 | /* a markup attribute value */ 80 | .atv { 81 | color: #006400; 82 | font-weight: normal; 83 | font-style: normal; 84 | } 85 | 86 | /* a declaration */ 87 | .dec { 88 | color: #000000; 89 | font-weight: bold; 90 | font-style: normal; 91 | } 92 | 93 | /* a variable name */ 94 | .var { 95 | color: #000000; 96 | font-weight: normal; 97 | font-style: normal; 98 | } 99 | 100 | /* a function name */ 101 | .fun { 102 | color: #000000; 103 | font-weight: bold; 104 | font-style: normal; 105 | } 106 | 107 | /* Specify class=linenums on a pre to get line numbering */ 108 | ol.linenums { 109 | margin-top: 0; 110 | margin-bottom: 0; 111 | } 112 | -------------------------------------------------------------------------------- /docs/1.1.0/styles/prettify-tomorrow.css: -------------------------------------------------------------------------------- 1 | /* Tomorrow Theme */ 2 | /* Original theme - https://github.com/chriskempson/tomorrow-theme */ 3 | /* Pretty printing styles. Used with prettify.js. */ 4 | /* SPAN elements with the classes below are added by prettyprint. */ 5 | /* plain text */ 6 | .pln { 7 | color: #4d4d4c; } 8 | 9 | @media screen { 10 | /* string content */ 11 | .str { 12 | color: #718c00; } 13 | 14 | /* a keyword */ 15 | .kwd { 16 | color: #8959a8; } 17 | 18 | /* a comment */ 19 | .com { 20 | color: #8e908c; } 21 | 22 | /* a type name */ 23 | .typ { 24 | color: #4271ae; } 25 | 26 | /* a literal value */ 27 | .lit { 28 | color: #f5871f; } 29 | 30 | /* punctuation */ 31 | .pun { 32 | color: #4d4d4c; } 33 | 34 | /* lisp open bracket */ 35 | .opn { 36 | color: #4d4d4c; } 37 | 38 | /* lisp close bracket */ 39 | .clo { 40 | color: #4d4d4c; } 41 | 42 | /* a markup tag name */ 43 | .tag { 44 | color: #c82829; } 45 | 46 | /* a markup attribute name */ 47 | .atn { 48 | color: #f5871f; } 49 | 50 | /* a markup attribute value */ 51 | .atv { 52 | color: #3e999f; } 53 | 54 | /* a declaration */ 55 | .dec { 56 | color: #f5871f; } 57 | 58 | /* a variable name */ 59 | .var { 60 | color: #c82829; } 61 | 62 | /* a function name */ 63 | .fun { 64 | color: #4271ae; } } 65 | /* Use higher contrast and text-weight for printable form. */ 66 | @media print, projection { 67 | .str { 68 | color: #060; } 69 | 70 | .kwd { 71 | color: #006; 72 | font-weight: bold; } 73 | 74 | .com { 75 | color: #600; 76 | font-style: italic; } 77 | 78 | .typ { 79 | color: #404; 80 | font-weight: bold; } 81 | 82 | .lit { 83 | color: #044; } 84 | 85 | .pun, .opn, .clo { 86 | color: #440; } 87 | 88 | .tag { 89 | color: #006; 90 | font-weight: bold; } 91 | 92 | .atn { 93 | color: #404; } 94 | 95 | .atv { 96 | color: #060; } } 97 | /* Style */ 98 | /* 99 | pre.prettyprint { 100 | background: white; 101 | font-family: Consolas, Monaco, 'Andale Mono', monospace; 102 | font-size: 12px; 103 | line-height: 1.5; 104 | border: 1px solid #ccc; 105 | padding: 10px; } 106 | */ 107 | 108 | /* Specify class=linenums on a pre to get line numbering */ 109 | ol.linenums { 110 | margin-top: 0; 111 | margin-bottom: 0; } 112 | 113 | /* IE indents via margin-left */ 114 | li.L0, 115 | li.L1, 116 | li.L2, 117 | li.L3, 118 | li.L4, 119 | li.L5, 120 | li.L6, 121 | li.L7, 122 | li.L8, 123 | li.L9 { 124 | /* */ } 125 | 126 | /* Alternate shading for lines */ 127 | li.L1, 128 | li.L3, 129 | li.L5, 130 | li.L7, 131 | li.L9 { 132 | /* */ } 133 | -------------------------------------------------------------------------------- /docs/1.1.1/Rest_Config.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Class: Config 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Class: Config

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 |
30 | 31 |

32 | Rest#Config

33 | 34 | 35 |
36 | 37 |
38 |
39 | 40 | 41 | 42 | 43 | 44 |

new Config()

45 | 46 | 47 | 48 | 49 | 50 |
51 |

The default configuration options

52 |
53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 |
Properties:
67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 105 | 106 | 107 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 134 | 135 | 136 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 163 | 164 | 165 | 170 | 171 | 172 | 173 | 174 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 240 | 241 | 242 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 269 | 270 | 271 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 298 | 299 | 300 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 329 | 330 | 331 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 |
NameTypeAttributesDescription
baseUrl 98 | 99 | 100 | String 101 | 102 | 103 | 104 | 108 | 109 | 110 | 111 |

The base URL for requests. I.e, if the baseUrl is set to http://google.com, all requests will be prefixed with http://google.com

defaultParams 127 | 128 | 129 | Object 130 | 131 | 132 | 133 | 137 | 138 | 139 | 140 |

The default parameters for requests. Can be overriden by specific requests

fields 156 | 157 | 158 | Object 159 | 160 | 161 | 162 | 166 | 167 | 168 | 169 |

The special fields used to determine url (and later, header) information

175 |
Properties
176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 |
NameTypeDescription
id 203 | 204 | 205 | Object 206 | 207 | 208 | 209 |

The property that RestJS should use as the id. This will be used for subsequent requests, such as DELETE, PUT or PATCH requests: <baseUrl>/<resource>/<id field>

221 | 222 |
headers 233 | 234 | 235 | Array.<Array.<String>> 236 | 237 | 238 | 239 | 243 | 244 | 245 | 246 |

The default headers for requests, defaults to an empty array, expected elements: [String, String]

responseType 262 | 263 | 264 | String 265 | 266 | 267 | 268 | 272 | 273 | 274 | 275 |

The response type for the request. See the docs for XMLHttpRequest.responseType

timeout 291 | 292 | 293 | number 294 | 295 | 296 | 297 | 301 | 302 | <optional>
303 | 304 | 305 | 306 |

The XHR timeout. See the docs for XMLHttpRequest.timeout

withCredentials 322 | 323 | 324 | boolean 325 | 326 | 327 | 328 | 332 | 333 | <optional>
334 | 335 | 336 | 337 |

Whether to send CORS credentials with the request or not. See the docs for XMLHttpRequest.withCredentials

348 | 349 | 350 | 351 | 352 |
353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 |
Source:
380 |
383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 |
391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 |
409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 |

Methods

424 | 425 | 426 | 427 | 428 | 429 | 430 |

(static) Rest.Config.set(config)

431 | 432 | 433 | 434 | 435 | 436 |
437 |

Sets a given config to the configuration object

438 |
439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 |
Parameters:
449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 |
NameTypeDescription
config 477 | 478 | 479 | Object 480 | 481 | 482 | 483 |

The specified config

495 | 496 | 497 | 498 | 499 | 500 | 501 |
502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 |
Source:
529 |
532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 |
540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 |
Example
556 | 557 |
Rest.Config.set({baseUrl: 'https://restjs.js.org'})
558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 |
568 | 569 |
570 | 571 | 572 | 573 | 574 |
575 | 576 | 579 | 580 |
581 | 582 |
583 | Documentation generated by JSDoc 3.4.3 on Wed Feb 15 2017 17:59:01 GMT-0800 (PST) 584 |
585 | 586 | 587 | 588 | 589 | -------------------------------------------------------------------------------- /docs/1.1.1/element.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Source: element.js 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Source: element.js

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 |
29 |
/**
 30 |  * The base element class
 31 |  *
 32 |  * @class Element
 33 |  */
 34 | let Element = {}
 35 | 
 36 | /**
 37 |  * Make a GET request
 38 |  * @param  {string|object} routeOrParams If it's a string, it's the route for the request, otherwise it's the params for the request
 39 |  * @return {Promise<Element>} A Promise that is resolved with an {@link Element}
 40 |  *
 41 |  * @example
 42 |  *
 43 |  * element.get({with: 'params'}).then(function(data) {
 44 |  *   // data is here, restified for further use
 45 |  * })
 46 |  *
 47 |  * element.get('route', {with: 'params'}).then(function(data) {
 48 |  *   // data is here, restified for further use
 49 |  * })
 50 |  *
 51 |  *
 52 |  * @name Element#get
 53 |  * @kind function
 54 |  */
 55 | Element.get = function() {
 56 |   let params = typeof arguments[0] === "object" ? arguments[0] : arguments[1] || {}
 57 |   let route = typeof arguments[0] === "string" ? arguments[0] : null
 58 | 
 59 |   let requestRoute = this.route + `/${this[this.config.fields.id]}`
 60 |   if(route) {
 61 |     requestRoute += "/" + route
 62 |   }
 63 | 
 64 |   return Rest._makeRequest(this.config, "GET", requestRoute, params, this.factory, null)
 65 | }
 66 | 
 67 | /**
 68 |  * Make a POST request, POSTing the serialized element
 69 |  * @param  {Object} params The URL parameters for the request
 70 |  * @return {Promise<Element>} A Promise that is resolved with an {@link Element}
 71 |  *
 72 |  * @example
 73 |  *
 74 |  * element.post({with: 'params'}).then(function(data) {
 75 |  *   // data is here, restified for further use
 76 |  * })
 77 |  *
 78 |  * @name Element#post
 79 |  * @kind function
 80 |  */
 81 | Element.post = function(params) {
 82 |   return Rest._makeRequest(this.config, "POST", this.route + (this.fromServer ? "/" + this[this.config.fields.id] : ""), params, this.factory, this)
 83 | }
 84 | 
 85 | /**
 86 |  * Make a PATCH request, PATCHing the body.<br/>
 87 |  * For more information on the format of the request, look at {@link Rest._findBodyAndParams}
 88 |  * @param  {Object} body   The body of the request
 89 |  * @param  {Object} params The URL parameters for the request
 90 |  * @return {Promise<Element>} A Promise that is resolved with an {@link Element}
 91 |  *
 92 |  * @example
 93 |  *
 94 |  * element.patch({name: "Matt Smith"}, {with: 'children'})
 95 |  * element.patch(['name'])
 96 |  * element.patch(['name'], {with: 'children'})
 97 |  * element.patch('name', 'season', {with: 'children'})
 98 |  * element.patch('name', 'season')
 99 |  *
100 |  * @see Rest._findBodyAndParams
101 |  * @name Element#patch
102 |  * @kind function
103 |  */
104 | Element.patch = function() {
105 |   let {body, params} = Rest._findBodyAndParams(arguments, this)
106 |   return Rest._makeRequest(this.config, "PATCH", this.route + `/${this[this.config.fields.id]}`, params, this.factory, body)
107 | }
108 | 
109 | /**
110 |  * Make a PUT request, PUTing the serialized element
111 |  * @param  {Object} params The URL parameters for the request
112 |  * @return {Promise<Element>} A Promise that is resolved with an {@link Element}
113 |  *
114 |  * @example
115 |  *
116 |  * element.put({with: 'params'}).then(function(data) {
117 |  *   // data is here, restified for further use
118 |  * })
119 |  *
120 |  * @name Element#put
121 |  * @kind function
122 |  */
123 | Element.put = function(params) {
124 |   return Rest._makeRequest(this.config, "PUT", this.route + `/${this[this.config.fields.id]}`, params, this.factory, this)
125 | }
126 | 
127 |
128 |
129 | 130 | 131 | 132 | 133 |
134 | 135 | 138 | 139 |
140 | 141 |
142 | Documentation generated by JSDoc 3.4.3 on Wed Feb 15 2017 17:59:01 GMT-0800 (PST) 143 |
144 | 145 | 146 | 147 | 148 | 149 | -------------------------------------------------------------------------------- /docs/1.1.1/factory.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Source: factory.js 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Source: factory.js

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 |
29 |
/**
 30 |  * The base factory class
 31 |  *
 32 |  * @class Factory
 33 |  */
 34 | let Factory = function() {}
 35 | 
 36 | /**
 37 |  * Creates an element
 38 |  * @param  {object}  element     The element to create
 39 |  * @param  {Boolean=} [fromServer=false] Whether this element is from the server or not
 40 |  * @return {Element}
 41 |  */
 42 | Factory.create = function(element, fromServer=false) {
 43 |   let instance = Object.create(Element, {
 44 | 
 45 |     /**
 46 |      * The route
 47 |      * @type {String}
 48 |      * @memberof Element
 49 |      * @instance
 50 |      */
 51 |     route: {
 52 |       configurable: false,
 53 |       enumerable: false,
 54 |       value: this.route
 55 |     },
 56 | 
 57 |     /**
 58 |      * Whether the element is from the server or not
 59 |      * @type {Boolean}
 60 |      * @memberOf Element
 61 |      * @instance
 62 |      */
 63 |     fromServer: {
 64 |       configurable: true,
 65 |       enumerable: false,
 66 |       value: fromServer
 67 |     },
 68 | 
 69 |     /**
 70 |      * The config object for the element
 71 |      * @type {Object}
 72 |      * @memberOf Element
 73 |      * @instance
 74 |      */
 75 |     config: {
 76 |       configurable: false,
 77 |       enumerable: false,
 78 |       value: this.config
 79 |     },
 80 | 
 81 |     /**
 82 |      * The Factory that created the element
 83 |      * @type {Factory}
 84 |      * @memberOf Element
 85 |      * @instance
 86 |      */
 87 |     factory: {
 88 |       configurable: false,
 89 |       enumerable: false,
 90 |       value: this
 91 |     }
 92 |   })
 93 | 
 94 |   let prototype = typeof this.elementTransformer == "object" ? this.elementTransformer : {}
 95 |   Object.assign(instance, element, prototype)
 96 | 
 97 |   if(typeof this.elementTransformer == "function")
 98 |     instance = this.elementTransformer(instance)
 99 | 
100 |   return instance
101 | }
102 | 
103 | /**
104 |  * Makes a request to the server for an array
105 |  * @param  {Object=} params={} The URL parameters for the request
106 |  * @return {Promise<xhr.response>} The request promise
107 |  */
108 | Factory.getList = function(params={}) {
109 |   return Rest._makeRequest(this.config, "GET", this.route, params, this, null)
110 | }
111 | 
112 | /**
113 |  * Make a get request for a given id
114 |  * @param  {Integer} id    The id of the element to fetch from the server
115 |  * @param  {Object=} params={} The URL parameters for the request
116 |  * @return {Promise<xhr.response>} The request promise
117 |  */
118 | Factory.get = function(id, params={}) {
119 |   return Rest._makeRequest(this.config, "GET", this.route + `/${id}`, params, this, null)
120 | }
121 | 
122 | /**
123 |  * Make a post request
124 |  * @param  {Object=} params={} The URL parameters for the request
125 |  * @param  {String=} route=    A custom route for the request
126 |  * @return {Promise<xhr.response>} The request promise
127 |  */
128 | Factory.post = function(body={}, params={}) {
129 |   return Rest._makeRequest(this.config, "POST", this.route, params, this, body)
130 | }
131 | 
132 | /**
133 |  * Make a post request
134 |  * @param  {Object=} params={} The URL parameters for the request
135 |  * @param  {String=} route=    A custom route for the request
136 |  * @return {Promise<xhr.response>} The request promise
137 |  */
138 | Factory.customPOST = function(route="", body={}, params={}) {
139 |   return Rest._makeRequest(this.config, "POST", this.route + `/${route}`, params, this, body)
140 | }
141 | 
142 |
143 |
144 | 145 | 146 | 147 | 148 |
149 | 150 | 153 | 154 |
155 | 156 |
157 | Documentation generated by JSDoc 3.4.3 on Wed Feb 15 2017 17:59:01 GMT-0800 (PST) 158 |
159 | 160 | 161 | 162 | 163 | 164 | -------------------------------------------------------------------------------- /docs/1.1.1/fonts/OpenSans-Bold-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daviesgeek/restjs/9bbe8713a62f511920d64da796adf4e1a615cfb6/docs/1.1.1/fonts/OpenSans-Bold-webfont.eot -------------------------------------------------------------------------------- /docs/1.1.1/fonts/OpenSans-Bold-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daviesgeek/restjs/9bbe8713a62f511920d64da796adf4e1a615cfb6/docs/1.1.1/fonts/OpenSans-Bold-webfont.woff -------------------------------------------------------------------------------- /docs/1.1.1/fonts/OpenSans-BoldItalic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daviesgeek/restjs/9bbe8713a62f511920d64da796adf4e1a615cfb6/docs/1.1.1/fonts/OpenSans-BoldItalic-webfont.eot -------------------------------------------------------------------------------- /docs/1.1.1/fonts/OpenSans-BoldItalic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daviesgeek/restjs/9bbe8713a62f511920d64da796adf4e1a615cfb6/docs/1.1.1/fonts/OpenSans-BoldItalic-webfont.woff -------------------------------------------------------------------------------- /docs/1.1.1/fonts/OpenSans-Italic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daviesgeek/restjs/9bbe8713a62f511920d64da796adf4e1a615cfb6/docs/1.1.1/fonts/OpenSans-Italic-webfont.eot -------------------------------------------------------------------------------- /docs/1.1.1/fonts/OpenSans-Italic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daviesgeek/restjs/9bbe8713a62f511920d64da796adf4e1a615cfb6/docs/1.1.1/fonts/OpenSans-Italic-webfont.woff -------------------------------------------------------------------------------- /docs/1.1.1/fonts/OpenSans-Light-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daviesgeek/restjs/9bbe8713a62f511920d64da796adf4e1a615cfb6/docs/1.1.1/fonts/OpenSans-Light-webfont.eot -------------------------------------------------------------------------------- /docs/1.1.1/fonts/OpenSans-Light-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daviesgeek/restjs/9bbe8713a62f511920d64da796adf4e1a615cfb6/docs/1.1.1/fonts/OpenSans-Light-webfont.woff -------------------------------------------------------------------------------- /docs/1.1.1/fonts/OpenSans-LightItalic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daviesgeek/restjs/9bbe8713a62f511920d64da796adf4e1a615cfb6/docs/1.1.1/fonts/OpenSans-LightItalic-webfont.eot -------------------------------------------------------------------------------- /docs/1.1.1/fonts/OpenSans-LightItalic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daviesgeek/restjs/9bbe8713a62f511920d64da796adf4e1a615cfb6/docs/1.1.1/fonts/OpenSans-LightItalic-webfont.woff -------------------------------------------------------------------------------- /docs/1.1.1/fonts/OpenSans-Regular-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daviesgeek/restjs/9bbe8713a62f511920d64da796adf4e1a615cfb6/docs/1.1.1/fonts/OpenSans-Regular-webfont.eot -------------------------------------------------------------------------------- /docs/1.1.1/fonts/OpenSans-Regular-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daviesgeek/restjs/9bbe8713a62f511920d64da796adf4e1a615cfb6/docs/1.1.1/fonts/OpenSans-Regular-webfont.woff -------------------------------------------------------------------------------- /docs/1.1.1/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Home 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Home

21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |

restjs 1.1.1

30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 |
46 |

RestJS

CircleCI

47 |

Sauce Test Status

48 |

RestJS is somewhat based off Restangular. It is an “ORM” style library for consuming REST APIs on the frontend.

49 |

This is very much still a 1.0 version, so expect breaking changes and feature updates. It's also only really been tested in Chrome on OS X and PhantomJS, so it definitely needs more browser testing.

50 |

If you'd like, fill out this form to receive an invite to Slack.

51 |

Installing

Install using Bower:

52 |
bower install restjs

By default, the non-minified, non-polyfill version is set as the main property for the Bower package. The polyfill version includes the Babel polyfill in the source. Depending on what you're doing, you might need the polyfill to be included. Here's a quick example of how to use the polyfill version instead:

53 |
{
 54 |   "overrides": {
 55 |     "restjs": {
 56 |       "main": [
 57 |         "dist/rest.polyfill.js"
 58 |       ]
 59 |     }
 60 |   }
 61 | }

Other options include the minified version (dist/rest.min.js), the Node version (dist/rest.node.js: includes an export statement for ES6 modules), and the polyfill & minified version (dist/rest.polyfill.min.js)

62 |

Usage

The 10 second version


 63 | // Create a model factory
 64 | let Doctor = Rest.factory('doctors')
 65 | 
 66 | // Create a new element, passing in the object as the first argument
 67 | let doctor = Doctor.create({id: 11, first: "Matt", last: "Smith"})
 68 | 
 69 | // Save it!
 70 | doctor.post()
 71 | 
 72 | // Update something
 73 | doctor.name = "Matthew"
 74 | doctor.patch()
 75 | 
 76 | // Get a list of users
 77 | Doctor.getList().then(function(doctors) {
 78 |   // Do something with the array
 79 | })

Config

Configuration can be set using Rest.Config.set():

80 |
Rest.Config.set({baseUrl: 'https://restjs.js.org'})
baseUrl: String

The base URL for requests. I.e, if the baseUrl is set to http://google.com, all requests will be prefixed with http://google.com

81 |
defaultParams: Object

The default parameters for requests. Can be overriden by specific requests

82 |
fields: Object

Custom fields that RestJS uses to pick up on properties needed.

83 |
     id: String

     The property that RestJS should use as the id. This will be used for subsequent requests, such as DELETE, PUT or PATCH requests: <baseUrl>/<resource>/<id field>

84 |
headers: String[String[]]

An array of headers to send for the request. The headers must be an array, with each element containing an array, with the first element being the header name and the second the header value.

85 |

 86 | Rest.Config.set(
 87 |   {
 88 |     headers: [
 89 |       ['X-Requested-With': 'RestJ']
 90 |     ]
 91 |   }
 92 | )

See XMLHttpRequest.setRequestHeader()

93 |
responseType: String

The type of the response. See XMLHttpRequest.responseType

94 |
timeout: Integer

The timeout setting for XHR requests. See XMLHttpRequest.timeout

95 |
withCredentials: Boolean

whether to send CORS credentials with the request or not. See XMLHttpRequest.withCredentials

96 |

Development

Run npm install to install all the build tools. src/rest.js contains all the source code. Run npm run build to run Babel to compile for the browser.

97 |

Tests

RestJS uses Karma, Mocha, and Chai for running tests. 98 | Run local tests with npm run unit. Running npm run test will first lint the files, then run all the tests on Sauce Labs using karma-sauce-launcher.

99 |

Docs

All docs are written using the JSDoc syntax.

100 |
101 | 102 | 103 | 104 | 105 | 106 | 107 |
108 | 109 | 112 | 113 |
114 | 115 |
116 | Documentation generated by JSDoc 3.4.3 on Wed Feb 15 2017 17:59:01 GMT-0800 (PST) 117 |
118 | 119 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /docs/1.1.1/scripts/linenumber.js: -------------------------------------------------------------------------------- 1 | /*global document */ 2 | (function() { 3 | var source = document.getElementsByClassName('prettyprint source linenums'); 4 | var i = 0; 5 | var lineNumber = 0; 6 | var lineId; 7 | var lines; 8 | var totalLines; 9 | var anchorHash; 10 | 11 | if (source && source[0]) { 12 | anchorHash = document.location.hash.substring(1); 13 | lines = source[0].getElementsByTagName('li'); 14 | totalLines = lines.length; 15 | 16 | for (; i < totalLines; i++) { 17 | lineNumber++; 18 | lineId = 'line' + lineNumber; 19 | lines[i].id = lineId; 20 | if (lineId === anchorHash) { 21 | lines[i].className += ' selected'; 22 | } 23 | } 24 | } 25 | })(); 26 | -------------------------------------------------------------------------------- /docs/1.1.1/scripts/prettify/Apache-License-2.0.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /docs/1.1.1/scripts/prettify/lang-css.js: -------------------------------------------------------------------------------- 1 | PR.registerLangHandler(PR.createSimpleLexer([["pln",/^[\t\n\f\r ]+/,null," \t\r\n "]],[["str",/^"(?:[^\n\f\r"\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*"/,null],["str",/^'(?:[^\n\f\r'\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*'/,null],["lang-css-str",/^url\(([^"')]*)\)/i],["kwd",/^(?:url|rgb|!important|@import|@page|@media|@charset|inherit)(?=[^\w-]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*)\s*:/i],["com",/^\/\*[^*]*\*+(?:[^*/][^*]*\*+)*\//],["com", 2 | /^(?:<\!--|--\>)/],["lit",/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],["lit",/^#[\da-f]{3,6}/i],["pln",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i],["pun",/^[^\s\w"']+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[["kwd",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[["str",/^[^"')]+/]]),["css-str"]); 3 | -------------------------------------------------------------------------------- /docs/1.1.1/scripts/prettify/prettify.js: -------------------------------------------------------------------------------- 1 | var q=null;window.PR_SHOULD_USE_CONTINUATION=!0; 2 | (function(){function L(a){function m(a){var f=a.charCodeAt(0);if(f!==92)return f;var b=a.charAt(1);return(f=r[b])?f:"0"<=b&&b<="7"?parseInt(a.substring(1),8):b==="u"||b==="x"?parseInt(a.substring(2),16):a.charCodeAt(1)}function e(a){if(a<32)return(a<16?"\\x0":"\\x")+a.toString(16);a=String.fromCharCode(a);if(a==="\\"||a==="-"||a==="["||a==="]")a="\\"+a;return a}function h(a){for(var f=a.substring(1,a.length-1).match(/\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\[0-3][0-7]{0,2}|\\[0-7]{1,2}|\\[\S\s]|[^\\]/g),a= 3 | [],b=[],o=f[0]==="^",c=o?1:0,i=f.length;c122||(d<65||j>90||b.push([Math.max(65,j)|32,Math.min(d,90)|32]),d<97||j>122||b.push([Math.max(97,j)&-33,Math.min(d,122)&-33]))}}b.sort(function(a,f){return a[0]-f[0]||f[1]-a[1]});f=[];j=[NaN,NaN];for(c=0;ci[0]&&(i[1]+1>i[0]&&b.push("-"),b.push(e(i[1])));b.push("]");return b.join("")}function y(a){for(var f=a.source.match(/\[(?:[^\\\]]|\\[\S\s])*]|\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\\d+|\\[^\dux]|\(\?[!:=]|[()^]|[^()[\\^]+/g),b=f.length,d=[],c=0,i=0;c=2&&a==="["?f[c]=h(j):a!=="\\"&&(f[c]=j.replace(/[A-Za-z]/g,function(a){a=a.charCodeAt(0);return"["+String.fromCharCode(a&-33,a|32)+"]"}));return f.join("")}for(var t=0,s=!1,l=!1,p=0,d=a.length;p=5&&"lang-"===b.substring(0,5))&&!(o&&typeof o[1]==="string"))c=!1,b="src";c||(r[f]=b)}i=d;d+=f.length;if(c){c=o[1];var j=f.indexOf(c),k=j+c.length;o[2]&&(k=f.length-o[2].length,j=k-c.length);b=b.substring(5);B(l+i,f.substring(0,j),e,p);B(l+i+j,c,C(b,c),p);B(l+i+k,f.substring(k),e,p)}else p.push(l+i,b)}a.e=p}var h={},y;(function(){for(var e=a.concat(m), 9 | l=[],p={},d=0,g=e.length;d=0;)h[n.charAt(k)]=r;r=r[1];n=""+r;p.hasOwnProperty(n)||(l.push(r),p[n]=q)}l.push(/[\S\s]/);y=L(l)})();var t=m.length;return e}function u(a){var m=[],e=[];a.tripleQuotedStrings?m.push(["str",/^(?:'''(?:[^'\\]|\\[\S\s]|''?(?=[^']))*(?:'''|$)|"""(?:[^"\\]|\\[\S\s]|""?(?=[^"]))*(?:"""|$)|'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$))/,q,"'\""]):a.multiLineStrings?m.push(["str",/^(?:'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$)|`(?:[^\\`]|\\[\S\s])*(?:`|$))/, 10 | q,"'\"`"]):m.push(["str",/^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(?:"|$))/,q,"\"'"]);a.verbatimStrings&&e.push(["str",/^@"(?:[^"]|"")*(?:"|$)/,q]);var h=a.hashComments;h&&(a.cStyleComments?(h>1?m.push(["com",/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,q,"#"]):m.push(["com",/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\n\r]*)/,q,"#"]),e.push(["str",/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,q])):m.push(["com",/^#[^\n\r]*/, 11 | q,"#"]));a.cStyleComments&&(e.push(["com",/^\/\/[^\n\r]*/,q]),e.push(["com",/^\/\*[\S\s]*?(?:\*\/|$)/,q]));a.regexLiterals&&e.push(["lang-regex",/^(?:^^\.?|[!+-]|!=|!==|#|%|%=|&|&&|&&=|&=|\(|\*|\*=|\+=|,|-=|->|\/|\/=|:|::|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|[?@[^]|\^=|\^\^|\^\^=|{|\||\|=|\|\||\|\|=|~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\s*(\/(?=[^*/])(?:[^/[\\]|\\[\S\s]|\[(?:[^\\\]]|\\[\S\s])*(?:]|$))+\/)/]);(h=a.types)&&e.push(["typ",h]);a=(""+a.keywords).replace(/^ | $/g, 12 | "");a.length&&e.push(["kwd",RegExp("^(?:"+a.replace(/[\s,]+/g,"|")+")\\b"),q]);m.push(["pln",/^\s+/,q," \r\n\t\xa0"]);e.push(["lit",/^@[$_a-z][\w$@]*/i,q],["typ",/^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/,q],["pln",/^[$_a-z][\w$@]*/i,q],["lit",/^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i,q,"0123456789"],["pln",/^\\[\S\s]?/,q],["pun",/^.[^\s\w"-$'./@\\`]*/,q]);return x(m,e)}function D(a,m){function e(a){switch(a.nodeType){case 1:if(k.test(a.className))break;if("BR"===a.nodeName)h(a), 13 | a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)e(a);break;case 3:case 4:if(p){var b=a.nodeValue,d=b.match(t);if(d){var c=b.substring(0,d.index);a.nodeValue=c;(b=b.substring(d.index+d[0].length))&&a.parentNode.insertBefore(s.createTextNode(b),a.nextSibling);h(a);c||a.parentNode.removeChild(a)}}}}function h(a){function b(a,d){var e=d?a.cloneNode(!1):a,f=a.parentNode;if(f){var f=b(f,1),g=a.nextSibling;f.appendChild(e);for(var h=g;h;h=g)g=h.nextSibling,f.appendChild(h)}return e} 14 | for(;!a.nextSibling;)if(a=a.parentNode,!a)return;for(var a=b(a.nextSibling,0),e;(e=a.parentNode)&&e.nodeType===1;)a=e;d.push(a)}var k=/(?:^|\s)nocode(?:\s|$)/,t=/\r\n?|\n/,s=a.ownerDocument,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=s.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);for(l=s.createElement("LI");a.firstChild;)l.appendChild(a.firstChild);for(var d=[l],g=0;g=0;){var h=m[e];A.hasOwnProperty(h)?window.console&&console.warn("cannot override language handler %s",h):A[h]=a}}function C(a,m){if(!a||!A.hasOwnProperty(a))a=/^\s*=o&&(h+=2);e>=c&&(a+=2)}}catch(w){"console"in window&&console.log(w&&w.stack?w.stack:w)}}var v=["break,continue,do,else,for,if,return,while"],w=[[v,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"], 18 | "catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],F=[w,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"],G=[w,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"], 19 | H=[G,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"],w=[w,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"],I=[v,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"], 20 | J=[v,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"],v=[v,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"],K=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/,N=/\S/,O=u({keywords:[F,H,w,"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END"+ 21 | I,J,v],hashComments:!0,cStyleComments:!0,multiLineStrings:!0,regexLiterals:!0}),A={};k(O,["default-code"]);k(x([],[["pln",/^[^]*(?:>|$)/],["com",/^<\!--[\S\s]*?(?:--\>|$)/],["lang-",/^<\?([\S\s]+?)(?:\?>|$)/],["lang-",/^<%([\S\s]+?)(?:%>|$)/],["pun",/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\S\s]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\S\s]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\S\s]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]), 22 | ["default-markup","htm","html","mxml","xhtml","xml","xsl"]);k(x([["pln",/^\s+/,q," \t\r\n"],["atv",/^(?:"[^"]*"?|'[^']*'?)/,q,"\"'"]],[["tag",/^^<\/?[a-z](?:[\w-.:]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^\s"'>]*(?:[^\s"'/>]|\/(?=\s)))/],["pun",/^[/<->]+/],["lang-js",/^on\w+\s*=\s*"([^"]+)"/i],["lang-js",/^on\w+\s*=\s*'([^']+)'/i],["lang-js",/^on\w+\s*=\s*([^\s"'>]+)/i],["lang-css",/^style\s*=\s*"([^"]+)"/i],["lang-css",/^style\s*=\s*'([^']+)'/i],["lang-css", 23 | /^style\s*=\s*([^\s"'>]+)/i]]),["in.tag"]);k(x([],[["atv",/^[\S\s]+/]]),["uq.val"]);k(u({keywords:F,hashComments:!0,cStyleComments:!0,types:K}),["c","cc","cpp","cxx","cyc","m"]);k(u({keywords:"null,true,false"}),["json"]);k(u({keywords:H,hashComments:!0,cStyleComments:!0,verbatimStrings:!0,types:K}),["cs"]);k(u({keywords:G,cStyleComments:!0}),["java"]);k(u({keywords:v,hashComments:!0,multiLineStrings:!0}),["bsh","csh","sh"]);k(u({keywords:I,hashComments:!0,multiLineStrings:!0,tripleQuotedStrings:!0}), 24 | ["cv","py"]);k(u({keywords:"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["perl","pl","pm"]);k(u({keywords:J,hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["rb"]);k(u({keywords:w,cStyleComments:!0,regexLiterals:!0}),["js"]);k(u({keywords:"all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes", 25 | hashComments:3,cStyleComments:!0,multilineStrings:!0,tripleQuotedStrings:!0,regexLiterals:!0}),["coffee"]);k(x([],[["str",/^[\S\s]+/]]),["regex"]);window.prettyPrintOne=function(a,m,e){var h=document.createElement("PRE");h.innerHTML=a;e&&D(h,e);E({g:m,i:e,h:h});return h.innerHTML};window.prettyPrint=function(a){function m(){for(var e=window.PR_SHOULD_USE_CONTINUATION?l.now()+250:Infinity;p=0){var k=k.match(g),f,b;if(b= 26 | !k){b=n;for(var o=void 0,c=b.firstChild;c;c=c.nextSibling)var i=c.nodeType,o=i===1?o?b:c:i===3?N.test(c.nodeValue)?b:o:o;b=(f=o===b?void 0:o)&&"CODE"===f.tagName}b&&(k=f.className.match(g));k&&(k=k[1]);b=!1;for(o=n.parentNode;o;o=o.parentNode)if((o.tagName==="pre"||o.tagName==="code"||o.tagName==="xmp")&&o.className&&o.className.indexOf("prettyprint")>=0){b=!0;break}b||((b=(b=n.className.match(/\blinenums\b(?::(\d+))?/))?b[1]&&b[1].length?+b[1]:!0:!1)&&D(n,b),d={g:k,h:n,i:b},E(d))}}p th:last-child { border-right: 1px solid #ddd; } 220 | 221 | .ancestors { color: #999; } 222 | .ancestors a 223 | { 224 | color: #999 !important; 225 | text-decoration: none; 226 | } 227 | 228 | .clear 229 | { 230 | clear: both; 231 | } 232 | 233 | .important 234 | { 235 | font-weight: bold; 236 | color: #950B02; 237 | } 238 | 239 | .yes-def { 240 | text-indent: -1000px; 241 | } 242 | 243 | .type-signature { 244 | color: #aaa; 245 | } 246 | 247 | .name, .signature { 248 | font-family: Consolas, Monaco, 'Andale Mono', monospace; 249 | } 250 | 251 | .details { margin-top: 14px; border-left: 2px solid #DDD; } 252 | .details dt { width: 120px; float: left; padding-left: 10px; padding-top: 6px; } 253 | .details dd { margin-left: 70px; } 254 | .details ul { margin: 0; } 255 | .details ul { list-style-type: none; } 256 | .details li { margin-left: 30px; padding-top: 6px; } 257 | .details pre.prettyprint { margin: 0 } 258 | .details .object-value { padding-top: 0; } 259 | 260 | .description { 261 | margin-bottom: 1em; 262 | margin-top: 1em; 263 | } 264 | 265 | .code-caption 266 | { 267 | font-style: italic; 268 | font-size: 107%; 269 | margin: 0; 270 | } 271 | 272 | .prettyprint 273 | { 274 | border: 1px solid #ddd; 275 | width: 80%; 276 | overflow: auto; 277 | } 278 | 279 | .prettyprint.source { 280 | width: inherit; 281 | } 282 | 283 | .prettyprint code 284 | { 285 | font-size: 100%; 286 | line-height: 18px; 287 | display: block; 288 | padding: 4px 12px; 289 | margin: 0; 290 | background-color: #fff; 291 | color: #4D4E53; 292 | } 293 | 294 | .prettyprint code span.line 295 | { 296 | display: inline-block; 297 | } 298 | 299 | .prettyprint.linenums 300 | { 301 | padding-left: 70px; 302 | -webkit-user-select: none; 303 | -moz-user-select: none; 304 | -ms-user-select: none; 305 | user-select: none; 306 | } 307 | 308 | .prettyprint.linenums ol 309 | { 310 | padding-left: 0; 311 | } 312 | 313 | .prettyprint.linenums li 314 | { 315 | border-left: 3px #ddd solid; 316 | } 317 | 318 | .prettyprint.linenums li.selected, 319 | .prettyprint.linenums li.selected * 320 | { 321 | background-color: lightyellow; 322 | } 323 | 324 | .prettyprint.linenums li * 325 | { 326 | -webkit-user-select: text; 327 | -moz-user-select: text; 328 | -ms-user-select: text; 329 | user-select: text; 330 | } 331 | 332 | .params .name, .props .name, .name code { 333 | color: #4D4E53; 334 | font-family: Consolas, Monaco, 'Andale Mono', monospace; 335 | font-size: 100%; 336 | } 337 | 338 | .params td.description > p:first-child, 339 | .props td.description > p:first-child 340 | { 341 | margin-top: 0; 342 | padding-top: 0; 343 | } 344 | 345 | .params td.description > p:last-child, 346 | .props td.description > p:last-child 347 | { 348 | margin-bottom: 0; 349 | padding-bottom: 0; 350 | } 351 | 352 | .disabled { 353 | color: #454545; 354 | } 355 | -------------------------------------------------------------------------------- /docs/1.1.1/styles/prettify-jsdoc.css: -------------------------------------------------------------------------------- 1 | /* JSDoc prettify.js theme */ 2 | 3 | /* plain text */ 4 | .pln { 5 | color: #000000; 6 | font-weight: normal; 7 | font-style: normal; 8 | } 9 | 10 | /* string content */ 11 | .str { 12 | color: #006400; 13 | font-weight: normal; 14 | font-style: normal; 15 | } 16 | 17 | /* a keyword */ 18 | .kwd { 19 | color: #000000; 20 | font-weight: bold; 21 | font-style: normal; 22 | } 23 | 24 | /* a comment */ 25 | .com { 26 | font-weight: normal; 27 | font-style: italic; 28 | } 29 | 30 | /* a type name */ 31 | .typ { 32 | color: #000000; 33 | font-weight: normal; 34 | font-style: normal; 35 | } 36 | 37 | /* a literal value */ 38 | .lit { 39 | color: #006400; 40 | font-weight: normal; 41 | font-style: normal; 42 | } 43 | 44 | /* punctuation */ 45 | .pun { 46 | color: #000000; 47 | font-weight: bold; 48 | font-style: normal; 49 | } 50 | 51 | /* lisp open bracket */ 52 | .opn { 53 | color: #000000; 54 | font-weight: bold; 55 | font-style: normal; 56 | } 57 | 58 | /* lisp close bracket */ 59 | .clo { 60 | color: #000000; 61 | font-weight: bold; 62 | font-style: normal; 63 | } 64 | 65 | /* a markup tag name */ 66 | .tag { 67 | color: #006400; 68 | font-weight: normal; 69 | font-style: normal; 70 | } 71 | 72 | /* a markup attribute name */ 73 | .atn { 74 | color: #006400; 75 | font-weight: normal; 76 | font-style: normal; 77 | } 78 | 79 | /* a markup attribute value */ 80 | .atv { 81 | color: #006400; 82 | font-weight: normal; 83 | font-style: normal; 84 | } 85 | 86 | /* a declaration */ 87 | .dec { 88 | color: #000000; 89 | font-weight: bold; 90 | font-style: normal; 91 | } 92 | 93 | /* a variable name */ 94 | .var { 95 | color: #000000; 96 | font-weight: normal; 97 | font-style: normal; 98 | } 99 | 100 | /* a function name */ 101 | .fun { 102 | color: #000000; 103 | font-weight: bold; 104 | font-style: normal; 105 | } 106 | 107 | /* Specify class=linenums on a pre to get line numbering */ 108 | ol.linenums { 109 | margin-top: 0; 110 | margin-bottom: 0; 111 | } 112 | -------------------------------------------------------------------------------- /docs/1.1.1/styles/prettify-tomorrow.css: -------------------------------------------------------------------------------- 1 | /* Tomorrow Theme */ 2 | /* Original theme - https://github.com/chriskempson/tomorrow-theme */ 3 | /* Pretty printing styles. Used with prettify.js. */ 4 | /* SPAN elements with the classes below are added by prettyprint. */ 5 | /* plain text */ 6 | .pln { 7 | color: #4d4d4c; } 8 | 9 | @media screen { 10 | /* string content */ 11 | .str { 12 | color: #718c00; } 13 | 14 | /* a keyword */ 15 | .kwd { 16 | color: #8959a8; } 17 | 18 | /* a comment */ 19 | .com { 20 | color: #8e908c; } 21 | 22 | /* a type name */ 23 | .typ { 24 | color: #4271ae; } 25 | 26 | /* a literal value */ 27 | .lit { 28 | color: #f5871f; } 29 | 30 | /* punctuation */ 31 | .pun { 32 | color: #4d4d4c; } 33 | 34 | /* lisp open bracket */ 35 | .opn { 36 | color: #4d4d4c; } 37 | 38 | /* lisp close bracket */ 39 | .clo { 40 | color: #4d4d4c; } 41 | 42 | /* a markup tag name */ 43 | .tag { 44 | color: #c82829; } 45 | 46 | /* a markup attribute name */ 47 | .atn { 48 | color: #f5871f; } 49 | 50 | /* a markup attribute value */ 51 | .atv { 52 | color: #3e999f; } 53 | 54 | /* a declaration */ 55 | .dec { 56 | color: #f5871f; } 57 | 58 | /* a variable name */ 59 | .var { 60 | color: #c82829; } 61 | 62 | /* a function name */ 63 | .fun { 64 | color: #4271ae; } } 65 | /* Use higher contrast and text-weight for printable form. */ 66 | @media print, projection { 67 | .str { 68 | color: #060; } 69 | 70 | .kwd { 71 | color: #006; 72 | font-weight: bold; } 73 | 74 | .com { 75 | color: #600; 76 | font-style: italic; } 77 | 78 | .typ { 79 | color: #404; 80 | font-weight: bold; } 81 | 82 | .lit { 83 | color: #044; } 84 | 85 | .pun, .opn, .clo { 86 | color: #440; } 87 | 88 | .tag { 89 | color: #006; 90 | font-weight: bold; } 91 | 92 | .atn { 93 | color: #404; } 94 | 95 | .atv { 96 | color: #060; } } 97 | /* Style */ 98 | /* 99 | pre.prettyprint { 100 | background: white; 101 | font-family: Consolas, Monaco, 'Andale Mono', monospace; 102 | font-size: 12px; 103 | line-height: 1.5; 104 | border: 1px solid #ccc; 105 | padding: 10px; } 106 | */ 107 | 108 | /* Specify class=linenums on a pre to get line numbering */ 109 | ol.linenums { 110 | margin-top: 0; 111 | margin-bottom: 0; } 112 | 113 | /* IE indents via margin-left */ 114 | li.L0, 115 | li.L1, 116 | li.L2, 117 | li.L3, 118 | li.L4, 119 | li.L5, 120 | li.L6, 121 | li.L7, 122 | li.L8, 123 | li.L9 { 124 | /* */ } 125 | 126 | /* Alternate shading for lines */ 127 | li.L1, 128 | li.L3, 129 | li.L5, 130 | li.L7, 131 | li.L9 { 132 | /* */ } 133 | -------------------------------------------------------------------------------- /docs/CNAME: -------------------------------------------------------------------------------- 1 | restjs.js.org 2 | -------------------------------------------------------------------------------- /docs/_config.yml: -------------------------------------------------------------------------------- 1 | name: "RestJS" 2 | exclude: 'docs/latest/index.template.md' -------------------------------------------------------------------------------- /docs/_layouts/default.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Restjs by daviesgeek 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 | RestJS logo 16 |
17 | 23 |
24 |
25 | {{ content }} 26 |
27 |
28 | 29 | -------------------------------------------------------------------------------- /docs/conf.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": ["plugins/markdown"], 3 | "source": { 4 | "include": ["package.json", "src", "README.md"] 5 | }, 6 | "private": true, 7 | "package": "package.json" 8 | } -------------------------------------------------------------------------------- /docs/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daviesgeek/restjs/9bbe8713a62f511920d64da796adf4e1a615cfb6/docs/images/logo.png -------------------------------------------------------------------------------- /docs/index-old.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Restjs by daviesgeek 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 | RestJS logo 16 |
17 | 22 |
23 |
24 |
25 |

RestJS

26 |

CircleCI

27 | 28 |

Sauce Test Status

29 |

An “ORM” style library for consuming REST APIs on the frontend. Inspired by Restangular, RestJS is an easy, semantic, and flexible library for all HTTP use in the browser.

30 |

This is very much still a 1.0 version, so expect breaking changes and feature updates. It's also only been used in Chrome on OS X and PhantomJS, so it definitely needs more browser testing.

31 | 32 |

If you'd like, fill out this form to receive an invite to Slack.

33 | 34 |

Installing

35 | 36 |

Install using Bower:

37 | 38 |
bower install restjs
39 | 40 |

By default, the non-minified, non-polyfill version is set as the main property for the Bower package. The polyfill version includes the Babel polyfill in the source. Depending on what you're doing, you might need the polyfill to be included. Here's a quick example of how to use the polyfill version instead:

41 | 42 |
{
43 |           "overrides": {
44 |             "restjs": {
45 |               "main": [
46 |                 "dist/rest.polyfill.js"
47 |               ]
48 |             }
49 |           }
50 |         }
51 | 52 |

53 | Usage

54 | 55 |

56 | The 10 second version

57 | 58 |
59 |         // Create a model factory
60 |         let Doctor = Rest.factory('doctors')
61 | 
62 |         // Create a new user, passing in the object as the first argument
63 |         let doctor = User.create({id: 11, first: "Matt", last: "Smith"})
64 | 
65 |         // Save it!
66 |         doctor.post()
67 | 
68 |         // Update something
69 |         doctor.name = "Matthew"
70 |         doctor.patch()
71 | 
72 |         // Get a list of users
73 |         Doctor.getList().then(function(doctors) {
74 |           // Do something with the array
75 |         })
76 |         
77 | 78 |

79 | Development

80 | 81 |

Run npm install to install all the build tools. src/rest.js contains all the source code. Run npm run build to run Babel to compile for the browser.

82 | 83 |

84 | Tests

85 | 86 |

RestJS uses Karma, Mocha, and Chai for running tests. 87 | Run local tests with npm run unit. Running npm run test will first lint the files, then run all the tests on Sauce Labs using karma-sauce-launcher.

88 | 89 |

90 | Docs

91 | 92 |

All docs are written using the JSDoc syntax.

93 |
94 |
95 |
96 | 97 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: default 3 | --- 4 | 5 | # RestJS 6 | 7 | [![CircleCI](https://circleci.com/gh/daviesgeek/restjs/tree/master.svg?style=svg)](https://circleci.com/gh/daviesgeek/restjs/tree/master) 8 | 9 | [![Sauce Test Status](https://saucelabs.com/browser-matrix/restjs.svg)](https://saucelabs.com/u/restjs) 10 | 11 | 12 | RestJS is somewhat based off [Restangular](https://github.com/mgonto/restangular). It is an “ORM” style library for consuming REST APIs on the frontend. 13 | 14 | This is very much still a 1.0 version, so expect breaking changes and feature updates. It's also only really been tested in Chrome on OS X and PhantomJS, so it definitely needs more browser testing. 15 | 16 | If you'd like, fill out [this form](http://goo.gl/forms/K3noZAe0MX1j8OjT2) to receive an invite to Slack. 17 | 18 | ## Installing 19 | 20 | Install using [Bower](http://bower.io): 21 | 22 | ```js 23 | bower install restjs 24 | ``` 25 | 26 | By default, the non-minified, non-polyfill version is set as [the `main` property](https://github.com/bower/spec/blob/master/json.md#main) for the Bower package. The polyfill version includes [the Babel polyfill](https://babeljs.io/docs/usage/polyfill/) in the source. Depending on what you're doing, you might need the polyfill to be included. Here's a quick example of how to use the polyfill version instead: 27 | 28 | ```js 29 | { 30 | "overrides": { 31 | "restjs": { 32 | "main": [ 33 | "dist/rest.polyfill.js" 34 | ] 35 | } 36 | } 37 | } 38 | ``` 39 | 40 | Other options include the minified version ([`dist/rest.min.js`](https://github.com/daviesgeek/restjs/blob/master/dist/rest.min.js)), the Node version ([`dist/rest.node.js`](https://github.com/daviesgeek/restjs/blob/master/dist/rest.min.js): includes an export statement for ES6 modules), and the polyfill & minified version ([`dist/rest.polyfill.min.js`](https://github.com/daviesgeek/restjs/blob/master/dist/rest.polyfill.min.js)) 41 | 42 | ## Usage 43 | 44 | ### The 10 second version 45 | 46 | ```js 47 | 48 | // Create a model factory 49 | let Doctor = Rest.factory('doctors') 50 | 51 | // Create a new element, passing in the object as the first argument 52 | let doctor = Doctor.create({id: 11, first: "Matt", last: "Smith"}) 53 | 54 | // Save it! 55 | doctor.post() 56 | 57 | // Update something 58 | doctor.name = "Matthew" 59 | doctor.patch() 60 | 61 | // Get a list of users 62 | Doctor.getList().then(function(doctors) { 63 | // Do something with the array 64 | }) 65 | ``` 66 | 67 | ### Config 68 | 69 | Configuration can be set using `Rest.Config.set()`: 70 | 71 | ```js 72 | Rest.Config.set({baseUrl: 'https://restjs.js.org'}) 73 | ``` 74 | ##### `baseUrl`: String 75 | The base URL for requests. I.e, if the `baseUrl` is set to `http://google.com`, all requests will be prefixed with `http://google.com` 76 | 77 | ##### `defaultParams`: Object 78 | The default parameters for requests. Can be overriden by specific requests 79 | 80 | ##### `fields`: Object 81 | Custom fields that RestJS uses to pick up on properties needed. 82 | 83 | ######      `id`: String 84 |      The property that RestJS should use as the id. This will be used for subsequent requests, such as DELETE, PUT or PATCH requests: `//` 85 | 86 | ##### `headers`: String[String[]] 87 | An array of headers to send for the request. The headers must be an array, with each element containing an array, with the first element being the header name and the second the header value. 88 | 89 | ```js 90 | 91 | Rest.Config.set( 92 | { 93 | headers: [ 94 | ['X-Requested-With': 'RestJ'] 95 | ] 96 | } 97 | ) 98 | 99 | ``` 100 | 101 | See [`XMLHttpRequest.setRequestHeader()`](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/setRequestHeader) 102 | 103 | ##### `responseType`: String 104 | The type of the response. See [`XMLHttpRequest.responseType`](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseType) 105 | 106 | ##### `timeout`: Integer 107 | The timeout setting for XHR requests. See [`XMLHttpRequest.timeout`](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/timeout) 108 | 109 | ##### `withCredentials`: Boolean 110 | whether to send CORS credentials with the request or not. See [`XMLHttpRequest.withCredentials`](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials) 111 | 112 | ## Development 113 | 114 | Run `npm install` to install all the build tools. `src/rest.js` contains all the source code. Run `npm run build` to run [Babel](https://babeljs.io/) to compile for the browser. 115 | 116 | ### Tests 117 | 118 | RestJS uses [Karma](https://karma-runner.github.io), [Mocha](https://mochajs.org/), and [Chai](http://chaijs.com/) for running tests. 119 | Run local tests with `npm run unit`. Running `npm run test` will first lint the files, then run all the tests on Sauce Labs using [karma-sauce-launcher](https://github.com/karma-runner/karma-sauce-launcher). 120 | 121 | ### Docs 122 | 123 | All docs are written using the [JSDoc](http://usejsdoc.org/) syntax. -------------------------------------------------------------------------------- /docs/latest/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: null 3 | --- 4 |

Redirecting...

5 | -------------------------------------------------------------------------------- /docs/latest/index.template.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: null 3 | --- 4 |

Redirecting...

-------------------------------------------------------------------------------- /docs/stylesheets/github-light.css: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2015 GitHub, Inc. 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | */ 25 | 26 | .pl-c /* comment */ { 27 | color: #969896; 28 | } 29 | 30 | .pl-c1 /* constant, markup.raw, meta.diff.header, meta.module-reference, meta.property-name, support, support.constant, support.variable, variable.other.constant */, 31 | .pl-s .pl-v /* string variable */ { 32 | color: #0086b3; 33 | } 34 | 35 | .pl-e /* entity */, 36 | .pl-en /* entity.name */ { 37 | color: #795da3; 38 | } 39 | 40 | .pl-s .pl-s1 /* string source */, 41 | .pl-smi /* storage.modifier.import, storage.modifier.package, storage.type.java, variable.other, variable.parameter.function */ { 42 | color: #333; 43 | } 44 | 45 | .pl-ent /* entity.name.tag */ { 46 | color: #63a35c; 47 | } 48 | 49 | .pl-k /* keyword, storage, storage.type */ { 50 | color: #a71d5d; 51 | } 52 | 53 | .pl-pds /* punctuation.definition.string, string.regexp.character-class */, 54 | .pl-s /* string */, 55 | .pl-s .pl-pse .pl-s1 /* string punctuation.section.embedded source */, 56 | .pl-sr /* string.regexp */, 57 | .pl-sr .pl-cce /* string.regexp constant.character.escape */, 58 | .pl-sr .pl-sra /* string.regexp string.regexp.arbitrary-repitition */, 59 | .pl-sr .pl-sre /* string.regexp source.ruby.embedded */ { 60 | color: #183691; 61 | } 62 | 63 | .pl-v /* variable */ { 64 | color: #ed6a43; 65 | } 66 | 67 | .pl-id /* invalid.deprecated */ { 68 | color: #b52a1d; 69 | } 70 | 71 | .pl-ii /* invalid.illegal */ { 72 | background-color: #b52a1d; 73 | color: #f8f8f8; 74 | } 75 | 76 | .pl-sr .pl-cce /* string.regexp constant.character.escape */ { 77 | color: #63a35c; 78 | font-weight: bold; 79 | } 80 | 81 | .pl-ml /* markup.list */ { 82 | color: #693a17; 83 | } 84 | 85 | .pl-mh /* markup.heading */, 86 | .pl-mh .pl-en /* markup.heading entity.name */, 87 | .pl-ms /* meta.separator */ { 88 | color: #1d3e81; 89 | font-weight: bold; 90 | } 91 | 92 | .pl-mq /* markup.quote */ { 93 | color: #008080; 94 | } 95 | 96 | .pl-mi /* markup.italic */ { 97 | color: #333; 98 | font-style: italic; 99 | } 100 | 101 | .pl-mb /* markup.bold */ { 102 | color: #333; 103 | font-weight: bold; 104 | } 105 | 106 | .pl-md /* markup.deleted, meta.diff.header.from-file */ { 107 | background-color: #ffecec; 108 | color: #bd2c00; 109 | } 110 | 111 | .pl-mi1 /* markup.inserted, meta.diff.header.to-file */ { 112 | background-color: #eaffea; 113 | color: #55a532; 114 | } 115 | 116 | .pl-mdr /* meta.diff.range */ { 117 | color: #795da3; 118 | font-weight: bold; 119 | } 120 | 121 | .pl-mo /* meta.output */ { 122 | color: #1d3e81; 123 | } 124 | 125 | -------------------------------------------------------------------------------- /docs/stylesheets/main.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding: 0; 3 | margin: 0; 4 | font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; 5 | font-size: 16px; 6 | line-height: 1.5; 7 | color: #606c71; 8 | } 9 | header { 10 | padding: 5rem 6rem; 11 | background-color: #159957; 12 | background-image: linear-gradient(120deg, #EDEAD8, #AFCAC1); 13 | height: 100%; 14 | width: 100%; 15 | text-align: center; 16 | } 17 | header img { 18 | width: 45rem; 19 | max-width: 100%; 20 | margin-bottom: 1rem; 21 | } 22 | .btn { 23 | margin-bottom: 1rem; 24 | color: rgba(90,91,101, 0.7); 25 | background-color: rgba(237,234,216, 0.08); 26 | border-color: rgba(90,91,101, 0.2); 27 | border-style: solid; 28 | border-width: 1px; 29 | border-radius: 0.3rem; 30 | transition: color 0.2s, background-color 0.2s, border-color 0.2s; 31 | padding: 0.75rem 1rem; 32 | text-decoration: none; 33 | } 34 | .btn:hover { 35 | background-color: rgba(255, 255, 255, 0.25); 36 | } 37 | h2 { 38 | font-size: 16px; 39 | font-weight: normal; 40 | } 41 | iframe { 42 | display: block; 43 | height: 100vh; 44 | width: 100vw; 45 | } 46 | 47 | pre { 48 | padding: 0.8rem; 49 | // margin-top: 0; 50 | // margin-bottom: 1rem; 51 | // font: 1rem Consolas, "Liberation Mono", Menlo, Courier, monospace; 52 | // color: #567482; 53 | // word-wrap: normal; 54 | background-color: #edece8; 55 | border: solid 1px #bfbfbb; 56 | border-radius: 0.3rem; 57 | } -------------------------------------------------------------------------------- /docs/stylesheets/normalize.css: -------------------------------------------------------------------------------- 1 | /*! normalize.css v3.0.2 | MIT License | git.io/normalize */ 2 | 3 | /** 4 | * 1. Set default font family to sans-serif. 5 | * 2. Prevent iOS text size adjust after orientation change, without disabling 6 | * user zoom. 7 | */ 8 | 9 | html { 10 | font-family: sans-serif; /* 1 */ 11 | -ms-text-size-adjust: 100%; /* 2 */ 12 | -webkit-text-size-adjust: 100%; /* 2 */ 13 | } 14 | 15 | /** 16 | * Remove default margin. 17 | */ 18 | 19 | body { 20 | margin: 0; 21 | } 22 | 23 | /* HTML5 display definitions 24 | ========================================================================== */ 25 | 26 | /** 27 | * Correct `block` display not defined for any HTML5 element in IE 8/9. 28 | * Correct `block` display not defined for `details` or `summary` in IE 10/11 29 | * and Firefox. 30 | * Correct `block` display not defined for `main` in IE 11. 31 | */ 32 | 33 | article, 34 | aside, 35 | details, 36 | figcaption, 37 | figure, 38 | footer, 39 | header, 40 | hgroup, 41 | main, 42 | menu, 43 | nav, 44 | section, 45 | summary { 46 | display: block; 47 | } 48 | 49 | /** 50 | * 1. Correct `inline-block` display not defined in IE 8/9. 51 | * 2. Normalize vertical alignment of `progress` in Chrome, Firefox, and Opera. 52 | */ 53 | 54 | audio, 55 | canvas, 56 | progress, 57 | video { 58 | display: inline-block; /* 1 */ 59 | vertical-align: baseline; /* 2 */ 60 | } 61 | 62 | /** 63 | * Prevent modern browsers from displaying `audio` without controls. 64 | * Remove excess height in iOS 5 devices. 65 | */ 66 | 67 | audio:not([controls]) { 68 | display: none; 69 | height: 0; 70 | } 71 | 72 | /** 73 | * Address `[hidden]` styling not present in IE 8/9/10. 74 | * Hide the `template` element in IE 8/9/11, Safari, and Firefox < 22. 75 | */ 76 | 77 | [hidden], 78 | template { 79 | display: none; 80 | } 81 | 82 | /* Links 83 | ========================================================================== */ 84 | 85 | /** 86 | * Remove the gray background color from active links in IE 10. 87 | */ 88 | 89 | a { 90 | background-color: transparent; 91 | } 92 | 93 | /** 94 | * Improve readability when focused and also mouse hovered in all browsers. 95 | */ 96 | 97 | a:active, 98 | a:hover { 99 | outline: 0; 100 | } 101 | 102 | /* Text-level semantics 103 | ========================================================================== */ 104 | 105 | /** 106 | * Address styling not present in IE 8/9/10/11, Safari, and Chrome. 107 | */ 108 | 109 | abbr[title] { 110 | border-bottom: 1px dotted; 111 | } 112 | 113 | /** 114 | * Address style set to `bolder` in Firefox 4+, Safari, and Chrome. 115 | */ 116 | 117 | b, 118 | strong { 119 | font-weight: bold; 120 | } 121 | 122 | /** 123 | * Address styling not present in Safari and Chrome. 124 | */ 125 | 126 | dfn { 127 | font-style: italic; 128 | } 129 | 130 | /** 131 | * Address variable `h1` font-size and margin within `section` and `article` 132 | * contexts in Firefox 4+, Safari, and Chrome. 133 | */ 134 | 135 | h1 { 136 | font-size: 2em; 137 | margin: 0.67em 0; 138 | } 139 | 140 | /** 141 | * Address styling not present in IE 8/9. 142 | */ 143 | 144 | mark { 145 | background: #ff0; 146 | color: #000; 147 | } 148 | 149 | /** 150 | * Address inconsistent and variable font size in all browsers. 151 | */ 152 | 153 | small { 154 | font-size: 80%; 155 | } 156 | 157 | /** 158 | * Prevent `sub` and `sup` affecting `line-height` in all browsers. 159 | */ 160 | 161 | sub, 162 | sup { 163 | font-size: 75%; 164 | line-height: 0; 165 | position: relative; 166 | vertical-align: baseline; 167 | } 168 | 169 | sup { 170 | top: -0.5em; 171 | } 172 | 173 | sub { 174 | bottom: -0.25em; 175 | } 176 | 177 | /* Embedded content 178 | ========================================================================== */ 179 | 180 | /** 181 | * Remove border when inside `a` element in IE 8/9/10. 182 | */ 183 | 184 | img { 185 | border: 0; 186 | } 187 | 188 | /** 189 | * Correct overflow not hidden in IE 9/10/11. 190 | */ 191 | 192 | svg:not(:root) { 193 | overflow: hidden; 194 | } 195 | 196 | /* Grouping content 197 | ========================================================================== */ 198 | 199 | /** 200 | * Address margin not present in IE 8/9 and Safari. 201 | */ 202 | 203 | figure { 204 | margin: 1em 40px; 205 | } 206 | 207 | /** 208 | * Address differences between Firefox and other browsers. 209 | */ 210 | 211 | hr { 212 | box-sizing: content-box; 213 | height: 0; 214 | } 215 | 216 | /** 217 | * Contain overflow in all browsers. 218 | */ 219 | 220 | pre { 221 | overflow: auto; 222 | } 223 | 224 | /** 225 | * Address odd `em`-unit font size rendering in all browsers. 226 | */ 227 | 228 | code, 229 | kbd, 230 | pre, 231 | samp { 232 | font-family: monospace, monospace; 233 | font-size: 1em; 234 | } 235 | 236 | /* Forms 237 | ========================================================================== */ 238 | 239 | /** 240 | * Known limitation: by default, Chrome and Safari on OS X allow very limited 241 | * styling of `select`, unless a `border` property is set. 242 | */ 243 | 244 | /** 245 | * 1. Correct color not being inherited. 246 | * Known issue: affects color of disabled elements. 247 | * 2. Correct font properties not being inherited. 248 | * 3. Address margins set differently in Firefox 4+, Safari, and Chrome. 249 | */ 250 | 251 | button, 252 | input, 253 | optgroup, 254 | select, 255 | textarea { 256 | color: inherit; /* 1 */ 257 | font: inherit; /* 2 */ 258 | margin: 0; /* 3 */ 259 | } 260 | 261 | /** 262 | * Address `overflow` set to `hidden` in IE 8/9/10/11. 263 | */ 264 | 265 | button { 266 | overflow: visible; 267 | } 268 | 269 | /** 270 | * Address inconsistent `text-transform` inheritance for `button` and `select`. 271 | * All other form control elements do not inherit `text-transform` values. 272 | * Correct `button` style inheritance in Firefox, IE 8/9/10/11, and Opera. 273 | * Correct `select` style inheritance in Firefox. 274 | */ 275 | 276 | button, 277 | select { 278 | text-transform: none; 279 | } 280 | 281 | /** 282 | * 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio` 283 | * and `video` controls. 284 | * 2. Correct inability to style clickable `input` types in iOS. 285 | * 3. Improve usability and consistency of cursor style between image-type 286 | * `input` and others. 287 | */ 288 | 289 | button, 290 | html input[type="button"], /* 1 */ 291 | input[type="reset"], 292 | input[type="submit"] { 293 | -webkit-appearance: button; /* 2 */ 294 | cursor: pointer; /* 3 */ 295 | } 296 | 297 | /** 298 | * Re-set default cursor for disabled elements. 299 | */ 300 | 301 | button[disabled], 302 | html input[disabled] { 303 | cursor: default; 304 | } 305 | 306 | /** 307 | * Remove inner padding and border in Firefox 4+. 308 | */ 309 | 310 | button::-moz-focus-inner, 311 | input::-moz-focus-inner { 312 | border: 0; 313 | padding: 0; 314 | } 315 | 316 | /** 317 | * Address Firefox 4+ setting `line-height` on `input` using `!important` in 318 | * the UA stylesheet. 319 | */ 320 | 321 | input { 322 | line-height: normal; 323 | } 324 | 325 | /** 326 | * It's recommended that you don't attempt to style these elements. 327 | * Firefox's implementation doesn't respect box-sizing, padding, or width. 328 | * 329 | * 1. Address box sizing set to `content-box` in IE 8/9/10. 330 | * 2. Remove excess padding in IE 8/9/10. 331 | */ 332 | 333 | input[type="checkbox"], 334 | input[type="radio"] { 335 | box-sizing: border-box; /* 1 */ 336 | padding: 0; /* 2 */ 337 | } 338 | 339 | /** 340 | * Fix the cursor style for Chrome's increment/decrement buttons. For certain 341 | * `font-size` values of the `input`, it causes the cursor style of the 342 | * decrement button to change from `default` to `text`. 343 | */ 344 | 345 | input[type="number"]::-webkit-inner-spin-button, 346 | input[type="number"]::-webkit-outer-spin-button { 347 | height: auto; 348 | } 349 | 350 | /** 351 | * 1. Address `appearance` set to `searchfield` in Safari and Chrome. 352 | * 2. Address `box-sizing` set to `border-box` in Safari and Chrome 353 | * (include `-moz` to future-proof). 354 | */ 355 | 356 | input[type="search"] { 357 | -webkit-appearance: textfield; /* 1 */ /* 2 */ 358 | box-sizing: content-box; 359 | } 360 | 361 | /** 362 | * Remove inner padding and search cancel button in Safari and Chrome on OS X. 363 | * Safari (but not Chrome) clips the cancel button when the search input has 364 | * padding (and `textfield` appearance). 365 | */ 366 | 367 | input[type="search"]::-webkit-search-cancel-button, 368 | input[type="search"]::-webkit-search-decoration { 369 | -webkit-appearance: none; 370 | } 371 | 372 | /** 373 | * Define consistent border, margin, and padding. 374 | */ 375 | 376 | fieldset { 377 | border: 1px solid #c0c0c0; 378 | margin: 0 2px; 379 | padding: 0.35em 0.625em 0.75em; 380 | } 381 | 382 | /** 383 | * 1. Correct `color` not being inherited in IE 8/9/10/11. 384 | * 2. Remove padding so people aren't caught out if they zero out fieldsets. 385 | */ 386 | 387 | legend { 388 | border: 0; /* 1 */ 389 | padding: 0; /* 2 */ 390 | } 391 | 392 | /** 393 | * Remove default vertical scrollbar in IE 8/9/10/11. 394 | */ 395 | 396 | textarea { 397 | overflow: auto; 398 | } 399 | 400 | /** 401 | * Don't inherit the `font-weight` (applied by a rule above). 402 | * NOTE: the default cannot safely be changed in Chrome and Safari on OS X. 403 | */ 404 | 405 | optgroup { 406 | font-weight: bold; 407 | } 408 | 409 | /* Tables 410 | ========================================================================== */ 411 | 412 | /** 413 | * Remove most spacing between table cells. 414 | */ 415 | 416 | table { 417 | border-collapse: collapse; 418 | border-spacing: 0; 419 | } 420 | 421 | td, 422 | th { 423 | padding: 0; 424 | } 425 | -------------------------------------------------------------------------------- /docs/stylesheets/stylesheet.css: -------------------------------------------------------------------------------- 1 | * { 2 | box-sizing: border-box; } 3 | 4 | body { 5 | padding: 0; 6 | margin: 0; 7 | font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; 8 | font-size: 16px; 9 | line-height: 1.5; 10 | color: #606c71; } 11 | 12 | a { 13 | color: #1e6bb8; 14 | text-decoration: none; } 15 | a:hover { 16 | text-decoration: underline; } 17 | 18 | .btn { 19 | display: inline-block; 20 | margin-bottom: 1rem; 21 | color: rgba(255, 255, 255, 0.7); 22 | background-color: rgba(255, 255, 255, 0.08); 23 | border-color: rgba(255, 255, 255, 0.2); 24 | border-style: solid; 25 | border-width: 1px; 26 | border-radius: 0.3rem; 27 | transition: color 0.2s, background-color 0.2s, border-color 0.2s; } 28 | .btn + .btn { 29 | margin-left: 1rem; } 30 | 31 | .btn:hover { 32 | color: rgba(255, 255, 255, 0.8); 33 | text-decoration: none; 34 | background-color: rgba(255, 255, 255, 0.2); 35 | border-color: rgba(255, 255, 255, 0.3); } 36 | 37 | @media screen and (min-width: 64em) { 38 | .btn { 39 | padding: 0.75rem 1rem; } } 40 | 41 | @media screen and (min-width: 42em) and (max-width: 64em) { 42 | .btn { 43 | padding: 0.6rem 0.9rem; 44 | font-size: 0.9rem; } } 45 | 46 | @media screen and (max-width: 42em) { 47 | .btn { 48 | display: block; 49 | width: 100%; 50 | padding: 0.75rem; 51 | font-size: 0.9rem; } 52 | .btn + .btn { 53 | margin-top: 1rem; 54 | margin-left: 0; } } 55 | 56 | .page-header { 57 | color: #fff; 58 | text-align: center; 59 | background-color: #159957; 60 | background-image: linear-gradient(120deg, #EDEAD8, #AFCAC1); 61 | } 62 | .page-header img { 63 | margin-left: -100px; 64 | } 65 | 66 | @media screen and (min-width: 64em) { 67 | .page-header { 68 | padding: 5rem 6rem; } } 69 | 70 | @media screen and (min-width: 42em) and (max-width: 64em) { 71 | .page-header { 72 | padding: 3rem 4rem; } } 73 | 74 | @media screen and (max-width: 42em) { 75 | .page-header { 76 | padding: 2rem 1rem; } } 77 | 78 | .project-name { 79 | margin-top: 0; 80 | margin-bottom: 0.1rem; 81 | } 82 | 83 | @media screen and (min-width: 64em) { 84 | .project-name { 85 | font-size: 3.25rem; } } 86 | 87 | @media screen and (min-width: 42em) and (max-width: 64em) { 88 | .project-name { 89 | font-size: 2.25rem; } } 90 | 91 | @media screen and (max-width: 42em) { 92 | .project-name { 93 | font-size: 1.75rem; } } 94 | 95 | .project-tagline { 96 | margin-bottom: 2rem; 97 | font-weight: normal; 98 | opacity: 0.7; } 99 | 100 | @media screen and (min-width: 64em) { 101 | .project-tagline { 102 | font-size: 1.25rem; } } 103 | 104 | @media screen and (min-width: 42em) and (max-width: 64em) { 105 | .project-tagline { 106 | font-size: 1.15rem; } } 107 | 108 | @media screen and (max-width: 42em) { 109 | .project-tagline { 110 | font-size: 1rem; } } 111 | 112 | .main-content :first-child { 113 | margin-top: 0; } 114 | .main-content img { 115 | max-width: 100%; } 116 | .main-content h1, .main-content h2, .main-content h3, .main-content h4, .main-content h5, .main-content h6 { 117 | margin-top: 2rem; 118 | margin-bottom: 1rem; 119 | font-weight: normal; 120 | color: #159957; } 121 | .main-content p { 122 | margin-bottom: 1em; } 123 | .main-content code { 124 | padding: 2px 4px; 125 | font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; 126 | font-size: 0.9rem; 127 | color: #383e41; 128 | background-color: #f3f6fa; 129 | border-radius: 0.3rem; } 130 | .main-content pre { 131 | padding: 0.8rem; 132 | margin-top: 0; 133 | margin-bottom: 1rem; 134 | font: 1rem Consolas, "Liberation Mono", Menlo, Courier, monospace; 135 | color: #567482; 136 | word-wrap: normal; 137 | background-color: #f3f6fa; 138 | border: solid 1px #dce6f0; 139 | border-radius: 0.3rem; } 140 | .main-content pre > code { 141 | padding: 0; 142 | margin: 0; 143 | font-size: 0.9rem; 144 | color: #567482; 145 | word-break: normal; 146 | white-space: pre; 147 | background: transparent; 148 | border: 0; } 149 | .main-content .highlight { 150 | margin-bottom: 1rem; } 151 | .main-content .highlight pre { 152 | margin-bottom: 0; 153 | word-break: normal; } 154 | .main-content .highlight pre, .main-content pre { 155 | padding: 0.8rem; 156 | overflow: auto; 157 | font-size: 0.9rem; 158 | line-height: 1.45; 159 | border-radius: 0.3rem; } 160 | .main-content pre code, .main-content pre tt { 161 | display: inline; 162 | max-width: initial; 163 | padding: 0; 164 | margin: 0; 165 | overflow: initial; 166 | line-height: inherit; 167 | word-wrap: normal; 168 | background-color: transparent; 169 | border: 0; } 170 | .main-content pre code:before, .main-content pre code:after, .main-content pre tt:before, .main-content pre tt:after { 171 | content: normal; } 172 | .main-content ul, .main-content ol { 173 | margin-top: 0; } 174 | .main-content blockquote { 175 | padding: 0 1rem; 176 | margin-left: 0; 177 | color: #819198; 178 | border-left: 0.3rem solid #dce6f0; } 179 | .main-content blockquote > :first-child { 180 | margin-top: 0; } 181 | .main-content blockquote > :last-child { 182 | margin-bottom: 0; } 183 | .main-content table { 184 | display: block; 185 | width: 100%; 186 | overflow: auto; 187 | word-break: normal; 188 | word-break: keep-all; } 189 | .main-content table th { 190 | font-weight: bold; } 191 | .main-content table th, .main-content table td { 192 | padding: 0.5rem 1rem; 193 | border: 1px solid #e9ebec; } 194 | .main-content dl { 195 | padding: 0; } 196 | .main-content dl dt { 197 | padding: 0; 198 | margin-top: 1rem; 199 | font-size: 1rem; 200 | font-weight: bold; } 201 | .main-content dl dd { 202 | padding: 0; 203 | margin-bottom: 1rem; } 204 | .main-content hr { 205 | height: 2px; 206 | padding: 0; 207 | margin: 1rem 0; 208 | background-color: #eff0f1; 209 | border: 0; } 210 | 211 | @media screen and (min-width: 64em) { 212 | .main-content { 213 | max-width: 64rem; 214 | padding: 2rem 6rem; 215 | margin: 0 auto; 216 | font-size: 1.1rem; } } 217 | 218 | @media screen and (min-width: 42em) and (max-width: 64em) { 219 | .main-content { 220 | padding: 2rem 4rem; 221 | font-size: 1.1rem; } } 222 | 223 | @media screen and (max-width: 42em) { 224 | .main-content { 225 | padding: 2rem 1rem; 226 | font-size: 1rem; } } 227 | 228 | .site-footer { 229 | padding-top: 2rem; 230 | margin-top: 2rem; 231 | border-top: solid 1px #eff0f1; } 232 | 233 | .site-footer-owner { 234 | display: block; 235 | font-weight: bold; } 236 | 237 | .site-footer-credits { 238 | color: #819198; } 239 | 240 | @media screen and (min-width: 64em) { 241 | .site-footer { 242 | font-size: 1rem; } } 243 | 244 | @media screen and (min-width: 42em) and (max-width: 64em) { 245 | .site-footer { 246 | font-size: 1rem; } } 247 | 248 | @media screen and (max-width: 42em) { 249 | .site-footer { 250 | font-size: 0.9rem; } } 251 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "restjs", 3 | "version": "1.1.1", 4 | "description": "An 'ORM' style library for consuming RESTful APIs on the frontend", 5 | "main": "dist/rest.node.js", 6 | "scripts": { 7 | "build": "scripts/build.sh", 8 | "test": "npm run lint && karma start test/config.js --single-run=true", 9 | "local-test": "npm run lint && karma start test/config.local.js --single-run=true", 10 | "local-test-watch": "npm run lint && karma start test/config.local.js --single-run=false", 11 | "lint": "eslint src/*", 12 | "unit": "karma start test/config.js --browsers=PhantomJS", 13 | "docs": "jsdoc --configure docs/conf.json --destination docs --private", 14 | "release": "scripts/release.sh" 15 | }, 16 | "author": "Matthew Davies (https://daviesgeek.com)", 17 | "license": "MIT", 18 | "eslintConfig": { 19 | "env": { 20 | "browser": true, 21 | "es6": true 22 | }, 23 | "ecmaFeatures": { 24 | "impliedStrict": true 25 | }, 26 | "extends": "eslint:recommended", 27 | "globals": { 28 | "Rest": true, 29 | "Factory": true 30 | }, 31 | "rules": { 32 | "indent": [ 33 | "error", 34 | 2 35 | ], 36 | "linebreak-style": [ 37 | "error", 38 | "unix" 39 | ], 40 | "quotes": [ 41 | "error", 42 | "double" 43 | ], 44 | "semi": [ 45 | "error", 46 | "never" 47 | ], 48 | "comma-dangle": [ 49 | "off", 50 | "always" 51 | ] 52 | } 53 | }, 54 | "devDependencies": { 55 | "babel-cli": "^6.9.0", 56 | "babel-polyfill": "^6.9.1", 57 | "babel-preset-es2015": "^6.9.0", 58 | "chai": "^3.5.0", 59 | "eslint": "^2.12.0", 60 | "jsdoc": "^3.4.0", 61 | "json": "^9.0.4", 62 | "karma": "^0.13.22", 63 | "karma-babel-preprocessor": "^6.0.1", 64 | "karma-chai": "^0.1.0", 65 | "karma-coverage": "^1.0.0", 66 | "karma-coveralls": "^1.1.2", 67 | "karma-junit-reporter": "^1.0.0", 68 | "karma-mocha": "^1.0.1", 69 | "karma-phantomjs-launcher": "^1.0.0", 70 | "karma-sauce-launcher": "^1.0.0", 71 | "karma-sinon": "^1.0.5", 72 | "mocha": "^2.5.3", 73 | "phantomjs-prebuilt": "^2.1.3", 74 | "sinon": "^1.17.4", 75 | "uglify-js": "^2.7.3" 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /scripts/build.sh: -------------------------------------------------------------------------------- 1 | # Keep in mind that this runs with all the node_module/.bin binaries (see https://docs.npmjs.com/cli/run-script) 2 | 3 | # Get the current version 4 | VERSION=$(json -f package.json version) 5 | 6 | if [ -z "$CIRCLE_ARTIFACTS"]; then 7 | DIST_FOLDER='dist' 8 | else 9 | DIST_FOLDER=$CIRCLE_ARTIFACTS 10 | fi 11 | 12 | # Make the dist folder and clear it if necessary 13 | rm -rf "$DIST_FOLDER" 14 | mkdir -p $DIST_FOLDER 15 | 16 | echo 'Compiling with Babel... \r\c' 17 | # First, compile the source using babel 18 | cat src/element.js src/factory.js src/rest.js | babel --presets es2015 --out-file "$DIST_FOLDER/rest.js" 19 | 20 | # And add the version number 21 | echo "Rest.VERSION = \"$VERSION\"" >> "$DIST_FOLDER/rest.js" 22 | 23 | echo 'Adding polyfill versions... \r\c' 24 | 25 | # Create the polyfill version 26 | cat ./node_modules/babel-polyfill/dist/polyfill.js >> "$DIST_FOLDER/rest.polyfill.js" 27 | cat "$DIST_FOLDER/rest.js" >> $DIST_FOLDER/rest.polyfill.js"" 28 | 29 | echo 'Compiling Node version... \r\c' 30 | cp $DIST_FOLDER/rest.js $DIST_FOLDER/rest.node.js 31 | echo "export default Rest;" >> "$DIST_FOLDER/rest.node.js" 32 | 33 | echo 'Minifying... \r\c' 34 | # Create a minified version of both dist files 35 | uglifyjs --mangle --output "$DIST_FOLDER/rest.min.js" -- "$DIST_FOLDER/rest.js" 36 | 37 | echo 'Adding polyfill to minified version...\r\c' 38 | cp "$DIST_FOLDER/rest.polyfill.js" "$DIST_FOLDER/rest.polyfill.min.js" 39 | cat ./node_modules/babel-polyfill/dist/polyfill.min.js >> "$DIST_FOLDER/rest.polyfill.min.js" 40 | 41 | echo 'Finished build! \n' -------------------------------------------------------------------------------- /scripts/release.sh: -------------------------------------------------------------------------------- 1 | npm run local-test 2 | npm run build 3 | node_modules/.bin/json -I -f package.json -e 'this.version="'$@'"' 4 | npm run docs 5 | mv "docs/restjs/$@" "docs/$@" 6 | rm -rf docs/restjs 7 | cat docs/latest/index.template.md > docs/latest/index.md 8 | echo "" >> docs/latest/index.md 9 | git add "docs" 10 | git commit -m "Added docs for $@" 11 | echo "All done. Don't forget to update the changelog, commit, tag and push!" -------------------------------------------------------------------------------- /src/element.js: -------------------------------------------------------------------------------- 1 | /** 2 | * The base element class 3 | * 4 | * @class Element 5 | */ 6 | let Element = {} 7 | 8 | /** 9 | * Make a GET request 10 | * @param {string|object} routeOrParams If it's a string, it's the route for the request, otherwise it's the params for the request 11 | * @return {Promise} A Promise that is resolved with an {@link Element} 12 | * 13 | * @example 14 | * 15 | * element.get({with: 'params'}).then(function(data) { 16 | * // data is here, restified for further use 17 | * }) 18 | * 19 | * element.get('route', {with: 'params'}).then(function(data) { 20 | * // data is here, restified for further use 21 | * }) 22 | * 23 | * 24 | * @name Element#get 25 | * @kind function 26 | */ 27 | Element.get = function() { 28 | let params = typeof arguments[0] === "object" ? arguments[0] : arguments[1] || {} 29 | let route = typeof arguments[0] === "string" ? arguments[0] : null 30 | 31 | let requestRoute = this.route + `/${this[this.config.fields.id]}` 32 | if(route) { 33 | requestRoute += "/" + route 34 | } 35 | 36 | return Rest._makeRequest(this.config, "GET", requestRoute, params, this.factory, null) 37 | } 38 | 39 | /** 40 | * Make a POST request, POSTing the serialized element 41 | * @param {Object} params The URL parameters for the request 42 | * @return {Promise} A Promise that is resolved with an {@link Element} 43 | * 44 | * @example 45 | * 46 | * element.post({with: 'params'}).then(function(data) { 47 | * // data is here, restified for further use 48 | * }) 49 | * 50 | * @name Element#post 51 | * @kind function 52 | */ 53 | Element.post = function(params) { 54 | return Rest._makeRequest(this.config, "POST", this.route + (this.fromServer ? "/" + this[this.config.fields.id] : ""), params, this.factory, this) 55 | } 56 | 57 | /** 58 | * Make a PATCH request, PATCHing the body.
59 | * For more information on the format of the request, look at {@link Rest._findBodyAndParams} 60 | * @param {Object} body The body of the request 61 | * @param {Object} params The URL parameters for the request 62 | * @return {Promise} A Promise that is resolved with an {@link Element} 63 | * 64 | * @example 65 | * 66 | * element.patch({name: "Matt Smith"}, {with: 'children'}) 67 | * element.patch(['name']) 68 | * element.patch(['name'], {with: 'children'}) 69 | * element.patch('name', 'season', {with: 'children'}) 70 | * element.patch('name', 'season') 71 | * 72 | * @see Rest._findBodyAndParams 73 | * @name Element#patch 74 | * @kind function 75 | */ 76 | Element.patch = function() { 77 | let {body, params} = Rest._findBodyAndParams(arguments, this) 78 | return Rest._makeRequest(this.config, "PATCH", this.route + `/${this[this.config.fields.id]}`, params, this.factory, body) 79 | } 80 | 81 | /** 82 | * Make a PUT request, PUTing the serialized element 83 | * @param {Object} params The URL parameters for the request 84 | * @return {Promise} A Promise that is resolved with an {@link Element} 85 | * 86 | * @example 87 | * 88 | * element.put({with: 'params'}).then(function(data) { 89 | * // data is here, restified for further use 90 | * }) 91 | * 92 | * @name Element#put 93 | * @kind function 94 | */ 95 | Element.put = function(params) { 96 | return Rest._makeRequest(this.config, "PUT", this.route + `/${this[this.config.fields.id]}`, params, this.factory, this) 97 | } 98 | -------------------------------------------------------------------------------- /src/factory.js: -------------------------------------------------------------------------------- 1 | /** 2 | * The base factory class 3 | * 4 | * @class Factory 5 | */ 6 | let Factory = function() {} 7 | 8 | /** 9 | * Creates an element 10 | * @param {object} element The element to create 11 | * @param {Boolean=} [fromServer=false] Whether this element is from the server or not 12 | * @return {Element} 13 | */ 14 | Factory.create = function(element, fromServer=false) { 15 | let instance = Object.create(Element, { 16 | 17 | /** 18 | * The route 19 | * @type {String} 20 | * @memberof Element 21 | * @instance 22 | */ 23 | route: { 24 | configurable: false, 25 | enumerable: false, 26 | value: this.route 27 | }, 28 | 29 | /** 30 | * Whether the element is from the server or not 31 | * @type {Boolean} 32 | * @memberOf Element 33 | * @instance 34 | */ 35 | fromServer: { 36 | configurable: true, 37 | enumerable: false, 38 | value: fromServer 39 | }, 40 | 41 | /** 42 | * The config object for the element 43 | * @type {Object} 44 | * @memberOf Element 45 | * @instance 46 | */ 47 | config: { 48 | configurable: false, 49 | enumerable: false, 50 | value: this.config 51 | }, 52 | 53 | /** 54 | * The Factory that created the element 55 | * @type {Factory} 56 | * @memberOf Element 57 | * @instance 58 | */ 59 | factory: { 60 | configurable: false, 61 | enumerable: false, 62 | value: this 63 | } 64 | }) 65 | 66 | let prototype = typeof this.elementTransformer == "object" ? this.elementTransformer : {} 67 | Object.assign(instance, element, prototype) 68 | 69 | if(typeof this.elementTransformer == "function") 70 | instance = this.elementTransformer(instance) 71 | 72 | return instance 73 | } 74 | 75 | /** 76 | * Makes a request to the server for an array 77 | * @param {Object=} params={} The URL parameters for the request 78 | * @return {Promise} The request promise 79 | */ 80 | Factory.getList = function(params={}) { 81 | return Rest._makeRequest(this.config, "GET", this.route, params, this, null) 82 | } 83 | 84 | /** 85 | * Make a get request for a given id 86 | * @param {Integer} id The id of the element to fetch from the server 87 | * @param {Object=} params={} The URL parameters for the request 88 | * @return {Promise} The request promise 89 | */ 90 | Factory.get = function(id, params={}) { 91 | return Rest._makeRequest(this.config, "GET", this.route + `/${id}`, params, this, null) 92 | } 93 | 94 | /** 95 | * Make a post request 96 | * @param {Object=} params={} The URL parameters for the request 97 | * @param {String=} route= A custom route for the request 98 | * @return {Promise} The request promise 99 | */ 100 | Factory.post = function(body={}, params={}) { 101 | return Rest._makeRequest(this.config, "POST", this.route, params, this, body) 102 | } 103 | 104 | /** 105 | * Make a post request 106 | * @param {Object=} params={} The URL parameters for the request 107 | * @param {String=} route= A custom route for the request 108 | * @return {Promise} The request promise 109 | */ 110 | Factory.customPOST = function(route="", body={}, params={}) { 111 | return Rest._makeRequest(this.config, "POST", this.route + `/${route}`, params, this, body) 112 | } 113 | -------------------------------------------------------------------------------- /test/config.js: -------------------------------------------------------------------------------- 1 | module.exports = function (config) { 2 | var customLaunchers = { 3 | "SL_Chrome": { 4 | base: "SauceLabs", 5 | browserName: "chrome", 6 | platform: "Windows 8.1" 7 | }, 8 | "SL_Chrome_Linux": { 9 | base: "SauceLabs", 10 | browserName: "chrome", 11 | platform: "Linux" 12 | }, 13 | "SL_Chrome_OSX": { 14 | base: "SauceLabs", 15 | browserName: "chrome", 16 | platform: "OS X 10.10" 17 | }, 18 | "SL_Firefox": { 19 | base: "SauceLabs", 20 | browserName: "firefox", 21 | platform: "Windows 8.1" 22 | }, 23 | "SL_Firefox_Linux": { 24 | base: "SauceLabs", 25 | browserName: "firefox", 26 | platform: "Linux" 27 | }, 28 | "SL_Firefox_OSX": { 29 | base: "SauceLabs", 30 | browserName: "firefox", 31 | platform: "OS X 10.10" 32 | }, 33 | 34 | "SL_IE_10": { 35 | base: "SauceLabs", 36 | browserName: "internet explorer", 37 | platform: "Windows 8", 38 | version: "10" 39 | }, 40 | "SL_IE_11": { 41 | base: "SauceLabs", 42 | browserName: "internet explorer", 43 | platform: "Windows 8.1", 44 | version: "11" 45 | }, 46 | "SL_Opera": { 47 | base: "SauceLabs", 48 | browserName: "opera", 49 | platform: "Windows 7" 50 | }, 51 | "SL_Opera_Linux": { 52 | base: "SauceLabs", 53 | browserName: "opera", 54 | platform: "Linux" 55 | }, 56 | "SL_Safari_6": { 57 | base: "SauceLabs", 58 | browserName: "safari", 59 | platform: "OS X 10.8", 60 | version: "6" 61 | }, 62 | "SL_Safari_7": { 63 | base: "SauceLabs", 64 | browserName: "safari", 65 | platform: "OS X 10.9", 66 | version: "7" 67 | }, 68 | "SL_Safari_8": { 69 | base: "SauceLabs", 70 | browserName: "safari", 71 | platform: "OS X 10.10", 72 | version: "8" 73 | }, 74 | } 75 | 76 | config.set({ 77 | basePath: '../', 78 | autoWatch: true, 79 | frameworks: ['mocha', 'chai', 'sinon'], 80 | files: [ 81 | 'node_modules/babel-polyfill/dist/polyfill.js', 82 | 'src/*.js', 83 | 84 | 'test/data.js', 85 | 'test/test.js', 86 | ], 87 | concurrency: 1, 88 | browsers: ['PhantomJS'].concat(Object.keys(customLaunchers)), 89 | 90 | reporters: ['progress', 'coverage', 'coveralls', 'junit', 'saucelabs'], 91 | preprocessors: { 92 | 'src/*.js': ['coverage', 'babel'], 93 | 'test/*.js': ['babel'], 94 | }, 95 | 96 | babelPreprocessor: { 97 | options: { 98 | presets: ['es2015'], 99 | sourceMap: 'inline' 100 | }, 101 | filename: function (file) { 102 | return file.originalPath.replace(/\.js$/, '.es5.js'); 103 | }, 104 | sourceFileName: function (file) { 105 | return file.originalPath; 106 | } 107 | }, 108 | 109 | plugins: [ 110 | 'karma-chai', 111 | 'karma-coverage', 112 | // 'karma-chrome-launcher', 113 | // 'karma-firefox-launcher', 114 | // 'karma-junit-reporter', 115 | 'karma-mocha', 116 | 'karma-phantomjs-launcher', 117 | 'karma-sinon', 118 | // 'karma-safari-launcher', 119 | 'karma-babel-preprocessor', 120 | 'karma-junit-reporter', 121 | 'karma-coveralls', 122 | 'karma-sauce-launcher', 123 | ], 124 | 125 | singleRun: false, 126 | coverageReporter: { 127 | reporters: [ 128 | { 129 | type: 'html', 130 | dir: (process.env.CIRCLE_TEST_REPORTS || '') + 'coverage/html' 131 | }, 132 | { 133 | type: 'lcov', 134 | dir: (process.env.CIRCLE_TEST_REPORTS || '') + 'coverage/lcov' 135 | } 136 | ] 137 | }, 138 | junitReporter: { 139 | outputDir: (process.env.CIRCLE_TEST_REPORTS || 'coverage') 140 | }, 141 | 142 | sauceLabs: { 143 | startConnect: true, 144 | username: 'restjs', 145 | accessKey: '066cbbf5-07ec-4933-a088-cc8352a7dd24', 146 | testName: "RestJS Unit Tests", 147 | }, 148 | customLaunchers: customLaunchers 149 | }) 150 | } -------------------------------------------------------------------------------- /test/config.local.js: -------------------------------------------------------------------------------- 1 | module.exports = function (config) { 2 | config.set({ 3 | basePath: '../', 4 | autoWatch: true, 5 | frameworks: ['mocha', 'chai', 'sinon'], 6 | files: [ 7 | 'node_modules/babel-polyfill/dist/polyfill.js', 8 | 'src/*.js', 9 | 10 | 'test/data.js', 11 | 'test/test.js', 12 | ], 13 | concurrency: 1, 14 | browsers: ['PhantomJS'], 15 | 16 | reporters: ['progress', 'coverage', 'coveralls', 'junit', 'saucelabs'], 17 | preprocessors: { 18 | 'src/*.js': ['coverage', 'babel'], 19 | 'test/*.js': ['babel'], 20 | }, 21 | 22 | babelPreprocessor: { 23 | options: { 24 | presets: ['es2015'], 25 | sourceMap: 'inline' 26 | }, 27 | filename: function (file) { 28 | return file.originalPath.replace(/\.js$/, '.es5.js'); 29 | }, 30 | sourceFileName: function (file) { 31 | return file.originalPath; 32 | } 33 | }, 34 | 35 | plugins: [ 36 | 'karma-chai', 37 | 'karma-coverage', 38 | // 'karma-chrome-launcher', 39 | // 'karma-firefox-launcher', 40 | // 'karma-junit-reporter', 41 | 'karma-mocha', 42 | 'karma-phantomjs-launcher', 43 | 'karma-sinon', 44 | // 'karma-safari-launcher', 45 | 'karma-babel-preprocessor', 46 | 'karma-junit-reporter', 47 | 'karma-coveralls', 48 | 'karma-sauce-launcher', 49 | ], 50 | 51 | singleRun: false, 52 | coverageReporter: { 53 | reporters: [ 54 | { 55 | type: 'html', 56 | dir: (process.env.CIRCLE_TEST_REPORTS || '') + 'coverage/html' 57 | }, 58 | { 59 | type: 'lcov', 60 | dir: (process.env.CIRCLE_TEST_REPORTS || '') + 'coverage/lcov' 61 | } 62 | ] 63 | }, 64 | junitReporter: { 65 | outputDir: (process.env.CIRCLE_TEST_REPORTS || 'coverage') 66 | } 67 | }) 68 | } -------------------------------------------------------------------------------- /test/data.js: -------------------------------------------------------------------------------- 1 | var data = { 2 | users: [ 3 | { 4 | "id": 1, 5 | "first_name": "Jose", 6 | "last_name": "Ellis", 7 | "email": "jellis0@japanpost.jp", 8 | "country": "Indonesia", 9 | "ip_address": "202.88.170.138" 10 | }, 11 | { 12 | "id": 2, 13 | "first_name": "Rebecca", 14 | "last_name": "Arnold", 15 | "email": "rarnold1@timesonline.co.uk", 16 | "country": "Portugal", 17 | "ip_address": "214.52.80.16" 18 | }, 19 | { 20 | "id": 3, 21 | "first_name": "Annie", 22 | "last_name": "Grant", 23 | "email": "agrant2@rakuten.co.jp", 24 | "country": "Norway", 25 | "ip_address": "119.155.7.212" 26 | }, 27 | { 28 | "id": 4, 29 | "first_name": "Nicholas", 30 | "last_name": "Jordan", 31 | "email": "njordan3@sourceforge.net", 32 | "country": "Germany", 33 | "ip_address": "152.150.196.26" 34 | }, 35 | { 36 | "id": 5, 37 | "first_name": "Wayne", 38 | "last_name": "Morales", 39 | "email": "wmorales4@ted.com", 40 | "country": "China", 41 | "ip_address": "146.78.9.169" 42 | }, 43 | { 44 | "id": 6, 45 | "first_name": "Julia", 46 | "last_name": "Roberts", 47 | "email": "jroberts5@newyorker.com", 48 | "country": "China", 49 | "ip_address": "92.13.152.17" 50 | }, 51 | { 52 | "id": 7, 53 | "first_name": "Mildred", 54 | "last_name": "Perez", 55 | "email": "mperez6@w3.org", 56 | "country": "Nigeria", 57 | "ip_address": "251.61.36.174" 58 | }, 59 | { 60 | "id": 8, 61 | "first_name": "Barbara", 62 | "last_name": "Matthews", 63 | "email": "bmatthews7@apache.org", 64 | "country": "Morocco", 65 | "ip_address": "249.52.199.231" 66 | }, 67 | { 68 | "id": 9, 69 | "first_name": "Thomas", 70 | "last_name": "Stephens", 71 | "email": "tstephens8@springer.com", 72 | "country": "Peru", 73 | "ip_address": "125.231.3.154" 74 | }, 75 | { 76 | "id": 10, 77 | "first_name": "Chris", 78 | "last_name": "Alvarez", 79 | "email": "calvarez9@psu.edu", 80 | "country": "Paraguay", 81 | "ip_address": "165.86.187.20" 82 | }, 83 | { 84 | "id": 11, 85 | "first_name": "Jeremy", 86 | "last_name": "Anderson", 87 | "email": "jandersona@unc.edu", 88 | "country": "Bulgaria", 89 | "ip_address": "196.24.19.91" 90 | }, 91 | { 92 | "id": 12, 93 | "first_name": "Sara", 94 | "last_name": "Reed", 95 | "email": "sreedb@economist.com", 96 | "country": "Finland", 97 | "ip_address": "180.92.97.216" 98 | }, 99 | { 100 | "id": 13, 101 | "first_name": "Roger", 102 | "last_name": "Fowler", 103 | "email": "rfowlerc@wix.com", 104 | "country": "Russia", 105 | "ip_address": "178.200.193.110" 106 | }, 107 | { 108 | "id": 14, 109 | "first_name": "Martha", 110 | "last_name": "Gibson", 111 | "email": "mgibsond@topsy.com", 112 | "country": "China", 113 | "ip_address": "215.240.201.105" 114 | }, 115 | { 116 | "id": 15, 117 | "first_name": "Samuel", 118 | "last_name": "Kennedy", 119 | "email": "skennedye@soundcloud.com", 120 | "country": "Libya", 121 | "ip_address": "248.232.220.200" 122 | } 123 | ] 124 | } -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | let expect = chai.expect 3 | 4 | describe('RestJS', function () { 5 | 6 | var User, server; 7 | 8 | beforeEach(function () { 9 | Rest.Config.set({ 10 | baseUrl: 'http://server.com', 11 | withCredentials: true, 12 | }) 13 | 14 | User = Rest.factory('users') 15 | 16 | server = sinon.fakeServer.create() 17 | server.autoRespond = true 18 | }) 19 | 20 | afterEach(function () { 21 | server.restore() 22 | }) 23 | 24 | /** 25 | * Factory tests 26 | */ 27 | 28 | it('should create a factory', function () { 29 | expect(User).to.have.property('getList') 30 | expect(User).to.have.property('get') 31 | }) 32 | 33 | it('should create an element using \'create\'', function () { 34 | let user = User.create({id: 1, first_name: "Matthew"}) 35 | shouldBeRestified(user, 'users', false) 36 | }) 37 | 38 | it('should make a getList request', function (done) { 39 | server.respondWith(function (request) { 40 | expect(request.method).to.equal('GET') 41 | expect(request.url).to.equal('http://server.com/users') 42 | expect(request.responseType).to.equal('json') 43 | request.respond(200, { 'Content-Type': 'application/json' }, JSON.stringify(data.users)) 44 | }) 45 | User.getList().then(function (users) { 46 | expect(users).to.exist 47 | users.forEach(function (user) { 48 | shouldBeRestified(user, 'users') 49 | }) 50 | done() 51 | }, done) 52 | }) 53 | 54 | it('should make a get request for a single element', function (done) { 55 | server.respondWith(function (request) { 56 | expect(request.method).to.equal('GET') 57 | expect(request.url).to.equal('http://server.com/users/1') 58 | expect(request.responseType).to.equal('json') 59 | request.respond(200, { 'Content-Type': 'application/json' }, JSON.stringify(data.users[0])) 60 | }) 61 | 62 | User.get(1).then(function(user) { 63 | expect(user).to.exist 64 | expect(user.id).to.equal(1) 65 | shouldBeRestified(user, 'users') 66 | done() 67 | }) 68 | }) 69 | 70 | /** 71 | * Element tests 72 | */ 73 | 74 | it('should make a post request', function (done) { 75 | server.respondWith(function (request) { 76 | expect(request.method).to.equal('POST') 77 | expect(request.url).to.equal('http://server.com/users') 78 | expect(request.responseType).to.equal('json') 79 | expect(request.requestBody).to.equal(JSON.stringify({"first_name": "Jose", "last_name": "Ellis", "email": "jellis0@japanpost.jp", "country": "Indonesia", "ip_address": "202.88.170.138"})) 80 | 81 | let returnUser = data.users[0] 82 | returnUser.id = 42 83 | 84 | request.respond(200, { 'Content-Type': 'application/json' }, JSON.stringify(returnUser)) 85 | }) 86 | 87 | User.create({ 88 | "first_name": "Jose", 89 | "last_name": "Ellis", 90 | "email": "jellis0@japanpost.jp", 91 | "country": "Indonesia", 92 | "ip_address": "202.88.170.138" 93 | }).post().then(function (user) { 94 | expect(user.id).to.equal(42) 95 | shouldBeRestified(user, 'users') 96 | done() 97 | }) 98 | 99 | }) 100 | 101 | describe('should make a patch request', function () { 102 | 103 | let user = Rest.factory('users').create({id: 1, first_name: "John", last_name: "Smith"}) 104 | 105 | shouldBeRestified(user, 'users', false) 106 | 107 | it('with an object', function (done) { 108 | server.respondWith(function (request) { 109 | expect(request.method).to.equal('PATCH') 110 | expect(request.url).to.equal('http://server.com/users/1') 111 | expect(request.responseType).to.equal('json') 112 | expect(request.requestBody).to.equal(JSON.stringify({first_name: "John"})) 113 | 114 | request.respond(200, { 'Content-Type': 'application/json' }, request.requestBody) 115 | }) 116 | 117 | user.patch({first_name: "John"}).then(function (data) { 118 | expect(JSON.stringify(data)).to.equal(JSON.stringify({first_name: "John"})) 119 | done() 120 | }) 121 | 122 | shouldBeRestified(user, 'users', false) 123 | }) 124 | 125 | it('with an object and params', function (done) { 126 | server.respondWith(function (request) { 127 | expect(request.method).to.equal('PATCH') 128 | expect(request.url).to.equal('http://server.com/users/1?with=all') 129 | expect(request.responseType).to.equal('json') 130 | expect(request.requestBody).to.equal(JSON.stringify({first_name: "John"})) 131 | 132 | request.respond(200, { 'Content-Type': 'application/json' }, request.requestBody) 133 | }) 134 | 135 | user.patch({first_name: "John"}, {with: 'all'}).then(function (data) { 136 | expect(JSON.stringify(data)).to.equal(JSON.stringify({first_name: "John"})) 137 | done() 138 | }) 139 | 140 | shouldBeRestified(user, 'users', false) 141 | }) 142 | 143 | it('with string properties', function (done) { 144 | server.respondWith(function (request) { 145 | expect(request.method).to.equal('PATCH') 146 | expect(request.url).to.equal('http://server.com/users/1') 147 | expect(request.responseType).to.equal('json') 148 | expect(request.requestBody).to.equal(JSON.stringify({id: 1, first_name: "John", last_name: "Smith"})) 149 | 150 | request.respond(200, { 'Content-Type': 'application/json' }, request.requestBody) 151 | }) 152 | 153 | user.patch('id', 'first_name', 'last_name').then(function (data) { 154 | expect(JSON.stringify(data)).to.equal(JSON.stringify({id: 1, first_name: "John", last_name: "Smith"})) 155 | done() 156 | }) 157 | 158 | shouldBeRestified(user, 'users', false) 159 | }) 160 | 161 | it('with string properties and params', function (done) { 162 | server.respondWith(function (request) { 163 | expect(request.method).to.equal('PATCH') 164 | expect(request.url).to.equal('http://server.com/users/1?with=all') 165 | expect(request.responseType).to.equal('json') 166 | expect(request.requestBody).to.equal(JSON.stringify({id: 1, first_name: "John", last_name: "Smith"})) 167 | 168 | request.respond(200, { 'Content-Type': 'application/json' }, request.requestBody) 169 | }) 170 | 171 | user.patch('id', 'first_name', 'last_name', {with: 'all'}).then(function (data) { 172 | expect(JSON.stringify(data)).to.equal(JSON.stringify(user)) 173 | done() 174 | }) 175 | 176 | shouldBeRestified(user, 'users', false) 177 | }) 178 | 179 | }) 180 | 181 | it('should make a put request', function (done) { 182 | server.respondWith(function (request) { 183 | expect(request.method).to.equal('PUT') 184 | expect(request.url).to.equal('http://server.com/users/1') 185 | expect(request.responseType).to.equal('json') 186 | expect(request.requestBody).to.equal(JSON.stringify({id: 1, first_name: "John", last_name: "Smith"})) 187 | 188 | request.respond(200, { 'Content-Type': 'application/json' }, request.requestBody) 189 | }) 190 | 191 | let user = User.create({id: 1, first_name: "John", last_name: "Smith"}) 192 | user.put().then(function (data) { 193 | expect(data).to.deep.equal(user) 194 | done() 195 | }) 196 | }) 197 | 198 | describe('should add factory methods', function () { 199 | 200 | it('as an object', function () { 201 | var ModelFactory = Rest.factory('users', { 202 | getUserTypes: function () { 203 | return ['admin', 'standard'] 204 | } 205 | }) 206 | 207 | expect(ModelFactory).to.have.property('getUserTypes') 208 | expect(ModelFactory.getUserTypes).to.be.a('function') 209 | expect(ModelFactory.getUserTypes()).to.deep.equal(['admin', 'standard']) 210 | }) 211 | 212 | it('as a function', function () { 213 | var ModelFactory = Rest.factory('users', function(factory) { 214 | factory.getUserTypes = function () { 215 | return ['admin', 'standard'] 216 | } 217 | return factory 218 | }) 219 | 220 | expect(ModelFactory).to.have.property('getUserTypes') 221 | expect(ModelFactory.getUserTypes).to.be.a('function') 222 | expect(ModelFactory.getUserTypes()).to.deep.equal(['admin', 'standard']) 223 | }) 224 | 225 | }) 226 | 227 | describe('should add element methods', function () { 228 | 229 | it('as an object', function () { 230 | var ModelFactory = Rest.factory('users', null, { 231 | types: ['admin', 'standard'], 232 | setRole: function(type) { 233 | if (this.types.indexOf(type) != -1) 234 | this.role = type 235 | } 236 | }) 237 | 238 | var user = ModelFactory.create({id: 1, name: "Bob", role: "standard"}) 239 | 240 | expect(user).to.have.property('types') 241 | expect(user).to.have.property('setRole') 242 | expect(user.setRole).to.be.a('function') 243 | 244 | user.setRole('admin') 245 | 246 | expect(user.role).to.equal('admin') 247 | }) 248 | 249 | it('as a function', function () { 250 | var ModelFactory = Rest.factory('users', null, function(user) { 251 | 252 | if(user.permissions == 'rwd') 253 | user.permissions = ['read', 'write', 'delete'] 254 | 255 | user.types = ['admin', 'standard'] 256 | user.setRole = function(type) { 257 | if (this.types.indexOf(type) != -1) 258 | this.role = type 259 | } 260 | 261 | return user 262 | }) 263 | 264 | var user = ModelFactory.create({id: 1, name: "Bob", role: "standard", permissions: 'rwd'}) 265 | 266 | shouldBeRestified(user, 'users', false) 267 | 268 | expect(user).to.have.property('types') 269 | expect(user).to.have.property('setRole') 270 | expect(user.setRole).to.be.a('function') 271 | expect(user.permissions).to.be.instanceof(Array) 272 | 273 | user.setRole('admin') 274 | 275 | expect(user.role).to.equal('admin') 276 | 277 | }) 278 | }) 279 | 280 | describe('should resolve/reject requests based on status codes', function() { 281 | 282 | it('should reject a 199 status code', function(done) { 283 | server.respondWith(function (request) { 284 | request.respond(199) 285 | }) 286 | User.getList().then(function() { 287 | throw new Error('Promise was unexpectedly fulfilled') 288 | }).catch(function () { 289 | done() 290 | }) 291 | }) 292 | 293 | it('should reject a 300 status code', function(done) { 294 | server.respondWith(function (request) { 295 | request.respond(300) 296 | }) 297 | User.getList().then(function() { 298 | throw new Error('Promise was unexpectedly fulfilled') 299 | }).catch(function () { 300 | done() 301 | }) 302 | }) 303 | 304 | it('should reject a 500 status code', function(done) { 305 | server.respondWith(function (request) { 306 | request.respond(500) 307 | }) 308 | User.getList().then(function() { 309 | throw new Error('Promise was unexpectedly fulfilled') 310 | }).catch(function () { 311 | done() 312 | }) 313 | }) 314 | 315 | it('should resolve a 200 status code', function(done) { 316 | server.respondWith(function (request) { 317 | request.respond(200) 318 | }) 319 | User.getList().catch(function() { 320 | throw new Error('Promise was unexpectedly rejected') 321 | }).then(done) 322 | }) 323 | 324 | it('should resolve a 201 status code', function(done) { 325 | server.respondWith(function (request) { 326 | request.respond(201) 327 | }) 328 | User.getList().catch(function() { 329 | throw new Error('Promise was unexpectedly rejected') 330 | }).then(done) 331 | }) 332 | }) 333 | 334 | 335 | function shouldBeRestified(element, route, fromServer=true) { 336 | expect(element).to.exist 337 | expect(element).to.have.property('get') 338 | expect(element).to.have.property('post') 339 | expect(element).to.have.property('patch') 340 | expect(element).to.have.property('put') 341 | expect(element).to.have.ownPropertyDescriptor('route', {enumerable: false, configurable: false, writable: false, value: route}) 342 | expect(element).to.have.ownPropertyDescriptor('fromServer', {enumerable: false, configurable: true, writable: false, value: fromServer}) 343 | } 344 | }) --------------------------------------------------------------------------------