123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506 |
- "use strict";
- var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
- var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
- var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
- /*
- * 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.
- *
- * @flow
- */
- /*:: import type { AttributeMap, ObjectCache, OpsMap, State } from './ObjectStateMutations';*/
- /*:: import type ParseFile from './ParseFile';*/
- /*:: import type { FileSource } from './ParseFile';*/
- /*:: import type { Op } from './ParseOp';*/
- /*:: import type ParseObject from './ParseObject';*/
- /*:: import type { QueryJSON } from './ParseQuery';*/
- /*:: import type ParseUser from './ParseUser';*/
- /*:: import type { AuthData } from './ParseUser';*/
- /*:: import type { PushData } from './Push';*/
- /*:: import type { RequestOptions, FullOptions } from './RESTController';*/
- /*:: type AnalyticsController = {
- track: (name: string, dimensions: { [key: string]: string }) => Promise,
- };*/
- /*:: type CloudController = {
- run: (name: string, data: mixed, options: RequestOptions) => Promise,
- getJobsData: (options: RequestOptions) => Promise,
- startJob: (name: string, data: mixed, options: RequestOptions) => Promise,
- };*/
- /*:: type ConfigController = {
- current: () => Promise,
- get: () => Promise,
- save: (attrs: { [key: string]: any }) => Promise,
- };*/
- /*:: type CryptoController = {
- encrypt: (obj: any, secretKey: string) => string,
- decrypt: (encryptedText: string, secretKey: any) => string,
- };*/
- /*:: type FileController = {
- saveFile: (name: string, source: FileSource, options: FullOptions) => Promise,
- saveBase64: (name: string, source: FileSource, options: FullOptions) => Promise,
- download: (uri: string) => Promise,
- };*/
- /*:: type InstallationController = {
- currentInstallationId: () => Promise,
- };*/
- /*:: type ObjectController = {
- fetch: (
- object: ParseObject | Array<ParseObject>,
- forceFetch: boolean,
- options: RequestOptions
- ) => Promise,
- save: (object: ParseObject | Array<ParseObject | ParseFile>, options: RequestOptions) => Promise,
- destroy: (object: ParseObject | Array<ParseObject>, options: RequestOptions) => Promise,
- };*/
- /*:: type ObjectStateController = {
- getState: (obj: any) => ?State,
- initializeState: (obj: any, initial?: State) => State,
- removeState: (obj: any) => ?State,
- getServerData: (obj: any) => AttributeMap,
- setServerData: (obj: any, attributes: AttributeMap) => void,
- getPendingOps: (obj: any) => Array<OpsMap>,
- setPendingOp: (obj: any, attr: string, op: ?Op) => void,
- pushPendingState: (obj: any) => void,
- popPendingState: (obj: any) => OpsMap,
- mergeFirstPendingState: (obj: any) => void,
- getObjectCache: (obj: any) => ObjectCache,
- estimateAttribute: (obj: any, attr: string) => mixed,
- estimateAttributes: (obj: any) => AttributeMap,
- commitServerChanges: (obj: any, changes: AttributeMap) => void,
- enqueueTask: (obj: any, task: () => Promise) => Promise,
- clearAllState: () => void,
- duplicateState: (source: any, dest: any) => void,
- };*/
- /*:: type PushController = {
- send: (data: PushData) => Promise,
- };*/
- /*:: type QueryController = {
- find: (className: string, params: QueryJSON, options: RequestOptions) => Promise,
- aggregate: (className: string, params: any, options: RequestOptions) => Promise,
- };*/
- /*:: type RESTController = {
- request: (method: string, path: string, data: mixed, options: RequestOptions) => Promise,
- ajax: (method: string, url: string, data: any, headers?: any, options: FullOptions) => Promise,
- };*/
- /*:: type SchemaController = {
- purge: (className: string) => Promise,
- get: (className: string, options: RequestOptions) => Promise,
- delete: (className: string, options: RequestOptions) => Promise,
- create: (className: string, params: any, options: RequestOptions) => Promise,
- update: (className: string, params: any, options: RequestOptions) => Promise,
- send(className: string, method: string, params: any, options: RequestOptions): Promise,
- };*/
- /*:: type SessionController = {
- getSession: (token: RequestOptions) => Promise,
- };*/
- /*:: type StorageController =
- | {
- async: 0,
- getItem: (path: string) => ?string,
- setItem: (path: string, value: string) => void,
- removeItem: (path: string) => void,
- getItemAsync?: (path: string) => Promise,
- setItemAsync?: (path: string, value: string) => Promise,
- removeItemAsync?: (path: string) => Promise,
- clear: () => void,
- }
- | {
- async: 1,
- getItem?: (path: string) => ?string,
- setItem?: (path: string, value: string) => void,
- removeItem?: (path: string) => void,
- getItemAsync: (path: string) => Promise,
- setItemAsync: (path: string, value: string) => Promise,
- removeItemAsync: (path: string) => Promise,
- clear: () => void,
- };*/
- /*:: type LocalDatastoreController = {
- fromPinWithName: (name: string) => ?any,
- pinWithName: (name: string, objects: any) => void,
- unPinWithName: (name: string) => void,
- getAllContents: () => ?any,
- clear: () => void,
- };*/
- /*:: type UserController = {
- setCurrentUser: (user: ParseUser) => Promise,
- currentUser: () => ?ParseUser,
- currentUserAsync: () => Promise,
- signUp: (user: ParseUser, attrs: AttributeMap, options: RequestOptions) => Promise,
- logIn: (user: ParseUser, options: RequestOptions) => Promise,
- become: (options: RequestOptions) => Promise,
- hydrate: (userJSON: AttributeMap) => Promise,
- logOut: (options: RequestOptions) => Promise,
- me: (options: RequestOptions) => Promise,
- requestPasswordReset: (email: string, options: RequestOptions) => Promise,
- updateUserOnDisk: (user: ParseUser) => Promise,
- upgradeToRevocableSession: (user: ParseUser, options: RequestOptions) => Promise,
- linkWith: (user: ParseUser, authData: AuthData) => Promise,
- removeUserFromDisk: () => Promise,
- verifyPassword: (username: string, password: string, options: RequestOptions) => Promise,
- requestEmailVerification: (email: string, options: RequestOptions) => Promise,
- };*/
- /*:: type HooksController = {
- get: (type: string, functionName?: string, triggerName?: string) => Promise,
- create: (hook: mixed) => Promise,
- delete: (hook: mixed) => Promise,
- update: (hook: mixed) => Promise,
- send: (method: string, path: string, body?: mixed) => Promise,
- };*/
- /*:: type WebSocketController = {
- onopen: () => void,
- onmessage: (message: any) => void,
- onclose: () => void,
- onerror: (error: any) => void,
- send: (data: any) => void,
- close: () => void,
- };*/
- /*:: type Config = {
- AnalyticsController?: AnalyticsController,
- CloudController?: CloudController,
- ConfigController?: ConfigController,
- FileController?: FileController,
- InstallationController?: InstallationController,
- ObjectController?: ObjectController,
- ObjectStateController?: ObjectStateController,
- PushController?: PushController,
- QueryController?: QueryController,
- RESTController?: RESTController,
- SchemaController?: SchemaController,
- SessionController?: SessionController,
- StorageController?: StorageController,
- LocalDatastoreController?: LocalDatastoreController,
- UserController?: UserController,
- HooksController?: HooksController,
- WebSocketController?: WebSocketController,
- };*/
- var config
- /*: Config & { [key: string]: mixed }*/
- = {
- // Defaults
- IS_NODE: typeof process !== 'undefined' && !!process.versions && !!process.versions.node && !process.versions.electron,
- REQUEST_ATTEMPT_LIMIT: 5,
- REQUEST_BATCH_SIZE: 20,
- REQUEST_HEADERS: {},
- SERVER_URL: 'https://api.parse.com/1',
- SERVER_AUTH_TYPE: null,
- SERVER_AUTH_TOKEN: null,
- LIVEQUERY_SERVER_URL: null,
- ENCRYPTED_KEY: null,
- VERSION: "js".concat("1.5.9"),
- APPLICATION_ID: null,
- JAVASCRIPT_KEY: null,
- MASTER_KEY: null,
- USE_MASTER_KEY: false,
- PERFORM_USER_REWRITE: true,
- FORCE_REVOCABLE_SESSION: false,
- ENCRYPTED_USER: false,
- IDEMPOTENCY: false
- };
- function requireMethods(name
- /*: string*/
- , methods
- /*: Array<string>*/
- , controller
- /*: any*/
- ) {
- (0, _forEach.default)(methods).call(methods, function (func) {
- if (typeof controller[func] !== 'function') {
- var _context;
- throw new Error((0, _concat.default)(_context = "".concat(name, " must implement ")).call(_context, func, "()"));
- }
- });
- }
- module.exports = {
- get: function (key
- /*: string*/
- )
- /*: any*/
- {
- if (config.hasOwnProperty(key)) {
- return config[key];
- }
- throw new Error("Configuration key not found: ".concat(key));
- },
- set: function (key
- /*: string*/
- , value
- /*: any*/
- )
- /*: void*/
- {
- config[key] = value;
- },
- /* Specialized Controller Setters/Getters */
- setAnalyticsController: function (controller
- /*: AnalyticsController*/
- ) {
- requireMethods('AnalyticsController', ['track'], controller);
- config.AnalyticsController = controller;
- },
- getAnalyticsController: function ()
- /*: AnalyticsController*/
- {
- return config.AnalyticsController;
- },
- setCloudController: function (controller
- /*: CloudController*/
- ) {
- requireMethods('CloudController', ['run', 'getJobsData', 'startJob'], controller);
- config.CloudController = controller;
- },
- getCloudController: function ()
- /*: CloudController*/
- {
- return config.CloudController;
- },
- setConfigController: function (controller
- /*: ConfigController*/
- ) {
- requireMethods('ConfigController', ['current', 'get', 'save'], controller);
- config.ConfigController = controller;
- },
- getConfigController: function ()
- /*: ConfigController*/
- {
- return config.ConfigController;
- },
- setCryptoController: function (controller
- /*: CryptoController*/
- ) {
- requireMethods('CryptoController', ['encrypt', 'decrypt'], controller);
- config.CryptoController = controller;
- },
- getCryptoController: function ()
- /*: CryptoController*/
- {
- return config.CryptoController;
- },
- setFileController: function (controller
- /*: FileController*/
- ) {
- requireMethods('FileController', ['saveFile', 'saveBase64'], controller);
- config.FileController = controller;
- },
- getFileController: function ()
- /*: FileController*/
- {
- return config.FileController;
- },
- setInstallationController: function (controller
- /*: InstallationController*/
- ) {
- requireMethods('InstallationController', ['currentInstallationId'], controller);
- config.InstallationController = controller;
- },
- getInstallationController: function ()
- /*: InstallationController*/
- {
- return config.InstallationController;
- },
- setObjectController: function (controller
- /*: ObjectController*/
- ) {
- requireMethods('ObjectController', ['save', 'fetch', 'destroy'], controller);
- config.ObjectController = controller;
- },
- getObjectController: function ()
- /*: ObjectController*/
- {
- return config.ObjectController;
- },
- setObjectStateController: function (controller
- /*: ObjectStateController*/
- ) {
- requireMethods('ObjectStateController', ['getState', 'initializeState', 'removeState', 'getServerData', 'setServerData', 'getPendingOps', 'setPendingOp', 'pushPendingState', 'popPendingState', 'mergeFirstPendingState', 'getObjectCache', 'estimateAttribute', 'estimateAttributes', 'commitServerChanges', 'enqueueTask', 'clearAllState'], controller);
- config.ObjectStateController = controller;
- },
- getObjectStateController: function ()
- /*: ObjectStateController*/
- {
- return config.ObjectStateController;
- },
- setPushController: function (controller
- /*: PushController*/
- ) {
- requireMethods('PushController', ['send'], controller);
- config.PushController = controller;
- },
- getPushController: function ()
- /*: PushController*/
- {
- return config.PushController;
- },
- setQueryController: function (controller
- /*: QueryController*/
- ) {
- requireMethods('QueryController', ['find', 'aggregate'], controller);
- config.QueryController = controller;
- },
- getQueryController: function ()
- /*: QueryController*/
- {
- return config.QueryController;
- },
- setRESTController: function (controller
- /*: RESTController*/
- ) {
- requireMethods('RESTController', ['request', 'ajax'], controller);
- config.RESTController = controller;
- },
- getRESTController: function ()
- /*: RESTController*/
- {
- return config.RESTController;
- },
- setSchemaController: function (controller
- /*: SchemaController*/
- ) {
- requireMethods('SchemaController', ['get', 'create', 'update', 'delete', 'send', 'purge'], controller);
- config.SchemaController = controller;
- },
- getSchemaController: function ()
- /*: SchemaController*/
- {
- return config.SchemaController;
- },
- setSessionController: function (controller
- /*: SessionController*/
- ) {
- requireMethods('SessionController', ['getSession'], controller);
- config.SessionController = controller;
- },
- getSessionController: function ()
- /*: SessionController*/
- {
- return config.SessionController;
- },
- setStorageController: function (controller
- /*: StorageController*/
- ) {
- if (controller.async) {
- requireMethods('An async StorageController', ['getItemAsync', 'setItemAsync', 'removeItemAsync', 'getAllKeysAsync'], controller);
- } else {
- requireMethods('A synchronous StorageController', ['getItem', 'setItem', 'removeItem', 'getAllKeys'], controller);
- }
- config.StorageController = controller;
- },
- setLocalDatastoreController: function (controller
- /*: LocalDatastoreController*/
- ) {
- requireMethods('LocalDatastoreController', ['pinWithName', 'fromPinWithName', 'unPinWithName', 'getAllContents', 'clear'], controller);
- config.LocalDatastoreController = controller;
- },
- getLocalDatastoreController: function ()
- /*: LocalDatastoreController*/
- {
- return config.LocalDatastoreController;
- },
- setLocalDatastore: function (store
- /*: any*/
- ) {
- config.LocalDatastore = store;
- },
- getLocalDatastore: function () {
- return config.LocalDatastore;
- },
- getStorageController: function ()
- /*: StorageController*/
- {
- return config.StorageController;
- },
- setAsyncStorage: function (storage
- /*: any*/
- ) {
- config.AsyncStorage = storage;
- },
- getAsyncStorage: function () {
- return config.AsyncStorage;
- },
- setWebSocketController: function (controller
- /*: WebSocketController*/
- ) {
- config.WebSocketController = controller;
- },
- getWebSocketController: function ()
- /*: WebSocketController*/
- {
- return config.WebSocketController;
- },
- setUserController: function (controller
- /*: UserController*/
- ) {
- requireMethods('UserController', ['setCurrentUser', 'currentUser', 'currentUserAsync', 'signUp', 'logIn', 'become', 'logOut', 'me', 'requestPasswordReset', 'upgradeToRevocableSession', 'requestEmailVerification', 'verifyPassword', 'linkWith'], controller);
- config.UserController = controller;
- },
- getUserController: function ()
- /*: UserController*/
- {
- return config.UserController;
- },
- setLiveQueryController: function (controller
- /*: any*/
- ) {
- requireMethods('LiveQueryController', ['setDefaultLiveQueryClient', 'getDefaultLiveQueryClient', '_clearCachedDefaultClient'], controller);
- config.LiveQueryController = controller;
- },
- getLiveQueryController: function ()
- /*: any*/
- {
- return config.LiveQueryController;
- },
- setHooksController: function (controller
- /*: HooksController*/
- ) {
- requireMethods('HooksController', ['create', 'get', 'update', 'remove'], controller);
- config.HooksController = controller;
- },
- getHooksController: function ()
- /*: HooksController*/
- {
- return config.HooksController;
- }
- };
|