├── .gitignore ├── .jshintrc ├── LICENSE.md ├── README.md ├── SECURITY.md ├── apis.json ├── browser ├── deployr.js └── deployr.min.js ├── deployr.js ├── examples ├── config.json ├── js-api │ ├── agency.js │ ├── apis.html │ ├── apis.js │ ├── chain.html │ ├── chain.js │ ├── code.html │ ├── code.js │ ├── ensure.js │ ├── entity.js │ ├── es-client.html │ ├── es-client.js │ ├── filter.js │ ├── no-chain.html │ ├── pipe.js │ ├── pipeline.js │ ├── promise.js │ ├── response.html │ ├── response.js │ ├── rinputs.html │ ├── rinputs.js │ ├── satscores.csv │ ├── script-auth.js │ ├── script.html │ ├── script.js │ ├── self-signed-cert.js │ ├── sugar.js │ ├── upload.html │ └── upload.js └── tutorial │ ├── authentication │ ├── authenticate.html │ └── authenticate.js │ ├── connection │ ├── connection.html │ └── connection.js │ └── services │ ├── background │ ├── auth-job-execute-code.html │ ├── auth-job-execute-code.js │ ├── auth-job-execute-script.html │ └── auth-job-execute-script.js │ ├── project │ ├── auth-project-create.html │ ├── auth-project-create.js │ ├── auth-project-directory.html │ ├── auth-project-directory.js │ ├── auth-project-execute-code.html │ ├── auth-project-execute-code.js │ ├── auth-project-execute-script.html │ ├── auth-project-execute-script.js │ ├── auth-project-packages.html │ ├── auth-project-packages.js │ ├── auth-project-pool-create.html │ ├── auth-project-pool-create.js │ ├── auth-project-workspace.html │ └── auth-project-workspace.js │ └── repository │ ├── auth-repository-management.html │ └── auth-repository-management.js ├── gulp ├── config.js ├── index.js ├── tasks │ ├── browserify.js │ ├── build.js │ ├── connect.js │ ├── default.js │ ├── header.js │ ├── jshint.js │ ├── start.js │ └── uglifyjs.js └── util │ ├── errors.js │ └── script-filter.js ├── gulpfile.js ├── lib ├── emitter.js ├── encoder.js ├── es.js ├── lang.js ├── logger.js ├── merge.js ├── optional.js ├── queue.js ├── rinput.js ├── rinputs.js ├── rtypes.js ├── selfish.js └── utils.js ├── package.json └── test └── test.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore build 2 | dist/ 3 | 4 | # Ignore extensions 5 | *.diff 6 | *.err 7 | *.log 8 | *.orig 9 | *.rej 10 | *.swo 11 | *.swp 12 | *.vi 13 | *.zip 14 | *~ 15 | 16 | # Ignore OS or Editor folders 17 | ._* 18 | .cache 19 | .DS_Store 20 | .project 21 | .settings 22 | .idea 23 | .tmproj 24 | *.esproj 25 | *.sublime-workspace 26 | *.sublime-project 27 | 28 | # Ignore node 29 | node_modules/ 30 | npm-debug.log -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "curly": false, 3 | "eqeqeq": true, 4 | "immed": true, 5 | "latedef": true, 6 | "newcap": true, 7 | "noarg": true, 8 | "sub": true, 9 | "undef": true, 10 | "boss": true, 11 | "eqnull": true, 12 | "node": true, 13 | "expr": true, 14 | "maxdepth": 3, 15 | "unused": true, 16 | "trailing": true, 17 | "quotmark": "simple", 18 | "strict": false, 19 | "browser": true, 20 | "newcap": false 21 | } 22 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (C) 2010-2016, Microsoft Corporation 2 | 3 | This program is licensed to you under the terms of Version 2.0 of the 4 | Apache License. This program is distributed WITHOUT 5 | ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 6 | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 7 | Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 8 | details. -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Security 4 | 5 | Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/). 6 | 7 | If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/opensource/security/definition), please report it to us as described below. 8 | 9 | ## Reporting Security Issues 10 | 11 | **Please do not report security vulnerabilities through public GitHub issues.** 12 | 13 | Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/opensource/security/create-report). 14 | 15 | If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey). 16 | 17 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc). 18 | 19 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: 20 | 21 | * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) 22 | * Full paths of source file(s) related to the manifestation of the issue 23 | * The location of the affected source code (tag/branch/commit or direct URL) 24 | * Any special configuration required to reproduce the issue 25 | * Step-by-step instructions to reproduce the issue 26 | * Proof-of-concept or exploit code (if possible) 27 | * Impact of the issue, including how an attacker might exploit the issue 28 | 29 | This information will help us triage your report more quickly. 30 | 31 | If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/opensource/security/bounty) page for more details about our active programs. 32 | 33 | ## Preferred Languages 34 | 35 | We prefer all communications to be in English. 36 | 37 | ## Policy 38 | 39 | Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/opensource/security/cvd). 40 | 41 | 42 | -------------------------------------------------------------------------------- /examples/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "endpoint": "http://localhost:8050", 3 | "cors": true, 4 | "credentials": { 5 | "username": "testuser", 6 | "password": "YOUR_TESTUSER_PASSWORD" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /examples/js-api/agency.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | * Copyright (C) 2010-2016, Microsoft Corporation 5 | * 6 | * This program is licensed to you under the terms of Version 2.0 of the 7 | * Apache License. This program is distributed WITHOUT 8 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 9 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 10 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 11 | * details. 12 | */ 13 | 14 | /* 15 | * usage: $ node agency.js 16 | * 17 | * Runs DeployR request chains using diffrent cookies. 18 | * 19 | * @NOTE - Any time deployr.io(...) is called it will create a new jsessionid, 20 | * in other words requests will not by sticky. Cookies are shared across 21 | * requests if you use the same `agent` (i.e. same authenticated user) 22 | * to make .io() calls to DeployR. 23 | * 24 | */ 25 | 26 | var deployr = require('../../deployr'), 27 | config = require('../config'), 28 | credentials = config.credentials; 29 | 30 | deployr.configure( { host: config.endpoint, sticky: false }); 31 | 32 | // ==================================================================== 33 | // should start with empty session and should gain a session cookie for 34 | // the chained requests 35 | // ==================================================================== 36 | 37 | var agent1 = deployr.io('/r/user/login') 38 | .data(credentials) 39 | .error(function(err) { 40 | console.log(err); 41 | }) 42 | .end(function(res) { 43 | console.log('agent1-HTTP COOKIE:: ' + agent1.getHeaders().Cookie); 44 | }); 45 | 46 | // ==================================================================== 47 | // should persist cookies across requests 48 | // ==================================================================== 49 | 50 | agent1.io('/r/project/create') 51 | .on('deployr-io:401', function(err) { 52 | console.log(err); 53 | }) 54 | .error(function(err) { console.log(err); }) 55 | .end(function(res) { 56 | console.log('agent1-HTTP COOKIE:: ' + agent1.getHeaders().Cookie); 57 | 58 | // add project-id to next `agent1.io` call which is `/r/project/close` 59 | return { project: res.get('project').project }; 60 | }); 61 | 62 | agent1.io('/r/project/close') 63 | .error(function(err) { console.log(err); }) 64 | .end(function(res) { 65 | console.log('agent1-HTTP COOKIE:: ' + agent1.getHeaders().Cookie); 66 | }) 67 | 68 | agent1.io('/r/user/about') 69 | .end(function(res) { 70 | console.log('agent1-HTTP COOKIE:: ' + agent1.getHeaders().Cookie); 71 | }); 72 | 73 | // ==================================================================== 74 | // should (not) share cookies with `agent1` 75 | // ==================================================================== 76 | 77 | // wait to send `agent3` until `agent2` returns so we can use agent2's cookies 78 | // notice no `.end()` used here. Remember `.end()` sends the request to DeployR 79 | var agent3 = deployr.script('/testuser/root/DeployR - Hello World.R'); 80 | 81 | var agent2 = deployr.script('/testuser/root/DeployR - Hello World.R') 82 | .error(function(err) { console.log(err); }) 83 | .end(function(res) { 84 | console.log('agent2-HTTP COOKIE:: ' + agent2.getHeaders().Cookie); 85 | 86 | 87 | // ==================================================================== 88 | // should share cookies with `agent2` 89 | // ==================================================================== 90 | agent3.share(agent2.getHeaders()).end(function(ires) { 91 | console.log('agent3-HTTP COOKIE:: ' + agent3.getHeaders().Cookie); 92 | }); 93 | }); 94 | 95 | // ==================================================================== 96 | // should not lose cookies between `agent2` 97 | // ==================================================================== 98 | 99 | agent1.script('/testuser/root/DeployR - Hello World.R') 100 | .error(function(err) { 101 | console.log(err); 102 | }) 103 | .end(function(res) { 104 | console.log('agent1-HTTP COOKIE:: ' + agent1.getHeaders().Cookie); 105 | }); 106 | -------------------------------------------------------------------------------- /examples/js-api/apis.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Example supported DeployR APIs 8 | 9 | 10 | 11 | 12 |

Example demonstrates how to list all supported DeployR APIs

13 |
14 |
    15 |
  1. Open the browser's debug window to view print logs for this example.
  2. 16 |
  3. View documentation for more information.
  4. 17 |
18 | 19 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /examples/js-api/apis.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | * Copyright (C) 2010-2016, Microsoft Corporation 5 | * 6 | * This program is licensed to you under the terms of Version 2.0 of the 7 | * Apache License. This program is distributed WITHOUT 8 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 9 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 10 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 11 | * details. 12 | */ 13 | 14 | /* 15 | * usage: $ node apis.js 16 | * 17 | * This example demonstrates how to list all the supported DeployR APIs and 18 | * printing to stdout. 19 | */ 20 | 21 | var util = require('util'), 22 | deployr = require('../../deployr'), 23 | flaten = true; 24 | 25 | var apis = deployr.apis(); 26 | 27 | console.log(util.inspect(apis, false, null, true)); 28 | 29 | console.log('\n============================================================\n'); 30 | 31 | apis = deployr.apis(flaten); 32 | console.log(util.inspect(apis, false, null, true)); 33 | -------------------------------------------------------------------------------- /examples/js-api/chain.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Example using request chaining 8 | 9 | 10 | 11 | 12 | 13 |

Example using request chaining

14 |
15 |
    16 |
  1. Populate /examples/config.json with the proper values before running.
  2. 17 |
  3. Open the browser's debug window to view print logs for this example.
  4. 18 |
  5. View documentation for more information.
  6. 19 |
20 | 21 | 132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /examples/js-api/chain.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | * Copyright (C) 2010-2016, Microsoft Corporation 5 | * 6 | * This program is licensed to you under the terms of Version 2.0 of the 7 | * Apache License. This program is distributed WITHOUT 8 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 9 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 10 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 11 | * details. 12 | */ 13 | 14 | /* 15 | * usage: $ node chain.js 16 | * 17 | * Runs a DeployR request chain in sequence but asynchronous: 18 | * -------------------------------------------------------------------- 19 | * 0. configure request to DeployR server endpoint 20 | * 1. /r/user/login 21 | * 2. /r/repository/script/execute 22 | * 3. /r/project/create 23 | * 4. /r/project/execute/script 24 | * 5. /r/project/close 25 | * 6. /r/user/logout 26 | * -------------------------------------------------------------------- 27 | * @NOTE - If error occures somewhere in the call chain it is aborted. 28 | */ 29 | 30 | var deployr = require('../../deployr'), 31 | config = require('../config'), 32 | credentials = config.credentials; 33 | 34 | deployr.configure({ logging: true, host: config.endpoint }) 35 | 36 | // ==================================================================== 37 | 38 | var ruser = deployr.auth(credentials.username, credentials.password); 39 | 40 | // ==================================================================== 41 | 42 | ruser.io('/r/repository/script/execute') 43 | .data({ filename: 'DeployR - Hello World', author: 'testuser' }) 44 | .numeric('input_randomNum', 10) 45 | .character('input_character', 'hello') 46 | .error(function(err) { 47 | // do something with the error 48 | }) 49 | .end(function(res, chain) { 50 | // do something with the success response 51 | }) 52 | // ==================================================================== 53 | .io('/r/project/create') 54 | .error(function(err) { 55 | // do something with the error 56 | }) 57 | .end(function(res, chain) { 58 | // attach project from `/r/project/create` on this io() call [2] 59 | return { project: res.get('project').project }; 60 | }) 61 | // ==================================================================== 62 | .io('/r/project/execute/script') 63 | .data({ filename: 'DeployR - Hello World', author: 'testuser' }) 64 | .numeric('input_randomNum', 10) 65 | .error(function(err) { 66 | // do something with the error 67 | }) 68 | .end(function(res, chain) { 69 | // attach project from `/r/project/create` on this io() call [2] 70 | return { project: chain[2].deployr.response.project.project }; 71 | }) 72 | // ==================================================================== 73 | .io('/r/project/close') 74 | .end(function(res, chain) { 75 | // do something with the success response 76 | }) 77 | // ==================================================================== 78 | .io('/r/user/logout') 79 | .end(function(res, chain) { 80 | // do something with the success response 81 | }); 82 | // ==================================================================== 83 | -------------------------------------------------------------------------------- /examples/js-api/code.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Example executing a block of R code on an `R session` 8 | 9 | 10 | 11 | 12 | 13 |

Example executing a block of R code on an `R session`

14 |
15 |
    16 |
  1. Populate /examples/config.json with the proper values before running.
  2. 17 |
  3. Open the browser's debug window to view print logs for this example.
  4. 18 |
  5. View documentation for more information.
  6. 19 |
