parse-mobx
Version:
A wrapper for ParseJS SDK to make Parse Objects observable in Mobx
504 lines (503 loc) • 12.7 kB
TypeScript
import { Attributes, CreateObjectOptions, DeleteObjectOptions, EventCallback } from './types';
export { configureParseMobx } from './config';
/**
* Parse Mobx Class
*/
export declare class ParseMobx {
/**
* Will set to true if the object is being saved.
* @type {boolean}
*/
loading: boolean;
/**
* Contains the observable attributes.
* @type {Parse.Attributes}
* @private
*/
private readonly attributes;
/**
* The parse Object
* @type {Parse.Object}
* @private
*/
private readonly parseObj;
/**
* Parse Object Id.
* @type {string}
* @private
*/
private readonly id;
/**
* ParseMobx Class constructor
* @param {Parse.Object} obj
*/
constructor(obj: Parse.Object);
/**
* Convert a ParseObject or array of ParseObjects to ParseMobx object or array of ParseMobx objects.
* @param param
* @static
* @returns {ParseMobx | ParseMobx[] | ((obj: Parse.Object) => any) | null}
*/
static toParseMobx(param: any): ParseMobx | ParseMobx[] | ((obj: Parse.Object) => any) | null;
/**
* Delete an Item from a list of observable ParseMobx
* @param {ParseMobx[]} list
* @param {ParseMobx} item
* @static
*/
static deleteListItemById(list: ParseMobx[], item: ParseMobx): void;
/**
* Update an Item in the list of parse mobx observable list.
* @param {ParseMobx[]} list
* @param {ParseMobx} item
* @deprecated
* @static
*/
static updateListItem(list: ParseMobx[], item: ParseMobx): void;
/**
* Atomically add an object to the end of the array associated with a given key.
* @param {string} attr
* @param {any} item
* @returns {this}
*/
add(attr: string, item: any): this;
/**
* Atomically add the objects to the end of the array associated with a given key.
* @param {string} attr
* @param {any[]} items
* @returns {this}
*/
addAll(attr: string, items: any[]): this;
/**
* Atomically add the objects to the array associated with a given key,
* only if it is not already present in the array. The position of the insert is not guaranteed.
* @param {string} attr
* @param {any[]} items
* @returns {this}
*/
addAllUnique(attr: string, items: any[]): this;
/**
* Atomically add an object to the array associated with a given key,
* only if it is not already present in the array. The position of the insert is not guaranteed.
* @param {string} key
* @param value
* @returns {this}
*/
addUnique(key: string, value: any): this;
/**
* Clear Parse Object
* @param options
* @returns {any}
*/
clear(options: any): any;
/**
*
* @returns {ParseMobx}
*/
clone(): ParseMobx;
/**
* Destroy Object on the server.
* @param {Parse.Object.DestroyOptions | undefined} options
* @returns {Promise<Parse.Object>}
*/
destroy(options?: Parse.Object.DestroyOptions | undefined): Promise<Parse.Object>;
/**
* Eventually Destroy an object on the server
* @param {Parse.Object.DestroyOptions | undefined} options
* @returns {Promise<Parse.Object>}
*/
destroyEventually(options?: Parse.Object.DestroyOptions | undefined): Promise<Parse.Object>;
/**
*
* @param {string | undefined} attr
* @returns {boolean}
*/
dirty(attr?: string | undefined): boolean;
/**
*
* @returns {string[]}
*/
dirtyKeys(): string[];
/**
*
* @param {T} other
* @returns {boolean}
*/
equals<T extends Parse.Object<Parse.Attributes>>(other: T): boolean;
/**
*
* @param {string} attr
* @returns {string}
*/
escape(attr: string): string;
/**
*
* @returns {boolean}
*/
existed(): boolean;
/**
*
* @param {Parse.RequestOptions | undefined} options
* @returns {Promise<boolean>}
*/
exists(options?: Parse.RequestOptions | undefined): Promise<boolean>;
/**
*
* @param {Parse.Object.FetchOptions | undefined} options
* @returns {Promise<this>}
*/
fetch(options?: Parse.Object.FetchOptions | undefined): Promise<this>;
/**
*
* @returns {Promise<Parse.Object>}
*/
fetchFromLocalDatastore(): Promise<Parse.Object>;
/**
*
* @param {(K[] | K)[] | K} keys
* @param {Parse.RequestOptions | undefined} options
* @returns {Promise<this>}
*/
fetchWithInclude<K extends string>(keys: K | (K | K[])[], options?: Parse.RequestOptions | undefined): Promise<this>;
/**
*
* @param {string} key
* @returns {any}
*/
get(key: string): any;
/**
* Return the id of the parse object.
* @returns {string}
*/
getId(): string;
/**
*
* @returns {Parse.ACL | undefined}
*/
getACL(): Parse.ACL | undefined;
/**
*
* @param {string} attr
* @returns {boolean}
*/
has(attr: string): boolean;
/**
*
* @param {string} attr
* @param {number | undefined} amount
* @returns {false | this}
*/
increment(attr: string, amount?: number | undefined): false | this;
/**
*
* @param {string} attr
* @param {number | undefined} amount
* @returns {false | this}
*/
decrement(attr: string, amount?: number | undefined): false | this;
/**
*
*/
initialize(): void;
/**
*
* @returns {boolean}
*/
isDataAvailable(): boolean;
/**
*
* @returns {boolean}
*/
isNew(): boolean;
/**
*
* @returns {Promise<boolean>}
*/
isPinned(): Promise<boolean>;
/**
*
* @returns {boolean}
*/
isValid(): boolean;
/**
*
* @returns {ParseMobx}
*/
newInstance(): ParseMobx;
/**
*
* @param {string} attr
* @returns {any}
*/
op(attr: string): any;
/**
*
* @returns {Promise<void>}
*/
pin(): Promise<void>;
/**
*
* @param {string} name
* @returns {Promise<void>}
*/
pinWithName(name: string): Promise<void>;
/**
*
* @param {K} attr
* @returns {Parse.Relation<any, R>}
*/
relation<R extends Parse.Object<Parse.Attributes>, K extends string = string>(attr: K): Parse.Relation<any, R>;
/**
*
* @param {string} key
* @param value
* @returns {this}
*/
remove(key: string, value: any): this;
/**
*
* @param {string} attr
* @param {any[]} items
* @returns {this}
*/
removeAll(attr: string, items: any[]): this;
/**
*
* @param {string} keys
* @returns {ParseMobx}
*/
revert(...keys: string[]): void;
/**
*
* @param {Parse.Object.SaveOptions} options
* @returns {Promise<this>}
*/
save(options?: Parse.Object.SaveOptions): Promise<this>;
/**
*
* @param {Parse.Object.SaveOptions | undefined} options
* @returns {Promise<this>}
*/
saveEventually(options?: Parse.Object.SaveOptions | undefined): Promise<this>;
/**
*
* @param {string} key
* @param value
* @param {Parse.Object.SetOptions} options
* @returns {this}
*/
set(key: string, value: any, options?: Parse.Object.SetOptions): this;
/**
*
* @param {Parse.ACL} acl
* @param {Parse.SuccessFailureOptions | undefined} options
* @returns {false | this}
*/
setACL(acl: Parse.ACL, options?: Parse.SuccessFailureOptions | undefined): false | this;
/**
*
* @returns {Parse.Object.ToJSON<Parse.Attributes> & Parse.JSONBaseAttributes}
*/
toJSON(): Parse.Object.ToJSON<Parse.Attributes> & Parse.JSONBaseAttributes;
/**
*
* @returns {Parse.Pointer}
*/
toPointer(): Parse.Pointer;
/**
* Creates an offline pointer to this object
* @returns {Parse.Pointer}
*/
toOfflinePointer(): Parse.Pointer;
/**
*
* @returns {Promise<void>}
*/
unPin(): Promise<void>;
/**
*
* @param {string} name
* @returns {Promise<void>}
*/
unPinWithName(name: string): Promise<void>;
/**
*
* @param {string} attr
* @param options
* @returns {this}
*/
unset(attr: string, options?: any): this;
/**
*
* @param {Parse.Attributes} attrs
* @param {Parse.SuccessFailureOptions | undefined} options
* @returns {false | Parse.Error}
*/
validate(attrs: Parse.Attributes, options?: Parse.SuccessFailureOptions | undefined): false | Parse.Error;
/**
*
* @returns {Parse.Object}
*/
getParseObject(): Parse.Object;
/**
* Clear pending operations on the Parse object
*/
_clearPendingOps(): void;
/**
* Get the internal Parse object ID
* @returns {string}
*/
_getId(): string;
/**
* Get the internal state identifier
* @returns {any}
*/
_getStateIdentifier(): any;
/**
* Check if a value is undefined and create the attribute for it with a default value/
* @param {string} key
* @param initValue
* @private
*/
private checkDefined;
/**
* returns the type of attribute's value
* @param {string} key
* @param {string} type
* @returns {boolean}
* @private
*/
private checkType;
}
/**
* MobxStore Class
*/
export declare class MobxStore {
/**
* Contains the observable parseMobx objects
* @type {ParseMobx[]}
*/
objects: ParseMobx[];
/**
* Contains the parse error object
* @type {Parse.Error}
*/
parseError?: Parse.Error;
/**
* Return the loading state of fetching objects, adding a new object or saving objects.
* @type {boolean}
*/
loading: boolean;
/**
* If liveQuery subscription is open, the value will be false.
* @type {boolean}
*/
subscriptionOpen: boolean;
/**
* The parse class name.
* @type {string}
* @private
*/
private readonly parseClassName;
/**
* The subscription object.
* @type {Parse.LiveQuerySubscription}
* @private
*/
private subscription?;
/**
* Class constructor
* @param {string} parseClassName
*/
constructor(parseClassName: string);
/**
* Fetch Objects from parse server and update the Objects list
* @param {Parse.Query} parseQuery
*/
fetchObjects(parseQuery?: Parse.Query): void;
/**
* Create and save an object to the list of observable objects.
* @param {Attributes} params
* @param {CreateObjectOptions} options
*/
createObject(params: Attributes, options?: CreateObjectOptions): void;
/**
* Clear error observable
*/
clearError(): void;
/**
* Delete an object on the server and update hte objects list.
* @param {ParseMobx} obj
* @param {DeleteObjectOptions} options
*/
deleteObject(obj: ParseMobx, options?: DeleteObjectOptions): void;
/**
* Subscribe to liveQuery
* @param {Parse.Query} parseQuery
*/
subscribe(parseQuery?: Parse.Query): void;
/**
* Register a callback for onCreate
* @param {EventCallback} callback
*/
onCreate(callback: EventCallback): void;
/**
* Register a callback for onUpdate
* @param {EventCallback} callback
*/
onUpdate(callback: EventCallback): void;
/**
* Register a callback for onEnter
* @param {EventCallback} callback
*/
onEnter(callback: EventCallback): void;
/**
* Register a callback for onLeave
* @param {EventCallback} callback
*/
onLeave(callback: EventCallback): void;
/**
* Register a callback for onDelete
* @param {EventCallback} callback
*/
onDelete(callback: EventCallback): void;
/**
* Unsubscribe from LiveQuery
*/
unsubscribe(): void;
/**
*
* @param {ParseMobx} object
* @private
* @returns {ParseMobx}
*/
private createCallback;
/**
*
* @param {ParseMobx} object
* @private
* @returns {ParseMobx}
*/
private updateCallback;
/**
*
* @param {ParseMobx} object
* @private
* @returns {ParseMobx}
*/
private enterCallback;
/**
*
* @param {ParseMobx} object
* @private
* @returns {ParseMobx}
*/
private leaveCallback;
/**
*
* @param {ParseMobx} object
* @private
* @returns {ParseMobx}
*/
private deleteCallback;
}