Skip to content

Allow selective reversion of fields in revert() Parse Object instance method. #249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
coverage
dist
lib
#lib
logs
node_modules
test_output
Expand Down
87 changes: 87 additions & 0 deletions lib/browser/Analytics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/**
* Copyright (c) 2015-present, Parse, LLC.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/

/**
* Parse.Analytics provides an interface to Parse's logging and analytics
* backend.
*
* @class Parse.Analytics
* @static
*/

/**
* Tracks the occurrence of a custom event with additional dimensions.
* Parse will store a data point at the time of invocation with the given
* event name.
*
* Dimensions will allow segmentation of the occurrences of this custom
* event. Keys and values should be {@code String}s, and will throw
* otherwise.
*
* To track a user signup along with additional metadata, consider the
* following:
* <pre>
* var dimensions = {
* gender: 'm',
* source: 'web',
* dayType: 'weekend'
* };
* Parse.Analytics.track('signup', dimensions);
* </pre>
*
* There is a default limit of 8 dimensions per event tracked.
*
* @method track
* @param {String} name The name of the custom event to report to Parse as
* having happened.
* @param {Object} dimensions The dictionary of information by which to
* segment this event.
* @param {Object} options A Backbone-style callback object.
* @return {Parse.Promise} A promise that is resolved when the round-trip
* to the server completes.
*/
'use strict';

var _interopRequireDefault = require('babel-runtime/helpers/interop-require-default')['default'];

Object.defineProperty(exports, '__esModule', {
value: true
});
exports.track = track;

var _CoreManager = require('./CoreManager');

var _CoreManager2 = _interopRequireDefault(_CoreManager);

function track(name, dimensions, options) {
name = name || '';
name = name.replace(/^\s*/, '');
name = name.replace(/\s*$/, '');
if (name.length === 0) {
throw new TypeError('A name for the custom event must be provided');
}

for (var key in dimensions) {
if (typeof key !== 'string' || typeof dimensions[key] !== 'string') {
throw new TypeError('track() dimensions expects keys and values of type "string".');
}
}

options = options || {};
return _CoreManager2['default'].getAnalyticsController().track(name, dimensions)._thenRunCallbacks(options);
}

_CoreManager2['default'].setAnalyticsController({
track: function track(name, dimensions) {
var RESTController = _CoreManager2['default'].getRESTController();
return RESTController.request('POST', 'events/' + name, { dimensions: dimensions });
}
});
108 changes: 108 additions & 0 deletions lib/browser/Cloud.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/**
* Copyright (c) 2015-present, Parse, LLC.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/

'use strict';

var _interopRequireDefault = require('babel-runtime/helpers/interop-require-default')['default'];

Object.defineProperty(exports, '__esModule', {
value: true
});
exports.run = run;

var _CoreManager = require('./CoreManager');

var _CoreManager2 = _interopRequireDefault(_CoreManager);

var _decode = require('./decode');

var _decode2 = _interopRequireDefault(_decode);

var _encode = require('./encode');

var _encode2 = _interopRequireDefault(_encode);

var _ParseError = require('./ParseError');

var _ParseError2 = _interopRequireDefault(_ParseError);

var _ParsePromise = require('./ParsePromise');

var _ParsePromise2 = _interopRequireDefault(_ParsePromise);

/**
* Contains functions for calling and declaring
* <a href="/docs/cloud_code_guide#functions">cloud functions</a>.
* <p><strong><em>
* Some functions are only available from Cloud Code.
* </em></strong></p>
*
* @class Parse.Cloud
* @static
*/

/**
* Makes a call to a cloud function.
* @method run
* @param {String} name The function name.
* @param {Object} data The parameters to send to the cloud function.
* @param {Object} options A Backbone-style options object
* options.success, if set, should be a function to handle a successful
* call to a cloud function. options.error should be a function that
* handles an error running the cloud function. Both functions are
* optional. Both functions take a single argument.
* @return {Parse.Promise} A promise that will be resolved with the result
* of the function.
*/

function run(name, data, options) {
options = options || {};

if (typeof name !== 'string' || name.length === 0) {
throw new TypeError('Cloud function name must be a string.');
}

var requestOptions = {};
if (options.useMasterKey) {
requestOptions.useMasterKey = options.useMasterKey;
}
if (options.sessionToken) {
requestOptions.sessionToken = options.sessionToken;
}

return _CoreManager2['default'].getCloudController().run(name, data, requestOptions)._thenRunCallbacks(options);
}

_CoreManager2['default'].setCloudController({
run: function run(name, data, options) {
var RESTController = _CoreManager2['default'].getRESTController();

var payload = (0, _encode2['default'])(data, true);

var requestOptions = {};
if (options.hasOwnProperty('useMasterKey')) {
requestOptions.useMasterKey = options.useMasterKey;
}
if (options.hasOwnProperty('sessionToken')) {
requestOptions.sessionToken = options.sessionToken;
}

var request = RESTController.request('POST', 'functions/' + name, payload, requestOptions);

return request.then(function (res) {
var decoded = (0, _decode2['default'])(res);
if (decoded && decoded.hasOwnProperty('result')) {
return _ParsePromise2['default'].as(decoded.result);
}
return _ParsePromise2['default'].error(new _ParseError2['default'](_ParseError2['default'].INVALID_JSON, 'The server returned an invalid response.'));
})._thenRunCallbacks(options);
}
});
Loading