20 | 21 | 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /examples/js-api/code.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | * Copyright (C) 2010-2016, Microsoft Corporation 5 | * 6 | * This program is licensed to you under the terms of Version 2.0 of the 7 | * Apache License. This program is distributed WITHOUT 8 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 9 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 10 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 11 | * details. 12 | */ 13 | 14 | /* 15 | * usage: $ node code.js 16 | * 17 | * Executes a block of R code on an R session. 18 | */ 19 | 20 | var util = require('util'), 21 | deployr = require('../../deployr'), 22 | config = require('../config'), 23 | credentials = config.credentials; 24 | 25 | /* 26 | * stdout helper to print a string representation of object for the example. 27 | */ 28 | var printf = function(property, obj) { 29 | console.log('========================'); 30 | console.log(property); 31 | console.log('========================'); 32 | console.log(util.inspect(obj, false, null, true)); 33 | console.log('\n\n'); 34 | }; 35 | 36 | console.log('Executing a block of R code on an `R session`...\n\n'); 37 | 38 | // ============================================================================ 39 | // Set the DeployR server endpoint URL and authenticate 40 | // ============================================================================ 41 | 42 | var ruser = deployr.configure({ host: config.endpoint }) 43 | .auth(credentials.username, credentials.password); 44 | 45 | // ============================================================================ 46 | // Executes a block of R code on the R session. 47 | // 48 | // @NOTE: 49 | // 50 | // 1. If no 'project' is passed to `.code(r, project) then a project is created 51 | // and included on this call's parameter as the R session identifier. 52 | // 53 | // 2. Be sure to close the project by calling `.release(project)`. It is the 54 | // responsibility of the developer to clean up projects. 55 | // ============================================================================ 56 | 57 | // project-id ref used to close project at the end 58 | var project = null; 59 | 60 | // R Code --> DeployR - Hello World.R 61 | var r = [ 'require(deployrUtils)', 62 | 'revoInput(\'{ "name": "input_randomNum", "label": "Sample size", "render": "integer", "default": 100, "min": 10, "max": 10000 }\')', 63 | 'x<-rnorm(input_randomNum)', 64 | 'plotTitle<-paste(\'Histogram of\', input_randomNum, "Random Values")', 65 | 'png(filename="histogram.png")', 66 | 'hist(x, main=plotTitle)', 67 | 'dev.off()' 68 | ].join('\n'); 69 | 70 | // execute the block of R code passing in an 'R numeric' named `input_random` 71 | ruser.code(r) 72 | .numeric('input_randomNum', 10) 73 | .error(function(err) { 74 | printf('Error', err); 75 | }) 76 | .end(function(res) { 77 | project = res.get('project').project; 78 | 79 | // print to stdout 80 | printf('console', res.get('console')); 81 | printf('code', res.get('code')); 82 | printf('artifacts', res.get('artifacts')); 83 | }) 84 | .ensure(function() { 85 | ruser.release(project); 86 | }); 87 | -------------------------------------------------------------------------------- /examples/js-api/ensure.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | * Copyright (C) 2010-2016, Microsoft Corporation 5 | * 6 | * This program is licensed to you under the terms of Version 2.0 of the 7 | * Apache License. This program is distributed WITHOUT 8 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 9 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 10 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 11 | * details. 12 | */ 13 | 14 | /* 15 | * usage: $ node ensure.js 16 | * 17 | * Simple promise chaining using `.ensure()` and `.then()` based on the 18 | * Promises/A+ specs. 19 | */ 20 | 21 | var config = require('../config'), 22 | credentials = config.credentials, 23 | deployr = require('../../deployr').configure( { host: config.endpoint }); 24 | 25 | var ruser = deployr.auth(credentials.username, credentials.password); 26 | 27 | ruser.script('/testuser/root/DeployR - Hello World.R') 28 | .end(function() { 29 | console.log('script'); 30 | }) 31 | .ensure(function() { 32 | console.log('finally cleanup...'); 33 | // using `ruser` implies that a logout occurs on the same user session 34 | ruser.release(); 35 | }) 36 | .then(function(res) { 37 | console.log('then this.'); 38 | return res; // pass result to the next `.then()` 39 | }, function(err) { 40 | console.log(err); 41 | }) 42 | .then(function(res) { 43 | console.log('after that then this.'); 44 | return res; // pass result to the next `.then()` 45 | }) 46 | .then(function(res) { 47 | console.log('after that then we are done.'); 48 | console.log(res); 49 | }); 50 | -------------------------------------------------------------------------------- /examples/js-api/entity.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | * Copyright (C) 2010-2016, Microsoft Corporation 5 | * 6 | * This program is licensed to you under the terms of Version 2.0 of the 7 | * Apache License. This program is distributed WITHOUT 8 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 9 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 10 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 11 | * details. 12 | */ 13 | 14 | /* 15 | * usage: $ node entiry.js 16 | * 17 | * Runs a DeployR basic auth using the `.entity('user')` helper method to 18 | * filter-out and return only the Top Level `user` entity from the response. 19 | * 20 | * The supported `Top Level` entities are: 21 | * - 'user' 22 | * - 'project' 23 | * - 'workspace' 24 | * - 'execution' 25 | * - 'directory' 26 | * - 'repository', 27 | * - 'packages' 28 | */ 29 | 30 | var config = require('../config'), 31 | credentials = config.credentials, 32 | deployr = require('../../deployr').configure( { host: config.endpoint }); 33 | 34 | deployr.io('/r/user/login') 35 | .data(credentials) 36 | .entity('user') 37 | .error(function(err) { 38 | console.log(err); 39 | }) 40 | .end(function(res) { 41 | // viewing the response will show only the `user` section returned and the 42 | // rest filtered out 43 | console.log(res); 44 | }) 45 | .io('/r/user/logout') 46 | .end(); 47 | -------------------------------------------------------------------------------- /examples/js-api/es-client.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | * Copyright (C) 2010-2016, Microsoft Corporation 5 | * 6 | * This program is licensed to you under the terms of Version 2.0 of the 7 | * Apache License. This program is distributed WITHOUT 8 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 9 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 10 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 11 | * details. 12 | */ 13 | 14 | /* 15 | * usage: $ node es-client.js 16 | * 17 | * Example binding to the DeployR EventStream API `/r/event/stream`. 18 | * 19 | * example dependencies: express 20 | * - $ npm install express 21 | */ 22 | 23 | var deployr = require('../../deployr'), 24 | config = require('../config'), 25 | util = require('util'), 26 | app = require('express')(); // just used in example for listening 27 | 28 | /* 29 | * stdout helper to print a string representation of object for the example. 30 | */ 31 | var printf = function(obj) { 32 | console.log(util.inspect(obj, false, null, true)); 33 | console.log('\n\n'); 34 | }; 35 | 36 | deployr.configure({ logging: false, host: config.endpoint }); 37 | 38 | var es = deployr.es(config.credentials) 39 | // 40 | // -------------------------------------------------------------------- 41 | // -- convenience functions for connection filter event type choices -- 42 | // 43 | //.project(pid) // equivalent to es.open({ project: pid }) 44 | //.job(jid) // equivalent to es.open({ job: jid }) 45 | //.httpEventOnly() // equivalent to es.open({ httpEventOnly: true }) 46 | //.revoEventOnly() // equivalent to es.open({ revoEventOnly: true }) 47 | //.managementEventOnly() // equivalent to es.open({ managementEventOnly: true }) 48 | // -------------------------------------------------------------------- 49 | // 50 | .on('es:connecting', function(data) { 51 | console.log('==================='); 52 | console.log('es:connecting'); 53 | console.log('==================='); 54 | printf(data); 55 | }) 56 | .on('es:open', function(data) { 57 | console.log('==================='); 58 | console.log('es:open'); 59 | console.log('==================='); 60 | }) 61 | .on('es:close', function(data) { 62 | console.log('==================='); 63 | console.log('es:close'); 64 | console.log('==================='); 65 | }) 66 | .on('es:error', function(data) { 67 | console.log('==================='); 68 | console.log('es:error'); 69 | console.log('==================='); 70 | printf(data); 71 | }) 72 | .on('es:streamConnect', function(data) { 73 | console.log('==================='); 74 | console.log('es:streamConnect'); 75 | console.log('==================='); 76 | printf(data); 77 | }) 78 | .on('es:streamDisconnect', function(data) { 79 | console.log('==================='); 80 | console.log('es:streamDisconnect'); 81 | console.log('==================='); 82 | printf(data); 83 | }) 84 | .on('es:executionConsole', function(data) { 85 | console.log('==================='); 86 | console.log('es:executionConsole'); 87 | console.log('==================='); 88 | printf(data); 89 | }) 90 | .on('es:executionRevo', function(data) { 91 | console.log('==================='); 92 | console.log('es:executionRevo'); 93 | console.log('==================='); 94 | printf(data); 95 | }) 96 | .on('es:executionError', function(data) { 97 | console.log('==================='); 98 | console.log('es:executionError'); 99 | console.log('==================='); 100 | printf(data); 101 | }) 102 | .on('es:jobLifecycle', function(data) { 103 | console.log('==================='); 104 | console.log('es:jobLifecycle'); 105 | console.log('==================='); 106 | printf(data); 107 | }) 108 | .on('es:gridHeartbeat', function(data) { 109 | console.log('==================='); 110 | console.log('es:gridHeartbeat'); 111 | console.log('==================='); 112 | printf(data); 113 | }) 114 | .on('es:gridActivity', function(data) { 115 | console.log('==================='); 116 | console.log('es:gridActivity'); 117 | console.log('==================='); 118 | printf(data); 119 | }) 120 | .on('es:gridWarning', function(data) { 121 | console.log('==================='); 122 | console.log('es:gridWarning'); 123 | console.log('==================='); 124 | printf(data); 125 | }) 126 | .on('es:securityLogin', function(data) { 127 | console.log('==================='); 128 | console.log('es:securityLogin'); 129 | console.log('==================='); 130 | printf(data); 131 | }) 132 | .on('es:securityLogout', function(data) { 133 | console.log('==================='); 134 | console.log('es:securityLogout'); 135 | console.log('==================='); 136 | printf(data); 137 | }) 138 | .open({ 139 | // 140 | // Shared cookies from other authenticated DeployR requests if you are 141 | // *not* authenticating via the `deployr.es(credentials)` above. 142 | // 143 | //cookies: [ 'JSESSIONID=086669ABC226EB78; Path=/deployr/; HttpOnly' ] 144 | 145 | // 146 | // Indicate the DeployR event stream to push events only for this 147 | // project. 148 | // 149 | //project: 'PROJECT-ID', 150 | 151 | // 152 | // Indicate the DeployR event stream to push events only for this job. 153 | // 154 | //job: 'JOB-ID', 155 | 156 | // 157 | // If true then an authenticated event stream will see only execution 158 | // events associated with the current HTTP session. 159 | // 160 | //httpEventOnly: true, 161 | 162 | // 163 | // If true then execution executionConsoleEvent events are suppressed on 164 | // the event stream 165 | // 166 | // 167 | //revoEventOnly: true 168 | 169 | // 170 | // If true then event stream connection type is management 171 | // 172 | //managementEventOnly: true 173 | }); 174 | -------------------------------------------------------------------------------- /examples/js-api/filter.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | * Copyright (C) 2010-2016, Microsoft Corporation 5 | * 6 | * This program is licensed to you under the terms of Version 2.0 of the 7 | * Apache License. This program is distributed WITHOUT 8 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 9 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 10 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 11 | * details. 12 | */ 13 | 14 | /* 15 | * usage: $ node filter.js 16 | * 17 | * This example demonstrates how to "filter" out a chained sequence of requests. 18 | * A filter is helpful to keep the request chain in a nice fluid sequence 19 | * without having to brake it up in your code with `if` `else` statements. 20 | */ 21 | 22 | var deployr = require('../../deployr'), 23 | config = require('../config'); 24 | 25 | deployr.configure({ host: config.endpoint, logging: false }); 26 | 27 | console.log('Starting...'); 28 | 29 | // 30 | // Execute R script `/author/directory/filename` three times in sequence. 31 | // - author: testuser 32 | // - directory: root 33 | // - filename: DeployR - Hello World.R 34 | // 35 | deployr.script('/testuser/root/DeployR - Hello World.R') 36 | .numeric('input_randomNum', 10) 37 | .end(function(res) { 38 | console.log('The next request will be filtered out.') 39 | return { consoleoff: false }; 40 | }) 41 | .script('/testuser/root/DeployR - Hello World.R') 42 | .filter(function(data) { 43 | // if false is returned this `io` call will be filtered from the chain 44 | return data.consoleoff; // `false` intentionally from above 45 | }) 46 | .numeric('input_randomNum', 20) 47 | .end(function(res) { 48 | console.log('I should not be called because I was filtered out.'); 49 | }) 50 | .script('/testuser/root/DeployR - Hello World.R') 51 | .numeric('input_randomNum', 30) 52 | .end(function(res) { 53 | console.log('Last request finished.') 54 | }) 55 | .ensure(function() { 56 | console.log('Completed...') 57 | }); 58 | -------------------------------------------------------------------------------- /examples/js-api/no-chain.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Example using no request chaining 8 | 9 | 10 | 11 | 12 | 13 |

Example using no request chaining

14 |
15 |
    16 |
  1. Populate /examples/config.json with the proper values before running.
  2. 17 |
  3. Open the browser's debug window to view print logs for this example.
  4. 18 |
  5. View documentation for more information.
  6. 19 |
