diff --git a/integration/test/ParseSchemaTest.js b/integration/test/ParseSchemaTest.js index 91dfbffc9..cd50331fa 100644 --- a/integration/test/ParseSchemaTest.js +++ b/integration/test/ParseSchemaTest.js @@ -47,6 +47,7 @@ describe('Schema', () => { .addDate('dateField') .addFile('fileField') .addGeoPoint('geoPointField') + .addPolygon('polygonField') .addArray('arrayField') .addObject('objectField') .addPointer('pointerField', '_User') @@ -62,6 +63,7 @@ describe('Schema', () => { assert.equal(result.fields.dateField.type, 'Date'); assert.equal(result.fields.fileField.type, 'File'); assert.equal(result.fields.geoPointField.type, 'GeoPoint'); + assert.equal(result.fields.polygonField.type, 'Polygon'); assert.equal(result.fields.arrayField.type, 'Array'); assert.equal(result.fields.objectField.type, 'Object'); assert.equal(result.fields.pointerField.type, 'Pointer'); @@ -132,6 +134,32 @@ describe('Schema', () => { }); }); + it('purge', (done) => { + const testSchema = new Parse.Schema('SchemaTest'); + const obj = new Parse.Object('SchemaTest'); + obj.save().then(() => { + return testSchema.delete().then(() => { + // Should never reach here + assert.equal(true, false); + }).catch((error) => { + assert.equal(error.code, Parse.Error.INVALID_SCHEMA_OPERATION); + assert.equal(error.message, 'Class SchemaTest is not empty, contains 1 objects, cannot drop schema.'); + return Parse.Promise.as(); + }); + }).then(() => { + return testSchema.purge(); + }).then(() => { + const query = new Parse.Query('SchemaTest'); + return query.count(); + }).then((count) => { + assert.equal(count, 0); + // Delete only works on empty schema, extra check + return testSchema.delete(); + }).then(() => { + done(); + }); + }); + it('save index', (done) => { const testSchema = new Parse.Schema('SchemaTest'); const index = { diff --git a/src/CoreManager.js b/src/CoreManager.js index 997f9cf3d..0d4a66b0b 100644 --- a/src/CoreManager.js +++ b/src/CoreManager.js @@ -78,6 +78,7 @@ type RESTController = { ajax: (method: string, url: string, data: any, headers?: any) => ParsePromise; }; type SchemaController = { + purge: (className: string) => ParsePromise; get: (className: string, options: RequestOptions) => ParsePromise; delete: (className: string, options: RequestOptions) => ParsePromise; create: (className: string, params: any, options: RequestOptions) => ParsePromise; @@ -295,7 +296,7 @@ module.exports = { }, setSchemaController(controller: SchemaController) { - requireMethods('SchemaController', ['get', 'create', 'update', 'delete', 'send'], controller); + requireMethods('SchemaController', ['get', 'create', 'update', 'delete', 'send', 'purge'], controller); config['SchemaController'] = controller; }, diff --git a/src/ParseError.js b/src/ParseError.js index e03499ec2..88d069ec1 100644 --- a/src/ParseError.js +++ b/src/ParseError.js @@ -20,7 +20,7 @@ class ParseError { this.code = code; this.message = message; } - + toString() { return 'ParseError: ' + this.code + ' ' + this.message; } @@ -466,6 +466,14 @@ ParseError.INVALID_LINKED_SESSION = 251; */ ParseError.UNSUPPORTED_SERVICE = 252; +/** + * Error code indicating an invalid operation occured on schema + * @property INVALID_SCHEMA_OPERATION + * @static + * @final + */ +ParseError.INVALID_SCHEMA_OPERATION = 255; + /** * Error code indicating that there were multiple errors. Aggregate errors * have an "errors" property, which is an array of error objects with more diff --git a/src/ParseSchema.js b/src/ParseSchema.js index 4eb8199d0..4577616c5 100644 --- a/src/ParseSchema.js +++ b/src/ParseSchema.js @@ -14,7 +14,7 @@ import ParsePromise from './ParsePromise'; import type { RequestOptions, FullOptions } from './RESTController'; -const FIELD_TYPES = ['String', 'Number', 'Boolean', 'Date', 'File', 'GeoPoint', 'Array', 'Object', 'Pointer', 'Relation']; +const FIELD_TYPES = ['String', 'Number', 'Boolean', 'Date', 'File', 'GeoPoint', 'Polygon', 'Array', 'Object', 'Pointer', 'Relation']; /** * A Parse.Schema object is for handling schema data from Parse. @@ -181,6 +181,7 @@ class ParseSchema { /** * Removing a Schema from Parse + * Can only be used on Schema without objects * * @param {Object} options A Backbone-style options object. * Valid options are: