mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-05 23:37:04 +00:00
[parse] Add Schema class (#39024)
This commit is contained in:
committed by
Armando Aguirre
parent
1033c4efd3
commit
a55beed407
Vendored
+136
@@ -14,6 +14,7 @@
|
||||
// Yago Tomé <https://github.com/yagotome>
|
||||
// Thibault MOCELLIN <https://github.com/tybi>
|
||||
// Raschid JF Rafaelly <https://github.com/RaschidJFR>
|
||||
// Jeff Gu Kang <https://github.com/jeffgukang>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.4
|
||||
|
||||
@@ -781,6 +782,141 @@ subscription.on('close', () => {});
|
||||
_linkWith(provider: any, options: { authData?: AuthData }, saveOpts?: FullOptions): Promise<User>;
|
||||
}
|
||||
|
||||
/**
|
||||
* A Parse.Schema object is for handling schema data from Parse.
|
||||
* All the schemas methods require MasterKey.
|
||||
*
|
||||
* @param {String} className Parse Class string
|
||||
*
|
||||
* https://parseplatform.org/Parse-SDK-JS/api/master/Parse.Schema.html
|
||||
*
|
||||
* ```
|
||||
* const schema = new Parse.Schema('MyClass');
|
||||
* schema.addString('field');
|
||||
* schema.addIndex('index_name', { field: 1 });
|
||||
* schema.save();
|
||||
* ```
|
||||
*/
|
||||
class Schema {
|
||||
|
||||
constructor(className: string)
|
||||
|
||||
/**
|
||||
* Static method to get all schemas
|
||||
* @param options Valid options are:
|
||||
* - useMasterKey: In Cloud Code and Node only, causes the Master Key to be used for this request.
|
||||
* - sessionToken: A valid session token, used for making a request on behalf of a specific user.
|
||||
*/
|
||||
static all(options?: ScopeOptions): Promise<Schema[]>
|
||||
|
||||
addArray(name: string): this
|
||||
addBoolean(name: string): this
|
||||
addDate(name: string): this
|
||||
addField(name: string, type?: Schema.TYPE): this
|
||||
addFile(name: string): this
|
||||
addGeoPoint(name: string): this
|
||||
|
||||
/**
|
||||
* Adding an Index to Create / Update a Schema
|
||||
* @param {String} name Name of the field that will be created on Parse
|
||||
* @param {Schema.Index} index { 'field': value } `field` should exist in the schema before using addIndex. `value` can be a (String|Number|Boolean|Date|Parse.File|Parse.GeoPoint|Array|Object|Pointer|Parse.Relation)
|
||||
* @return Returns the schema, so you can chain this call.
|
||||
* @example
|
||||
* ```
|
||||
* schema.addIndex('index_name', {'field': 1});
|
||||
* ```
|
||||
*/
|
||||
addIndex(name: string, index: Schema.Index): this
|
||||
|
||||
addNumber(name: string): this
|
||||
addObject(name: string): this
|
||||
|
||||
/**
|
||||
* Adding Pointer Field
|
||||
* @param {String} name Name of the field that will be created on Parse
|
||||
* @param {String} targetClass Name of the target Pointer Class
|
||||
* @return Returns the schema, so you can chain this call.
|
||||
*/
|
||||
addPointer(name: string, targetClass: string): this
|
||||
|
||||
addPolygon(name: string): this
|
||||
|
||||
/**
|
||||
* Adding Relation Field
|
||||
* @param {String} name Name of the field that will be created on Parse
|
||||
* @param {String} targetClass Name of the target Pointer Class
|
||||
* @return Returns the schema, so you can chain this call.
|
||||
*/
|
||||
addRelation(name: string, targetClass: string): this
|
||||
|
||||
addString(name: string): this
|
||||
|
||||
/**
|
||||
* Removing a Schema from Parse Can only be used on Schema without objects
|
||||
* @param options
|
||||
* Valid options are:
|
||||
* - useMasterKey: In Cloud Code and Node only, causes the Master Key to be used for this request.
|
||||
* - sessionToken: A valid session token, used for making a request on behalf of a specific user.
|
||||
* @returns {Promise} A promise that is resolved with the result when the query completes.
|
||||
*/
|
||||
// @TODO Fix Promise<any>
|
||||
delete(options?: ScopeOptions): Promise<any>
|
||||
|
||||
/**
|
||||
* Deleting a Field to Update on a Schema
|
||||
* @param name Name of the field
|
||||
* @return Returns the schema, so you can chain this call.
|
||||
*/
|
||||
deleteField(name: string): this
|
||||
|
||||
/**
|
||||
* Deleting a Index Field to Update on a Schema
|
||||
* @param name Name of the index field
|
||||
* @return Returns the schema, so you can chain this call.
|
||||
*/
|
||||
deleteIndex(name: string): this
|
||||
|
||||
/**
|
||||
* Get the Schema from Parse
|
||||
*/
|
||||
get(options?: ScopeOptions): Promise<Schema>
|
||||
|
||||
/**
|
||||
* Removes all objects from a Schema (class) in Parse. EXERCISE CAUTION, running this will delete all objects for this schema and cannot be reversed
|
||||
*/
|
||||
// TODO Fix Promise<any>
|
||||
purge(): Promise<any>
|
||||
|
||||
/**
|
||||
* Create a new Schema on Parse
|
||||
*/
|
||||
save(options?: ScopeOptions): Promise<Schema>
|
||||
|
||||
/**
|
||||
* Update a Schema on Parse
|
||||
*/
|
||||
update(options?: ScopeOptions): Promise<Schema>
|
||||
}
|
||||
|
||||
namespace Schema {
|
||||
|
||||
type TYPE =
|
||||
| string
|
||||
| number
|
||||
| boolean
|
||||
| Date
|
||||
| File
|
||||
| GeoPoint
|
||||
| Array<any>
|
||||
| object
|
||||
| Pointer
|
||||
| Relation
|
||||
|
||||
interface Index {
|
||||
[fieldName: string]: TYPE
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace Analytics {
|
||||
|
||||
|
||||
@@ -617,3 +617,61 @@ async function test_local_datastore() {
|
||||
|
||||
Parse.setLocalDatastoreController({});
|
||||
}
|
||||
|
||||
async function test_schema() {
|
||||
|
||||
Parse.Schema.all({ useMasterKey: true })
|
||||
Parse.Schema.all({ sessionToken: '' })
|
||||
|
||||
const schema = new Parse.Schema('TestSchema');
|
||||
|
||||
schema.addField('defaultFieldString')
|
||||
schema.addString('stringField')
|
||||
schema.addNumber('numberField')
|
||||
schema.addBoolean('booleanField')
|
||||
schema.addDate('dateField')
|
||||
schema.addFile('fileField')
|
||||
schema.addGeoPoint('geoPointField')
|
||||
schema.addPolygon('polygonField')
|
||||
schema.addArray('arrayField')
|
||||
schema.addObject('objectField')
|
||||
schema.addPointer('pointerField', '_User')
|
||||
schema.addRelation('relationField', '_User');
|
||||
|
||||
schema.addIndex('testIndex', { stringField: 1 });
|
||||
|
||||
schema.deleteField('defaultFieldString')
|
||||
schema.deleteIndex('testIndex')
|
||||
|
||||
// Master Key
|
||||
schema.delete({ useMasterKey: true })
|
||||
.then((results) => { });
|
||||
|
||||
schema.get({ useMasterKey: true })
|
||||
.then((results) => { })
|
||||
|
||||
schema.purge()
|
||||
.then((results) => { })
|
||||
|
||||
schema.save({ useMasterKey: true })
|
||||
.then((results) => { })
|
||||
|
||||
schema.update({ useMasterKey: true })
|
||||
.then((results) => { })
|
||||
|
||||
// Session Token
|
||||
schema.delete({ sessionToken: '' })
|
||||
.then((results) => { });
|
||||
|
||||
schema.get({ sessionToken: '' })
|
||||
.then((results) => { })
|
||||
|
||||
schema.purge()
|
||||
.then((results) => { })
|
||||
|
||||
schema.save({ sessionToken: '' })
|
||||
.then((results) => { })
|
||||
|
||||
schema.update({ sessionToken: '' })
|
||||
.then((results) => { })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user