function SchemaStore(state, action) { switch (action.type) { case ActionTypes.FETCH: if (state && new Date() - state.get('lastFetch') < 60000) { return Parse.Promise.as(state); } return action.app.apiRequest( 'GET', 'schemas', {}, { useMasterKey: true } ).then(({ results }) => { let classes = {}; let CLPs = {}; if (results) { results.forEach(({ className, fields, classLevelPermissions }) => { classes[className] = Map(fields); CLPs[className] = Map(classLevelPermissions); }); } return Map({ lastFetch: new Date(), classes: Map(classes), CLPs: Map(CLPs), }); }); case ActionTypes.CREATE_CLASS: return action.app.apiRequest( 'POST', 'schemas/' + action.className, { className: action.className, fields: action.fields }, { useMasterKey: true } ).then(({ fields }) => { return state .setIn(['classes', action.className], Map(fields)) .setIn(['CLPs', action.className], Map({})); }); case ActionTypes.DROP_CLASS: return action.app.apiRequest( 'DELETE', 'schemas/' + action.className, {}, { useMasterKey: true } ).then(() => { return state .deleteIn(['classes', action.className]) .deleteIn(['CLPs', action.className]); }); case ActionTypes.ADD_COLUMN: let newField = { [action.name]: { type: action.columnType } }; if (action.columnType === 'Pointer' || action.columnType === 'Relation') { newField[action.name].targetClass = action.targetClass; } return action.app.apiRequest( 'PUT', 'schemas/' + action.className, { className: action.className, fields: newField }, { useMasterKey: true } ).then(({ fields }) => { return state.setIn(['classes', action.className], Map(fields)); }); case ActionTypes.DROP_COLUMN: let droppedField = { [action.name]: { __op: 'Delete' } }; return action.app.apiRequest( 'PUT', 'schemas/' + action.className, { className: action.className, fields: droppedField }, { useMasterKey: true } ).then(({ fields }) => { return state.setIn(['classes', action.className], Map(fields)); }); case ActionTypes.SET_CLP: return action.app.apiRequest( 'PUT', 'schemas/' + action.className, { classLevelPermissions: action.clp }, { useMasterKey: true } ).then(({ classLevelPermissions, className }) => { return state.setIn(['CLPs', className], Map(classLevelPermissions)); }); } }
deleteApp(slug, password) { return del('/apps/' + slug + '?password_confirm_delete=' + password).then(() => { for (let i = 0; i < appsStore.length; i++) { if (appsStore[i].slug == slug) { appsStore.splice(i, 1); return; } } }); }, // Fetch the latest usage and request info for the apps index getAllAppsIndexStats() { return Parse.Promise.when(this.apps().map(app => { return Parse.Promise.when( app.getClassCount('_Installation').then(count => app.installations = count), app.getClassCount('_User').then(count => app.users = count) ); })); }, // Options should be a list containing a subset of // ["schema", "app_settings", "config", "cloud_code", "background_jobs"] // indicating which parts of the app to clone. cloneApp(slug, name, options) { //Clone nothing by default let optionsForRuby = { cloud_code: false, background_jobs: false, config: false, schema: false, app_settings: false,
source={() => Parse.Promise.as(Math.random())}