UNPKG

parse

Version:
354 lines (353 loc) 12.2 kB
"use strict"; var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property"); _Object$defineProperty(exports, "__esModule", { value: true }); exports.ReadPreferenceOption = void 0; /* eslint-disable @typescript-eslint/no-invalid-void-type -- Cloud trigger handlers legitimately return void | T */ /** * @typedef Parse.Cloud.FunctionRequest * @property {string} installationId If set, the installationId triggering the request. * @property {boolean} master If true, means the master key was used. * @property {Parse.User} user If set, the user that made the request. * @property {object} params The params passed to the cloud function. */ /** * @typedef Parse.Cloud.TriggerRequest * @property {string} installationId If set, the installationId triggering the request. * @property {boolean} master If true, means the master key was used. * @property {Parse.User} user If set, the user that made the request. * @property {Parse.Object} object The object triggering the hook. * @property {string} ip The IP address of the client making the request. * @property {object} headers The original HTTP headers for the request. * @property {string} triggerName The name of the trigger (`beforeSave`, `afterSave`, ...) * @property {object} log The current logger inside Parse Server. * @property {Parse.Object} original If set, the object, as currently stored. */ /** * @typedef Parse.Cloud.FileTriggerRequest * @property {string} installationId If set, the installationId triggering the request. * @property {boolean} master If true, means the master key was used. * @property {Parse.User} user If set, the user that made the request. * @property {Parse.File} file The file triggering the hook. * @property {string} ip The IP address of the client making the request. * @property {object} headers The original HTTP headers for the request. * @property {string} triggerName The name of the trigger (`beforeSaveFile`, `afterSaveFile`, ...) * @property {object} log The current logger inside Parse Server. */ /** * @typedef Parse.Cloud.ConnectTriggerRequest * @property {string} installationId If set, the installationId triggering the request. * @property {boolean} useMasterKey If true, means the master key was used. * @property {Parse.User} user If set, the user that made the request. * @property {number} clients The number of clients connected. * @property {number} subscriptions The number of subscriptions connected. * @property {string} sessionToken If set, the session of the user that made the request. */ /** * @typedef Parse.Cloud.JobRequest * @property {object} params The params passed to the background job. * @property {Function} message If message is called with a string argument, will update the current message to be stored in the job status. */ /** * @typedef Parse.Cloud.HTTPOptions * @property {string | object} body The body of the request. * @property {boolean} followRedirects Whether to follow redirects caused by HTTP 3xx responses. Defaults to false. * @property {object} headers The headers for the request. * @property {string} method The method of the request. GET, POST, PUT, DELETE, HEAD, and OPTIONS are supported. * @property {string | object} params The query portion of the url. * @property {string} url The url to send the request to. */ /** * @typedef Parse.Cloud.HTTPResponse * @property {Buffer} buffer The raw byte representation of the response body. * @property {object} cookies The cookies sent by the server. * @property {object} data The parsed response body as a JavaScript object. * @property {object} headers The headers sent by the server. * @property {number} status The status code. * @property {string} text The raw text representation of the response body. */ let ReadPreferenceOption = exports.ReadPreferenceOption = /*#__PURE__*/function (ReadPreferenceOption) { ReadPreferenceOption["Primary"] = "PRIMARY"; ReadPreferenceOption["PrimaryPreferred"] = "PRIMARY_PREFERRED"; ReadPreferenceOption["Secondary"] = "SECONDARY"; ReadPreferenceOption["SecondaryPreferred"] = "SECONDARY_PREFERRED"; ReadPreferenceOption["Nearest"] = "NEAREST"; return ReadPreferenceOption; }({}); /** * Defines a Cloud Function. * * **Available in Cloud Code only.** * * @param name The name of the Cloud Function * @param handler The Cloud Function to register. This function should take one parameter {@link FunctionRequest} * @param validator An optional function to validate the request */ /** * Defines a Background Job. * * **Available in Cloud Code only.** * * @param name The name of the Background Job * @param handler The Background Job to register. This function should take one parameter {@link JobRequest} */ /** * Registers a before save function. * * **Available in Cloud Code only.** * * If you want to use beforeSave for a predefined class in the Parse JavaScript SDK (e.g. {@link Parse.User}), * you should pass the class itself and not the String for arg1. * * ``` * Parse.Cloud.beforeSave('MyCustomClass', (request) => { * // code here * }) * * Parse.Cloud.beforeSave(Parse.User, (request) => { * // code here * }) * ``` * * @param className The Parse.Object subclass to register the before save function for. * @param handler The function to run before a save. * @param validator An optional function to validate the request */ /** * Registers an after save function. * * **Available in Cloud Code only.** * * If you want to use afterSave for a predefined class in the Parse JavaScript SDK (e.g. {@link Parse.User}), * you should pass the class itself and not the String for arg1. * * ``` * Parse.Cloud.afterSave('MyCustomClass', (request) => { * // code here * }) * * Parse.Cloud.afterSave(Parse.User, (request) => { * // code here * }) * ``` * * @param className The Parse.Object subclass to register the after save function for. * @param handler The function to run after a save. * @param validator An optional function to validate the request */ /** * Registers a before delete function. * * **Available in Cloud Code only.** * * If you want to use beforeDelete for a predefined class in the Parse JavaScript SDK (e.g. {@link Parse.User}), * you should pass the class itself and not the String for arg1. * * ``` * Parse.Cloud.beforeDelete('MyCustomClass', (request) => { * // code here * }) * * Parse.Cloud.beforeDelete(Parse.User, (request) => { * // code here * }) * ``` * * @param className The Parse.Object subclass to register the before delete function for. * @param handler The function to run before a delete. * @param validator An optional function to validate the request */ /** * Registers an after delete function. * * **Available in Cloud Code only.** * * If you want to use afterDelete for a predefined class in the Parse JavaScript SDK (e.g. {@link Parse.User}), * you should pass the class itself and not the String for arg1. * * ``` * Parse.Cloud.afterDelete('MyCustomClass', (request) => { * // code here * }) * * Parse.Cloud.afterDelete(Parse.User, (request) => { * // code here * }) * ``` * * @param className The Parse.Object subclass to register the after delete function for. * @param handler The function to run after a delete. * @param validator An optional function to validate the request */ /** * Registers a before find function. * * **Available in Cloud Code only.** * * @param className The Parse.Object subclass to register the before find function for. * @param handler The function to run before a find. * @param validator An optional function to validate the request */ /** * Registers an after find function. * * **Available in Cloud Code only.** * * @param className The Parse.Object subclass to register the after find function for. * @param handler The function to run after a find. * @param validator An optional function to validate the request */ /** * Registers a before login function. * * **Available in Cloud Code only.** * * @param handler The function to run before a login. * @param validator An optional function to validate the request */ /** * Registers an after login function. * * **Available in Cloud Code only.** * * @param handler The function to run after a login. */ /** * Registers an after logout function. * * **Available in Cloud Code only.** * * @param handler The function to run after a logout. */ /** * Registers a before password reset request function. * * **Available in Cloud Code only.** * * @param handler The function to run before a password reset request. * @param validator An optional function to validate the request */ /** * Registers a before save file function. * * **Available in Cloud Code only.** * * A new Parse.File can be returned to override the file that gets saved. * * ``` * Parse.Cloud.beforeSaveFile(({ file, user }) => { * file.addMetadata('foo', 'bar'); * file.addTag('createdBy', user.id); * }); * ``` * * @param handler The function to run before a file saves. */ /** * Registers an after save file function. * * **Available in Cloud Code only.** * * ``` * Parse.Cloud.afterSaveFile(async ({ file, user }) => { * const fileObject = new Parse.Object('FileObject'); * fileObject.set('name', file.name()); * fileObject.set('createdBy', user); * await fileObject.save({ sessionToken: user.getSessionToken() }); * }); * ``` * * @param handler The function to run after a file saves. */ /** * Registers a before delete file function. * * **Available in Cloud Code only.** * * @param handler The function to run before a file is deleted. */ /** * Registers an after delete file function. * * **Available in Cloud Code only.** * * @param handler The function to run after a file is deleted. */ /** * Registers a before connect function for LiveQuery. * * **Available in Cloud Code only.** * * ``` * Parse.Cloud.beforeConnect((request) => { * if (!request.user) { * throw "Please login before you attempt to connect." * } * }); * ``` * * @param handler The function to run before a LiveQuery connection is made. * @param validator An optional function to validate the request */ /** * Registers a before subscribe function for LiveQuery. * * **Available in Cloud Code only.** * * ``` * Parse.Cloud.beforeSubscribe('MyObject', (request) => { * if (!request.user.get('Admin')) { * throw new Parse.Error(101, 'You are not authorized to subscribe to MyObject.'); * } * let query = request.query; * query.select("name", "year"); * }); * ``` * * @param className The Parse.Object subclass to register the before subscribe function for. * @param handler The function to run before a subscription. * @param validator An optional function to validate the request */ /** * Registers an after live query event function. * * **Available in Cloud Code only.** * * @param className The Parse.Object subclass to register the after live query event function for. * @param handler The function to run after a live query event. * @param validator An optional function to validate the request */ /** * Sends an email. * * **Available in Cloud Code only.** * * @param data The email data. * @param data.from The sender email address. * @param data.to The recipient email address. * @param data.subject The email subject. * @param data.text The plain text content. * @param data.html The HTML content. */ /** * Makes an HTTP Request. * * **Available in Cloud Code only.** * * By default, Parse.Cloud.httpRequest does not follow redirects caused by HTTP 3xx response codes. * You can use the followRedirects option in the {@link HTTPOptions} object to change this behavior. * * ``` * Parse.Cloud.httpRequest({ * url: 'http://www.example.com/' * }).then(function(httpResponse) { * console.log(httpResponse.text); * }, function(httpResponse) { * console.error('Request failed with response code ' + httpResponse.status); * }); * ``` * * @param options The HTTPOptions object that makes the request. * @returns A promise that will be resolved with a {@link HTTPResponse} object when the request completes. */