Skip to content

Instantly share code, notes, and snippets.

@lbrenman
Last active June 3, 2016 17:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lbrenman/d3065a7cabb53dee44477dc1e8e9c6fb to your computer and use it in GitHub Desktop.
Save lbrenman/d3065a7cabb53dee44477dc1e8e9c6fb to your computer and use it in GitHub Desktop.
Arrow Client Side SDK Example

Welcome

Welcome to your new Titanium SDK!

Installation

To use this SDK, you should copy the MyArrowApp directory in its entirety in to the appropriate place within your Titanium project.

Usage

Once you have it installed, you can require your main SDK file to get models, endpoints, and change configuration at runtime:

var MyArrowApp = require('MyArrowApp');
MyArrowApp.port = 8080;
// MyArrowApp.domain = 'http://your.domain.com';
// Basic Auth.
MyArrowApp.Authorization = 'KXUJoLX58LuzNjWd7Y0lcdIYTr0R5xb6';
// Production Basic Auth.
MyArrowApp.Authorization = 'mgCzMKbg2tD7ekigSdrz+cVSAk6OQ6yp';
// Development Basic Auth.
MyArrowApp.Authorization = 'KXUJoLX58LuzNjWd7Y0lcdIYTr0R5xb6';
// MyArrowApp.timeout = 30000;

var User = MyArrowApp.getModel('user');
User.findAll(function(err, results, client) {
    console.log(results);
});

MyArrowApp.getAPI('/api/test', 'GET').execute(function(err, results, client) {
    console.log(results);
});

Caching

The client SDK can cache GET results for quick retrieval later using various strategies. By default, it doesn't do any caching. But you can change that very easily:

// For everything:
MyArrowApp.cachePolicy = {
	type: MyArrowApp.Policy.CacheElseNetwork, // Use cached results right away if we can.
	duration: 60 * 60 * 1000 // Cache for one hour (in milliseconds)
};

// For an MyArrowApp model:
var User = MyArrowApp.getModel('user');
User.cachePolicy = ...;

// For a particular MyArrowApp method:
User.findAll(function(err, results, client) {}, { cachePolicy: ... });

There are multiple strategies available:

NoCache

No caches are used or saved. This is the default caching policy.

CacheElseNetwork

If a local cache of the results is available, it will be used; otherwise, the network will be used. Results will be cached.

NetworkElseCache

If the network is available, it will be used for results; otherwise, the local cache will be used. Results will be cached.

CacheThenNetwork

If a local cache of the result is available, it will be used immediately, and then the network will be used. The callback will, thus, be called twice. Results will be cached.

CacheOnly

If a local cache of results is available, it will be used.

NetworkOnly

If the network is available, it will be used for results. Results will be cached.

Appcelerator Arrow Client Side SDK example

This blog post will provide a simple step-by-step example of generating and utilizing the Arrow Client Side SDK for an Arrow Application.

For this example, I will utilize a simple ArrowDB Arrow project and a simple HelloWorld Titanium application.

The Arrow Admin console enables you to test the APIs and also provides sample code to consume the API as shown below. As you can see, the Titanium code sample provided in the admin console shows how to manually make an HTTPClient web service call in order to retrieve the ArrowDB data. We will utilize the Client Side SDK to retrieve this data instead.

ArrowDB Project

My simple Arrow project has an ArrowDB employee model shown below:

var Arrow = require('arrow');
var Model = Arrow.createModel('employee', {
	fields: {
		firstname: {
			type: String
		},
		lastname: {
			type: String
		},
		title: {
			type: String
		}
	},
	connector: 'appc.arrowdb',
	actions: [
		'create',
		'read',
		'update',
		'delete',
		'deleteAll'
	]
});
module.exports = Model;

A sample FindAll response is shown below:

{
  "success": true,
  "request-id": "92b3cd5c-19da-447b-86f9-7236e5f57e3e",
  "key": "employees",
  "employees": [
    {
      "id": "572919b528ddb0090682772f",
      "firstname": "John",
      "lastname": "Doe",
      "title": "Account Representative"
    },
    {
      "id": "572919851cfadc0903834b44",
      "firstname": "Susan",
      "lastname": "French",
      "title": "VP WW Sales"
    },
    {
      "id": "572919741cfadc0903834b26",
      "firstname": "David",
      "lastname": "Glass",
      "title": "CEO"
    }
  ]
}

Generate the SDK

The Appcelerator Command Line tool now supports generating a client side SDK in order to ease client side integration of your Arrow APIs instead manually making an HTTPClient web service call.

Once you have a working Arrow project working and published (or running locally), it is time to generate the client SDK.

Type the following from the command line:

appc generate

Select "Arrow SDK" in the response:

? What type of component would you like to generate?
  Arrow Component
 Arrow SDK
  CLI Plugin

Then select the client SDK type:

? Which type of App SDK?
  Alloy
  Android
  jQuery
  NodeJS
  Objective-C
 Titanium

I chose Titanium for this example but you can see all the client SDK types that are currently supported.

Enter a name for the generated SDK (e.g.MyArrowApp).

? What should the name of the SDK be? MyArrowApp

Specify the folder to put the SDK into. I left this as default (sdk):

? Generate files into which directory? (sdk)

Look in your Arrow project folder and you will see the generated SDK, MyArrowApp.js.

The readme provided in the SDK folder provides excellent documentation on how to install and use the SDK, including how to take advantage of client side caching.

Installing and Using the SDK

In my example, I created a Default Alloy Project in Appcelerator Studio.

Then, in order to use the Titanium Client SDK created above, copy the MyArrowApp.js file to your project's app/lib folder.

NOTE: You may need to create the app/lib folder

Then I copied and pasted the sample code from the Usage section of the sdk/readme.md file into the Titanium index.js controller file into the doCLick function as follows:

var MyArrowApp = require('MyArrowApp');
MyArrowApp.port = 8080;
MyArrowApp.Authorization = 'KXUJoLX58LuzNjWd7Y0lcdIYTr0R5xb6';

var Employee = MyArrowApp.getModel('employee');
Employee.findAll(function(err, results, client) {
  console.log(results);
});

Running the TItanum application and clickin gon the "Hello World " Label causes this code to execute and to display the ArrowDB employee data in the console as follows:

[INFO] :   [LiveView] Reloading App
[INFO] :   UI SHUTDOWN COMPLETE. TRYING TO RESUME RESTART
[INFO] :   HelloWorldLB/1.0 (5.2.2.b685ddb)
[INFO] :   (
[INFO] :           {
[INFO] :           firstname = John;
[INFO] :           id = 572919b528ddb0090682772f;
[INFO] :           lastname = Doe;
[INFO] :           title = "Account Representative";
[INFO] :       },
[INFO] :           {
[INFO] :           firstname = Susan;
[INFO] :           id = 572919851cfadc0903834b44;
[INFO] :           lastname = French;
[INFO] :           title = "VP WW Sales";
[INFO] :       },
[INFO] :           {
[INFO] :           firstname = David;
[INFO] :           id = 572919741cfadc0903834b26;
[INFO] :           lastname = Glass;
[INFO] :           title = CEO;
[INFO] :       }
[INFO] :   )

Summary

In this blog post we saw how Arrow can generate client side SDKs for your Arrow project so that the Arrow API's can be accessed programmatically in your Titanium apps (as well as native, web, NodeJS, etc...). Code for this project can be found here.