20 | 21 | 168 | 169 | 170 | 171 | -------------------------------------------------------------------------------- /examples/js-api/pipe.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | * Copyright (C) 2010-2016, Microsoft Corporation 5 | * 6 | * This program is licensed to you under the terms of Version 2.0 of the 7 | * Apache License. This program is distributed WITHOUT 8 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 9 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 10 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 11 | * details. 12 | */ 13 | 14 | /* 15 | * usage: $ node pipe.js 16 | * 17 | * Streaming JSON parser to pull out all `artifact urls` from a DeployR response 18 | * and prints them to stdout. 19 | * 20 | * dependencies: JSONStream 21 | * - $ npm install JSONStream 22 | */ 23 | 24 | var JSONStream = require('JSONStream'), 25 | config = require('../config'), 26 | credentials = config.credentials, 27 | deployr = require('../../deployr').configure({ host: config.endpoint }); 28 | 29 | deployr.script('/testuser/root/DeployR - Hello World.R') 30 | .numeric('input_randomNum', 10) 31 | .pipe(JSONStream.parse('deployr.response.execution.artifacts.*.url')) 32 | .pipe(JSONStream.stringify(false)) 33 | .pipe(process.stdout); 34 | -------------------------------------------------------------------------------- /examples/js-api/pipeline.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | * Copyright (C) 2010-2016, Microsoft Corporation 5 | * 6 | * This program is licensed to you under the terms of Version 2.0 of the 7 | * Apache License. This program is distributed WITHOUT 8 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 9 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 10 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 11 | * details. 12 | */ 13 | 14 | /* 15 | * usage: $ node pipeline.js 16 | * 17 | * Runs two 'tasks' of DeployR request chains in sequence but asynchronous: 18 | * ---------------------------------------------------------------------------- 19 | * 0. configure request to DeployR server `http://dhost:dport` 20 | * 21 | * -------------------------------- 22 | * Batch 1 (runs first) 23 | * -------------------------------- 24 | * 1. /r/user/login 25 | * 2. /r/repository/script/execute 26 | * 3. /r/project/create 27 | * 4. /r/project/execute/script 28 | * 5. /r/project/close 29 | * -------------------------------- 30 | * Batch 2 (runs second) 31 | * -------------------------------- 32 | * 1. /r/user/about 33 | * 2. /r/user/logout 34 | * ---------------------------------------------------------------------------- 35 | * @NOTE - If error occures somewhere in the call chain it is aborted. 36 | */ 37 | 38 | var deployr = require('../../deployr'), 39 | config = require('../config'), 40 | credentials = config.credentials; 41 | 42 | deployr.configure({ logging: false, host: config.endpoint }); 43 | 44 | function firstTask() { 45 | 46 | return deployr.io('/r/user/login') 47 | .delay() 48 | .data(credentials) 49 | .end() 50 | .io('/r/repository/script/execute') 51 | .delay() 52 | .data({ filename: 'DeployR - Hello World', author: 'testuser' }) 53 | .numeric('input_randomNum', 10) 54 | .end() 55 | .io('/r/project/create') 56 | .delay() 57 | .end(function (res, chain) { 58 | // attach project from `/r/project/create` on this io() call [2] 59 | return { project: res.deployr.response.project.project }; 60 | }) 61 | .io('/r/project/execute/script') 62 | .delay() 63 | .data({ filename: 'DeployR - Hello World', author: 'testuser' }) 64 | .numeric('input_randomNum', 10) 65 | .end(function (res, chain) { 66 | // attach project from `/r/project/create` on this io() call [2] 67 | return { project: chain[2].deployr.response.project.project }; 68 | }) 69 | // ================================================================ 70 | .io('/r/project/close') 71 | .delay() 72 | .end(); 73 | } 74 | 75 | function secondTask() { 76 | return deployr.io('/r/user/about') 77 | .delay() 78 | .end() 79 | .io('/r/user/logout') 80 | .delay() 81 | .end(); 82 | } 83 | 84 | /* 85 | * deployr.pipline() 86 | * 87 | * Runs an array of `tasks` in sequence, without overlap where a `task` is one 88 | * or more chained sequ `.io()` call(s) to DeployR. This examples piplines two 89 | * `task` batches. 90 | * 91 | * @@@ Important @@@ 92 | * 93 | * You must `.delay()` the `.io()` calls otherwise they will run immediately and 94 | * in parallel. 95 | */ 96 | 97 | console.log('Starting the DeployR request pipeline...'); 98 | 99 | deployr.pipeline([firstTask(), secondTask()]) 100 | .then(function(chain) { 101 | console.log('[success]--------------------------------------------------'); 102 | 103 | // print results for each request in each task that ran through the pipeline 104 | chain.results.forEach(function(task, index) { 105 | console.log('---------------------------------'); 106 | console.log('Task ' + (index + 1) + ' results'); 107 | console.log('---------------------------------'); 108 | task.forEach(function(result) { console.log(result); }); 109 | }); 110 | 111 | console.log('-----------------------------------------------------------'); 112 | }, function(err) { 113 | console.log('[error]----------------------------------------------------'); 114 | console.log(err); 115 | console.log('-----------------------------------------------------------'); 116 | }); 117 | -------------------------------------------------------------------------------- /examples/js-api/promise.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | * Copyright (C) 2010-2016, Microsoft Corporation 5 | * 6 | * This program is licensed to you under the terms of Version 2.0 of the 7 | * Apache License. This program is distributed WITHOUT 8 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 9 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 10 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 11 | * details. 12 | */ 13 | 14 | /* 15 | * usage: $ node promise.js 16 | * 17 | * Simple promise chaining using `.promise()` rather than `.end()` to send the 18 | * DeployR request. The return value of `.promise()` will be a Promise based on 19 | * the Promises/A+ specs. 20 | */ 21 | 22 | var config = require('../config'), 23 | credentials = config.credentials, 24 | deployr = require('../../deployr').configure( { host: config.endpoint }); 25 | 26 | var ruser = deployr.auth(credentials.username, credentials.password); 27 | 28 | ruser.io('/r/user/about') 29 | .promise() // using `.promise()` instead of `.end()` to send the request 30 | .then(function(res) { 31 | console.log('then this.'); 32 | return res; // pass result to the next `.then()` 33 | }, function(err) { 34 | console.log(err); 35 | }) 36 | .then(function(res) { 37 | console.log('after that then this.'); 38 | return res; // pass result to the next `.then()` 39 | }) 40 | .then(function(res) { 41 | console.log('after that then we are done.'); 42 | console.log(res); 43 | }) 44 | .ensure(function() { 45 | console.log('finally cleanup...'); 46 | ruser.release(); 47 | }); 48 | -------------------------------------------------------------------------------- /examples/js-api/response.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Example inspecting response 8 | 9 | 10 | 11 | 12 | 13 |

Example inspecting response

14 |
15 |
    16 |
  1. Populate /examples/config.json with the proper values before running.
  2. 17 |
  3. Open the browser's debug window to view print logs for this example.
  4. 18 |
  5. View documentation for more information.
  6. 19 |
20 | 21 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /examples/js-api/response.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | * Copyright (C) 2010-2016, Microsoft Corporation 5 | * 6 | * This program is licensed to you under the terms of Version 2.0 of the 7 | * Apache License. This program is distributed WITHOUT 8 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 9 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 10 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 11 | * details. 12 | */ 13 | 14 | /* 15 | * usage: $ node response.js 16 | * 17 | * Example inspecting and printing a DeployR `/r/repository/script/execute` 18 | * response using the `.get(key)` helper for easy response property lookup. 19 | */ 20 | var util = require('util'), 21 | deployr = require('../../deployr'), 22 | config = require('../config'); 23 | 24 | /* 25 | * stdout helper to print a string representation of an object for the example. 26 | */ 27 | var printf = function(key, obj) { 28 | console.log('========================'); 29 | console.log(key); 30 | console.log('========================'); 31 | console.log(util.inspect(obj, false, null, true)); 32 | console.log('\n\n'); 33 | }; 34 | 35 | deployr.configure({ host: config.endpoint }) 36 | .script('/testuser/root/DeployR - Hello World.R') 37 | .numeric('input_randomNum', 10) 38 | .end(function(res) { 39 | printf('Response', res); 40 | printf('call', res.get('call')); 41 | printf('success', res.get('success')); 42 | printf('artifacts', res.get('artifacts')); 43 | printf('console', res.get('console')); 44 | }); 45 | -------------------------------------------------------------------------------- /examples/js-api/satscores.csv: -------------------------------------------------------------------------------- 1 | State,ExpPerPupil,PupilTchrRatio,TchrSalary,PctSAT,VerbalSAT,MathSAT,AveSAT 2 | Alabama,4.405,17.2,31.144,8,491,538,1029 3 | Alaska,8.963,17.6,47.951,47,445,489,934 4 | Arizona,4.778,19.3,32.175,27,448,496,944 5 | Arkansas,4.459,17.1,28.934,6,482,523,1005 6 | California,4.992,24,41.078,45,417,485,902 7 | Colorado,5.443,18.4,34.571,29,462,518,980 8 | Connecticut,8.817,14.4,50.045,81,431,477,908 9 | Delaware,7.03,16.6,39.076,68,429,468,897 10 | Florida,5.718,19.1,32.588,48,420,469,889 11 | Georgia,5.193,16.3,32.291,65,406,448,854 12 | Hawaii,6.078,17.9,38.518,57,407,482,889 13 | Idaho,4.21,19.1,29.783,15,468,511,979 14 | Illinois,6.136,17.3,39.431,13,488,560,1048 15 | Indiana,5.826,17.5,36.785,58,415,467,882 16 | Iowa,5.483,15.8,31.511,5,516,583,1099 17 | Kansas,5.817,15.1,34.652,9,503,557,1060 18 | Kentucky,5.217,17,32.257,11,477,522,999 19 | Louisiana,4.761,16.8,26.461,9,486,535,1021 20 | Maine,6.428,13.8,31.972,68,427,469,896 21 | Maryland,7.245,17,40.661,64,430,479,909 22 | Massachusetts,7.287,14.8,40.795,80,430,477,907 23 | Michigan,6.994,20.1,41.895,11,484,549,1033 24 | Minnesota,6,17.5,35.948,9,506,579,1085 25 | Mississippi,4.08,17.5,26.818,4,496,540,1036 26 | Missouri,5.383,15.5,31.189,9,495,550,1045 27 | Montana,5.692,16.3,28.785,21,473,536,1009 28 | Nebraska,5.935,14.5,30.922,9,494,556,1050 29 | Nevada,5.16,18.7,34.836,30,434,483,917 30 | New Hampshire,5.859,15.6,34.72,70,444,491,935 31 | New Jersey,9.774,13.8,46.087,70,420,478,898 32 | New Mexico,4.586,17.2,28.493,11,485,530,1015 33 | New York,9.623,15.2,47.612,74,419,473,892 34 | North Carolina,5.077,16.2,30.793,60,411,454,865 35 | North Dakota,4.775,15.3,26.327,5,515,592,1107 36 | Ohio,6.162,16.6,36.802,23,460,515,975 37 | Oklahoma,4.845,15.5,28.172,9,491,536,1027 38 | Oregon,6.436,19.9,38.555,51,448,499,947 39 | Pennsylvania,7.109,17.1,44.51,70,419,461,880 40 | Rhode Island,7.469,14.7,40.729,70,425,463,888 41 | South Carolina,4.797,16.4,30.279,58,401,443,844 42 | South Dakota,4.775,14.4,25.994,5,505,563,1068 43 | Tennessee,4.388,18.6,32.477,12,497,543,1040 44 | Texas,5.222,15.7,31.223,47,419,474,893 45 | Utah,3.656,24.3,29.082,4,513,563,1076 46 | Vermont,6.75,13.8,35.406,68,429,472,901 47 | Virginia,5.327,14.6,33.987,65,428,468,896 48 | Washington,5.906,20.2,36.151,48,443,494,937 49 | West Virginia,6.107,14.8,31.944,17,448,484,932 50 | Wisconsin,6.93,15.9,37.746,9,501,572,1073 51 | Wyoming,6.16,14.9,31.285,10,476,525,1001 52 | -------------------------------------------------------------------------------- /examples/js-api/script-auth.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | * Copyright (C) 2010-2016, Microsoft Corporation 5 | * 6 | * This program is licensed to you under the terms of Version 2.0 of the 7 | * Apache License. This program is distributed WITHOUT 8 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 9 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 10 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 11 | * details. 12 | */ 13 | 14 | /* 15 | * usage: $ node script.js 16 | * 17 | * Executes the repository-managed R script 'DeployR - Hello World.R' on an 18 | * anonymous project passing in `R numeric` value of '10' named 'input_randNum'. 19 | * 20 | * ############################################################################# 21 | * # 'DeployR - Hello World.R 22 | * ############################################################################# 23 | * 24 | * # generate a vector of random numbers, using object "input_randomNum" to 25 | * # indicate how many values to create 26 | * 27 | * require(RevoScriptTools) 28 | * revoInput('{ "name": "input_randomNum", "label": "Sample size", "render": "integer", "default": 100, "min": 10, "max": 10000 }') 29 | * 30 | * x<-rnorm(input_randomNum) 31 | * plotTitle<-paste('Histogram of', input_randomNum, "Random Values") 32 | * 33 | * #generate a histogram of those random numbers, and write 34 | * #the histogram to a file 35 | * png(filename="histogram.png") 36 | * hist(x, main=plotTitle) 37 | * dev.off() 38 | */ 39 | 40 | var util = require('util'), 41 | deployr = require('../../deployr'), 42 | config = require('../config'), 43 | credentials = config.credentials; 44 | 45 | /* 46 | * stdout helper to print a string representation of object for the example. 47 | */ 48 | var printf = function(property, obj) { 49 | console.log('========================'); 50 | console.log(property); 51 | console.log('========================'); 52 | console.log(util.inspect(obj, false, null, true)); 53 | console.log('\n\n'); 54 | }; 55 | 56 | console.log('Executing the repository-managed R script ' + 57 | '"DeployR - Hello World.R" twice for:\n' + 58 | 'author: testuser\n' + 59 | 'directory: root\n' + 60 | 'filename: DeployR - Hello World.R\n'); 61 | 62 | // ============================================================================ 63 | // Set the DeployR server endpoint URL 64 | // ============================================================================ 65 | 66 | var ruser = deployr.configure({ host: config.endpoint, logging: false }) 67 | .auth(credentials.username, credentials.password); 68 | 69 | 70 | // 71 | // Execute R script `/author/directory/filename` 72 | // - author: testuser 73 | // - directory: root 74 | // - filename: DeployR - Hello World.R 75 | // 76 | ruser.script('/testuser/root/DeployR - Hello World.R') 77 | .numeric('input_randomNum', 10) 78 | .data({ enableConsoleEvents: true }) 79 | .error(function(err) { 80 | console.log(err) 81 | }) 82 | .end(function(res) { 83 | printf('artifacts', res.get('artifacts')); // stdout 84 | }); 85 | -------------------------------------------------------------------------------- /examples/js-api/script.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Example executing a repository-managed `R script` 8 | 9 | 10 | 11 | 12 | 13 |

Example executing a repository-managed `R script`

14 |
15 |
    16 |
  1. Populate /examples/config.json with the proper values before running.
  2. 17 |
  3. Open the browser's debug window to view print logs for this example.
  4. 18 |
  5. View documentation for more information.
  6. 19 |
20 | 21 | 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /examples/js-api/script.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | * Copyright (C) 2010-2016, Microsoft Corporation 5 | * 6 | * This program is licensed to you under the terms of Version 2.0 of the 7 | * Apache License. This program is distributed WITHOUT 8 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 9 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 10 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 11 | * details. 12 | */ 13 | 14 | /* 15 | * usage: $ node script.js 16 | * 17 | * Executes the repository-managed R script 'DeployR - Hello World.R' on an 18 | * anonymous project passing in `R numeric` value of '10' named 'input_randNum'. 19 | * 20 | * ############################################################################# 21 | * # 'DeployR - Hello World.R 22 | * ############################################################################# 23 | * 24 | * # generate a vector of random numbers, using object "input_randomNum" to 25 | * # indicate how many values to create 26 | * 27 | * require(RevoScriptTools) 28 | * revoInput('{ "name": "input_randomNum", "label": "Sample size", "render": "integer", "default": 100, "min": 10, "max": 10000 }') 29 | * 30 | * x<-rnorm(input_randomNum) 31 | * plotTitle<-paste('Histogram of', input_randomNum, "Random Values") 32 | * 33 | * #generate a histogram of those random numbers, and write 34 | * #the histogram to a file 35 | * png(filename="histogram.png") 36 | * hist(x, main=plotTitle) 37 | * dev.off() 38 | */ 39 | 40 | var util = require('util'), 41 | deployr = require('../../deployr'), 42 | config = require('../config'); 43 | 44 | /* 45 | * stdout helper to print a string representation of object for the example. 46 | */ 47 | var printf = function(property, obj) { 48 | console.log('========================'); 49 | console.log(property); 50 | console.log('========================'); 51 | console.log(util.inspect(obj, false, null, true)); 52 | console.log('\n\n'); 53 | }; 54 | 55 | console.log('Executing the repository-managed R script ' + 56 | '"DeployR - Hello World.R" twice for:\n' + 57 | 'author: testuser\n' + 58 | 'directory: root\n' + 59 | 'filename: DeployR - Hello World.R\n'); 60 | 61 | // ============================================================================ 62 | // Set the DeployR server endpoint URL 63 | // ============================================================================ 64 | 65 | deployr.configure({ host: config.endpoint, logging: false }); 66 | 67 | // 68 | // Execute R script `/author/directory/filename` 69 | // - author: testuser 70 | // - directory: root 71 | // - filename: DeployR - Hello World.R 72 | // 73 | deployr.script('/testuser/root/DeployR - Hello World.R') 74 | .numeric('input_randomNum', 10) 75 | .error(function(err) { 76 | console.log(err) 77 | }) 78 | .end(function(res) { 79 | printf('artifacts', res.get('artifacts')); // stdout 80 | }); 81 | 82 | // 83 | // Alternatively you can use the `.io('/r/repository/script/execute')` syntax. 84 | // The two are equivalent. 85 | // 86 | deployr.io('/r/repository/script/execute') 87 | .data({ 88 | author: 'testuser', 89 | directory: 'root', 90 | filename: 'DeployR - Hello World.R' 91 | }) 92 | .numeric('input_randomNum', 10) 93 | .error(function(err) { 94 | console.log(err) 95 | }) 96 | .end(function(res) { 97 | printf('artifacts', res.get('artifacts')); // stdout 98 | }); 99 | -------------------------------------------------------------------------------- /examples/js-api/self-signed-cert.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | * Copyright (C) 2010-2016, Microsoft Corporation 5 | * 6 | * This program is licensed to you under the terms of Version 2.0 of the 7 | * Apache License. This program is distributed WITHOUT 8 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 9 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 10 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 11 | * details. 12 | */ 13 | 14 | /* 15 | * usage: $ node self-singed-cert.js 16 | * 17 | * Successfully executes on "https" using a self signed certificate on a 18 | * DeployR server with SSL. 19 | */ 20 | 21 | var deployr = require('../../deployr'), 22 | config = require('../config'); 23 | 24 | // ============================================================================ 25 | // Assuming endpoint of https://dhost:7401 and SSL enabled with a self signed 26 | // cert, set the DeployR server endpoint URL with the `allowSelfSignedSSLCert` 27 | // set to `true`. 28 | // ============================================================================ 29 | 30 | deployr.configure({ host: config.endpoint, allowSelfSignedSSLCert: true }); 31 | 32 | // should run successfully... 33 | deployr.io('/r/server/info') 34 | .error(function(err) { 35 | console.log(err) 36 | }) 37 | .end(function(res) { 38 | console.log('Successfully executed on "https" using a self signed ' + 39 | 'certificate on DeployR server \n "' + config.endpoint + '"'); 40 | }); 41 | -------------------------------------------------------------------------------- /examples/js-api/sugar.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | * Copyright (C) 2010-2016, Microsoft Corporation 5 | * 6 | * This program is licensed to you under the terms of Version 2.0 of the 7 | * Apache License. This program is distributed WITHOUT 8 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 9 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 10 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 11 | * details. 12 | */ 13 | 14 | /* 15 | * usage: $ node sugar.js 16 | * 17 | * Make DeployR "sweeter" for human use using the `script` and `auth` sugar 18 | * methods. 19 | */ 20 | 21 | var util = require('util'), 22 | deployr = require('../../deployr'), 23 | config = require('../config'), 24 | credentials = config.credentials; 25 | 26 | /* 27 | * stdout helper to print a string representation of object for the example. 28 | */ 29 | var printf = function(property, obj) { 30 | console.log('========================'); 31 | console.log(property); 32 | console.log('========================'); 33 | console.log(util.inspect(obj, false, null, true)); 34 | console.log('\n\n'); 35 | }; 36 | 37 | // ============================================================================ 38 | // Set the DeployR server endpoint URL 39 | // ============================================================================ 40 | 41 | deployr.configure({ host: config.endpoint, logging: false }); 42 | 43 | // ============================================================================ 44 | // Executes repository-managed scripts on an Anonymous Project. 45 | // ============================================================================ 46 | 47 | deployr.script('/testuser/root/DeployR - Hello World.R') 48 | .numeric('input_randomNum', 10) 49 | .end(function(res) { 50 | printf('console', res.get('console')); // stdout 51 | }); 52 | 53 | // ============================================================================ 54 | // Executes repository-managed scripts on the R session. 55 | // @NOTE: 56 | // 57 | // `.script( { project: true } ...)` will implicitly create a temporary project 58 | // and use it for the script execution 59 | // ============================================================================ 60 | 61 | var project = null; // project-id used to close project at the end 62 | 63 | // If you had a valid ProjectID here you could use it. Since we do not we can 64 | // pass in `true` and a temp project will be created as a convenience. 65 | var createProject = true; 66 | 67 | // login 68 | var ruser = deployr.auth(credentials.username, credentials.password); 69 | 70 | // Executes repository-managed scripts on the R session. 71 | ruser.script('/testuser/root/DeployR - Hello World.R', createProject) 72 | .numeric('input_randomNum', 10) 73 | .end(function(res) { 74 | project = res.get('project').project; // save project so we can close later 75 | 76 | // stdout 77 | printf('console', res.get('console')); 78 | printf('artifacts', res.get('artifacts')); 79 | }) 80 | .ensure(function() { 81 | ruser.release(project); 82 | }); 83 | -------------------------------------------------------------------------------- /examples/js-api/upload.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Example File Upload 9 | 10 | 11 | 12 | 13 | 14 |

Example File Upload

15 |
16 |
    17 |
  1. Populate /examples/config.json with the proper values before running.
  2. 18 |
  3. Choose the /examples/js-api/satscores.csv file to upload.
  4. 19 |
  5. Click the `upload` button.
  6. 20 |
  7. Open the browser's debug window to view print logs for this example.
  8. 21 |
  9. View documentation for more information.
  10. 22 |
23 | 24 |
25 | 26 |
27 |

28 | 29 |

30 | 31 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /examples/js-api/upload.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | * Copyright (C) 2010-2016, Microsoft Corporation 5 | * 6 | * This program is licensed to you under the terms of Version 2.0 of the 7 | * Apache License. This program is distributed WITHOUT 8 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 9 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 10 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 11 | * details. 12 | */ 13 | 14 | /* 15 | * usage: $ node upload.js 16 | * 17 | * Simple file upload using `.attach(/path/to/file)` 18 | * 19 | */ 20 | var path = require('path'), 21 | config = require('../config'), 22 | credentials = config.credentials, 23 | deployr = require('../../deployr').configure( { host: config.endpoint }); 24 | 25 | var ruser = deployr.auth(credentials.username, credentials.password); 26 | 27 | ruser.io('/r/repository/file/upload') 28 | .data({ filename: 'nodejs-satscores.csv', descr: 'Sample file upload.' }) 29 | .attach(path.join(__dirname, 'satscores.csv')) 30 | .error(function(err) { 31 | console.log(err); 32 | }) 33 | .end(function(res, chain) { 34 | console.log(res); 35 | }) 36 | .ensure(function() { 37 | ruser.release(); 38 | }); 39 | -------------------------------------------------------------------------------- /examples/tutorial/authentication/authenticate.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Authenticate 7 | 8 | 9 | 10 | 11 |

Authentication

12 |
13 |
    14 |
  1. Populate /examples/config.json with the proper values before running.
  2. 15 |
  3. Open the browser's debug window to view print logs for this example.
  4. 16 |
  5. View documentation for more information.
  6. 17 |
18 | 19 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /examples/tutorial/authentication/authenticate.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | * Copyright (C) 2010-2016, Microsoft Corporation 5 | * 6 | * This program is licensed to you under the terms of Version 2.0 of the 7 | * Apache License. This program is distributed WITHOUT 8 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 9 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 10 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 11 | * details. 12 | */ 13 | 14 | /* ---------------------------------------------------------------------------- 15 | * usage: $ node authenticate.js 16 | * see: https://microsoft.github.io/deployr-api-docs/#users 17 | * 18 | * 1. Determine DeployR server endpoint. 19 | * 2. Establish an authenticated handle with the DeployR server. 20 | * 3. Release connection before application exits. 21 | * ---------------------------------------------------------------------------- 22 | */ 23 | 24 | var deployr = require('../../../deployr'), 25 | config = require('../../config'), 26 | ruser = null; // The user resquest session 27 | 28 | deployr.configure( { logging: false, host: config.endpoint }); 29 | 30 | /* 31 | * Run example. 32 | * @NOTE - Remember the`.end()` will send the request for `/ruser/login` 33 | * If `.end()` is never called the request will not be sent. 34 | */ 35 | 36 | ruser = deployr.io('/r/user/login'); 37 | 38 | ruser.data(config.credentials) 39 | .error(function(err) { 40 | console.warn('Authenticate: ex=' + err.get('error')); 41 | }) 42 | .end(function(res) { 43 | console.log('Authenticate: established authenticated connection, rUser=' 44 | + res.get('user').username); 45 | }) 46 | .ensure(function() { 47 | /* 48 | * Release connection and logout before application exits. 49 | */ 50 | ruser.release(); 51 | }); 52 | 53 | -------------------------------------------------------------------------------- /examples/tutorial/connection/connection.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Connection 8 | 9 | 10 | 11 | 12 |

Connection

13 |
14 |
    15 |
  1. Populate /examples/config.json with the proper values before running.
  2. 16 |
  3. Open the browser's debug window to view print logs for this example.
  4. 17 |
  5. View documentation for more information.
  6. 18 |
19 | 20 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /examples/tutorial/connection/connection.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | * Copyright (C) 2010-2016, Microsoft Corporation 5 | * 6 | * This program is licensed to you under the terms of Version 2.0 of the 7 | * Apache License. This program is distributed WITHOUT 8 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 9 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 10 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 11 | * details. 12 | */ 13 | 14 | /* ---------------------------------------------------------------------------- 15 | * usage: $ node connection.js 16 | * 17 | * 1. Determine DeployR server endpoint. 18 | * ---------------------------------------------------------------------------- 19 | */ 20 | 21 | var deployr = require('../../../deployr'), 22 | config = require('../../config'); 23 | 24 | /* 25 | * Run example. 26 | */ 27 | console.log('Connect: using endpoint=' + config.endpoint); 28 | deployr.configure( { host: config.endpoint } ); 29 | -------------------------------------------------------------------------------- /examples/tutorial/services/background/auth-job-execute-code.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Background Job (code) 8 | 9 | 10 | 11 | 12 | 13 |

Background Job (code)

14 |
15 |
    16 |
  1. Populate /examples/config.json with the proper values before running.
  2. 17 |
  3. Open the browser's debug window to view print logs for this example.
  4. 18 |
  5. View documentation for more information.
  6. 19 |
20 | 21 | 125 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /examples/tutorial/services/background/auth-job-execute-code.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | * Copyright (C) 2010-2016, Microsoft Corporation 5 | * 6 | * This program is licensed to you under the terms of Version 2.0 of the 7 | * Apache License. This program is distributed WITHOUT 8 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 9 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 10 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 11 | * details. 12 | */ 13 | 14 | /* ---------------------------------------------------------------------------- 15 | * usage: $ node auth-job-execute-code.js 16 | * see: https://microsoft.github.io/deployr-api-docs/#r-job-submit 17 | * 18 | * 1. Determine DeployR server endpoint. 19 | * 2. Establish an authenticated handle with the DeployR server. 20 | * 3. Submit a background job to execute an arbitrary block of R code. 21 | * 4. Query for the job status every 2 seconds for `Completed` status. 22 | * 5. On status `Completed` retrieve results of the background job execution. 23 | * ---------------------------------------------------------------------------- 24 | */ 25 | 26 | var deployr = require('../../../../deployr'), 27 | config = require('../../../config'), 28 | jobPending = true, // R job status 29 | intervalId = null, // ID value of the timer that will be set 30 | ruser = null; // The user resquest session 31 | 32 | /* 33 | * This helper queries the job status for a `Completed` state. 34 | */ 35 | function query(job) { 36 | ruser.io('/r/job/query') 37 | .data({ job: job }) 38 | .end(function(res) { 39 | console.log('Job Status=' + res.get('status') + ' rJob=' + job); 40 | 41 | jobPending = res.get('status') !== 'Completed'; 42 | 43 | if (!jobPending) { 44 | console.log('AuthJobExecuteCode: retrieved background ' + 45 | 'job result on project, rJob=' + res.get('job').job); 46 | } 47 | }); 48 | } 49 | 50 | /* 51 | * Configure the DeployR server endpoint and subscribe to all errors at a global 52 | * level. 53 | */ 54 | deployr.configure( { 55 | logging: false, 56 | host: config.endpoint, 57 | events: { 58 | error: function(api, err) { 59 | jobPending = false; 60 | console.warn('AuthJobExecuteCode: ex=' + err.get('error')); 61 | } 62 | } 63 | }); 64 | 65 | /* 66 | * Run example. 67 | */ 68 | ruser = deployr.io('/r/user/login') 69 | .data(config.credentials) 70 | .end(function(res) { 71 | console.log('Authenticate: established authenticated connection, rUser=' 72 | + res.get('user').username); 73 | }) 74 | .io('/r/job/submit') 75 | .data({ 76 | priority: 'medium', 77 | name: 'Background Code Execution', 78 | descr: 'Background code execution.', 79 | code: 'demo(graphics)' 80 | }) 81 | .end(function(res) { 82 | var job = res.get('job').job; 83 | console.log('AuthJobExecuteCode: submitted background job ' + 84 | 'for execution, rJob=' + job); 85 | 86 | // query job status every 2 seconds 87 | intervalId = setInterval(function() { 88 | if (jobPending) { 89 | query(job); 90 | } else { 91 | clearInterval(intervalId); 92 | ruser.release(); 93 | } 94 | }, 2000); 95 | }); 96 | -------------------------------------------------------------------------------- /examples/tutorial/services/background/auth-job-execute-script.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Background Job (script) 8 | 9 | 10 | 11 | 12 | 13 |

Background Job (script)

14 |
15 |
    16 |
  1. Populate /examples/config.json with the proper values before running.
  2. 17 |
  3. Open the browser's debug window to view print logs for this example.
  4. 18 |
  5. View documentation for more information.
  6. 19 |
20 | 21 | 126 | 127 | 128 | 129 | -------------------------------------------------------------------------------- /examples/tutorial/services/background/auth-job-execute-script.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | * Copyright (C) 2010-2016, Microsoft Corporation 5 | * 6 | * This program is licensed to you under the terms of Version 2.0 of the 7 | * Apache License. This program is distributed WITHOUT 8 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 9 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 10 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 11 | * details. 12 | */ 13 | 14 | /* ---------------------------------------------------------------------------- 15 | * usage: $ node auth-job-execute-script.js 16 | * see: https://microsoft.github.io/deployr-api-docs/#r-job-submit 17 | * 18 | * 1. Determine DeployR server endpoint. 19 | * 2. Establish an authenticated handle with the DeployR server. 20 | * 3. Submit a background job to execute a repository-managed script: 21 | * `/testuser/root/Histogram of Auto Sales.R` 22 | * 4. Query for the job status every 2 seconds for `Completed` status. 23 | * 5. On status `Completed` retrieve results of the background job execution. 24 | * ---------------------------------------------------------------------------- 25 | */ 26 | 27 | var deployr = require('../../../../deployr'), 28 | config = require('../../../config'), 29 | jobPending = true, // R job status 30 | intervalId = null, // ID value of the timer that will be set 31 | ruser = null; // The user resquest session 32 | 33 | /* 34 | * This helper queries the job status for a `Completed` state. 35 | */ 36 | function query(job) { 37 | ruser.io('/r/job/query') 38 | .data({ job: job }) 39 | .end(function(res) { 40 | console.log('Job Status=' + res.get('status') + ' rJob=' + job); 41 | 42 | jobPending = res.get('status') !== 'Completed'; 43 | 44 | if (!jobPending) { 45 | console.log('AuthJobExecuteScript: retrieved background ' + 46 | 'job result on project, rJob=' + res.get('job').job); 47 | } 48 | }); 49 | } 50 | 51 | /* 52 | * Configure the DeployR server endpoint and subscribe to all errors at a global 53 | * level. 54 | */ 55 | deployr.configure( { 56 | logging: false, 57 | host: config.endpoint, 58 | events: { 59 | error: function(api, err) { 60 | jobPending = false; 61 | console.warn('AuthJobExecuteScript: ex=' + err.get('error')); 62 | } 63 | } 64 | }); 65 | 66 | /* 67 | * Run example. 68 | */ 69 | ruser = deployr.io('/r/user/login') 70 | .data(config.credentials) 71 | .end(function(res) { 72 | console.log('Authenticate: established authenticated connection, rUser=' 73 | + res.get('user').username); 74 | }) 75 | .io('/r/job/submit') 76 | .data({ 77 | name: 'Background Script Execution', 78 | descr: 'Background script execution.', 79 | rscriptname: 'Histogram of Auto Sales', 80 | rscriptdirectory: 'root', 81 | rscriptauthor: 'testuser', 82 | priority: 'high' 83 | }) 84 | .end(function(res) { 85 | var job = res.get('job').job; 86 | console.log('AuthJobExecuteScript: submitted background job ' + 87 | 'for execution, rJob=' + job); 88 | 89 | // query job status every 2 seconds 90 | intervalId = setInterval(function() { 91 | if (jobPending) { 92 | query(job); 93 | } else { 94 | clearInterval(intervalId); 95 | ruser.release(); 96 | } 97 | }, 2000); 98 | }); 99 | -------------------------------------------------------------------------------- /examples/tutorial/services/project/auth-project-create.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Project Create 8 | 9 | 10 | 11 | 12 | 13 |

Project Create

14 |
15 |
    16 |
  1. Populate /examples/config.json with the proper values before running.
  2. 17 |
  3. Open the browser's debug window to view print logs for this example.
  4. 18 |
  5. View documentation for more information.
  6. 19 |
20 | 21 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /examples/tutorial/services/project/auth-project-create.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | * Copyright (C) 2010-2016, Microsoft Corporation 5 | * 6 | * This program is licensed to you under the terms of Version 2.0 of the 7 | * Apache License. This program is distributed WITHOUT 8 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 9 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 10 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 11 | * details. 12 | */ 13 | 14 | /* ---------------------------------------------------------------------------- 15 | * usage: $ node auth-project-create.js 16 | * see: https://microsoft.github.io/deployr-api-docs/#r-project-create 17 | * 18 | * 1. Determine DeployR server endpoint. 19 | * 2. Establish an authenticated handle with the DeployR server. 20 | * 3. Create a temporary project (R session). 21 | * 4. Release connection, close project and logout. 22 | * ---------------------------------------------------------------------------- 23 | */ 24 | 25 | var deployr = require('../../../../deployr'), 26 | config = require('../../../config'), 27 | project = null, 28 | ruser = null; // The user resquest session 29 | 30 | /* 31 | * Configure the DeployR server endpoint and subscribe to all errors at a global 32 | * level. 33 | */ 34 | deployr.configure( { 35 | logging: false, 36 | host: config.endpoint, 37 | events: { 38 | error: function(api, err) { 39 | console.warn('AuthProjectCreate: ex=' + err.get('error')); 40 | } 41 | } 42 | }); 43 | 44 | /* 45 | * Run example. 46 | * @NOTE - Remember the`.end()` will send the request for `/r/user/login` 47 | * If `.end()` is never called the request will not be sent. 48 | */ 49 | ruser = deployr.io('/r/user/login'); 50 | 51 | ruser.data(config.credentials) 52 | .end(function(res) { 53 | console.log('AuthProjectCreate: established authenticated ' + 54 | 'connection, rUser=' + res.get('user').username); 55 | }) 56 | // ========================================================================= 57 | .io('/r/project/create') 58 | .end(function(res) { 59 | project = res.get('project').project; 60 | 61 | console.log('AuthProjectCreate: created temporary R session, ' + 62 | 'rProject=' + project); 63 | }) 64 | // ========================================================================= 65 | .ensure(function() { 66 | /* 67 | * Release connection before application exits. 68 | */ 69 | ruser.release([ project ]); 70 | }); 71 | -------------------------------------------------------------------------------- /examples/tutorial/services/project/auth-project-directory.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Project Directory 8 | 9 | 10 | 11 | 12 | 13 |

Project Directory

14 |
15 |
    16 |
  1. Populate /examples/config.json with the proper values before running.
  2. 17 |
  3. Open the browser's debug window to view print logs for this example.
  4. 18 |
  5. View documentation for more information.
  6. 19 |
20 | 21 | 141 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /examples/tutorial/services/project/auth-project-directory.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | * Copyright (C) 2010-2016, Microsoft Corporation 5 | * 6 | * This program is licensed to you under the terms of Version 2.0 of the 7 | * Apache License. This program is distributed WITHOUT 8 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 9 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 10 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 11 | * details. 12 | */ 13 | 14 | /* ---------------------------------------------------------------------------- 15 | * usage: $ node auth-project-directory.js 16 | * 17 | * 1. Determine DeployR server endpoint. 18 | * 2. Establish an authenticated handle with the DeployR server. 19 | * 3. Create a temporary project (R session). 20 | * 4. Create a file in the R session's working directory by writing text to a 21 | * named file. 22 | * 5. Retrieve a list of files in the R session's working directory. 23 | * 6. Delete all files in the R session's working directory. 24 | * 7. Release connection, close project and logout. 25 | * ---------------------------------------------------------------------------- 26 | */ 27 | 28 | var deployr = require('../../../../deployr'), 29 | config = require('../../../config'), 30 | project = null, 31 | ruser = null; // The user resquest session 32 | 33 | /* 34 | * Configure the DeployR server endpoint and subscribe to all errors at a global 35 | * level. 36 | */ 37 | deployr.configure( { 38 | logging: false, 39 | host: config.endpoint, 40 | events: { 41 | error: function(api, err) { 42 | console.warn('AuthProjectDirectory: ex=' + err.get('error')); 43 | } 44 | } 45 | }); 46 | 47 | /* 48 | * Run example. 49 | * @NOTE - Remember the`.end()` will send the request for `/r/user/login` 50 | * If `.end()` is never called the request will not be sent. 51 | */ 52 | ruser = deployr.io('/r/user/login'); 53 | 54 | ruser.data(config.credentials) 55 | .end(function(res) { 56 | console.log('AuthProjectDirectory: established authenticated ' + 57 | 'connection, rUser=' + res.get('user').username); 58 | }) 59 | // ========================================================================= 60 | .io('/r/project/create') 61 | .end(function(res) { 62 | project = res.get('project').project; 63 | 64 | console.log('AuthProjectDirectory: created temporary R session, ' + 65 | 'rProject=' + project); 66 | 67 | // pass `project` to next async call in io queue 68 | return { project: project }; 69 | }) 70 | // ========================================================================= 71 | .io('/r/project/directory/write') 72 | .data({ filename: 'hello.txt', text: 'Hello World!' }) 73 | .end(function(res) { 74 | var fileURL = res.get('url'); 75 | console.log(fileURL); 76 | 77 | // pass `project` to next async call in io queue 78 | return { project: project }; 79 | }) 80 | // ========================================================================= 81 | .io('/r/project/directory/list') 82 | .end(function(res) { 83 | var files = res.get('files'), 84 | filename = []; 85 | 86 | files.forEach(function(file) { 87 | console.log('AuthProjectDirectory: working directory, ' + 88 | 'found file name=' + file.filename + 89 | ', type=' + file.type + 90 | ', size=' + file.length); 91 | 92 | // delete filename list 93 | filename.push(file.filename); 94 | 95 | console.info('AuthProjectDirectory: working directory, ' + 96 | 'deleted file name=' + file.filename + 97 | ', type=' + file.type + 98 | ', size=' + file.length); 99 | }); 100 | 101 | // pass `project` `filename` to next async call in io queue 102 | return { project: project, filename: filename.join(',') }; 103 | }) 104 | // ========================================================================= 105 | .io('/r/project/directory/delete') 106 | .end() 107 | // ========================================================================= 108 | .ensure(function() { 109 | /* 110 | * Release connection before application exits. 111 | */ 112 | ruser.release([ project ]); 113 | }); 114 | -------------------------------------------------------------------------------- /examples/tutorial/services/project/auth-project-execute-code.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Project Execute (code) 8 | 9 | 10 | 11 | 12 | 13 |

Project Execute (code)

14 |
15 |
    16 |
  1. Populate /examples/config.json with the proper values before running.
  2. 17 |
  3. Open the browser's debug window to view print logs for this example.
  4. 18 |
  5. View documentation for more information.
  6. 19 |
20 | 21 | 119 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /examples/tutorial/services/project/auth-project-execute-code.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | * Copyright (C) 2010-2016, Microsoft Corporation 5 | * 6 | * This program is licensed to you under the terms of Version 2.0 of the 7 | * Apache License. This program is distributed WITHOUT 8 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 9 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 10 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 11 | * details. 12 | */ 13 | 14 | /* ---------------------------------------------------------------------------- 15 | * usage: $ node auth-project-execute-code.js 16 | * see: https://microsoft.github.io/deployr-api-docs/#r-project-execute-code 17 | * 18 | * 1. Determine DeployR server endpoint. 19 | * 2. Establish an authenticated handle with the DeployR server. 20 | * 3. Create a temporary project (R session). 21 | * 4. Execute an analytics Web service based on an arbitrary block of R code. 22 | * 5. Retrieve script execution results. 23 | * 6. Release connection, close project and logout. 24 | * ---------------------------------------------------------------------------- 25 | */ 26 | 27 | var deployr = require('../../../../deployr'), 28 | config = require('../../../config'), 29 | project = null, 30 | ruser = null; // The user resquest session 31 | 32 | /* 33 | * Configure the DeployR server endpoint and subscribe to all errors at a global 34 | * level. 35 | */ 36 | deployr.configure( { 37 | logging: false, 38 | host: config.endpoint, 39 | events: { 40 | error: function(api, err) { 41 | console.warn('AuthProjectExecuteCode: ex=' + err.get('error')); 42 | } 43 | } 44 | }); 45 | 46 | /* 47 | * Run example. 48 | * @NOTE - Remember the`.end()` will send the request for `/r/user/login` 49 | * If `.end()` is never called the request will not be sent. 50 | */ 51 | ruser = deployr.io('/r/user/login'); 52 | 53 | ruser.data(config.credentials) 54 | .end(function(res) { 55 | console.log('AuthProjectExecuteCode: established authenticated ' + 56 | 'connection, rUser=' + res.get('user').username); 57 | }) 58 | // ========================================================================= 59 | .io('/r/project/create') 60 | .end(function(res) { 61 | project = res.get('project').project; 62 | 63 | console.log('AuthProjectExecuteCode: created temporary R session, ' + 64 | 'rProject=' + project); 65 | 66 | // pass `project` to next async call in io queue 67 | return { project: project }; 68 | }) 69 | // ========================================================================= 70 | .io('/r/project/execute/code') 71 | .data({ code: 'demo(graphics)' }) 72 | .end(function(res) { 73 | var exec = res.get('execution').execution; 74 | console.log('AuthProjectExecuteCode: R code execution completed, ' + 75 | 'rProjectExecution=' + exec); 76 | 77 | /* 78 | * Retrieve script execution results. 79 | */ 80 | var rconsole = res.get('console'); 81 | var plots = res.get('results'); 82 | var files = res.get('artifacts'); 83 | var objects = res.workspace(); // --or-- res.get('workspace').objects; 84 | }) 85 | // ========================================================================= 86 | .ensure(function() { 87 | /* 88 | * Release connection before application exits. 89 | */ 90 | ruser.release([ project ]); 91 | }); 92 | -------------------------------------------------------------------------------- /examples/tutorial/services/project/auth-project-execute-script.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Project Execute (script) 8 | 9 | 10 | 11 | 12 | 13 |

Project Execute (script)

14 |
15 |
    16 |
  1. Populate /examples/config.json with the proper values before running.
  2. 17 |
  3. Open the browser's debug window to view print logs for this example.
  4. 18 |
  5. View documentation for more information.
  6. 19 |
20 | 21 | 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /examples/tutorial/services/project/auth-project-execute-script.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | * Copyright (C) 2010-2016, Microsoft Corporation 5 | * 6 | * This program is licensed to you under the terms of Version 2.0 of the 7 | * Apache License. This program is distributed WITHOUT 8 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 9 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 10 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 11 | * details. 12 | */ 13 | 14 | /* ---------------------------------------------------------------------------- 15 | * usage: $ node auth-project-execute-script.js 16 | * see: https://microsoft.github.io/deployr-api-docs/#r-project-execute-script 17 | * 18 | * 1. Determine DeployR server endpoint. 19 | * 2. Establish an authenticated handle with the DeployR server. 20 | * 3. Create a temporary project (R session). 21 | * 4. Execute an analytics Web service based on a repository-managed R script: 22 | `/testuser/root/Histogram of Auto Sales.R` 23 | * 5. Retrieve script execution results. 24 | * 6. Release connection, close project and logout. 25 | * ---------------------------------------------------------------------------- 26 | */ 27 | 28 | var deployr = require('../../../../deployr'), 29 | config = require('../../../config'), 30 | project = null, 31 | ruser = null; // The user resquest session 32 | 33 | /* 34 | * Configure the DeployR server endpoint and subscribe to all errors at a global 35 | * level. 36 | */ 37 | deployr.configure( { 38 | logging: false, 39 | host: config.endpoint, 40 | events: { 41 | error: function(api, err) { 42 | console.warn('AuthProjectExecuteScript: ex=' + err.get('error')); 43 | } 44 | } 45 | }); 46 | 47 | /* 48 | * Run example. 49 | * @NOTE - Remember the`.end()` will send the request for `/r/user/login` 50 | * If `.end()` is never called the request will not be sent. 51 | */ 52 | ruser = deployr.io('/r/user/login'); 53 | 54 | ruser.data(config.credentials) 55 | .end(function(res) { 56 | console.log('AuthProjectExecuteScript: established authenticated ' + 57 | 'connection, rUser=' + res.get('user').username); 58 | }) 59 | // ========================================================================= 60 | .io('/r/project/create') 61 | .end(function(res) { 62 | project = res.get('project').project; 63 | 64 | console.log('AuthProjectExecuteScript: created temporary R session, ' + 65 | 'rProject=' + project); 66 | 67 | // pass `project` to next async call in io queue 68 | return { project: project }; 69 | }) 70 | // ========================================================================= 71 | .io('/r/project/execute/script') 72 | .data({ filename: 'Histogram of Auto Sales.R', author: 'testuser', directory: 'root' }) 73 | .end(function(res) { 74 | var exec = res.get('execution').execution; 75 | console.log('AuthProjectExecuteScript: R code execution completed, ' + 76 | 'rProjectExecution=' + exec); 77 | 78 | /* 79 | * Retrieve script execution results. 80 | */ 81 | var rconsole = res.get('console'); 82 | var plots = res.get('results'); 83 | var files = res.get('artifacts'); 84 | var objects = res.workspace(); // --or-- res.get('workspace').objects; 85 | }) 86 | // ========================================================================= 87 | .ensure(function() { 88 | /* 89 | * Release connection before application exits. 90 | */ 91 | ruser.release([ project ]); 92 | }); 93 | -------------------------------------------------------------------------------- /examples/tutorial/services/project/auth-project-packages.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Project Packages 8 | 9 | 10 | 11 | 12 | 13 |

Project Packages

14 |
15 |
    16 |
  1. Populate /examples/config.json with the proper values before running.
  2. 17 |
  3. Open the browser's debug window to view print logs for this example.
  4. 18 |
  5. View documentation for more information.
  6. 19 |
20 | 21 | 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /examples/tutorial/services/project/auth-project-packages.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | * Copyright (C) 2010-2016, Microsoft Corporation 5 | * 6 | * This program is licensed to you under the terms of Version 2.0 of the 7 | * Apache License. This program is distributed WITHOUT 8 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 9 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 10 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 11 | * details. 12 | */ 13 | 14 | /* ---------------------------------------------------------------------------- 15 | * usage: $ node auth-project-packages.js 16 | * see: https://microsoft.github.io/deployr-api-docs/#r-project-package-list 17 | * 18 | * 1. Determine DeployR server endpoint. 19 | * 2. Establish an authenticated handle with the DeployR server. 20 | * 3. Create a temporary project (R session). 21 | * 4. Retrieve a list of R packages that are current attached on the R session. 22 | * 5. Release connection, close project and logout. 23 | * ---------------------------------------------------------------------------- 24 | */ 25 | 26 | var deployr = require('../../../../deployr'), 27 | config = require('../../../config'), 28 | project = null, 29 | ruser = null; // The user resquest session 30 | 31 | /* 32 | * Configure the DeployR server endpoint and subscribe to all errors at a global 33 | * level. 34 | */ 35 | deployr.configure( { 36 | logging: false, 37 | host: config.endpoint, 38 | events: { 39 | error: function(api, err) { 40 | console.warn('AuthProjectPackages: ex=' + err.get('error')); 41 | } 42 | } 43 | }); 44 | 45 | /* 46 | * Run example. 47 | * @NOTE - Remember the`.end()` will send the request for `/r/user/login` 48 | * If `.end()` is never called the request will not be sent. 49 | */ 50 | ruser = deployr.io('/r/user/login'); 51 | 52 | ruser.data(config.credentials) 53 | .end(function(res) { 54 | console.log('AuthProjectPackages: established authenticated ' + 55 | 'connection, rUser=' + res.get('user').username); 56 | }) 57 | // ========================================================================= 58 | .io('/r/project/create') 59 | .end(function(res) { 60 | project = res.get('project').project; 61 | 62 | console.log('AuthProjectPackages: created temporary R session, ' + 63 | 'rProject=' + project); 64 | 65 | // pass `project` to next async call in io queue 66 | return { project: project }; 67 | }) 68 | // ========================================================================= 69 | .io('/r/project/package/list') 70 | .end(function(res) { 71 | var packages = res.get('packages'); 72 | packages.forEach(function(pkg) { 73 | console.log('AuthProjectPackages: R session, found attached R package ' + 74 | 'name=' + pkg.name + 75 | ', repo=' + pkg.repo + 76 | ', version=' + pkg.version); 77 | }); 78 | }) 79 | // ========================================================================= 80 | .ensure(function() { 81 | /* 82 | * Release connection before application exits. 83 | */ 84 | ruser.release([ project ]); 85 | }); 86 | -------------------------------------------------------------------------------- /examples/tutorial/services/project/auth-project-pool-create.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Project Pool Create 8 | 9 | 10 | 11 | 12 | 13 |

Project Pool Create

14 |
15 |
    16 |
  1. Populate /examples/config.json with the proper values before running.
  2. 17 |
  3. Open the browser's debug window to view print logs for this example.
  4. 18 |
  5. View documentation for more information.
  6. 19 |
20 | 21 | 104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /examples/tutorial/services/project/auth-project-pool-create.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | * Copyright (C) 2010-2016, Microsoft Corporation 5 | * 6 | * This program is licensed to you under the terms of Version 2.0 of the 7 | * Apache License. This program is distributed WITHOUT 8 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 9 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 10 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 11 | * details. 12 | */ 13 | 14 | /* ---------------------------------------------------------------------------- 15 | * usage: $ node auth-project-pool-create.js 16 | * see: https://microsoft.github.io/deployr-api-docs/#r-project-pool 17 | * 18 | * 1. Determine DeployR server endpoint. 19 | * 2. Establish an authenticated handle with the DeployR server. 20 | * 3. Create a pool of temporary projects (R sessions). 21 | * 4. Release connection, close all projects and logout. 22 | * ---------------------------------------------------------------------------- 23 | */ 24 | 25 | var deployr = require('../../../../deployr'), 26 | config = require('../../../config'), 27 | projects = [], 28 | ruser = null; // The user resquest session 29 | 30 | /* 31 | * Configure the DeployR server endpoint and subscribe to all errors at a global 32 | * level. 33 | */ 34 | deployr.configure( { 35 | logging: false, 36 | host: config.endpoint, 37 | events: { 38 | error: function(api, err) { 39 | console.warn('AuthProjectPoolCreate: ex=' + err.get('error')); 40 | } 41 | } 42 | }); 43 | 44 | /* 45 | * Run example. 46 | * @NOTE - Remember the`.end()` will send the request for `/r/user/login` 47 | * If `.end()` is never called the request will not be sent. 48 | */ 49 | ruser = deployr.io('/r/user/login'); 50 | 51 | ruser.data(config.credentials) 52 | .data(config.credentials) 53 | .end(function(res) { 54 | console.log('AuthProjectPoolCreate: established authenticated ' + 55 | 'connection, rUser=' + res.get('user').username); 56 | }) 57 | // ========================================================================= 58 | .io('/r/project/pool') 59 | .data({ poolsize: 4 }) 60 | .end(function(res) { 61 | var pool = res.get('projects'); 62 | 63 | pool.forEach(function(project) { projects.push(project.project); }); 64 | 65 | console.log('AuthProjectPoolCreate: created pool of ' + 66 | pool.length + ' temporary R sessions, pool=' + projects); 67 | }) 68 | // ========================================================================= 69 | .ensure(function() { 70 | /* 71 | * Release connection before application exits. 72 | */ 73 | ruser.release(projects); 74 | }); 75 | -------------------------------------------------------------------------------- /examples/tutorial/services/project/auth-project-workspace.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | * Copyright (C) 2010-2016, Microsoft Corporation 5 | * 6 | * This program is licensed to you under the terms of Version 2.0 of the 7 | * Apache License. This program is distributed WITHOUT 8 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 9 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 10 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 11 | * details. 12 | */ 13 | 14 | /* ---------------------------------------------------------------------------- 15 | * usage: $ node auth-project-workspace.js 16 | * 17 | * 1. Determine DeployR server endpoint. 18 | * 2. Establish an authenticated handle with the DeployR server. 19 | * 3. Create a temporary project (R session). 20 | * 4. Execute a block of R code to create an object in the R session's workspace. 21 | * 5. Retrieve the object "x" from the R session's workspace. 22 | * 6. Create R object data in the R sesssion's workspace by pushing 23 | * DeployR-encoded data from the client application: 24 | * - Prepare sample R object vector data. 25 | * - Use RDataFactory to encode the sample R object vector data. 26 | * - Push encoded R object into the workspace. 27 | * 7. Retrieve the object "y" from the R session's workspace. 28 | * 8. Retrieve a list of R objects in the R session's workspace. 29 | * 9. Release connection, close project and logout. 30 | * ---------------------------------------------------------------------------- 31 | */ 32 | 33 | var deployr = require('../../../../deployr'), 34 | config = require('../../../config'), 35 | project = null, 36 | ruser = null; // The user resquest session 37 | 38 | /* 39 | * Configure the DeployR server endpoint and subscribe to all errors at a global 40 | * level. 41 | */ 42 | deployr.configure( { 43 | logging: false, 44 | host: config.endpoint, 45 | events: { 46 | error: function(api, err) { 47 | console.warn('AuthProjectWorkspace: ex=' + err.get('error')); 48 | } 49 | } 50 | }); 51 | 52 | /* 53 | * Run example. 54 | * @NOTE - Remember the`.end()` will send the request for `/r/user/login` 55 | * If `.end()` is never called the request will not be sent. 56 | */ 57 | ruser = deployr.io('/r/user/login'); 58 | 59 | ruser.data(config.credentials) 60 | .end(function(res) { 61 | console.log('AuthProjectWorkspace: established authenticated ' + 62 | 'connection, rUser=' + res.get('user').username); 63 | }) 64 | // ========================================================================= 65 | .io('/r/project/create') 66 | .end(function(res) { 67 | project = res.get('project').project; 68 | 69 | console.log('AuthProjectWorkspace: created temporary R session, ' + 70 | 'rProject=' + project); 71 | 72 | // pass `project` to next async call in io queue 73 | return { project: project }; 74 | }) 75 | // ========================================================================= 76 | .io('/r/project/execute/code') 77 | .data({ code: 'x <- T' }) 78 | .end(function(res) { 79 | // pass `project` to next async call in io queue 80 | return { project: project }; 81 | }) 82 | // ========================================================================= 83 | .io('/r/project/workspace/get') 84 | .data({ name: 'x' }) 85 | .end(function(res) { 86 | /* 87 | * Retrieve the object "x" from the R session's workspace. 88 | */ 89 | var encodedX = res.workspace(); 90 | 91 | console.log('AuthProjectWorkspace: retrieved object x ' + 92 | 'from workspace, encodedX=' + encodedX.value); 93 | 94 | // pass `project` to next async call in io queue 95 | return { project: project }; 96 | }) 97 | // ========================================================================= 98 | .io('/r/project/workspace/push') 99 | .numericVector('y', [10.0, 11.1, 12.2, 13.3, 14.4]) 100 | .end(function(res) { 101 | // pass `project` to next async call in io queue 102 | return { project: project }; 103 | }) 104 | // ========================================================================= 105 | .io('/r/project/workspace/get') 106 | .data({ name: 'y' }) 107 | .end(function(res) { 108 | /* 109 | * Retrieve the object "y" from the R session's workspace. 110 | */ 111 | var encodedY = res.workspace(); 112 | 113 | console.log('AuthProjectWorkspace: retrieved object y ' + 114 | 'from workspace, encodedY=' + encodedY.value); 115 | 116 | // pass `project` to next async call in io queue 117 | return { project: project }; 118 | }) 119 | // ========================================================================= 120 | .io('/r/project/workspace/list') 121 | .end(function(res) { 122 | var objects = res.workspace(); 123 | }) 124 | // ========================================================================= 125 | .ensure(function() { 126 | /* 127 | * Release connection before application exits. 128 | */ 129 | ruser.release([ project ]); 130 | }); 131 | -------------------------------------------------------------------------------- /examples/tutorial/services/repository/auth-repository-management.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Repository 7 | 8 | 9 | 10 | 11 |

Repository

12 |
13 |
    14 |
  1. Populate /examples/config.json with the proper values before running.
  2. 15 |
  3. Open the browser's debug window to view print logs for this example.
  4. 16 |
  5. View documentation for more information.
  6. 17 |
18 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /examples/tutorial/services/repository/auth-repository-management.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | * Copyright (C) 2010-2016, Microsoft Corporation 5 | * 6 | * This program is licensed to you under the terms of Version 2.0 of the 7 | * Apache License. This program is distributed WITHOUT 8 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 9 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 10 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 11 | * details. 12 | */ 13 | 14 | /* ---------------------------------------------------------------------------- 15 | * usage: $ node auth-repository-management.js 16 | * see: https://microsoft.github.io/deployr-api-docs/#repository 17 | * 18 | * 1. Determine DeployR server endpoint. 19 | * 2. Establish an authenticated handle with the DeployR server. 20 | * 3. Create a file in the authenticated user's private repository and set 21 | * shared access on the file so other authenticated users can access the file. 22 | * 4. Retrieve a list of files in the authenticated user's private repository. 23 | * ---------------------------------------------------------------------------- 24 | */ 25 | 26 | var deployr = require('../../../../deployr'), 27 | config = require('../../../config'), 28 | ruser = null; // The user resquest session 29 | 30 | /* 31 | * Configure the DeployR server endpoint and subscribe to all errors at a global 32 | * level. 33 | */ 34 | deployr.configure( { 35 | logging: false, 36 | host: config.endpoint, 37 | events: { 38 | error: function(api, err) { 39 | console.warn('AuthRepositoryManagement: ex=' + err.get('error')); 40 | } 41 | } 42 | }); 43 | 44 | /* 45 | * Run example. 46 | * @NOTE - Remember the`.end()` will send the request for `.io()` 47 | * If `.end()` is never called the requests will not be sent. 48 | */ 49 | ruser = deployr.io('/r/user/login'); 50 | 51 | ruser.data(config.credentials) 52 | .end(function(res) { 53 | console.log('AuthRepositoryManagement: established authenticated ' + 54 | 'connection, rUser=' + res.get('user').username); 55 | }) 56 | // ========================================================================= 57 | .io('/r/repository/file/write') 58 | .data({ filename: 'hello.txt', shared: true, text: 'Hello World!' }) 59 | .end(function(res) { 60 | var fileURL = res.get('url'); 61 | console.log(fileURL); 62 | }) 63 | // ========================================================================= 64 | .io('/r/repository/file/list') 65 | .end(function(res) { 66 | var files = res.get('files'); 67 | files.forEach(function(file) { 68 | console.log('AuthRepositoryManagement: private repository, ' + 69 | 'found file name=' + 70 | file.filename + ", directory=" + 71 | file.directory + ", access=" + 72 | file.access); 73 | }); 74 | }) 75 | // ========================================================================= 76 | .ensure(function() { 77 | /* 78 | * Release connection before application exits. 79 | */ 80 | ruser.release(); 81 | }); 82 | -------------------------------------------------------------------------------- /gulp/config.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (C) 2010-2016, Microsoft Corporation 3 | * 4 | * This program is licensed to you under the terms of Version 2.0 of the 5 | * Apache License. This program is distributed WITHOUT 6 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 7 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 8 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 9 | * details. 10 | */ 11 | 12 | var path = require('path'), 13 | pkg = require('../package.json'); 14 | 15 | module.exports = { 16 | port: '8080', 17 | root: path.resolve('./'), 18 | dist: './browser', 19 | name: pkg.name, 20 | pkg: pkg 21 | }; -------------------------------------------------------------------------------- /gulp/index.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (C) 2010-2016, Microsoft Corporation 3 | * 4 | * This program is licensed to you under the terms of Version 2.0 of the 5 | * Apache License. This program is distributed WITHOUT 6 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 7 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 8 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 9 | * details. 10 | */ 11 | 12 | var fs = require('fs'), 13 | whitelist = require('./util/script-filter'), 14 | tasks = fs.readdirSync('./gulp/tasks/').filter(whitelist); 15 | 16 | tasks.forEach(function(task) { 17 | require('./tasks/' + task); 18 | }); -------------------------------------------------------------------------------- /gulp/tasks/browserify.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (C) 2010-2016, Microsoft Corporation 3 | * 4 | * This program is licensed to you under the terms of Version 2.0 of the 5 | * Apache License. This program is distributed WITHOUT 6 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 7 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 8 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 9 | * details. 10 | */ 11 | 12 | var browserify = require('browserify'), 13 | gulp = require('gulp'), 14 | source = require('vinyl-source-stream'), 15 | plumber = require('gulp-plumber'), 16 | onError = require('../util/errors'), 17 | config = require('../config'); 18 | 19 | /* 20 | * Task: browserify 21 | * 22 | * Runs `browserify` on the `deployr` source. 23 | */ 24 | gulp.task('browserify', function() { 25 | return browserify({ debug: true, standalone: config.name, entries: ['./' + config.name + '.js'] }) 26 | .ignore('http') 27 | .bundle() 28 | .pipe(plumber({ errorHandler: onError})) 29 | .pipe(source(config.name + '.js')) 30 | .pipe(gulp.dest(config.dist)); 31 | }); -------------------------------------------------------------------------------- /gulp/tasks/build.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (C) 2010-2016, Microsoft Corporation 3 | * 4 | * This program is licensed to you under the terms of Version 2.0 of the 5 | * Apache License. This program is distributed WITHOUT 6 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 7 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 8 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 9 | * details. 10 | */ 11 | 12 | var gulp = require('gulp'); 13 | 14 | /* 15 | * Task: build 16 | * 17 | * The main build task to prepare the deployr source for browser environments. 18 | */ 19 | gulp.task('build', ['jshint', 'header']); -------------------------------------------------------------------------------- /gulp/tasks/connect.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (C) 2010-2016, Microsoft Corporation 3 | * 4 | * This program is licensed to you under the terms of Version 2.0 of the 5 | * Apache License. This program is distributed WITHOUT 6 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 7 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 8 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 9 | * details. 10 | */ 11 | 12 | var gulp = require('gulp'), 13 | connect = require('gulp-connect'), 14 | config = require('../config'); 15 | 16 | /* 17 | * Task: connect 18 | * 19 | * Run a webserver for viewing ./examples HTML samples (with LiveReload) 20 | */ 21 | gulp.task('connect', ['build'], function() { 22 | connect.server({ 23 | root: [config.root + '/examples/', config.dist], 24 | port: config.port, 25 | livereload: true 26 | }); 27 | 28 | // Watch JS 29 | gulp.watch([config.name + '.js', './lib/**/*.js'], ['build']); 30 | 31 | // Watch Examples that use HTML and livereload 32 | gulp.watch('./examples/**/*.html', ['build']); 33 | }); -------------------------------------------------------------------------------- /gulp/tasks/default.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (C) 2010-2016, Microsoft Corporation 3 | * 4 | * This program is licensed to you under the terms of Version 2.0 of the 5 | * Apache License. This program is distributed WITHOUT 6 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 7 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 8 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 9 | * details. 10 | */ 11 | 12 | var gulp = require('gulp'); 13 | 14 | /* 15 | * Task: default 16 | * 17 | * The default gulp task for deployr. 18 | */ 19 | gulp.task('default', ['build']); -------------------------------------------------------------------------------- /gulp/tasks/jshint.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (C) 2010-2016, Microsoft Corporation 3 | * 4 | * This program is licensed to you under the terms of Version 2.0 of the 5 | * Apache License. This program is distributed WITHOUT 6 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 7 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 8 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 9 | * details. 10 | */ 11 | 12 | var gulp = require('gulp'), 13 | jshint = require("gulp-jshint"), 14 | config = require('../config'); 15 | 16 | /* 17 | * Task: jshist 18 | * 19 | * Lint's the entire `deployr` source. 20 | */ 21 | gulp.task('jshint', function () { 22 | return gulp.src([config.name + '.js', './lib*.js']) 23 | .pipe(jshint({lookup: true})) 24 | .pipe(jshint.reporter('default')); 25 | }); 26 | -------------------------------------------------------------------------------- /gulp/tasks/start.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (C) 2010-2016, Microsoft Corporation 3 | * 4 | * This program is licensed to you under the terms of Version 2.0 of the 5 | * Apache License. This program is distributed WITHOUT 6 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 7 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 8 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 9 | * details. 10 | */ 11 | 12 | var gulp = require('gulp'); 13 | 14 | /* 15 | * Task: start 16 | * 17 | * Runs the build and starts the `Connect` HTTP server for viewing all the 18 | * ./examples HTML samples. 19 | */ 20 | gulp.task('start', ['connect']); 21 | -------------------------------------------------------------------------------- /gulp/tasks/uglifyjs.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (C) 2010-2016, Microsoft Corporation 3 | * 4 | * This program is licensed to you under the terms of Version 2.0 of the 5 | * Apache License. This program is distributed WITHOUT 6 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 7 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 8 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 9 | * details. 10 | */ 11 | 12 | var gulp = require('gulp'), 13 | uglify = require('gulp-uglify'), 14 | plumber = require('gulp-plumber'), 15 | rename = require("gulp-rename"), 16 | onError = require('../util/errors'), 17 | config = require('../config'); 18 | 19 | /* 20 | * Task: uglifyjs 21 | */ 22 | gulp.task('uglify', ['browserify'], function() { 23 | return gulp.src(['./browser/' + config.name + '.js']) 24 | .pipe(plumber({ errorHandler: onError })) 25 | .pipe(uglify()) 26 | .pipe(rename({ 27 | extname: '.min.js' 28 | })) 29 | .pipe(gulp.dest('./browser/')); 30 | }); -------------------------------------------------------------------------------- /gulp/util/errors.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (C) 2010-2016, Microsoft Corporation 3 | * 4 | * This program is licensed to you under the terms of Version 2.0 of the 5 | * Apache License. This program is distributed WITHOUT 6 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 7 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 8 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 9 | * details. 10 | */ 11 | 12 | var gutil = require('gulp-util'); 13 | 14 | module.exports = function(err) { 15 | gutil.log(gutil.colors.green(err)); 16 | }; -------------------------------------------------------------------------------- /gulp/util/script-filter.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (C) 2010-2016, Microsoft Corporation 3 | * 4 | * This program is licensed to you under the terms of Version 2.0 of the 5 | * Apache License. This program is distributed WITHOUT 6 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 7 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 8 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 9 | * details. 10 | */ 11 | 12 | var path = require('path'); 13 | 14 | module.exports = function(name) { 15 | return /(\.(js)$)/i.test(path.extname(name)); 16 | }; -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (C) 2010-2016, Microsoft Corporation 3 | * 4 | * This program is licensed to you under the terms of Version 2.0 of the 5 | * Apache License. This program is distributed WITHOUT 6 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 7 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 8 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 9 | * details. 10 | */ 11 | 12 | require('./gulp'); 13 | -------------------------------------------------------------------------------- /lib/emitter.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (C) 2010-2016, Microsoft Corporation 3 | * 4 | * This program is licensed to you under the terms of Version 2.0 of the 5 | * Apache License. This program is distributed WITHOUT 6 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 7 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 8 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 9 | * details. 10 | */ 11 | 12 | var Base = require('./selfish').Base; 13 | 14 | function debug(msg) { } 15 | 16 | module.exports = Base.extend({ 17 | 18 | initialize: function() { 19 | this.events = {}; 20 | this.scope = null; 21 | }, 22 | 23 | /** 24 | * Adds a listener. Multiple can be added per name. Aliased as `on`. 25 | * 26 | * @param {String} name The name of the event 27 | * @param {Function} handler A callback 28 | * @return {Emitter} `this` for chaining 29 | */ 30 | on: function(name, handler) { 31 | if (name in this.events === false) { this.events[name] = []; } 32 | 33 | this.events[name].push(handler); 34 | debug('Emitter.on("' + name + '")'); 35 | 36 | return this; 37 | }, 38 | 39 | /** 40 | * Triggers all matching listeners. 41 | * 42 | * @param {String} name The name of the event 43 | * @return {Emitter} `this` for chaining 44 | */ 45 | emit: function(name) { 46 | if (name in this.events === false) { return this; } 47 | 48 | for (var i = 0; i < this.events[name].length; i++) { 49 | debug('Fired event: "' + name + '"'); 50 | this.events[name][i].apply(this.scope || this, Array.prototype.slice.call(arguments, 1)); 51 | } 52 | 53 | return this; 54 | }, 55 | 56 | /** 57 | * Removes all matching listeners. 58 | * 59 | * @param {String} name The name of the event 60 | * @return {Emitter} `this` for chaining 61 | */ 62 | offAll: function(name) { 63 | if (!name) { 64 | for (var e in this.events) { 65 | delete this.events[e]; 66 | } 67 | } else { 68 | if (name in this.events === false) { return this; } 69 | delete this.events[name]; 70 | } 71 | 72 | return this; 73 | }, 74 | 75 | /** 76 | * Removes a listener based on an index. 77 | * 78 | * @private 79 | * @param {String} name The name of the event 80 | * @param {Number} index The index of the event 81 | */ 82 | offAt: function(name, index) { 83 | var array = this.events[name], 84 | rest = array.slice(index + 1); 85 | 86 | array.length = index; 87 | array.push.apply(array, rest); 88 | this.events[name] = array; 89 | }, 90 | 91 | /** 92 | * Removes a listener based on the handler function. 93 | * 94 | * @param {String} name The name of the event 95 | * @param {Function} handler The handler function to remove 96 | * @return {Emitter} `this` for chaining 97 | */ 98 | off: function(name, handler) { 99 | if (name in this.events === false) { return this; } 100 | 101 | // remove all events handlers by this name 102 | if (!handler) { 103 | return this.offAll(name); 104 | } else { // remove all events handlers == 'handler' by this name 105 | for (var i = 0; i < this.events[name].length; i++) { 106 | if (this.events[name][i] == handler) { 107 | this.offAt(name, i); 108 | return this; 109 | } 110 | } 111 | } 112 | 113 | return this; 114 | } 115 | 116 | }); -------------------------------------------------------------------------------- /lib/lang.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (C) 2010-2016, Microsoft Corporation 3 | * 4 | * This program is licensed to you under the terms of Version 2.0 of the 5 | * Apache License. This program is distributed WITHOUT 6 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 7 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 8 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 9 | * details. 10 | * 11 | * This component is a DeployR port of yui-lang.js by Yahoo! 12 | * 13 | * Software License Agreement (BSD License) 14 | * Copyright (c) 2013, Yahoo! Inc. All rights reserved. 15 | * 16 | * Redistribution and use of this software in source and binary forms, with or 17 | * without modification, are permitted provided that the following conditions 18 | * are met: 19 | * 20 | * Redistributions of source code must retain the above copyright notice, this 21 | * list of conditions and the following disclaimer. Redistributions in binary 22 | * form must reproduce the above copyright notice, this list of conditions and 23 | * the following disclaimer in the documentation and/or other materials provided 24 | * with the distribution. 25 | * 26 | * Neither the name of Yahoo! Inc. nor the names of YUI's contributors may be 27 | * used to endorse or promote products derived from this software without 28 | * specific prior written permission of Yahoo! Inc. 29 | * 30 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 31 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 32 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 33 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 34 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 35 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 36 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 37 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 38 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 39 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 40 | * POS SIBILITY OF SUCH DAMAGE. 41 | */ 42 | 43 | /** 44 | * Provides core language utilites and extensions used throughout DeployR. 45 | * 46 | * @class Lang 47 | * @static 48 | */ 49 | var L = {}, 50 | TOSTRING = Object.prototype.toString, 51 | TYPES = { 52 | 'undefined' : 'undefined', 53 | 'number' : 'number', 54 | 'boolean' : 'boolean', 55 | 'string' : 'string', 56 | '[object Function]' : 'function', 57 | '[object RegExp]' : 'regexp', 58 | '[object Array]' : 'array', 59 | '[object Date]' : 'date', 60 | '[object Error]' : 'error' 61 | }, unsafeNatives = false; 62 | 63 | /** 64 | * Determines whether or not the provided item is null. 65 | * @method isNull 66 | * @static 67 | * @param o The object to test. 68 | * @return {boolean} true if o is null. 69 | */ 70 | L.isNull = function(o) { 71 | return o === null; 72 | }; 73 | 74 | /** 75 | * Determines whether or not the provided item is undefined. 76 | * @method isUndefined 77 | * @static 78 | * @param o The object to test. 79 | * @return {boolean} true if o is undefined. 80 | */ 81 | L.isUndefined = function(o) { 82 | return typeof o === 'undefined'; 83 | }; 84 | 85 | /** 86 | * Determines whether or not the provided item is of type object 87 | * or function. Note that arrays are also objects, so 88 | * Y.Lang.isObject([]) === true. 89 | * @method isObject 90 | * @static 91 | * @param o The object to test. 92 | * @param failfn {boolean} fail if the input is a function. 93 | * @return {boolean} true if o is an object. 94 | * @see isPlainObject 95 | */ 96 | L.isObject = function(o, failfn) { 97 | var t = typeof o; 98 | return (o && (t === 'object' || (!failfn && (t === 'function' || L.isFunction(o))))) || false; 99 | }; 100 | /** 101 | * Determines whether or not the provided item is an array. 102 | * 103 | * Returns `false` for array-like collections such as the function `arguments` 104 | * collection or `HTMLElement` collections. 105 | * 106 | * @method isArray 107 | * @param o The object to test. 108 | * @return {boolean} true if o is an array. 109 | * @static 110 | */ 111 | L.isArray = (!unsafeNatives && Array.isArray) || 112 | function(o) { 113 | return L.type(o) === 'array'; 114 | }; 115 | 116 | L.isFunction = function isFunctionA(o) { 117 | return (typeof(o) === "function"); 118 | }; 119 | 120 | /** 121 | * Determines whether or not the provided item is a boolean. 122 | * @method isBoolean 123 | * @static 124 | * @param o The object to test. 125 | * @return {boolean} true if o is a boolean. 126 | */ 127 | L.isBoolean = function(o) { 128 | return typeof o === 'boolean'; 129 | }; 130 | 131 | /** 132 | * Determines whether or not the supplied item is a date instance. 133 | * @method isDate 134 | * @static 135 | * @param o The object to test. 136 | * @return {boolean} true if o is a date. 137 | */ 138 | L.isDate = function(o) { 139 | return L.type(o) === 'date' && o.toString() !== 'Invalid Date' && !isNaN(o); 140 | }; 141 | 142 | /** 143 | * Determines whether or not the provided item is a legal number. 144 | * @method isNumber 145 | * @static 146 | * @param o The object to test. 147 | * @return {boolean} true if o is a number. 148 | */ 149 | L.isNumber = function(o) { 150 | return typeof o === 'number' && isFinite(o); 151 | }; 152 | 153 | /** 154 | * Determines whether or not the provided item is a string. 155 | * @method isString 156 | * @static 157 | * @param o The object to test. 158 | * @return {boolean} true if o is a string. 159 | */ 160 | L.isString = function(o) { 161 | return typeof o === 'string'; 162 | }; 163 | 164 | /** 165 | * Returns a string representing the type of the item passed in. 166 | * 167 | * @method type 168 | * @param o the item to test. 169 | * @return {string} the detected type. 170 | * @static 171 | */ 172 | L.type = function(o) { 173 | return TYPES[ typeof o] || TYPES[TOSTRING.call(o)] || ( o ? 'object' : 'null'); 174 | }; 175 | 176 | module.exports = L; -------------------------------------------------------------------------------- /lib/logger.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (C) 2010-2016, Microsoft Corporation 3 | * 4 | * This program is licensed to you under the terms of Version 2.0 of the 5 | * Apache License. This program is distributed WITHOUT 6 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 7 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 8 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 9 | * details. 10 | */ 11 | 12 | var Logger = {}, 13 | loggerMap = {}, 14 | globalLogger; 15 | 16 | /** 17 | * Universal stdout|stderr printer 18 | */ 19 | function log(messages, context) { 20 | if (!console) { return; } 21 | 22 | function sep(level) { 23 | var sep = '=========================================================' + 24 | '=========================================================\n', 25 | offset = 0; 26 | 27 | if (level === Logger.DEBUG || level === Logger.ERROR) offset = 8; 28 | else if (level === Logger.INFO || level === Logger.WARN) offset = 8; 29 | else offset = 7; 30 | 31 | return { start: sep.substring(offset), end: sep }; 32 | } 33 | 34 | var hdlr, 35 | args = Array.prototype.slice.call(messages, 0), 36 | name = context.name, 37 | error = context.level === Logger.ERROR, 38 | delim = sep(context.level); 39 | 40 | if (context.level === Logger.WARN && console.warn) { 41 | hdlr = 'warn'; 42 | } else if (context.level === Logger.ERROR && console.error) { 43 | hdlr = 'error'; 44 | } else if (context.level === Logger.INFO && console.info) { 45 | hdlr = 'info'; 46 | } else { 47 | hdlr = 'log'; 48 | } 49 | 50 | // -- custom format logging statement for deployr request/response/error -- 51 | args.unshift('[' + (error ? Logger.ERROR.name : name) + '] ' + delim.start); 52 | args.push(delim.end); 53 | 54 | console[hdlr](args[0], [args[1] + ' ---> ' + args[2]['call']]); 55 | 56 | for (var i = 2; i < args.length; i++) { console.log(args[i]); } 57 | } 58 | 59 | /** 60 | * Logging category by id. 61 | */ 62 | function Category(id, level, fn) { 63 | this.id = id; 64 | this.context = level || Logger.DEBUG; 65 | } 66 | 67 | Category.prototype = { 68 | log: function(level, msgArgs) { 69 | if (level.value >= this.context.value) { 70 | log(msgArgs, { 71 | level: level, 72 | name: this.context.name, 73 | value: this.context.value 74 | }); 75 | } 76 | }, 77 | 78 | debug: function () { 79 | this.log(Logger.DEBUG, arguments); 80 | }, 81 | 82 | error: function () { 83 | this.log(Logger.ERROR, arguments); 84 | }, 85 | 86 | info: function () { 87 | this.log(Logger.INFO, arguments); 88 | }, 89 | 90 | warn: function () { 91 | this.log(Logger.WARN, arguments); 92 | }, 93 | 94 | setLevel: function(level) { 95 | if (level && 'value' in level) { 96 | this.context = level; 97 | } 98 | } 99 | }; 100 | 101 | Logger.DEBUG = { value: 1, name: 'DEBUG' }; 102 | Logger.INFO = { value: 2, name: 'INFO' }; 103 | Logger.WARN = { value: 4, name: 'WARN' }; 104 | Logger.ERROR = { value: 8, name: 'ERROR' }; 105 | Logger.OFF = { value: 99, name: 'OFF' }; 106 | 107 | Logger.setLevel = function(newLevel) { 108 | globalLogger.setLevel(newLevel); 109 | }; 110 | 111 | Logger.debug = function () { 112 | globalLogger.debug.apply(globalLogger, arguments); 113 | }; 114 | 115 | Logger.info = function () { 116 | globalLogger.info.apply(globalLogger, arguments); 117 | }; 118 | 119 | Logger.warn = function () { 120 | globalLogger.warn.apply(globalLogger, arguments); 121 | }; 122 | 123 | Logger.error = function () { 124 | globalLogger.error.apply(globalLogger, arguments); 125 | }; 126 | 127 | Logger.get = function (id, level, fn) { 128 | return (loggerMap[id] || (function() { 129 | loggerMap[id] = new Category(id, level, fn); 130 | return loggerMap[id]; 131 | })()); 132 | }; 133 | 134 | // --- setup the global logger --- 135 | globalLogger = Logger.get('global'); 136 | 137 | module.exports = Logger; 138 | -------------------------------------------------------------------------------- /lib/merge.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (C) 2010-2016, Microsoft Corporation 3 | * 4 | * This program is licensed to you under the terms of Version 2.0 of the 5 | * Apache License. This program is distributed WITHOUT 6 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 7 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 8 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 9 | * details. 10 | */ 11 | 12 | function merge(to, from) { 13 | if (typeof(to) !== 'object') { to = {}; } 14 | if (typeof(from) !== 'object') { from = {}; } 15 | 16 | for (var k in from) { to[k] = from[k]; } 17 | 18 | return to; 19 | } 20 | 21 | module.exports = merge; -------------------------------------------------------------------------------- /lib/optional.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (C) 2010-2016, Microsoft Corporation 3 | * 4 | * This program is licensed to you under the terms of Version 2.0 of the 5 | * Apache License. This program is distributed WITHOUT 6 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 7 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 8 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 9 | * details. 10 | */ 11 | 12 | module.exports = function(module) { 13 | try { 14 | return require(module); 15 | } catch (e) {} 16 | }; -------------------------------------------------------------------------------- /lib/queue.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (C) 2010-2016, Microsoft Corporation 3 | * 4 | * This program is licensed to you under the terms of Version 2.0 of the 5 | * Apache License. This program is distributed WITHOUT 6 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 7 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 8 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 9 | * details. 10 | */ 11 | 12 | function Queue() { 13 | this.emptyCallback = null; 14 | this.callbacks = []; 15 | this.yielded = false; 16 | this.response = null; 17 | this.responseChain = []; 18 | } 19 | 20 | Queue.prototype = { 21 | 22 | add: function(fn, ctx, defer) { 23 | // currently not waiting and there is no defer delay just make call 24 | if (!this.yielded && !defer) { 25 | fn.apply(ctx || this, [this.response]); 26 | } else { // add to queue 27 | this.callbacks.push({ fn: fn, ctx: ctx }); 28 | } 29 | }, 30 | 31 | size: function() { 32 | return this.callbacks.length; 33 | }, 34 | 35 | isEmpty: function() { 36 | return this.callbacks.length === 0; 37 | }, 38 | 39 | empty: function(fn, ctx) { 40 | this.emptyCallback = { fn: fn, ctx: ctx }; 41 | }, 42 | 43 | yield: function(yield) { 44 | this.yielded = yield; 45 | }, 46 | 47 | take: function(response, error, args) { 48 | var cb; 49 | 50 | if (response) { 51 | this.response = response; 52 | this.responseChain.push(response); 53 | } 54 | 55 | 56 | if (!this.yielded && this.callbacks[0]) { 57 | cb = this.callbacks.shift(); 58 | cb.fn.apply(cb.ctx || this, [this.responseChain, error, args]); 59 | 60 | // notify that the queue is now empty 61 | if (this.callbacks[0] && this.emptyCallback) { 62 | this.emptyCallback.fn.call(this.emptyCallback.ctx || this); 63 | } 64 | } 65 | }, 66 | 67 | flush: function(response, error, args) { 68 | if (response) { 69 | this.response = response; 70 | this.responseChain.push(response); 71 | } 72 | 73 | // pop and call next inline 74 | while (this.callbacks[0]) { 75 | if (this.yielded) { break; } 76 | var cb = this.callbacks.shift(); 77 | cb.fn.apply(cb.ctx || this, [this.responseChain, error, args]); 78 | 79 | // notify that the queue is now empty 80 | if (this.callbacks[0] && this.emptyCallback) { 81 | this.emptyCallback.fn.call(this.emptyCallback.ctx || this); 82 | } 83 | } 84 | } 85 | }; 86 | 87 | module.exports = Queue; -------------------------------------------------------------------------------- /lib/rinput.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (C) 2010-2016, Microsoft Corporation 3 | * 4 | * This program is licensed to you under the terms of Version 2.0 of the 5 | * Apache License. This program is distributed WITHOUT 6 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 7 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 8 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 9 | * details. 10 | */ 11 | 12 | var Base = require('./selfish').Base, 13 | RTypes = require('./rtypes'); 14 | 15 | module.exports = Base.extend(RTypes, { 16 | initialize: function initialize(name, value, options) { 17 | this.name = name; 18 | this.value = value; 19 | this.options = options || {}; 20 | }, 21 | 22 | numeric: function () { 23 | // support `String` numbers (e.g. "1.2") 24 | this.value = parseFloat(this.value); 25 | 26 | return this.assert({ 27 | type: this.deployr.RNUMERIC, 28 | name: this.name, 29 | value: this.value, 30 | toString: this.toString 31 | }); 32 | }, 33 | 34 | integer: function () { 35 | // support `String` integer (e.g. "15") 36 | this.value = parseInt(this.value, 10); 37 | 38 | return this.assert({ 39 | type: this.deployr.RINTEGER, 40 | name: this.name, 41 | value: this.value, 42 | toString: this.toString 43 | }); 44 | }, 45 | 46 | logical: function () { 47 | return this.assert({ 48 | type: this.deployr.RBOOLEAN, 49 | name: this.name, 50 | value: this.value, 51 | toString: this.toString 52 | }); 53 | }, 54 | 55 | character: function () { 56 | return this.assert({ 57 | type: this.deployr.RSTRING, 58 | name: this.name, 59 | value: this.value, 60 | toString: this.toString 61 | }); 62 | }, 63 | 64 | date: function () { 65 | return this.assert({ 66 | type: this.deployr.RDATE, 67 | name: this.name, 68 | value: this.value, 69 | format: 'yyyy-MM-dd', 70 | toString: this.toString 71 | }); 72 | }, 73 | 74 | posixct: function () { 75 | return this.assert({ 76 | type: this.deployr.RPOSIX_DATE, 77 | name: this.name, 78 | value: this.value, 79 | format: 'yyyy-MM-dd HH:mm:ss Z', 80 | toString: this.toString 81 | }); 82 | }, 83 | 84 | numericVector: function () { 85 | return this.assert({ 86 | type: this.deployr.RNUMERIC_VECTOR, 87 | name: this.name, 88 | value: this.value, 89 | toString: this.toString 90 | }); 91 | }, 92 | 93 | integerVector: function () { 94 | return this.assert({ 95 | type: this.deployr.RINTEGER_VECTOR, 96 | name: this.name, 97 | value: this.value, 98 | toString: this.toString 99 | }); 100 | }, 101 | 102 | logicalVector: function () { 103 | return this.assert({ 104 | type: this.deployr.RBOOLEAN_VECTOR, 105 | name: this.name, 106 | value: this.value, 107 | toString: this.toString 108 | }); 109 | }, 110 | 111 | characterVector: function () { 112 | return this.assert({ 113 | type: this.deployr.RSTRING_VECTOR, 114 | name: this.name, 115 | value: this.value, 116 | toString: this.toString 117 | }); 118 | }, 119 | 120 | dateVector: function () { 121 | return this.assert({ 122 | type: this.deployr.RDATE_VECTOR, 123 | name: this.name, 124 | value: this.value, 125 | format: 'yyyy-MM-dd', 126 | toString: this.toString 127 | }); 128 | }, 129 | 130 | posixctVector: function () { 131 | return this.assert({ 132 | type: this.deployr.RPOSIX_DATE_VECTOR, 133 | name: this.name, 134 | value: this.value, 135 | format: 'yyyy-MM-dd HH:mm:ss Z', 136 | toString: this.toString 137 | }); 138 | }, 139 | 140 | list: function () { 141 | return this.assert({ 142 | type: this.deployr.RLIST, 143 | name: this.name, 144 | value: this.value, 145 | toString: this.toString 146 | }); 147 | }, 148 | 149 | dataframe: function () { 150 | return this.assert({ 151 | type: this.deployr.RDATAFRAME, 152 | name: this.name, 153 | value: this.value, 154 | toString: this.toString 155 | }); 156 | }, 157 | 158 | factor: function () { 159 | var opts = this.options; 160 | 161 | return this.assert( { 162 | type: this.deployr.RFACTOR, 163 | name: this.name, 164 | value: this.value, 165 | ordered: false, 166 | levels: opts.levels, 167 | labels: opts.labels, 168 | toString: this.toString 169 | }); 170 | }, 171 | 172 | ordered: function () { 173 | var opts = this.options; 174 | 175 | return this.assert( { 176 | type: this.deployr.RORDERED, 177 | name: this.name, 178 | value: this.value, 179 | ordered: true, 180 | levels: opts.levels, 181 | labels: opts.labels, 182 | toString: this.toString 183 | }); 184 | }, 185 | 186 | numericMatrix: function () { 187 | return this.assert({ 188 | type: this.deployr.RNUMERIC_MATRIX, 189 | name: this.name, 190 | value: this.value, 191 | toString: this.toString 192 | }); 193 | }, 194 | 195 | integerMatrix: function () { 196 | return this.assert({ 197 | type: this.deployr.RINTEGER_MATRIX, 198 | name: this.name, 199 | value: this.value, 200 | toString: this.toString 201 | }); 202 | }, 203 | 204 | logicalMatrix: function () { 205 | return this.assert({ 206 | type: this.deployr.RBOOLEAN_MATRIX, 207 | name: this.name, 208 | value: this.value, 209 | toString: this.toString 210 | }); 211 | }, 212 | 213 | characterMatrix: function () { 214 | return this.assert({ 215 | type: this.deployr.RSTRING_MATRIX, 216 | name: this.name, 217 | value: this.value, 218 | toString: this.toString 219 | }); 220 | }, 221 | 222 | toString: function() { 223 | var opts = this.options || {}, 224 | levels = opts.levels ? '[ levels = ' + opts.levels + ']' : '', 225 | labels = opts.labels ? '[ labels = ' + opts.labels + ']' : ''; 226 | 227 | return '[ name = ' + this.name + ' ] ' + 228 | '[ value = ' + this.value + ' ] ' + 229 | '[ type = ' + this.type + ' ] ' + 230 | levels + labels; 231 | } 232 | }); -------------------------------------------------------------------------------- /lib/rinputs.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (C) 2010-2016, Microsoft Corporation 3 | * 4 | * This program is licensed to you under the terms of Version 2.0 of the 5 | * Apache License. This program is distributed WITHOUT 6 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 7 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 8 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 9 | * details. 10 | */ 11 | 12 | var Base = require('./selfish').Base, 13 | RTypes = require('./rtypes'), 14 | Lang = require('./lang'), 15 | RInput = require('./rinput'); 16 | 17 | function create(type, name, value, options) { 18 | var rinput; 19 | 20 | if (Lang.isObject(name)) { 21 | rinput = name; 22 | if (!rinput.type !== type) { 23 | throw new Error('IllegalArgumentError:' + 24 | 'Expecting "' + type + '" but found "' + rinput.type + '"'); 25 | } 26 | } else { 27 | rinput = RInput.new(name, value, options)[type](); 28 | } 29 | 30 | return rinput; 31 | } 32 | 33 | module.exports = Base.extend(RTypes, { 34 | numeric: function (name, value) { 35 | this.inputs.push(create(this.deployr.RNUMERIC, name, value)); 36 | return this; 37 | }, 38 | 39 | integer: function (name, value) { 40 | this.inputs.push(create(this.deployr.RINTEGER, name, value)); 41 | return this; 42 | }, 43 | 44 | logical: function (name, value) { 45 | this.inputs.push(create(this.deployr.RBOOLEAN, name, value)); 46 | return this; 47 | }, 48 | 49 | character: function (name, value) { 50 | this.inputs.push(create(this.deployr.RSTRING, name, value)); 51 | return this; 52 | }, 53 | 54 | date: function (name, value) { 55 | this.inputs.push(create(this.deployr.RDATE, name, value)); 56 | return this; 57 | }, 58 | 59 | posixct: function (name, value) { 60 | this.inputs.push(create(this.deployr.RPOSIX_DATE, name, value)); 61 | return this; 62 | }, 63 | 64 | numericVector: function (name, value) { 65 | this.inputs.push(create(this.deployr.RNUMERIC_VECTOR, name, value)); 66 | return this; 67 | }, 68 | 69 | integerVector: function (name, value) { 70 | this.inputs.push(create(this.deployr.RINTEGER_VECTOR, name, value)); 71 | return this; 72 | }, 73 | 74 | logicalVector: function (name, value) { 75 | this.inputs.push(create(this.deployr.RBOOLEAN_VECTOR, name, value)); 76 | return this; 77 | }, 78 | 79 | characterVector: function (name, value) { 80 | this.inputs.push(create(this.deployr.RSTRING_VECTOR, name, value)); 81 | return this; 82 | }, 83 | 84 | dateVector: function (name, value) { 85 | this.inputs.push(create(this.deployr.RDATE_VECTOR, name, value)); 86 | return this; 87 | }, 88 | 89 | posixctVector: function (name, value) { 90 | this.inputs.push(create(this.deployr.RPOSIX_DATE_VECTOR, name, value)); 91 | return this; 92 | }, 93 | 94 | list: function (name, value) { 95 | this.inputs.push(create(this.deployr.RLIST, name, value)); 96 | return this; 97 | }, 98 | 99 | dataframe: function (name, value) { 100 | this.inputs.push(create(this.deployr.RDATAFRAME, name, value)); 101 | return this; 102 | }, 103 | 104 | factor: function (name, value, levels, labels) { 105 | var opts = { levels: levels, labels: labels }; 106 | this.inputs.push(create(this.deployr.RFACTOR, name, value, opts)); 107 | return this; 108 | }, 109 | 110 | ordered: function (name, value, levels, labels) { 111 | var opts = { levels: levels, labels: labels }; 112 | this.inputs.push(create(this.deployr.RORDERED, name, value, opts)); 113 | return this; 114 | }, 115 | 116 | numericMatrix: function (name, value) { 117 | this.inputs.push(create(this.deployr.RNUMERIC_MATRIX, name, value)); 118 | return this; 119 | }, 120 | 121 | integerMatrix: function (name, value) { 122 | this.inputs.push(create(this.deployr.RINTEGER_MATRIX, name, value)); 123 | return this; 124 | }, 125 | 126 | logicalMatrix: function (name, value) { 127 | this.inputs.push(create(this.deployr.RBOOLEAN_MATRIX, name, value)); 128 | return this; 129 | }, 130 | 131 | characterMatrix: function (name, value) { 132 | this.inputs.push(create(this.deployr.RSTRING_MATRIX, name, value)); 133 | return this; 134 | } 135 | }); -------------------------------------------------------------------------------- /lib/rtypes.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (C) 2010-2016, Microsoft Corporation 3 | * 4 | * This program is licensed to you under the terms of Version 2.0 of the 5 | * Apache License. This program is distributed WITHOUT 6 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 7 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 8 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 9 | * details. 10 | */ 11 | 12 | var Base = require('./selfish').Base, 13 | Lang = require('./lang'), 14 | map = {}; // deployr->To->R catalog 15 | 16 | module.exports = Base.extend({ 17 | r: { 18 | PRIMITIVE: 'primitive', 19 | DATAFRAME: 'dataframe', 20 | LIST: 'list', 21 | MATRIX: 'matrix', 22 | DATE: 'date', 23 | FACTOR: 'factor', 24 | VECTOR: 'vector' 25 | }, 26 | 27 | deployr: { 28 | RBOOLEAN: 'logical', 29 | RNUMERIC: 'numeric', 30 | RINTEGER: 'integer', 31 | RSTRING: 'character', 32 | RDATE: 'date', 33 | RPOSIX_DATE: 'posixct', 34 | RBOOLEAN_VECTOR: 'logicalVector', 35 | RNUMERIC_VECTOR:'numericVector', 36 | RINTEGER_VECTOR: 'integerVector', 37 | RSTRING_VECTOR: 'characterVector', 38 | RDATE_VECTOR: 'dateVector', 39 | RPOSIX_DATE_VECTOR: 'posixctVector', 40 | RLIST: 'list', 41 | RDATAFRAME: 'dataframe', 42 | RFACTOR: 'factor', 43 | RORDERED: 'ordered', 44 | RBOOLEAN_MATRIX: 'logicalMatrix', 45 | RNUMERIC_MATRIX: 'numericMatrix', 46 | RINTEGER_MATRIX: 'integerMatrix', 47 | RSTRING_MATRIX: 'characterMatrix' 48 | }, 49 | 50 | isDate: function(type) { 51 | return (type === this.deployr.RDATE || 52 | type === this.deployr.RPOSIX_DATE || 53 | type === this.deployr.RDATE_VECTOR || 54 | type === this.deployr.RPOSIX_DATE_VECTOR || 55 | type === this.r.DATE); 56 | }, 57 | 58 | deployrToR: function(type) { 59 | var deployr = this.deployr, 60 | r = this.r; 61 | 62 | if (!map[type]) { // build catalog only once 63 | map[deployr.RBOOLEAN] = r.PRIMITIVE; 64 | map[deployr.RNUMERIC] = r.PRIMITIVE; 65 | map[deployr.RINTEGER] = r.PRIMITIVE; 66 | map[deployr.RSTRING] = r.PRIMITIVE; 67 | map[deployr.RDATE] = r.DATE; 68 | map[deployr.RPOSIX_DATE] = r.DATE; 69 | map[deployr.RBOOLEAN_VECTOR] = r.VECTOR; 70 | map[deployr.RNUMERIC_VECTOR] = r.VECTOR; 71 | map[deployr.RINTEGER_VECTOR] = r.VECTOR; 72 | map[deployr.RSTRING_VECTOR] = r.VECTOR; 73 | map[deployr.RDATE_VECTOR] = r.VECTOR; 74 | map[deployr.RPOSIX_DATE_VECTOR] = r.VECTOR; 75 | map[deployr.RLIST] = r.LIST; 76 | map[deployr.RDATAFRAME] = r.DATAFRAME; 77 | map[deployr.RFACTOR] = r.FACTOR; 78 | map[deployr.RORDERED] = r.FACTOR; 79 | map[deployr.RBOOLEAN_MATRIX] = r.MATRIX; 80 | map[deployr.RNUMERIC_MATRIX] = r.MATRIX; 81 | map[deployr.RINTEGER_MATRIX] = r.MATRIX; 82 | map[deployr.RSTRING_MATRIX] = r.MATRIX; 83 | } 84 | 85 | return map[type]; 86 | }, 87 | 88 | /** 89 | * Assert that the `rinput` value is the correct JavaScript Data Type. 90 | */ 91 | assert: function (rinput) { 92 | var deployr = this.deployr, 93 | NOOP = null, 94 | values = rinput.value, 95 | fn; 96 | 97 | values = !Lang.isArray(values) ? [values] : values; 98 | 99 | for (var i = 0; i < values.length; i++) { 100 | var value = values[i]; 101 | 102 | switch (rinput.type) { 103 | case deployr.RNUMERIC : 104 | case deployr.RNUMERIC_VECTOR : 105 | case deployr.RINTEGER : 106 | case deployr.RINTEGER_VECTOR : 107 | fn = Lang.isNumber; 108 | break; 109 | 110 | case deployr.RBOOLEAN : 111 | case deployr.RBOOLEAN_VECTOR : 112 | fn = Lang.isBoolean; 113 | break; 114 | 115 | case deployr.RSTRING : 116 | case deployr.RSTRING_VECTOR : 117 | fn = Lang.isString; 118 | break; 119 | 120 | case deployr.RDATE : 121 | case deployr.RPOSIX_DATE : 122 | case deployr.RDATE_VECTOR : 123 | case deployr.RPOSIX_DATE_VECTOR : 124 | fn = Lang.isDate; 125 | break; 126 | 127 | case deployr.RFACTOR : 128 | case deployr.RORDERED : 129 | case deployr.RDATAFRAME : 130 | case deployr.RINTEGER_MATRIX : 131 | case deployr.RBOOLEAN_MATRIX : 132 | case deployr.RSTRING_MATRIX : 133 | fn = NOOP; 134 | break 135 | } 136 | 137 | if (fn && !fn(value)) { 138 | throw new Error('RInputFormatError: ' + '"' + value + 139 | '" is not a valid "' + rinput.type + '" type for input ' + 140 | '"' + rinput.name + '"'); 141 | } 142 | } 143 | 144 | return rinput; 145 | } 146 | }); -------------------------------------------------------------------------------- /lib/selfish.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * https://github.com/Gozala/selfish 3 | */ 4 | 5 | /* vim:set ts=2 sw=2 sts=2 expandtab */ 6 | /*jshint undef: true es5: true node: true devel: true evil: true 7 | forin: true latedef: false supernew: true */ 8 | /*global define: true */ 9 | 10 | !(typeof define !== "function" ? function($){ $(null, typeof exports !== 'undefined' ? exports : window); } : define)(function(require, exports) { 11 | 12 | "use strict"; 13 | 14 | exports.Base = Object.freeze(Object.create(Object.prototype, { 15 | /** 16 | * Creates an object that inherits from `this` object (Analog of 17 | * `new Object()`). 18 | * @examples 19 | * 20 | * var Dog = Base.extend({ 21 | * bark: function bark() { 22 | * return 'Ruff! Ruff!' 23 | * } 24 | * }); 25 | * var dog = Dog.new(); 26 | */ 27 | 'new': { value: function create() { 28 | var object = Object.create(this); 29 | object.initialize.apply(object, arguments); 30 | return object; 31 | }}, 32 | /** 33 | * When new instance of the this prototype is created it's `initialize` 34 | * method is called with all the arguments passed to the `new`. You can 35 | * override `initialize` to set up an instance. 36 | */ 37 | initialize: { value: function initialize() { 38 | }}, 39 | /** 40 | * Merges all the properties of the passed objects into `this` instance (This 41 | * method can be used on instances only as prototype objects are frozen). 42 | * 43 | * If two or more argument objects have own properties with the same name, 44 | * the property is overridden, with precedence from right to left, implying, 45 | * that properties of the object on the left are overridden by a same named 46 | * property of the object on the right. 47 | * 48 | * @examples 49 | * 50 | * var Pet = Dog.extend({ 51 | * initialize: function initialize(options) { 52 | * // this.name = options.name -> would have thrown (frozen prototype) 53 | * this.merge(options) // will override all properties. 54 | * }, 55 | * call: function(name) { 56 | * return this.name === name ? this.bark() : '' 57 | * }, 58 | * name: null 59 | * }) 60 | * var pet = Pet.new({ name: 'Benzy', breed: 'Labrador' }) 61 | * pet.call('Benzy') // 'Ruff! Ruff!' 62 | */ 63 | merge: { value: function merge() { 64 | var descriptor = {}; 65 | Array.prototype.forEach.call(arguments, function (properties) { 66 | Object.getOwnPropertyNames(properties).forEach(function(name) { 67 | descriptor[name] = Object.getOwnPropertyDescriptor(properties, name); 68 | }); 69 | }); 70 | Object.defineProperties(this, descriptor); 71 | return this; 72 | }}, 73 | /** 74 | * Takes any number of argument objects and returns frozen, composite object 75 | * that inherits from `this` object and combines all of the own properties of 76 | * the argument objects. (Objects returned by this function are frozen as 77 | * they are intended to be used as types). 78 | * 79 | * If two or more argument objects have own properties with the same name, 80 | * the property is overridden, with precedence from right to left, implying, 81 | * that properties of the object on the left are overridden by a same named 82 | * property of the object on the right. 83 | * @examples 84 | * 85 | * // ## Object composition ## 86 | * 87 | * var HEX = Base.extend({ 88 | * hex: function hex() { 89 | * return '#' + this.color; 90 | * } 91 | * }) 92 | * 93 | * var RGB = Base.extend({ 94 | * red: function red() { 95 | * return parseInt(this.color.substr(0, 2), 16); 96 | * }, 97 | * green: function green() { 98 | * return parseInt(this.color.substr(2, 2), 16); 99 | * }, 100 | * blue: function blue() { 101 | * return parseInt(this.color.substr(4, 2), 16); 102 | * } 103 | * }) 104 | * 105 | * var CMYK = Base.extend(RGB, { 106 | * black: function black() { 107 | * var color = Math.max(Math.max(this.red(), this.green()), this.blue()); 108 | * return (1 - color / 255).toFixed(4); 109 | * }, 110 | * cyan: function cyan() { 111 | * var K = this.black(); 112 | * return (((1 - this.red() / 255).toFixed(4) - K) / (1 - K)).toFixed(4); 113 | * }, 114 | * magenta: function magenta() { 115 | * var K = this.black(); 116 | * return (((1 - this.green() / 255).toFixed(4) - K) / (1 - K)).toFixed(4); 117 | * }, 118 | * yellow: function yellow() { 119 | * var K = this.black(); 120 | * return (((1 - this.blue() / 255).toFixed(4) - K) / (1 - K)).toFixed(4); 121 | * } 122 | * }) 123 | * 124 | * var Color = Base.extend(HEX, RGB, CMYK, { 125 | * initialize: function Color(color) { 126 | * this.color = color; 127 | * } 128 | * }); 129 | * 130 | * // ## Prototypal inheritance ## 131 | * 132 | * var Pixel = Color.extend({ 133 | * initialize: function Pixel(x, y, hex) { 134 | * Color.initialize.call(this, hex); 135 | * this.x = x; 136 | * this.y = y; 137 | * }, 138 | * toString: function toString() { 139 | * return this.x + ':' + this.y + '@' + this.hex(); 140 | * } 141 | * }); 142 | * 143 | * var pixel = Pixel.new(11, 23, 'CC3399') 144 | * pixel.toString(); // 11:23@#CC3399 145 | * 146 | * pixel.red(); // 204 147 | * pixel.green(); // 51 148 | * pixel.blue(); // 153 149 | * 150 | * pixel.cyan(); // 0.0000 151 | * pixel.magenta(); // 0.7500 152 | * pixel.yellow(); // 0.2500 153 | * 154 | */ 155 | extend: { value: function extend() { 156 | return Object.freeze(this.merge.apply(Object.create(this), arguments)); 157 | }} 158 | })); 159 | 160 | }); -------------------------------------------------------------------------------- /lib/utils.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (C) 2010-2016, Microsoft Corporation 3 | * 4 | * This program is licensed to you under the terms of Version 2.0 of the 5 | * Apache License. This program is distributed WITHOUT 6 | * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 7 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 8 | * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more 9 | * details. 10 | */ 11 | 12 | var Lang = require('./lang'); 13 | 14 | var get = exports.get = function(s, key) { 15 | function traverse(obj, fn, parent) { 16 | for (var i in obj) { 17 | var result = fn.apply(this, [i, obj[i], parent]); 18 | if (result) { 19 | return result; 20 | } else { 21 | if (obj[i] instanceof Object && !(obj[i] instanceof Array)) { 22 | traverse(obj[i], fn, i); 23 | } 24 | } 25 | } 26 | } 27 | 28 | function getProperty(obj, property) { 29 | var acc = {}; 30 | traverse(obj, function(key, value, parent) { 31 | if (key === property) { 32 | acc = value; 33 | return acc; 34 | } else { 35 | return null; 36 | } 37 | }); 38 | return acc; 39 | } 40 | 41 | function empty(obj) { 42 | for (var prop in obj) { if (obj.hasOwnProperty(prop)) return obj; } 43 | return !Lang.isObject(obj) ? obj : null; 44 | } 45 | 46 | return empty(getProperty(s, key)); 47 | }; 48 | 49 | var inArray = exports.inArray = function(haystack, needle, key) { 50 | var i, max = haystack.length; 51 | 52 | for (i = 0; i < max; i++) { 53 | if (key) { 54 | if (haystack[i][key] === needle) { return haystack[i]; } 55 | } else { 56 | if (haystack[i] === needle) { return haystack[i]; } 57 | } 58 | } 59 | return null; 60 | }; 61 | 62 | exports.merge = function(to, from) { 63 | if (!to || typeof(to) !== 'object') { to = {}; } 64 | if (!from || typeof(from) !== 'object') { from = {}; } 65 | 66 | for (var k in from) { to[k] = from[k]; } 67 | 68 | return to; 69 | }; 70 | 71 | exports.workspace = function(obj, name) { 72 | var ws = get(obj, 'workspace'); 73 | return (ws ? name ? inArray(ws.objects, name, 'name') : ws.objects || ws.object: null); 74 | }; 75 | 76 | exports.signature = function() { 77 | var args = Array.prototype.slice.call(arguments['0'], 0), 78 | len = args.length, 79 | create = false, 80 | opts = {}, 81 | api; 82 | 83 | if (len === 1 && Lang.isObject(args[0])) { 84 | opts = args[0]; 85 | api = opts.project ? '/r/project/execute/script' : 86 | '/r/repository/script/execute'; 87 | } else if (len === 1 && Lang.isString(args[0])) { 88 | args = args[0].split('\/'); 89 | api = '/r/repository/script/execute' 90 | opts = { 91 | author: args[1], 92 | directory: args[2], 93 | filename: args[3] 94 | }; 95 | } else if (len === 2) { 96 | // ex: .script('/testuser/root/DeployR - Hello World.R', project) 97 | var project = args[1]; 98 | api = project ? '/r/project/execute/script' : '/r/repository/script/execute'; 99 | 100 | args = args[0].split('\/'); 101 | opts = { 102 | project: project, 103 | author: args[1], 104 | directory: args[2], 105 | filename: args[3] 106 | }; 107 | } else if (len > 2) { 108 | // ex: .script('DeployR - Hello World.R', 'testuser', 'root') 109 | opts = { 110 | author: args[2], 111 | directory: args[1], 112 | filename: args[0] 113 | }; 114 | } 115 | 116 | // indicate a new project should be created 117 | if (opts.project && Lang.isBoolean(opts.project)) { 118 | delete opts['project']; 119 | create = true; 120 | } 121 | 122 | return { 123 | api: api, 124 | opts: opts, 125 | create: create 126 | }; 127 | }; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "deployr", 3 | "version": "8.0.5", 4 | "description": "Simplified JavaScript client library for making requests to DeployR.", 5 | "keywords": [ 6 | "deployr", 7 | "deployr.io", 8 | "ajax", 9 | "R", 10 | "api", 11 | "simple" 12 | ], 13 | "author": "DeployR - Microsoft Corporation", 14 | "contributors": [ 15 | "Sean Wells" 16 | ], 17 | "repository": { 18 | "type": "git", 19 | "url": "git://github.com/microsoft/js-client-library.git" 20 | }, 21 | "homepage": "http://go.microsoft.com/fwlink/?LinkID=698842", 22 | "scripts": { 23 | "start": "gulp start", 24 | "build": "gulp" 25 | }, 26 | "devDependencies": { 27 | "browserify": "^13.0.1", 28 | "gulp": "^3.9.1", 29 | "gulp-connect": "^4.1.0", 30 | "gulp-header": "^1.8.7", 31 | "gulp-jshint": "^2.0.1", 32 | "gulp-livereload": "^3.8.1", 33 | "gulp-plumber": "^1.1.0", 34 | "gulp-rename": "^1.2.2", 35 | "gulp-uglify": "^1.5.4", 36 | "gulp-util": "^3.0.7", 37 | "tape": "^4.6.0", 38 | "vinyl-source-stream": "^1.1.0" 39 | }, 40 | "dependencies": { 41 | "d.js": "^0.7.3", 42 | "superagent": "^0.21.0", 43 | "ws": "^0.4.32" 44 | }, 45 | "main": "deployr.js", 46 | "engines": { 47 | "node": ">= 0.10.0" 48 | }, 49 | "license": "Apache-2.0", 50 | "bugs": { 51 | "url": "https://github.com/microsoft/js-client-library/issues" 52 | }, 53 | "directories": { 54 | "example": "examples", 55 | "test": "test" 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /test/test.md: -------------------------------------------------------------------------------- 1 | Tests 2 | ===== 3 | 4 | Coming soon... --------------------------------------------------------------------------------