/**
* this is your configuration file defaults.
*
* You can create additional configuration files to that the server will load based on your
* environment. For example, if you want to have specific settings for production which are different
* than your local development environment, you can create a production.js and a local.js. Any changes
* in those files will overwrite changes to this file (a object merge is performed). By default, your
* local.js file will not be commited to git or the registry.
*
* This is a JavaScript file (instead of JSON) so you can also perform logic in this file if needed.
*/
module.exports = {
// these are your generated API keys. They were generated uniquely when you created this project.
// DO NOT SHARE these keys with other projects and be careful with these keys since they control
// access to your API using the default configuration. if you don't want two different keys for
// production and test (not recommended), use the key 'apikey'. To simulate running in production,
// set the environment variable NODE_ENV to production before running such as:
//
// NODE_ENV=production appc run
//
// production key, this is the key that will be required when you are running in production
apikey_production: 'mgCzMKbg2tD7ekigSdrz+cVSAk6OQ6yp',
// development key, this is the key that will be required when you are testing non-production (such as locally)
apikey_development: 'KXUJoLX58LuzNjWd7Y0lcdIYTr0R5xb6',
// preproduction key, this is the key that will be required when you are testing non-production (such as locally)
apikey_preproduction: 'fLjAq6RD0McvqF0K6itGdAUiU+C3Uopv',
// by default the authentication strategy is 'basic' which will use HTTP Basic Authorization where the
// usename is the key and the password is blank. the other option is 'apikey' where the value of the
// APIKey header is the value of the key. you can also set this to 'plugin' and define the key 'APIKeyAuthPlugin'
// which points to a file or a module that implements the authentication strategy
APIKeyAuthType: 'basic',
// The number of milliseconds before timing out a request to the server.
timeout: 120000,
// logging configuration
logLevel: 'debug', // Log level of the main logger.
logging: {
// location of the logs if enabled
logdir: './logs',
// turn on transaction logs
transactionLogEnabled: true
},
// prefix to use for apis
apiPrefix: '/api',
// control the settings for the admin website
admin: {
// control whether the admin website is available
enabled: true,
// the prefix to the admin website
prefix: '/arrow',
// the prefix for the public apidocs website
apiDocPrefix: '/apidoc',
// if you set disableAuth, in production only your API docs will show up
disableAuth: false,
// if you set disableAPIDoc, your API docs will not show up (regardless of disableAuth)
disableAPIDoc: false,
// if you set disableDefault404, Arrow will not register a default 404 handler
disableDefault404: false,
// set to true to allow the admin website to be accessed in production. however, you will still need a
// login unless disableAuth is false. if you set this to false, the admin website will not be enabled
// when in production (still respects enabled above)
enableAdminInProduction: true,
// set the email addresses you want to be able to log in to the admin website
validEmails: ["lbrenman@appcelerator.com"],
// set the organization ids you want to be able to log in to the admin website
validOrgs: [100000142]
},
// you can generally leave this as-is since it is generated for each new project you created.
session: {
encryptionAlgorithm: 'aes256',
encryptionKey: 'jhyNQVlU5Cuqk5+iL60sD/5hY1Hvz9bqAkOjO3bEo7w=',
signatureAlgorithm: 'sha512-drop256',
signatureKey: 'ACd7H68HIIBTuL3I1vtzUbJp1x/PydKXxfr0EpJ/3ltAOoUQQP6PhTYR8EAjnpGDElbggRqq6lbFg3KnWOU80w==',
secret: '7bfu2hXj9+o4gXJ4PzANORr8b3HdRTuC', // should be a large unguessable string
duration: 86400000, // how long the session will stay valid in ms
activeDuration: 300000 // if expiresIn < activeDuration, the session will be extended by activeDuration milliseconds
},
// your connector configuration goes here
connectors: {
}
};
var Arrow = require('arrow');
var Model = Arrow.createModel('employee', {
fields: {
firstname: {
type: String
},
lastname: {
type: String
},
title: {
type: String
}
},
connector: 'appc.arrowdb',
actions: [
'create',
'read',
'update',
'delete',
'deleteAll'
]
});
module.exports = Model;
function doClick(e) {
alert($.label.text);
var MyArrowApp = require('MyArrowApp');
MyArrowApp.port = 8080;
// MyArrowApp.domain = 'http://your.domain.com';
// Basic Auth.
// MyArrowApp.Authorization = 'KXUJoLX58LuzNjWd7Y0lcdIYTr0R5xb6';
// Production Basic Auth.
// MyArrowApp.Authorization = 'mgCzMKbg2tD7ekigSdrz+cVSAk6OQ6yp';
// Development Basic Auth.
MyArrowApp.Authorization = 'KXUJoLX58LuzNjWd7Y0lcdIYTr0R5xb6';
// MyArrowApp.timeout = 30000;
var Employee = MyArrowApp.getModel('employee');
Employee.findAll(function(err, results, client) {
console.log(results);
});
// MyArrowApp.getAPI('/api/test', 'GET').execute(function(err, results, client) {
// console.log(results);
// });
}
$.index.open();
var config = {
headers: {},
timeout: 30000,
domain: 'http://localhost',
port: 0
};
var NoCache = 1,
CacheElseNetwork = 2,
NetworkElseCache = 4,
CacheThenNetwork = 8,
CacheOnly = 16,
NetworkOnly = 32;
var SDK = module.exports = {
/*
Public API.
*/
getModel: function (name, failIfMissing) {
name = String(name || '').replace('connector/', '');
var result = this.models[name];
if (!result) {
for (var modelName in this.models) {
if (this.models.hasOwnProperty(modelName) && name === modelName.split('/').pop()) {
result = this.models[modelName];
break;
}
}
}
if (!result && failIfMissing) {
throw new Error('Couldn\'t find model named: ' + name);
}
return result;
},
getAPI: function (pathOrNickname, method) {
for (var i = 0; i < this.apis.length; i++) {
var API = this.apis[i];
if (1 === arguments.length) {
if (API.nickname === pathOrNickname) {
return API;
}
}
else {
if (API.path === pathOrNickname && API.method === method) {
return API;
}
}
}
return null;
},
/*
Constants.
*/
Policy: {
/**
* No caches are used or saved. This is the default caching policy for models.
*/
NoCache: 1,
/**
* If a local cache of the results is available, it will be used; otherwise, the network will be used. Results will
* be cached.
*/
CacheElseNetwork: 2,
/**
* If the network is available, it will be used for results; otherwise, the local cache will be used. Results will
* be cached.
*/
NetworkElseCache: 4,
/**
* If a local cache of the result is available, it will be used immediately, and then the network will be used. The
* callback will, thus, be called twice. Results will be cached.
*/
CacheThenNetwork: 8,
/**
* If a local cache of results is available, it will be used.
*/
CacheOnly: 16,
/**
* If the network is available, it will be used for results. Results will be cached.
*/
NetworkOnly: 32
},
/*
Configuration.
*/
cachePolicy: {type: NoCache},
get domain() { return config.domain; },
set domain(val) { config.domain = val; },
get port() { return config.port; },
set port(val) { config.port = val; },
get timeout() { return config.timeout; },
set timeout(val) { config.timeout = val; },
get APIKey() { return config.APIKey; },
set APIKey(val) {
config.APIKey = val;
config.headers.APIKey = val;
},
get Authorization() { return config.Authorization; },
set Authorization(val) {
config.Authorization = val;
if (0 === val.indexOf('Basic ')) {
config.headers.Authorization = val;
}
else if (':' === val.slice(-1)) {
config.headers.Authorization = 'Basic ' + Ti.Utils.base64encode(val);
}
else {
config.headers.Authorization = 'Basic ' + Ti.Utils.base64encode(val + ':');
}
},
/*
Utility.
*/
isFunction: function isFunction(val) {
return 'function' === typeof val;
},
appendQuery: function appendQuery(url, query) {
for (var queryName in query) {
if (query.hasOwnProperty(queryName)) {
url += (url.indexOf('?') === -1 ? '?' : '&') + queryName;
if (query[queryName] !== '') {
url += '=' + encodeURIComponent(query[queryName]);
}
}
}
return url;
},
constructHTTP: function constructHTTP(method, url, onLoad, onError) {
var client = Ti.Network.createHTTPClient({
onload: onLoad,
onerror: onError,
timeout: config.timeout
});
client.open(method, url);
// Add headers.
for (var headerName in config.headers) {
if (config.headers.hasOwnProperty(headerName)) {
client.setRequestHeader(headerName, config.headers[headerName]);
}
}
return client;
},
getURL: function getURL(path) {
var url = config.domain;
if (config.port && config.port !== 80) {
url += ':' + config.port;
}
url += path;
return url;
},
/**
* Turns a url and method in to a hash that can uniquely and securely identify it.
*/
getCacheHash: function getCacheHash(method, url) {
var key = method + ':' + url + '\n';
// Add headers.
for (var headerName in config.headers) {
if (config.headers.hasOwnProperty(headerName)) {
key += headerName + ':' + config.headers[headerName] + '\n';
}
}
return Ti.Utils.sha256(key);
},
/**
* Gets the cache db, ensuring it has the proper schema set up.
* @returns {Window}
*/
getCacheDB: function () {
if (this.cacheDB) {
return Ti.Database.open(this.cacheDB);
}
this.cacheDB = 'MyArrowAppCache';
var db = Ti.Database.open(this.cacheDB);
db.execute('CREATE TABLE IF NOT EXISTS cache(hash TEXT PRIMARY KEY, until INTEGER, result BLOB);');
db.file.setRemoteBackup(false);
return db;
},
/**
* Checks the cache to see if results have been cached for the specific request.
* @param hash A string that uniquely identifies the request.
* @returns The cached results, or undefined.
*/
readCache: function (hash) {
var db = this.getCacheDB();
db.execute('DELETE FROM cache WHERE until < ?', Date.now());
var result = db.execute('SELECT result FROM cache WHERE hash = ? LIMIT 1', hash),
retVal;
if (result.isValidRow()) {
retVal = JSON.parse(result.fieldByName('result'));
}
result.close();
db.close();
return retVal;
},
/**
*
* @param hash
* @param duration
* @param results
*/
writeCache: function (hash, duration, results) {
var db = this.getCacheDB();
db.execute('INSERT OR REPLACE INTO cache (hash, until, result) VALUES (?, ?, ?);',
hash,
Date.now() + duration,
JSON.stringify(results));
db.close();
},
/*
Definitions.
*/
models: {
'employee': {
cachePolicy: {
duration: 360000,
type: NoCache
},
'deleteAll': function method(callback, options) {
var url = SDK.getURL('/api/employee');
var client = SDK.constructHTTP('DELETE', url, onLoad, onError);
client.send();
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
callback(e.error, null, client);
clean();
}
function clean() {
callback = url = client = null;
}
},
'create': function method(body, callback, options) {
if (SDK.isFunction(body)) {
callback = body;
body = {};
}
var url = SDK.getURL('/api/employee');
var client = SDK.constructHTTP('POST', url, onLoad, onError);
client.send(body);
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
callback(e.error, null, client);
clean();
}
function clean() {
body = callback = url = client = null;
}
},
'findAll': function method(callback, options) {
var url = SDK.getURL('/api/employee');
var cachePolicy = (options && options.cachePolicy) || this.cachePolicy || SDK.cachePolicy,
cacheHash = SDK.getCacheHash('GET', url);
// If we're using one of the policies that can use the cache...
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.CacheThenNetwork | SDK.Policy.CacheOnly))) {
var cached = SDK.readCache(cacheHash);
if (cached) {
callback && callback(null, cached, null);
// CacheElseNetwork or CacheOnly? Then we can return.
if (cachePolicy.type !== SDK.Policy.CacheThenNetwork) {
clean();
return cached;
}
// CacheThenNetwork would carry on.
}
// CacheOnly will never hit the network; it wants to return, even if we don't find results.
if (cachePolicy.type === SDK.Policy.CacheOnly) {
callback && callback(new Error('No results have been cached yet.'), null, null);
clean();
return;
}
}
var client = SDK.constructHTTP('GET', url, onLoad, onError);
client.send();
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.NetworkElseCache | SDK.Policy.CacheThenNetwork | SDK.Policy.NetworkOnly))) {
SDK.writeCache(cacheHash, cachePolicy.duration, body);
// TODO: When we do a findAll, cache findByID, too.
// TODO: Non-GETs should bust the cache for find, right?
}
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
if (!!(cachePolicy.type & (SDK.Policy.NetworkElseCache))) {
var cached = SDK.readCache(url);
if (cached) {
callback(null, cached, null);
clean();
return;
}
}
callback(e.error, null, client);
clean();
}
function clean() {
callback = url = client = null;
}
},
'count': function method(query, callback, options) {
if (SDK.isFunction(query)) {
callback = query;
query = {};
}
var url = SDK.getURL('/api/employee/count');
if (query) {
url = SDK.appendQuery(url, query);
}
var cachePolicy = (options && options.cachePolicy) || this.cachePolicy || SDK.cachePolicy,
cacheHash = SDK.getCacheHash('GET', url);
// If we're using one of the policies that can use the cache...
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.CacheThenNetwork | SDK.Policy.CacheOnly))) {
var cached = SDK.readCache(cacheHash);
if (cached) {
callback && callback(null, cached, null);
// CacheElseNetwork or CacheOnly? Then we can return.
if (cachePolicy.type !== SDK.Policy.CacheThenNetwork) {
clean();
return cached;
}
// CacheThenNetwork would carry on.
}
// CacheOnly will never hit the network; it wants to return, even if we don't find results.
if (cachePolicy.type === SDK.Policy.CacheOnly) {
callback && callback(new Error('No results have been cached yet.'), null, null);
clean();
return;
}
}
var client = SDK.constructHTTP('GET', url, onLoad, onError);
client.send();
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.NetworkElseCache | SDK.Policy.CacheThenNetwork | SDK.Policy.NetworkOnly))) {
SDK.writeCache(cacheHash, cachePolicy.duration, body);
// TODO: When we do a findAll, cache findByID, too.
// TODO: Non-GETs should bust the cache for find, right?
}
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
if (!!(cachePolicy.type & (SDK.Policy.NetworkElseCache))) {
var cached = SDK.readCache(url);
if (cached) {
callback(null, cached, null);
clean();
return;
}
}
callback(e.error, null, client);
clean();
}
function clean() {
query = callback = url = client = null;
}
},
'query': function method(query, callback, options) {
if (SDK.isFunction(query)) {
callback = query;
query = {};
}
var url = SDK.getURL('/api/employee/query');
if (query) {
url = SDK.appendQuery(url, query);
}
var cachePolicy = (options && options.cachePolicy) || this.cachePolicy || SDK.cachePolicy,
cacheHash = SDK.getCacheHash('GET', url);
// If we're using one of the policies that can use the cache...
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.CacheThenNetwork | SDK.Policy.CacheOnly))) {
var cached = SDK.readCache(cacheHash);
if (cached) {
callback && callback(null, cached, null);
// CacheElseNetwork or CacheOnly? Then we can return.
if (cachePolicy.type !== SDK.Policy.CacheThenNetwork) {
clean();
return cached;
}
// CacheThenNetwork would carry on.
}
// CacheOnly will never hit the network; it wants to return, even if we don't find results.
if (cachePolicy.type === SDK.Policy.CacheOnly) {
callback && callback(new Error('No results have been cached yet.'), null, null);
clean();
return;
}
}
var client = SDK.constructHTTP('GET', url, onLoad, onError);
client.send();
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.NetworkElseCache | SDK.Policy.CacheThenNetwork | SDK.Policy.NetworkOnly))) {
SDK.writeCache(cacheHash, cachePolicy.duration, body);
// TODO: When we do a findAll, cache findByID, too.
// TODO: Non-GETs should bust the cache for find, right?
}
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
if (!!(cachePolicy.type & (SDK.Policy.NetworkElseCache))) {
var cached = SDK.readCache(url);
if (cached) {
callback(null, cached, null);
clean();
return;
}
}
callback(e.error, null, client);
clean();
}
function clean() {
query = callback = url = client = null;
}
},
'upsert': function method(body, callback, options) {
if (SDK.isFunction(body)) {
callback = body;
body = {};
}
var url = SDK.getURL('/api/employee/upsert');
var client = SDK.constructHTTP('POST', url, onLoad, onError);
client.send(body);
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
callback(e.error, null, client);
clean();
}
function clean() {
body = callback = url = client = null;
}
},
'findAndModify': function method(query, body, callback, options) {
if (SDK.isFunction(query)) {
callback = query;
query = {};
body = {};
}
else if (SDK.isFunction(body)) {
callback = body;
body = {};
}
var url = SDK.getURL('/api/employee/findAndModify');
if (query) {
url = SDK.appendQuery(url, query);
}
var client = SDK.constructHTTP('PUT', url, onLoad, onError);
client.send(body);
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
callback(e.error, null, client);
clean();
}
function clean() {
query = body = callback = url = client = null;
}
},
'delete': function method(id, callback, options) {
var url = SDK.getURL('/api/employee/:id');
url = url.replace(':id', id);
var client = SDK.constructHTTP('DELETE', url, onLoad, onError);
client.send();
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
callback(e.error, null, client);
clean();
}
function clean() {
id = callback = url = client = null;
}
},
'update': function method(id, body, callback, options) {
if (SDK.isFunction(body)) {
callback = body;
body = {};
}
var url = SDK.getURL('/api/employee/:id');
url = url.replace(':id', id);
var client = SDK.constructHTTP('PUT', url, onLoad, onError);
client.send(body);
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
callback(e.error, null, client);
clean();
}
function clean() {
id = body = callback = url = client = null;
}
},
'findByID': function method(id, callback, options) {
var url = SDK.getURL('/api/employee/:id');
url = url.replace(':id', id);
var cachePolicy = (options && options.cachePolicy) || this.cachePolicy || SDK.cachePolicy,
cacheHash = SDK.getCacheHash('GET', url);
// If we're using one of the policies that can use the cache...
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.CacheThenNetwork | SDK.Policy.CacheOnly))) {
var cached = SDK.readCache(cacheHash);
if (cached) {
callback && callback(null, cached, null);
// CacheElseNetwork or CacheOnly? Then we can return.
if (cachePolicy.type !== SDK.Policy.CacheThenNetwork) {
clean();
return cached;
}
// CacheThenNetwork would carry on.
}
// CacheOnly will never hit the network; it wants to return, even if we don't find results.
if (cachePolicy.type === SDK.Policy.CacheOnly) {
callback && callback(new Error('No results have been cached yet.'), null, null);
clean();
return;
}
}
var client = SDK.constructHTTP('GET', url, onLoad, onError);
client.send();
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.NetworkElseCache | SDK.Policy.CacheThenNetwork | SDK.Policy.NetworkOnly))) {
SDK.writeCache(cacheHash, cachePolicy.duration, body);
// TODO: When we do a findAll, cache findByID, too.
// TODO: Non-GETs should bust the cache for find, right?
}
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
if (!!(cachePolicy.type & (SDK.Policy.NetworkElseCache))) {
var cached = SDK.readCache(url);
if (cached) {
callback(null, cached, null);
clean();
return;
}
}
callback(e.error, null, client);
clean();
}
function clean() {
id = callback = url = client = null;
}
},
'distinct': function method(field, query, callback, options) {
if (SDK.isFunction(query)) {
callback = query;
query = {};
}
var url = SDK.getURL('/api/employee/distinct/:field');
url = url.replace(':field', field);
if (query) {
url = SDK.appendQuery(url, query);
}
var cachePolicy = (options && options.cachePolicy) || this.cachePolicy || SDK.cachePolicy,
cacheHash = SDK.getCacheHash('GET', url);
// If we're using one of the policies that can use the cache...
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.CacheThenNetwork | SDK.Policy.CacheOnly))) {
var cached = SDK.readCache(cacheHash);
if (cached) {
callback && callback(null, cached, null);
// CacheElseNetwork or CacheOnly? Then we can return.
if (cachePolicy.type !== SDK.Policy.CacheThenNetwork) {
clean();
return cached;
}
// CacheThenNetwork would carry on.
}
// CacheOnly will never hit the network; it wants to return, even if we don't find results.
if (cachePolicy.type === SDK.Policy.CacheOnly) {
callback && callback(new Error('No results have been cached yet.'), null, null);
clean();
return;
}
}
var client = SDK.constructHTTP('GET', url, onLoad, onError);
client.send();
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.NetworkElseCache | SDK.Policy.CacheThenNetwork | SDK.Policy.NetworkOnly))) {
SDK.writeCache(cacheHash, cachePolicy.duration, body);
// TODO: When we do a findAll, cache findByID, too.
// TODO: Non-GETs should bust the cache for find, right?
}
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
if (!!(cachePolicy.type & (SDK.Policy.NetworkElseCache))) {
var cached = SDK.readCache(url);
if (cached) {
callback(null, cached, null);
clean();
return;
}
}
callback(e.error, null, client);
clean();
}
function clean() {
field = query = callback = url = client = null;
}
}
},
'testuser': {
cachePolicy: {
duration: 360000,
type: NoCache
},
'query': function method(query, callback, options) {
if (SDK.isFunction(query)) {
callback = query;
query = {};
}
var url = SDK.getURL('/api/testuser/query');
if (query) {
url = SDK.appendQuery(url, query);
}
var cachePolicy = (options && options.cachePolicy) || this.cachePolicy || SDK.cachePolicy,
cacheHash = SDK.getCacheHash('GET', url);
// If we're using one of the policies that can use the cache...
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.CacheThenNetwork | SDK.Policy.CacheOnly))) {
var cached = SDK.readCache(cacheHash);
if (cached) {
callback && callback(null, cached, null);
// CacheElseNetwork or CacheOnly? Then we can return.
if (cachePolicy.type !== SDK.Policy.CacheThenNetwork) {
clean();
return cached;
}
// CacheThenNetwork would carry on.
}
// CacheOnly will never hit the network; it wants to return, even if we don't find results.
if (cachePolicy.type === SDK.Policy.CacheOnly) {
callback && callback(new Error('No results have been cached yet.'), null, null);
clean();
return;
}
}
var client = SDK.constructHTTP('GET', url, onLoad, onError);
client.send();
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.NetworkElseCache | SDK.Policy.CacheThenNetwork | SDK.Policy.NetworkOnly))) {
SDK.writeCache(cacheHash, cachePolicy.duration, body);
// TODO: When we do a findAll, cache findByID, too.
// TODO: Non-GETs should bust the cache for find, right?
}
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
if (!!(cachePolicy.type & (SDK.Policy.NetworkElseCache))) {
var cached = SDK.readCache(url);
if (cached) {
callback(null, cached, null);
clean();
return;
}
}
callback(e.error, null, client);
clean();
}
function clean() {
query = callback = url = client = null;
}
},
'count': function method(query, callback, options) {
if (SDK.isFunction(query)) {
callback = query;
query = {};
}
var url = SDK.getURL('/api/testuser/count');
if (query) {
url = SDK.appendQuery(url, query);
}
var cachePolicy = (options && options.cachePolicy) || this.cachePolicy || SDK.cachePolicy,
cacheHash = SDK.getCacheHash('GET', url);
// If we're using one of the policies that can use the cache...
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.CacheThenNetwork | SDK.Policy.CacheOnly))) {
var cached = SDK.readCache(cacheHash);
if (cached) {
callback && callback(null, cached, null);
// CacheElseNetwork or CacheOnly? Then we can return.
if (cachePolicy.type !== SDK.Policy.CacheThenNetwork) {
clean();
return cached;
}
// CacheThenNetwork would carry on.
}
// CacheOnly will never hit the network; it wants to return, even if we don't find results.
if (cachePolicy.type === SDK.Policy.CacheOnly) {
callback && callback(new Error('No results have been cached yet.'), null, null);
clean();
return;
}
}
var client = SDK.constructHTTP('GET', url, onLoad, onError);
client.send();
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.NetworkElseCache | SDK.Policy.CacheThenNetwork | SDK.Policy.NetworkOnly))) {
SDK.writeCache(cacheHash, cachePolicy.duration, body);
// TODO: When we do a findAll, cache findByID, too.
// TODO: Non-GETs should bust the cache for find, right?
}
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
if (!!(cachePolicy.type & (SDK.Policy.NetworkElseCache))) {
var cached = SDK.readCache(url);
if (cached) {
callback(null, cached, null);
clean();
return;
}
}
callback(e.error, null, client);
clean();
}
function clean() {
query = callback = url = client = null;
}
},
'findAll': function method(callback, options) {
var url = SDK.getURL('/api/testuser');
var cachePolicy = (options && options.cachePolicy) || this.cachePolicy || SDK.cachePolicy,
cacheHash = SDK.getCacheHash('GET', url);
// If we're using one of the policies that can use the cache...
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.CacheThenNetwork | SDK.Policy.CacheOnly))) {
var cached = SDK.readCache(cacheHash);
if (cached) {
callback && callback(null, cached, null);
// CacheElseNetwork or CacheOnly? Then we can return.
if (cachePolicy.type !== SDK.Policy.CacheThenNetwork) {
clean();
return cached;
}
// CacheThenNetwork would carry on.
}
// CacheOnly will never hit the network; it wants to return, even if we don't find results.
if (cachePolicy.type === SDK.Policy.CacheOnly) {
callback && callback(new Error('No results have been cached yet.'), null, null);
clean();
return;
}
}
var client = SDK.constructHTTP('GET', url, onLoad, onError);
client.send();
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.NetworkElseCache | SDK.Policy.CacheThenNetwork | SDK.Policy.NetworkOnly))) {
SDK.writeCache(cacheHash, cachePolicy.duration, body);
// TODO: When we do a findAll, cache findByID, too.
// TODO: Non-GETs should bust the cache for find, right?
}
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
if (!!(cachePolicy.type & (SDK.Policy.NetworkElseCache))) {
var cached = SDK.readCache(url);
if (cached) {
callback(null, cached, null);
clean();
return;
}
}
callback(e.error, null, client);
clean();
}
function clean() {
callback = url = client = null;
}
},
'deleteAll': function method(callback, options) {
var url = SDK.getURL('/api/testuser');
var client = SDK.constructHTTP('DELETE', url, onLoad, onError);
client.send();
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
callback(e.error, null, client);
clean();
}
function clean() {
callback = url = client = null;
}
},
'create': function method(body, callback, options) {
if (SDK.isFunction(body)) {
callback = body;
body = {};
}
var url = SDK.getURL('/api/testuser');
var client = SDK.constructHTTP('POST', url, onLoad, onError);
client.send(body);
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
callback(e.error, null, client);
clean();
}
function clean() {
body = callback = url = client = null;
}
},
'upsert': function method(body, callback, options) {
if (SDK.isFunction(body)) {
callback = body;
body = {};
}
var url = SDK.getURL('/api/testuser/upsert');
var client = SDK.constructHTTP('POST', url, onLoad, onError);
client.send(body);
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
callback(e.error, null, client);
clean();
}
function clean() {
body = callback = url = client = null;
}
},
'findAndModify': function method(query, body, callback, options) {
if (SDK.isFunction(query)) {
callback = query;
query = {};
body = {};
}
else if (SDK.isFunction(body)) {
callback = body;
body = {};
}
var url = SDK.getURL('/api/testuser/findAndModify');
if (query) {
url = SDK.appendQuery(url, query);
}
var client = SDK.constructHTTP('PUT', url, onLoad, onError);
client.send(body);
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
callback(e.error, null, client);
clean();
}
function clean() {
query = body = callback = url = client = null;
}
},
'update': function method(id, body, callback, options) {
if (SDK.isFunction(body)) {
callback = body;
body = {};
}
var url = SDK.getURL('/api/testuser/:id');
url = url.replace(':id', id);
var client = SDK.constructHTTP('PUT', url, onLoad, onError);
client.send(body);
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
callback(e.error, null, client);
clean();
}
function clean() {
id = body = callback = url = client = null;
}
},
'delete': function method(id, callback, options) {
var url = SDK.getURL('/api/testuser/:id');
url = url.replace(':id', id);
var client = SDK.constructHTTP('DELETE', url, onLoad, onError);
client.send();
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
callback(e.error, null, client);
clean();
}
function clean() {
id = callback = url = client = null;
}
},
'findByID': function method(id, callback, options) {
var url = SDK.getURL('/api/testuser/:id');
url = url.replace(':id', id);
var cachePolicy = (options && options.cachePolicy) || this.cachePolicy || SDK.cachePolicy,
cacheHash = SDK.getCacheHash('GET', url);
// If we're using one of the policies that can use the cache...
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.CacheThenNetwork | SDK.Policy.CacheOnly))) {
var cached = SDK.readCache(cacheHash);
if (cached) {
callback && callback(null, cached, null);
// CacheElseNetwork or CacheOnly? Then we can return.
if (cachePolicy.type !== SDK.Policy.CacheThenNetwork) {
clean();
return cached;
}
// CacheThenNetwork would carry on.
}
// CacheOnly will never hit the network; it wants to return, even if we don't find results.
if (cachePolicy.type === SDK.Policy.CacheOnly) {
callback && callback(new Error('No results have been cached yet.'), null, null);
clean();
return;
}
}
var client = SDK.constructHTTP('GET', url, onLoad, onError);
client.send();
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.NetworkElseCache | SDK.Policy.CacheThenNetwork | SDK.Policy.NetworkOnly))) {
SDK.writeCache(cacheHash, cachePolicy.duration, body);
// TODO: When we do a findAll, cache findByID, too.
// TODO: Non-GETs should bust the cache for find, right?
}
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
if (!!(cachePolicy.type & (SDK.Policy.NetworkElseCache))) {
var cached = SDK.readCache(url);
if (cached) {
callback(null, cached, null);
clean();
return;
}
}
callback(e.error, null, client);
clean();
}
function clean() {
id = callback = url = client = null;
}
},
'distinct': function method(field, query, callback, options) {
if (SDK.isFunction(query)) {
callback = query;
query = {};
}
var url = SDK.getURL('/api/testuser/distinct/:field');
url = url.replace(':field', field);
if (query) {
url = SDK.appendQuery(url, query);
}
var cachePolicy = (options && options.cachePolicy) || this.cachePolicy || SDK.cachePolicy,
cacheHash = SDK.getCacheHash('GET', url);
// If we're using one of the policies that can use the cache...
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.CacheThenNetwork | SDK.Policy.CacheOnly))) {
var cached = SDK.readCache(cacheHash);
if (cached) {
callback && callback(null, cached, null);
// CacheElseNetwork or CacheOnly? Then we can return.
if (cachePolicy.type !== SDK.Policy.CacheThenNetwork) {
clean();
return cached;
}
// CacheThenNetwork would carry on.
}
// CacheOnly will never hit the network; it wants to return, even if we don't find results.
if (cachePolicy.type === SDK.Policy.CacheOnly) {
callback && callback(new Error('No results have been cached yet.'), null, null);
clean();
return;
}
}
var client = SDK.constructHTTP('GET', url, onLoad, onError);
client.send();
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.NetworkElseCache | SDK.Policy.CacheThenNetwork | SDK.Policy.NetworkOnly))) {
SDK.writeCache(cacheHash, cachePolicy.duration, body);
// TODO: When we do a findAll, cache findByID, too.
// TODO: Non-GETs should bust the cache for find, right?
}
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
if (!!(cachePolicy.type & (SDK.Policy.NetworkElseCache))) {
var cached = SDK.readCache(url);
if (cached) {
callback(null, cached, null);
clean();
return;
}
}
callback(e.error, null, client);
clean();
}
function clean() {
field = query = callback = url = client = null;
}
}
}
},
apis: [
{
nickname: 'GET /api/testapi',
path: '/api/testapi/:id',
method: 'GET',
execute: function method(id, callback, options) {
var url = SDK.getURL('/api/testapi/:id');
url = url.replace(':id', id);
var cachePolicy = (options && options.cachePolicy) || this.cachePolicy || SDK.cachePolicy,
cacheHash = SDK.getCacheHash('GET', url);
// If we're using one of the policies that can use the cache...
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.CacheThenNetwork | SDK.Policy.CacheOnly))) {
var cached = SDK.readCache(cacheHash);
if (cached) {
callback && callback(null, cached, null);
// CacheElseNetwork or CacheOnly? Then we can return.
if (cachePolicy.type !== SDK.Policy.CacheThenNetwork) {
clean();
return cached;
}
// CacheThenNetwork would carry on.
}
// CacheOnly will never hit the network; it wants to return, even if we don't find results.
if (cachePolicy.type === SDK.Policy.CacheOnly) {
callback && callback(new Error('No results have been cached yet.'), null, null);
clean();
return;
}
}
var client = SDK.constructHTTP('GET', url, onLoad, onError);
client.send();
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.NetworkElseCache | SDK.Policy.CacheThenNetwork | SDK.Policy.NetworkOnly))) {
SDK.writeCache(cacheHash, cachePolicy.duration, body);
// TODO: When we do a findAll, cache findByID, too.
// TODO: Non-GETs should bust the cache for find, right?
}
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
if (!!(cachePolicy.type & (SDK.Policy.NetworkElseCache))) {
var cached = SDK.readCache(url);
if (cached) {
callback(null, cached, null);
clean();
return;
}
}
callback(e.error, null, client);
clean();
}
function clean() {
id = callback = url = client = null;
}
}
},
{
nickname: 'Query',
path: '/api/testuser/query',
method: 'GET',
execute: function method(query, callback, options) {
if (SDK.isFunction(query)) {
callback = query;
query = {};
}
var url = SDK.getURL('/api/testuser/query');
if (query) {
url = SDK.appendQuery(url, query);
}
var cachePolicy = (options && options.cachePolicy) || this.cachePolicy || SDK.cachePolicy,
cacheHash = SDK.getCacheHash('GET', url);
// If we're using one of the policies that can use the cache...
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.CacheThenNetwork | SDK.Policy.CacheOnly))) {
var cached = SDK.readCache(cacheHash);
if (cached) {
callback && callback(null, cached, null);
// CacheElseNetwork or CacheOnly? Then we can return.
if (cachePolicy.type !== SDK.Policy.CacheThenNetwork) {
clean();
return cached;
}
// CacheThenNetwork would carry on.
}
// CacheOnly will never hit the network; it wants to return, even if we don't find results.
if (cachePolicy.type === SDK.Policy.CacheOnly) {
callback && callback(new Error('No results have been cached yet.'), null, null);
clean();
return;
}
}
var client = SDK.constructHTTP('GET', url, onLoad, onError);
client.send();
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.NetworkElseCache | SDK.Policy.CacheThenNetwork | SDK.Policy.NetworkOnly))) {
SDK.writeCache(cacheHash, cachePolicy.duration, body);
// TODO: When we do a findAll, cache findByID, too.
// TODO: Non-GETs should bust the cache for find, right?
}
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
if (!!(cachePolicy.type & (SDK.Policy.NetworkElseCache))) {
var cached = SDK.readCache(url);
if (cached) {
callback(null, cached, null);
clean();
return;
}
}
callback(e.error, null, client);
clean();
}
function clean() {
query = callback = url = client = null;
}
}
},
{
nickname: 'Count',
path: '/api/testuser/count',
method: 'GET',
execute: function method(query, callback, options) {
if (SDK.isFunction(query)) {
callback = query;
query = {};
}
var url = SDK.getURL('/api/testuser/count');
if (query) {
url = SDK.appendQuery(url, query);
}
var cachePolicy = (options && options.cachePolicy) || this.cachePolicy || SDK.cachePolicy,
cacheHash = SDK.getCacheHash('GET', url);
// If we're using one of the policies that can use the cache...
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.CacheThenNetwork | SDK.Policy.CacheOnly))) {
var cached = SDK.readCache(cacheHash);
if (cached) {
callback && callback(null, cached, null);
// CacheElseNetwork or CacheOnly? Then we can return.
if (cachePolicy.type !== SDK.Policy.CacheThenNetwork) {
clean();
return cached;
}
// CacheThenNetwork would carry on.
}
// CacheOnly will never hit the network; it wants to return, even if we don't find results.
if (cachePolicy.type === SDK.Policy.CacheOnly) {
callback && callback(new Error('No results have been cached yet.'), null, null);
clean();
return;
}
}
var client = SDK.constructHTTP('GET', url, onLoad, onError);
client.send();
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.NetworkElseCache | SDK.Policy.CacheThenNetwork | SDK.Policy.NetworkOnly))) {
SDK.writeCache(cacheHash, cachePolicy.duration, body);
// TODO: When we do a findAll, cache findByID, too.
// TODO: Non-GETs should bust the cache for find, right?
}
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
if (!!(cachePolicy.type & (SDK.Policy.NetworkElseCache))) {
var cached = SDK.readCache(url);
if (cached) {
callback(null, cached, null);
clean();
return;
}
}
callback(e.error, null, client);
clean();
}
function clean() {
query = callback = url = client = null;
}
}
},
{
nickname: 'Find All',
path: '/api/testuser',
method: 'GET',
execute: function method(callback, options) {
var url = SDK.getURL('/api/testuser');
var cachePolicy = (options && options.cachePolicy) || this.cachePolicy || SDK.cachePolicy,
cacheHash = SDK.getCacheHash('GET', url);
// If we're using one of the policies that can use the cache...
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.CacheThenNetwork | SDK.Policy.CacheOnly))) {
var cached = SDK.readCache(cacheHash);
if (cached) {
callback && callback(null, cached, null);
// CacheElseNetwork or CacheOnly? Then we can return.
if (cachePolicy.type !== SDK.Policy.CacheThenNetwork) {
clean();
return cached;
}
// CacheThenNetwork would carry on.
}
// CacheOnly will never hit the network; it wants to return, even if we don't find results.
if (cachePolicy.type === SDK.Policy.CacheOnly) {
callback && callback(new Error('No results have been cached yet.'), null, null);
clean();
return;
}
}
var client = SDK.constructHTTP('GET', url, onLoad, onError);
client.send();
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.NetworkElseCache | SDK.Policy.CacheThenNetwork | SDK.Policy.NetworkOnly))) {
SDK.writeCache(cacheHash, cachePolicy.duration, body);
// TODO: When we do a findAll, cache findByID, too.
// TODO: Non-GETs should bust the cache for find, right?
}
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
if (!!(cachePolicy.type & (SDK.Policy.NetworkElseCache))) {
var cached = SDK.readCache(url);
if (cached) {
callback(null, cached, null);
clean();
return;
}
}
callback(e.error, null, client);
clean();
}
function clean() {
callback = url = client = null;
}
}
},
{
nickname: 'Delete All',
path: '/api/testuser',
method: 'DELETE',
execute: function method(callback, options) {
var url = SDK.getURL('/api/testuser');
var client = SDK.constructHTTP('DELETE', url, onLoad, onError);
client.send();
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
callback(e.error, null, client);
clean();
}
function clean() {
callback = url = client = null;
}
}
},
{
nickname: 'Create',
path: '/api/testuser',
method: 'POST',
execute: function method(body, callback, options) {
if (SDK.isFunction(body)) {
callback = body;
body = {};
}
var url = SDK.getURL('/api/testuser');
var client = SDK.constructHTTP('POST', url, onLoad, onError);
client.send(body);
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
callback(e.error, null, client);
clean();
}
function clean() {
body = callback = url = client = null;
}
}
},
{
nickname: 'Upsert',
path: '/api/testuser/upsert',
method: 'POST',
execute: function method(body, callback, options) {
if (SDK.isFunction(body)) {
callback = body;
body = {};
}
var url = SDK.getURL('/api/testuser/upsert');
var client = SDK.constructHTTP('POST', url, onLoad, onError);
client.send(body);
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
callback(e.error, null, client);
clean();
}
function clean() {
body = callback = url = client = null;
}
}
},
{
nickname: 'Find and Modify',
path: '/api/testuser/findAndModify',
method: 'PUT',
execute: function method(query, body, callback, options) {
if (SDK.isFunction(query)) {
callback = query;
query = {};
body = {};
}
else if (SDK.isFunction(body)) {
callback = body;
body = {};
}
var url = SDK.getURL('/api/testuser/findAndModify');
if (query) {
url = SDK.appendQuery(url, query);
}
var client = SDK.constructHTTP('PUT', url, onLoad, onError);
client.send(body);
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
callback(e.error, null, client);
clean();
}
function clean() {
query = body = callback = url = client = null;
}
}
},
{
nickname: 'Update',
path: '/api/testuser/:id',
method: 'PUT',
execute: function method(id, body, callback, options) {
if (SDK.isFunction(body)) {
callback = body;
body = {};
}
var url = SDK.getURL('/api/testuser/:id');
url = url.replace(':id', id);
var client = SDK.constructHTTP('PUT', url, onLoad, onError);
client.send(body);
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
callback(e.error, null, client);
clean();
}
function clean() {
id = body = callback = url = client = null;
}
}
},
{
nickname: 'Delete One',
path: '/api/testuser/:id',
method: 'DELETE',
execute: function method(id, callback, options) {
var url = SDK.getURL('/api/testuser/:id');
url = url.replace(':id', id);
var client = SDK.constructHTTP('DELETE', url, onLoad, onError);
client.send();
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
callback(e.error, null, client);
clean();
}
function clean() {
id = callback = url = client = null;
}
}
},
{
nickname: 'Find By ID',
path: '/api/testuser/:id',
method: 'GET',
execute: function method(id, callback, options) {
var url = SDK.getURL('/api/testuser/:id');
url = url.replace(':id', id);
var cachePolicy = (options && options.cachePolicy) || this.cachePolicy || SDK.cachePolicy,
cacheHash = SDK.getCacheHash('GET', url);
// If we're using one of the policies that can use the cache...
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.CacheThenNetwork | SDK.Policy.CacheOnly))) {
var cached = SDK.readCache(cacheHash);
if (cached) {
callback && callback(null, cached, null);
// CacheElseNetwork or CacheOnly? Then we can return.
if (cachePolicy.type !== SDK.Policy.CacheThenNetwork) {
clean();
return cached;
}
// CacheThenNetwork would carry on.
}
// CacheOnly will never hit the network; it wants to return, even if we don't find results.
if (cachePolicy.type === SDK.Policy.CacheOnly) {
callback && callback(new Error('No results have been cached yet.'), null, null);
clean();
return;
}
}
var client = SDK.constructHTTP('GET', url, onLoad, onError);
client.send();
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.NetworkElseCache | SDK.Policy.CacheThenNetwork | SDK.Policy.NetworkOnly))) {
SDK.writeCache(cacheHash, cachePolicy.duration, body);
// TODO: When we do a findAll, cache findByID, too.
// TODO: Non-GETs should bust the cache for find, right?
}
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
if (!!(cachePolicy.type & (SDK.Policy.NetworkElseCache))) {
var cached = SDK.readCache(url);
if (cached) {
callback(null, cached, null);
clean();
return;
}
}
callback(e.error, null, client);
clean();
}
function clean() {
id = callback = url = client = null;
}
}
},
{
nickname: 'Distinct',
path: '/api/testuser/distinct/:field',
method: 'GET',
execute: function method(field, query, callback, options) {
if (SDK.isFunction(query)) {
callback = query;
query = {};
}
var url = SDK.getURL('/api/testuser/distinct/:field');
url = url.replace(':field', field);
if (query) {
url = SDK.appendQuery(url, query);
}
var cachePolicy = (options && options.cachePolicy) || this.cachePolicy || SDK.cachePolicy,
cacheHash = SDK.getCacheHash('GET', url);
// If we're using one of the policies that can use the cache...
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.CacheThenNetwork | SDK.Policy.CacheOnly))) {
var cached = SDK.readCache(cacheHash);
if (cached) {
callback && callback(null, cached, null);
// CacheElseNetwork or CacheOnly? Then we can return.
if (cachePolicy.type !== SDK.Policy.CacheThenNetwork) {
clean();
return cached;
}
// CacheThenNetwork would carry on.
}
// CacheOnly will never hit the network; it wants to return, even if we don't find results.
if (cachePolicy.type === SDK.Policy.CacheOnly) {
callback && callback(new Error('No results have been cached yet.'), null, null);
clean();
return;
}
}
var client = SDK.constructHTTP('GET', url, onLoad, onError);
client.send();
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.NetworkElseCache | SDK.Policy.CacheThenNetwork | SDK.Policy.NetworkOnly))) {
SDK.writeCache(cacheHash, cachePolicy.duration, body);
// TODO: When we do a findAll, cache findByID, too.
// TODO: Non-GETs should bust the cache for find, right?
}
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
if (!!(cachePolicy.type & (SDK.Policy.NetworkElseCache))) {
var cached = SDK.readCache(url);
if (cached) {
callback(null, cached, null);
clean();
return;
}
}
callback(e.error, null, client);
clean();
}
function clean() {
field = query = callback = url = client = null;
}
}
},
{
nickname: 'Delete All',
path: '/api/employee',
method: 'DELETE',
execute: function method(callback, options) {
var url = SDK.getURL('/api/employee');
var client = SDK.constructHTTP('DELETE', url, onLoad, onError);
client.send();
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
callback(e.error, null, client);
clean();
}
function clean() {
callback = url = client = null;
}
}
},
{
nickname: 'Create',
path: '/api/employee',
method: 'POST',
execute: function method(body, callback, options) {
if (SDK.isFunction(body)) {
callback = body;
body = {};
}
var url = SDK.getURL('/api/employee');
var client = SDK.constructHTTP('POST', url, onLoad, onError);
client.send(body);
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
callback(e.error, null, client);
clean();
}
function clean() {
body = callback = url = client = null;
}
}
},
{
nickname: 'Find All',
path: '/api/employee',
method: 'GET',
execute: function method(callback, options) {
var url = SDK.getURL('/api/employee');
var cachePolicy = (options && options.cachePolicy) || this.cachePolicy || SDK.cachePolicy,
cacheHash = SDK.getCacheHash('GET', url);
// If we're using one of the policies that can use the cache...
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.CacheThenNetwork | SDK.Policy.CacheOnly))) {
var cached = SDK.readCache(cacheHash);
if (cached) {
callback && callback(null, cached, null);
// CacheElseNetwork or CacheOnly? Then we can return.
if (cachePolicy.type !== SDK.Policy.CacheThenNetwork) {
clean();
return cached;
}
// CacheThenNetwork would carry on.
}
// CacheOnly will never hit the network; it wants to return, even if we don't find results.
if (cachePolicy.type === SDK.Policy.CacheOnly) {
callback && callback(new Error('No results have been cached yet.'), null, null);
clean();
return;
}
}
var client = SDK.constructHTTP('GET', url, onLoad, onError);
client.send();
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.NetworkElseCache | SDK.Policy.CacheThenNetwork | SDK.Policy.NetworkOnly))) {
SDK.writeCache(cacheHash, cachePolicy.duration, body);
// TODO: When we do a findAll, cache findByID, too.
// TODO: Non-GETs should bust the cache for find, right?
}
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
if (!!(cachePolicy.type & (SDK.Policy.NetworkElseCache))) {
var cached = SDK.readCache(url);
if (cached) {
callback(null, cached, null);
clean();
return;
}
}
callback(e.error, null, client);
clean();
}
function clean() {
callback = url = client = null;
}
}
},
{
nickname: 'Count',
path: '/api/employee/count',
method: 'GET',
execute: function method(query, callback, options) {
if (SDK.isFunction(query)) {
callback = query;
query = {};
}
var url = SDK.getURL('/api/employee/count');
if (query) {
url = SDK.appendQuery(url, query);
}
var cachePolicy = (options && options.cachePolicy) || this.cachePolicy || SDK.cachePolicy,
cacheHash = SDK.getCacheHash('GET', url);
// If we're using one of the policies that can use the cache...
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.CacheThenNetwork | SDK.Policy.CacheOnly))) {
var cached = SDK.readCache(cacheHash);
if (cached) {
callback && callback(null, cached, null);
// CacheElseNetwork or CacheOnly? Then we can return.
if (cachePolicy.type !== SDK.Policy.CacheThenNetwork) {
clean();
return cached;
}
// CacheThenNetwork would carry on.
}
// CacheOnly will never hit the network; it wants to return, even if we don't find results.
if (cachePolicy.type === SDK.Policy.CacheOnly) {
callback && callback(new Error('No results have been cached yet.'), null, null);
clean();
return;
}
}
var client = SDK.constructHTTP('GET', url, onLoad, onError);
client.send();
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.NetworkElseCache | SDK.Policy.CacheThenNetwork | SDK.Policy.NetworkOnly))) {
SDK.writeCache(cacheHash, cachePolicy.duration, body);
// TODO: When we do a findAll, cache findByID, too.
// TODO: Non-GETs should bust the cache for find, right?
}
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
if (!!(cachePolicy.type & (SDK.Policy.NetworkElseCache))) {
var cached = SDK.readCache(url);
if (cached) {
callback(null, cached, null);
clean();
return;
}
}
callback(e.error, null, client);
clean();
}
function clean() {
query = callback = url = client = null;
}
}
},
{
nickname: 'Query',
path: '/api/employee/query',
method: 'GET',
execute: function method(query, callback, options) {
if (SDK.isFunction(query)) {
callback = query;
query = {};
}
var url = SDK.getURL('/api/employee/query');
if (query) {
url = SDK.appendQuery(url, query);
}
var cachePolicy = (options && options.cachePolicy) || this.cachePolicy || SDK.cachePolicy,
cacheHash = SDK.getCacheHash('GET', url);
// If we're using one of the policies that can use the cache...
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.CacheThenNetwork | SDK.Policy.CacheOnly))) {
var cached = SDK.readCache(cacheHash);
if (cached) {
callback && callback(null, cached, null);
// CacheElseNetwork or CacheOnly? Then we can return.
if (cachePolicy.type !== SDK.Policy.CacheThenNetwork) {
clean();
return cached;
}
// CacheThenNetwork would carry on.
}
// CacheOnly will never hit the network; it wants to return, even if we don't find results.
if (cachePolicy.type === SDK.Policy.CacheOnly) {
callback && callback(new Error('No results have been cached yet.'), null, null);
clean();
return;
}
}
var client = SDK.constructHTTP('GET', url, onLoad, onError);
client.send();
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.NetworkElseCache | SDK.Policy.CacheThenNetwork | SDK.Policy.NetworkOnly))) {
SDK.writeCache(cacheHash, cachePolicy.duration, body);
// TODO: When we do a findAll, cache findByID, too.
// TODO: Non-GETs should bust the cache for find, right?
}
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
if (!!(cachePolicy.type & (SDK.Policy.NetworkElseCache))) {
var cached = SDK.readCache(url);
if (cached) {
callback(null, cached, null);
clean();
return;
}
}
callback(e.error, null, client);
clean();
}
function clean() {
query = callback = url = client = null;
}
}
},
{
nickname: 'Upsert',
path: '/api/employee/upsert',
method: 'POST',
execute: function method(body, callback, options) {
if (SDK.isFunction(body)) {
callback = body;
body = {};
}
var url = SDK.getURL('/api/employee/upsert');
var client = SDK.constructHTTP('POST', url, onLoad, onError);
client.send(body);
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
callback(e.error, null, client);
clean();
}
function clean() {
body = callback = url = client = null;
}
}
},
{
nickname: 'Find and Modify',
path: '/api/employee/findAndModify',
method: 'PUT',
execute: function method(query, body, callback, options) {
if (SDK.isFunction(query)) {
callback = query;
query = {};
body = {};
}
else if (SDK.isFunction(body)) {
callback = body;
body = {};
}
var url = SDK.getURL('/api/employee/findAndModify');
if (query) {
url = SDK.appendQuery(url, query);
}
var client = SDK.constructHTTP('PUT', url, onLoad, onError);
client.send(body);
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
callback(e.error, null, client);
clean();
}
function clean() {
query = body = callback = url = client = null;
}
}
},
{
nickname: 'Delete One',
path: '/api/employee/:id',
method: 'DELETE',
execute: function method(id, callback, options) {
var url = SDK.getURL('/api/employee/:id');
url = url.replace(':id', id);
var client = SDK.constructHTTP('DELETE', url, onLoad, onError);
client.send();
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
callback(e.error, null, client);
clean();
}
function clean() {
id = callback = url = client = null;
}
}
},
{
nickname: 'Update',
path: '/api/employee/:id',
method: 'PUT',
execute: function method(id, body, callback, options) {
if (SDK.isFunction(body)) {
callback = body;
body = {};
}
var url = SDK.getURL('/api/employee/:id');
url = url.replace(':id', id);
var client = SDK.constructHTTP('PUT', url, onLoad, onError);
client.send(body);
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
callback(e.error, null, client);
clean();
}
function clean() {
id = body = callback = url = client = null;
}
}
},
{
nickname: 'Find By ID',
path: '/api/employee/:id',
method: 'GET',
execute: function method(id, callback, options) {
var url = SDK.getURL('/api/employee/:id');
url = url.replace(':id', id);
var cachePolicy = (options && options.cachePolicy) || this.cachePolicy || SDK.cachePolicy,
cacheHash = SDK.getCacheHash('GET', url);
// If we're using one of the policies that can use the cache...
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.CacheThenNetwork | SDK.Policy.CacheOnly))) {
var cached = SDK.readCache(cacheHash);
if (cached) {
callback && callback(null, cached, null);
// CacheElseNetwork or CacheOnly? Then we can return.
if (cachePolicy.type !== SDK.Policy.CacheThenNetwork) {
clean();
return cached;
}
// CacheThenNetwork would carry on.
}
// CacheOnly will never hit the network; it wants to return, even if we don't find results.
if (cachePolicy.type === SDK.Policy.CacheOnly) {
callback && callback(new Error('No results have been cached yet.'), null, null);
clean();
return;
}
}
var client = SDK.constructHTTP('GET', url, onLoad, onError);
client.send();
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.NetworkElseCache | SDK.Policy.CacheThenNetwork | SDK.Policy.NetworkOnly))) {
SDK.writeCache(cacheHash, cachePolicy.duration, body);
// TODO: When we do a findAll, cache findByID, too.
// TODO: Non-GETs should bust the cache for find, right?
}
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
if (!!(cachePolicy.type & (SDK.Policy.NetworkElseCache))) {
var cached = SDK.readCache(url);
if (cached) {
callback(null, cached, null);
clean();
return;
}
}
callback(e.error, null, client);
clean();
}
function clean() {
id = callback = url = client = null;
}
}
},
{
nickname: 'Distinct',
path: '/api/employee/distinct/:field',
method: 'GET',
execute: function method(field, query, callback, options) {
if (SDK.isFunction(query)) {
callback = query;
query = {};
}
var url = SDK.getURL('/api/employee/distinct/:field');
url = url.replace(':field', field);
if (query) {
url = SDK.appendQuery(url, query);
}
var cachePolicy = (options && options.cachePolicy) || this.cachePolicy || SDK.cachePolicy,
cacheHash = SDK.getCacheHash('GET', url);
// If we're using one of the policies that can use the cache...
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.CacheThenNetwork | SDK.Policy.CacheOnly))) {
var cached = SDK.readCache(cacheHash);
if (cached) {
callback && callback(null, cached, null);
// CacheElseNetwork or CacheOnly? Then we can return.
if (cachePolicy.type !== SDK.Policy.CacheThenNetwork) {
clean();
return cached;
}
// CacheThenNetwork would carry on.
}
// CacheOnly will never hit the network; it wants to return, even if we don't find results.
if (cachePolicy.type === SDK.Policy.CacheOnly) {
callback && callback(new Error('No results have been cached yet.'), null, null);
clean();
return;
}
}
var client = SDK.constructHTTP('GET', url, onLoad, onError);
client.send();
function onLoad() {
if (!callback) {
return;
}
var body = this.responseText;
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) {
try {
body = JSON.parse(body);
if (body.key && body[body.key] !== undefined) {
body = body[body.key];
}
}
catch (e) {
console.error('Failed to parse the body from the server:');
console.error(body);
console.error(e);
}
}
if (this.status >= 200 && this.status <= 299) {
if (!!(cachePolicy.type & (SDK.Policy.CacheElseNetwork | SDK.Policy.NetworkElseCache | SDK.Policy.CacheThenNetwork | SDK.Policy.NetworkOnly))) {
SDK.writeCache(cacheHash, cachePolicy.duration, body);
// TODO: When we do a findAll, cache findByID, too.
// TODO: Non-GETs should bust the cache for find, right?
}
callback(null, body, client);
}
else {
callback(body, null, client);
}
clean();
}
function onError(e) {
if (!callback) {
return;
}
if (!!(cachePolicy.type & (SDK.Policy.NetworkElseCache))) {
var cached = SDK.readCache(url);
if (cached) {
callback(null, cached, null);
clean();
return;
}
}
callback(e.error, null, client);
clean();
}
function clean() {
field = query = callback = url = client = null;
}
}
}
]
};
@egonbeermat
Copy link

Thanks for this. What should be the domain/port be set to for development/production when testing on a physical device, or when the app is deployed to an app store, to use a published ArrowDB ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment