storage.d.ts 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585
  1. import { Realtime } from 'leancloud-realtime';
  2. import { Adapters } from '@leancloud/adapter-types';
  3. export as namespace AV;
  4. interface IteratorResult<T> {
  5. done: boolean;
  6. value: T;
  7. }
  8. interface AsyncIterator<T> {
  9. next(): Promise<IteratorResult<T>>;
  10. }
  11. declare class EventEmitter<T> {
  12. on<K extends keyof T>(event: K, listener: T[K]): this;
  13. on(evt: string, listener: Function): this;
  14. once<K extends keyof T>(event: K, listener: T[K]): this;
  15. once(evt: string, listener: Function): this;
  16. off<K extends keyof T>(event: T | string, listener?: Function): this;
  17. emit<K extends keyof T>(event: T | string, ...args: any[]): boolean;
  18. }
  19. export var applicationId: string;
  20. export var applicationKey: string;
  21. export var masterKey: string;
  22. interface FetchOptions {
  23. keys?: string | string[];
  24. include?: string | string[];
  25. includeACL?: boolean;
  26. }
  27. export interface AuthOptions {
  28. /**
  29. * In Cloud Code and Node only, causes the Master Key to be used for this request.
  30. */
  31. useMasterKey?: boolean;
  32. sessionToken?: string;
  33. user?: User;
  34. }
  35. interface SMSAuthOptions extends AuthOptions {
  36. validateToken?: string;
  37. }
  38. interface CaptchaOptions {
  39. size?: number;
  40. width?: number;
  41. height?: number;
  42. ttl?: number;
  43. }
  44. interface FileSaveOptions extends AuthOptions {
  45. keepFileName?: boolean;
  46. key?: string;
  47. onprogress?: (event: {
  48. loaded: number;
  49. total: number;
  50. percent: number;
  51. }) => any;
  52. }
  53. export interface WaitOption {
  54. /**
  55. * Set to true to wait for the server to confirm success
  56. * before triggering an event.
  57. */
  58. wait?: boolean;
  59. }
  60. export interface SilentOption {
  61. /**
  62. * Set to true to avoid firing the event.
  63. */
  64. silent?: boolean;
  65. }
  66. export interface AnonymousAuthData {
  67. /**
  68. * random UUID with lowercase hexadecimal digits
  69. */
  70. id: string;
  71. [extraAttribute: string]: any;
  72. }
  73. export interface AuthDataWithUID {
  74. uid: string;
  75. access_token: string;
  76. [extraAttribute: string]: any;
  77. }
  78. export interface AuthDataWithOpenID {
  79. openid: string;
  80. access_token: string;
  81. [extraAttribute: string]: any;
  82. }
  83. export type AuthData = AnonymousAuthData | AuthDataWithUID | AuthDataWithOpenID;
  84. export interface IBaseObject {
  85. toJSON(): any;
  86. }
  87. export class BaseObject implements IBaseObject {
  88. toJSON(): any;
  89. }
  90. /**
  91. * Creates a new ACL.
  92. * If no argument is given, the ACL has no permissions for anyone.
  93. * If the argument is a AV.User, the ACL will have read and write
  94. * permission for only that user.
  95. * If the argument is any other JSON object, that object will be interpretted
  96. * as a serialized ACL created with toJSON().
  97. * @see AV.Object#setACL
  98. * @class
  99. *
  100. * <p>An ACL, or Access Control List can be added to any
  101. * <code>AV.Object</code> to restrict access to only a subset of users
  102. * of your application.</p>
  103. */
  104. export class ACL extends BaseObject {
  105. constructor(arg1?: any);
  106. setPublicReadAccess(allowed: boolean): void;
  107. getPublicReadAccess(): boolean;
  108. setPublicWriteAccess(allowed: boolean): void;
  109. getPublicWriteAccess(): boolean;
  110. setReadAccess(userId: User, allowed: boolean): void;
  111. getReadAccess(userId: User): boolean;
  112. setReadAccess(userId: string, allowed: boolean): void;
  113. getReadAccess(userId: string): boolean;
  114. setRoleReadAccess(role: Role, allowed: boolean): void;
  115. setRoleReadAccess(role: string, allowed: boolean): void;
  116. getRoleReadAccess(role: Role): boolean;
  117. getRoleReadAccess(role: string): boolean;
  118. setRoleWriteAccess(role: Role, allowed: boolean): void;
  119. setRoleWriteAccess(role: string, allowed: boolean): void;
  120. getRoleWriteAccess(role: Role): boolean;
  121. getRoleWriteAccess(role: string): boolean;
  122. setWriteAccess(userId: User, allowed: boolean): void;
  123. setWriteAccess(userId: string, allowed: boolean): void;
  124. getWriteAccess(userId: User): boolean;
  125. getWriteAccess(userId: string): boolean;
  126. }
  127. export namespace File {
  128. export type CensorResult = 'rejected' | 'passed' | 'review';
  129. }
  130. /**
  131. * A AV.File is a local representation of a file that is saved to the AV
  132. * cloud.
  133. * @class
  134. * @param name {String} The file's name. This will be prefixed by a unique
  135. * value once the file has finished saving. The file name must begin with
  136. * an alphanumeric character, and consist of alphanumeric characters,
  137. * periods, spaces, underscores, or dashes.
  138. * @param data {Array} The data for the file, as either:
  139. * 1. an Array of byte value Numbers, or
  140. * 2. an Object like { base64: "..." } with a base64-encoded String.
  141. * 3. a File object selected with a file upload control. (3) only works
  142. * in Firefox 3.6+, Safari 6.0.2+, Chrome 7+, and IE 10+.
  143. * For example:<pre>
  144. * var fileUploadControl = $("#profilePhotoFileUpload")[0];
  145. * if (fileUploadControl.files.length > 0) {
  146. * var file = fileUploadControl.files[0];
  147. * var name = "photo.jpg";
  148. * var AVFile = new AV.File(name, file);
  149. * AVFile.save().then(function() {
  150. * // The file has been saved to AV.
  151. * }, function(error) {
  152. * // The file either could not be read, or could not be saved to AV.
  153. * });
  154. * }</pre>
  155. * @param type {String} Optional Content-Type header to use for the file. If
  156. * this is omitted, the content type will be inferred from the name's
  157. * extension.
  158. */
  159. export class File extends BaseObject {
  160. id?: string;
  161. createdAt?: Date;
  162. updatedAt?: Date;
  163. constructor(name: string, data: any, type?: string);
  164. static withURL(name: string, url: string): File;
  165. static createWithoutData(objectId: string): File;
  166. static censor(objectId: string): Promise<File.CensorResult>;
  167. destroy(options?: AuthOptions): Promise<void>;
  168. fetch(fetchOptions?: FetchOptions, options?: AuthOptions): Promise<this>;
  169. get(key: string): any;
  170. getACL(): ACL;
  171. metaData(): any;
  172. metaData(metaKey: string): any;
  173. metaData(metaKey: string, metaValue: any): any;
  174. name(): string;
  175. ownerId(): string;
  176. url(): string;
  177. save(options?: FileSaveOptions): Promise<this>;
  178. set(key: string, value: any): this;
  179. set(data: { [key: string]: any }): this;
  180. setACL(acl: ACL): this;
  181. setUploadHeader(key: string, value: string): this;
  182. size(): any;
  183. thumbnailURL(width: number, height: number): string;
  184. censor(): Promise<File.CensorResult>;
  185. toFullJSON(): any;
  186. }
  187. /**
  188. * Creates a new GeoPoint with any of the following forms:<br>
  189. * <pre>
  190. * new GeoPoint(otherGeoPoint)
  191. * new GeoPoint(30, 30)
  192. * new GeoPoint([30, 30])
  193. * new GeoPoint({latitude: 30, longitude: 30})
  194. * new GeoPoint() // defaults to (0, 0)
  195. * </pre>
  196. * @class
  197. *
  198. * <p>Represents a latitude / longitude point that may be associated
  199. * with a key in a AVObject or used as a reference point for geo queries.
  200. * This allows proximity-based queries on the key.</p>
  201. *
  202. * <p>Only one key in a class may contain a GeoPoint.</p>
  203. *
  204. * <p>Example:<pre>
  205. * var point = new AV.GeoPoint(30.0, -20.0);
  206. * var object = new AV.Object("PlaceObject");
  207. * object.set("location", point);
  208. * object.save();</pre></p>
  209. */
  210. export class GeoPoint extends BaseObject {
  211. latitude: number;
  212. longitude: number;
  213. constructor(other: GeoPoint);
  214. // -90.0 <= latitude <= 90.0, and -180.0 <= longitude <= 180.0,
  215. // but TypeScript does not support refinement types yet (Microsoft/TypeScript#7599),
  216. // so we just specify number here.
  217. constructor(lat: number, lon: number);
  218. constructor(latLon: [number, number]);
  219. constructor(latLonObj: { latitude: number; longitude: number });
  220. constructor();
  221. static current(options?: AuthOptions): Promise<GeoPoint>;
  222. radiansTo(point: GeoPoint): number;
  223. kilometersTo(point: GeoPoint): number;
  224. milesTo(point: GeoPoint): number;
  225. }
  226. /**
  227. * A class that is used to access all of the children of a many-to-many relationship.
  228. * Each instance of AV.Relation is associated with a particular parent object and key.
  229. */
  230. export class Relation<T extends Queriable> extends BaseObject {
  231. parent: Object;
  232. key: string;
  233. targetClassName: string;
  234. constructor(parent?: Object, key?: string);
  235. static reverseQuery<U extends Queriable>(
  236. parentClass: string | U,
  237. relationKey: string,
  238. child: Object
  239. ): Query<U>;
  240. //Adds a AV.Object or an array of AV.Objects to the relation.
  241. add(object: T): void;
  242. // Returns a AV.Query that is limited to objects in this relation.
  243. query(): Query<T>;
  244. // Removes a AV.Object or an array of AV.Objects from this relation.
  245. remove(object: T): void;
  246. }
  247. /**
  248. * Creates a new model with defined attributes. A client id (cid) is
  249. * automatically generated and assigned for you.
  250. *
  251. * <p>You won't normally call this method directly. It is recommended that
  252. * you use a subclass of <code>AV.Object</code> instead, created by calling
  253. * <code>extend</code>.</p>
  254. *
  255. * <p>However, if you don't want to use a subclass, or aren't sure which
  256. * subclass is appropriate, you can use this form:<pre>
  257. * var object = new AV.Object("ClassName");
  258. * </pre>
  259. * That is basically equivalent to:<pre>
  260. * var MyClass = AV.Object.extend("ClassName");
  261. * var object = new MyClass();
  262. * </pre></p>
  263. *
  264. * @param {Object} attributes The initial set of data to store in the object.
  265. * @param {Object} options A set of Backbone-like options for creating the
  266. * object. The only option currently supported is "collection".
  267. * @see AV.Object.extend
  268. *
  269. * @class
  270. *
  271. * <p>The fundamental unit of AV data, which implements the Backbone Model
  272. * interface.</p>
  273. */
  274. export class Object extends BaseObject {
  275. id?: string;
  276. createdAt?: Date;
  277. updatedAt?: Date;
  278. attributes: any;
  279. changed: boolean;
  280. className: string;
  281. query: Query<this>;
  282. constructor(className?: string, options?: any);
  283. constructor(attributes?: string[], options?: any);
  284. static createWithoutData<T extends Object>(
  285. className: string,
  286. objectId: string
  287. ): T;
  288. static createWithoutData<T extends Object>(
  289. className: new (...args: any[]) => T,
  290. objectId: string
  291. ): T;
  292. static extend(
  293. className: string,
  294. protoProps?: any,
  295. classProps?: any
  296. ): typeof Object;
  297. static fetchAll<T extends Object>(
  298. list: T[],
  299. options?: AuthOptions
  300. ): Promise<Array<T | Error>>;
  301. static destroyAll(
  302. list: Object[],
  303. options?: Object.DestroyAllOptions
  304. ): Promise<Array<void | Error>>;
  305. static saveAll<T extends Object>(
  306. list: T[],
  307. options?: Object.SaveAllOptions
  308. ): Promise<Array<T | Error>>;
  309. static register(klass: new (...args: any[]) => Object, name?: string): void;
  310. initialize(): void;
  311. add(attributeName: string, item: any): this;
  312. addUnique(attributeName: string, item: any): any;
  313. bitAnd(attributeName: string, item: number): this;
  314. bitOr(attributeName: string, item: number): this;
  315. bitXor(attributeName: string, item: number): this;
  316. change(options: any): this;
  317. clear(options: any): any;
  318. revert(keys?: string | string[]): this;
  319. clone(): this;
  320. destroy(options?: Object.DestroyOptions): Promise<this>;
  321. dirty(key?: string): boolean;
  322. dirtyKeys(): string[];
  323. escape(attr: string): string;
  324. fetch(fetchOptions?: FetchOptions, options?: AuthOptions): Promise<this>;
  325. fetchWhenSave(enable: boolean): void;
  326. get(attr: string): any;
  327. getACL(): ACL;
  328. getCreatedAt(): Date;
  329. getObjectId(): string;
  330. getUpdatedAt(): Date;
  331. has(attr: string): boolean;
  332. increment(attr: string, amount?: number): this;
  333. isValid(): boolean;
  334. op(attr: string): any;
  335. previous(attr: string): any;
  336. previousAttributes(): any;
  337. relation<T extends Queriable>(attr: string): Relation<T>;
  338. remove(attr: string, item: any): this;
  339. save(
  340. attrs?: object | null,
  341. options?: Object.SaveOptions<this>
  342. ): Promise<this>;
  343. save(
  344. key: string,
  345. value: any,
  346. options?: Object.SaveOptions<this>
  347. ): Promise<this>;
  348. set(key: string, value: any, options?: Object.SetOptions): this;
  349. set(data: { [key: string]: any }, options?: Object.SetOptions): this;
  350. setACL(acl: ACL, options?: Object.SetOptions): this;
  351. unset(attr: string, options?: Object.SetOptions): this;
  352. validate(attrs: any): any;
  353. toFullJSON(): any;
  354. ignoreHook(
  355. hookName:
  356. | 'beforeSave'
  357. | 'afterSave'
  358. | 'beforeUpdate'
  359. | 'afterUpdate'
  360. | 'beforeDelete'
  361. | 'afterDelete'
  362. ): void;
  363. disableBeforeHook(): void;
  364. disableAfterHook(): void;
  365. }
  366. export namespace Object {
  367. interface DestroyOptions extends AuthOptions, WaitOption {}
  368. interface DestroyAllOptions extends AuthOptions {}
  369. interface SaveOptions<T extends Queriable>
  370. extends AuthOptions,
  371. SilentOption,
  372. WaitOption {
  373. fetchWhenSave?: boolean;
  374. query?: Query<T>;
  375. }
  376. interface SaveAllOptions extends AuthOptions {
  377. fetchWhenSave?: boolean;
  378. }
  379. interface SetOptions extends SilentOption {}
  380. }
  381. /**
  382. * Every AV application installed on a device registered for
  383. * push notifications has an associated Installation object.
  384. */
  385. export class Installation extends Object {
  386. badge: any;
  387. channels: string[];
  388. timeZone: any;
  389. deviceType: string;
  390. pushType: string;
  391. installationId: string;
  392. deviceToken: string;
  393. channelUris: string;
  394. appName: string;
  395. appVersion: string;
  396. AVVersion: string;
  397. appIdentifier: string;
  398. }
  399. /**
  400. * @class
  401. *
  402. * <p>AV.Events is a fork of Backbone's Events module, provided for your
  403. * convenience.</p>
  404. *
  405. * <p>A module that can be mixed in to any object in order to provide
  406. * it with custom events. You may bind callback functions to an event
  407. * with `on`, or remove these functions with `off`.
  408. * Triggering an event fires all callbacks in the order that `on` was
  409. * called.
  410. *
  411. * <pre>
  412. * var object = {};
  413. * _.extend(object, AV.Events);
  414. * object.on('expand', function(){ alert('expanded'); });
  415. * object.trigger('expand');</pre></p>
  416. *
  417. * <p>For more information, see the
  418. * <a href="http://documentcloud.github.com/backbone/#Events">Backbone
  419. * documentation</a>.</p>
  420. */
  421. export class Events {
  422. static off(events: string[], callback?: Function, context?: any): Events;
  423. static on(events: string[], callback?: Function, context?: any): Events;
  424. static trigger(events: string[]): Events;
  425. static bind(): Events;
  426. static unbind(): Events;
  427. on(eventName: string, callback?: Function, context?: any): Events;
  428. off(eventName?: string, callback?: Function, context?: any): Events;
  429. trigger(eventName: string, ...args: any[]): Events;
  430. bind(eventName: string, callback: Function, context?: any): Events;
  431. unbind(eventName?: string, callback?: Function, context?: any): Events;
  432. }
  433. declare type Queriable = Object | File;
  434. declare class BaseQuery<T extends Queriable> extends BaseObject {
  435. className: string;
  436. constructor(objectClass: new (...args: any[]) => T);
  437. constructor(objectClass: string);
  438. addAscending(key: string): this;
  439. addAscending(key: string[]): this;
  440. addDescending(key: string): this;
  441. addDescending(key: string[]): this;
  442. ascending(key: string): this;
  443. ascending(key: string[]): this;
  444. descending(key: string): this;
  445. descending(key: string[]): this;
  446. include(...keys: string[]): this;
  447. include(keys: string[]): this;
  448. select(...keys: string[]): this;
  449. select(keys: string[]): this;
  450. limit(n: number): this;
  451. skip(n: number): this;
  452. find(options?: AuthOptions): Promise<T[]>;
  453. }
  454. /**
  455. * Creates a new AV AV.Query for the given AV.Object subclass.
  456. * @param objectClass -
  457. * An instance of a subclass of AV.Object, or a AV className string.
  458. * @class
  459. *
  460. * <p>AV.Query defines a query that is used to fetch AV.Objects. The
  461. * most common use case is finding all objects that match a query through the
  462. * <code>find</code> method. For example, this sample code fetches all objects
  463. * of class <code>MyClass</code>. It calls a different function depending on
  464. * whether the fetch succeeded or not.
  465. *
  466. * <pre>
  467. * var query = new AV.Query(MyClass);
  468. * query.find({
  469. * success: function(results) {
  470. * // results is an array of AV.Object.
  471. * },
  472. *
  473. * error: function(error) {
  474. * // error is an instance of AV.Error.
  475. * }
  476. * });</pre></p>
  477. *
  478. * <p>A AV.Query can also be used to retrieve a single object whose id is
  479. * known, through the get method. For example, this sample code fetches an
  480. * object of class <code>MyClass</code> and id <code>myId</code>. It calls a
  481. * different function depending on whether the fetch succeeded or not.
  482. *
  483. * <pre>
  484. * var query = new AV.Query(MyClass);
  485. * query.get(myId, {
  486. * success: function(object) {
  487. * // object is an instance of AV.Object.
  488. * },
  489. *
  490. * error: function(object, error) {
  491. * // error is an instance of AV.Error.
  492. * }
  493. * });</pre></p>
  494. *
  495. * <p>A AV.Query can also be used to count the number of objects that match
  496. * the query without retrieving all of those objects. For example, this
  497. * sample code counts the number of objects of the class <code>MyClass</code>
  498. * <pre>
  499. * var query = new AV.Query(MyClass);
  500. * query.count({
  501. * success: function(number) {
  502. * // There are number instances of MyClass.
  503. * },
  504. *
  505. * error: function(error) {
  506. * // error is an instance of AV.Error.
  507. * }
  508. * });</pre></p>
  509. */
  510. export class Query<T extends Queriable> extends BaseQuery<T> {
  511. static or<U extends Queriable>(...querys: Query<U>[]): Query<U>;
  512. static and<U extends Queriable>(...querys: Query<U>[]): Query<U>;
  513. static doCloudQuery<U extends Queriable>(
  514. cql: string,
  515. pvalues?: any,
  516. options?: AuthOptions
  517. ): Promise<U>;
  518. static fromJSON<U extends Queriable>(json: object): Query<U>;
  519. containedIn(key: string, values: any[]): this;
  520. contains(key: string, substring: string): this;
  521. containsAll(key: string, values: any[]): this;
  522. count(options?: AuthOptions): Promise<number>;
  523. descending(key: string): this;
  524. descending(key: string[]): this;
  525. destroyAll(options?: AuthOptions): Promise<void>;
  526. doesNotExist(key: string): this;
  527. doesNotMatchKeyInQuery<U extends Queriable>(
  528. key: string,
  529. queryKey: string,
  530. query: Query<U>
  531. ): this;
  532. doesNotMatchQuery<U extends Queriable>(key: string, query: Query<U>): this;
  533. each(callback: Function, options?: AuthOptions): Promise<T>;
  534. endsWith(key: string, suffix: string): this;
  535. equalTo(key: string, value: any): this;
  536. exists(key: string): this;
  537. findAndCount(options?: AuthOptions): Promise<[T[], number]>;
  538. first(options?: AuthOptions): Promise<T | undefined>;
  539. get(objectId: string, options?: AuthOptions): Promise<T>;
  540. greaterThan(key: string, value: any): this;
  541. greaterThanOrEqualTo(key: string, value: any): this;
  542. includeACL(value?: boolean): this;
  543. lessThan(key: string, value: any): this;
  544. lessThanOrEqualTo(key: string, value: any): this;
  545. matches(key: string, regex: RegExp, modifiers?: any): this;
  546. matchesKeyInQuery<U extends Queriable>(
  547. key: string,
  548. queryKey: string,
  549. query: Query<U>
  550. ): this;
  551. matchesQuery<U extends Queriable>(key: string, query: Query<U>): this;
  552. near(key: string, point: GeoPoint): this;
  553. notContainedIn(key: string, values: any[]): this;
  554. notEqualTo(key: string, value: any): this;
  555. sizeEqualTo(key: string, value: number): this;
  556. startsWith(key: string, prefix: string): this;
  557. withinGeoBox(key: string, southwest: GeoPoint, northeast: GeoPoint): this;
  558. withinKilometers(key: string, point: GeoPoint, maxDistance: number): this;
  559. withinMiles(key: string, point: GeoPoint, maxDistance: number): this;
  560. withinRadians(key: string, point: GeoPoint, maxDistance: number): this;
  561. scan(
  562. options?: { orderedBy?: string; batchSize?: number },
  563. authOptions?: AuthOptions
  564. ): AsyncIterator<T>;
  565. subscribe(options?: { subscriptionId?: string }): Promise<LiveQuery<T>>;
  566. }
  567. export class LiveQuery<T> extends EventEmitter<LiveQueryEvent<T>> {
  568. static pause(): void;
  569. static resume(): void;
  570. unsubscribe(): Promise<void>;
  571. }
  572. declare interface LiveQueryEvent<T> {
  573. create: (target?: T) => any;
  574. update: (target?: T, updatedKeys?: string[]) => any;
  575. enter: (target?: T, updatedKeys?: string[]) => any;
  576. leave: (target?: T, updatedKeys?: string[]) => any;
  577. delete: (target?: T) => any;
  578. }
  579. export class SearchQuery<T extends Queriable> extends BaseQuery<T> {
  580. sid(sid: string): this;
  581. queryString(q: string): this;
  582. highlights(highlights: string[]): this;
  583. highlights(highlight: string): this;
  584. sortBy(builder: SearchSortBuilder): this;
  585. hits(): number;
  586. hasMore(): boolean;
  587. reset(): void;
  588. }
  589. export class SearchSortBuilder {
  590. constructor();
  591. ascending(key: string, mode?: string, missingKeyBehaviour?: string): this;
  592. descending(key: string, mode?: string, missingKeyBehaviour?: string): this;
  593. whereNear(
  594. key: string,
  595. point?: GeoPoint,
  596. options?: { order?: string; mode?: string; unit?: string }
  597. ): this;
  598. build(): string;
  599. }
  600. /**
  601. * Represents a Role on the AV server. Roles represent groupings of
  602. * Users for the purposes of granting permissions (e.g. specifying an ACL
  603. * for an Object). Roles are specified by their sets of child users and
  604. * child roles, all of which are granted any permissions that the parent
  605. * role has.
  606. *
  607. * <p>Roles must have a name (which cannot be changed after creation of the
  608. * role), and must specify an ACL.</p>
  609. * @class
  610. * A AV.Role is a local representation of a role persisted to the AV
  611. * cloud.
  612. */
  613. export class Role extends Object {
  614. constructor(name: string, acl: ACL);
  615. getRoles(): Relation<Role>;
  616. getUsers(): Relation<User>;
  617. getName(): string;
  618. setName(name: string): Role;
  619. }
  620. interface OAuthLoginOptions {
  621. failOnNotExist?: boolean;
  622. }
  623. interface UnionOptions {
  624. unionIdPlatform?: string;
  625. asMainAccount?: boolean;
  626. }
  627. interface UnionLoginOptions extends OAuthLoginOptions, UnionOptions {}
  628. interface MiniappOptions extends UnionOptions {
  629. preferUnionId: boolean;
  630. }
  631. interface MiniappLoginOptions extends OAuthLoginOptions, MiniappOptions {}
  632. interface AuthInfo {
  633. authData: { [key: string]: any };
  634. provider: string;
  635. platform?: string;
  636. }
  637. /**
  638. * @class
  639. *
  640. * <p>A AV.User object is a local representation of a user persisted to the
  641. * AV cloud. This class is a subclass of a AV.Object, and retains the
  642. * same functionality of a AV.Object, but also extends it with various
  643. * user specific methods, like authentication, signing up, and validation of
  644. * uniqueness.</p>
  645. */
  646. export class User extends Object {
  647. static current(): User;
  648. static currentAsync(): Promise<User>;
  649. static signUp(
  650. username: string,
  651. password: string,
  652. attrs?: any,
  653. options?: AuthOptions
  654. ): Promise<User>;
  655. static logIn(username: string, password: string): Promise<User>;
  656. static logOut(): Promise<User>;
  657. static become(sessionToken: string): Promise<User>;
  658. static loginAnonymously(): Promise<User>;
  659. static loginWithMiniApp(
  660. authInfo?: AuthInfo,
  661. options?: OAuthLoginOptions
  662. ): Promise<User>;
  663. static loginWithWeapp(options?: MiniappLoginOptions): Promise<User>;
  664. static loginWithWeappWithUnionId(
  665. unionId: string,
  666. unionLoginOptions?: UnionLoginOptions
  667. ): Promise<User>;
  668. static loginWithQQApp(options?: MiniappLoginOptions): Promise<User>;
  669. static loginWithQQAppWithUnionId(
  670. unionId: string,
  671. unionLoginOptions?: UnionLoginOptions
  672. ): Promise<User>;
  673. static logInWithMobilePhone(
  674. mobilePhone: string,
  675. password: string
  676. ): Promise<User>;
  677. static logInWithMobilePhoneSmsCode(
  678. mobilePhone: string,
  679. smsCode: string
  680. ): Promise<User>;
  681. static loginWithEmail(email: string, password: string): Promise<User>;
  682. static loginWithAuthData(
  683. authData: AuthData,
  684. platform: string,
  685. options?: OAuthLoginOptions
  686. ): Promise<User>;
  687. static signUpOrlogInWithAuthData(
  688. authData: AuthData,
  689. platform: string,
  690. options?: OAuthLoginOptions
  691. ): Promise<User>;
  692. static loginWithAuthDataAndUnionId(
  693. authData: AuthData,
  694. platform: string,
  695. unionId: string,
  696. unionLoginOptions?: UnionLoginOptions
  697. ): Promise<User>;
  698. static signUpOrlogInWithAuthDataAndUnionId(
  699. authData: AuthData,
  700. platform: string,
  701. unionId: string,
  702. unionLoginOptions?: UnionLoginOptions
  703. ): Promise<User>;
  704. static signUpOrlogInWithMobilePhone(
  705. mobilePhoneNumber: string,
  706. smsCode: string,
  707. attributes?: any,
  708. options?: AuthOptions
  709. ): Promise<User>;
  710. static requestEmailVerify(
  711. email: string,
  712. options?: AuthOptions
  713. ): Promise<User>;
  714. static requestLoginSmsCode(
  715. mobilePhoneNumber: string,
  716. options?: SMSAuthOptions
  717. ): Promise<void>;
  718. static requestMobilePhoneVerify(
  719. mobilePhoneNumber: string,
  720. options?: SMSAuthOptions
  721. ): Promise<void>;
  722. static requestPasswordReset(
  723. email: string,
  724. options?: AuthOptions
  725. ): Promise<User>;
  726. static requestPasswordResetBySmsCode(
  727. mobilePhoneNumber: string,
  728. options?: SMSAuthOptions
  729. ): Promise<void>;
  730. static resetPasswordBySmsCode(
  731. code: string,
  732. password: string,
  733. options?: AuthOptions
  734. ): Promise<User>;
  735. static verifyMobilePhone(code: string, options?: AuthOptions): Promise<User>;
  736. static requestChangePhoneNumber(
  737. mobilePhoneNumber: string,
  738. ttl?: number,
  739. options?: SMSAuthOptions
  740. ): Promise<void>;
  741. static changePhoneNumber(
  742. mobilePhoneNumber: string,
  743. code: string
  744. ): Promise<void>;
  745. static followerQuery<T extends User>(userObjectId: string): Query<T>;
  746. static followeeQuery<T extends User>(userObjectId: string): Query<T>;
  747. loginWithWeapp(options?: MiniappLoginOptions): Promise<User>;
  748. loginWithWeappWithUnionId(
  749. unionId: string,
  750. unionLoginOptions?: UnionLoginOptions
  751. ): Promise<User>;
  752. loginWithQQApp(options?: MiniappLoginOptions): Promise<User>;
  753. loginWithQQAppWithUnionId(
  754. unionId: string,
  755. unionLoginOptions?: UnionLoginOptions
  756. ): Promise<User>;
  757. loginWithAuthData(
  758. authData: AuthData,
  759. platform: string,
  760. options?: OAuthLoginOptions
  761. ): Promise<User>;
  762. loginWithAuthDataAndUnionId(
  763. authData: AuthData,
  764. platform: string,
  765. unionId: string,
  766. unionLoginOptions?: UnionLoginOptions
  767. ): Promise<User>;
  768. signUp(attrs?: any, options?: AuthOptions): Promise<User>;
  769. logIn(): Promise<User>;
  770. linkWithWeapp(): Promise<User>;
  771. isAuthenticated(): Promise<boolean>;
  772. isAnonymous(): boolean;
  773. isCurrent(): boolean;
  774. associateWithWeapp(options?: MiniappOptions): Promise<User>;
  775. associateWithWeappWithUnionId(
  776. unionId: string,
  777. unionOptions?: UnionOptions
  778. ): Promise<User>;
  779. associateWithQQApp(options?: MiniappOptions): Promise<User>;
  780. associateWithQQAppWithUnionId(
  781. unionId: string,
  782. unionOptions?: UnionOptions
  783. ): Promise<User>;
  784. associateWithAuthData(authData: AuthData, platform: string): Promise<User>;
  785. associateWithAuthDataAndUnionId(
  786. authData: AuthData,
  787. platform: string,
  788. unionId: string,
  789. unionOptions?: UnionOptions
  790. ): Promise<User>;
  791. dissociateAuthData(platform: string): Promise<User>;
  792. getEmail(): string;
  793. setEmail(email: string): boolean;
  794. setMobilePhoneNumber(mobilePhoneNumber: string): boolean;
  795. getMobilePhoneNumber(): string;
  796. getUsername(): string;
  797. setUsername(username: string): boolean;
  798. setPassword(password: string): boolean;
  799. getSessionToken(): string;
  800. refreshSessionToken(options?: AuthOptions): Promise<User>;
  801. getRoles(options?: AuthOptions): Promise<Role[]>;
  802. follow(user: User | string, authOptions?: AuthOptions): Promise<void>;
  803. follow(
  804. options: { user: User | string; attributes?: object },
  805. authOptions?: AuthOptions
  806. ): Promise<void>;
  807. unfollow(user: User | string, authOptions?: AuthOptions): Promise<void>;
  808. unfollow(
  809. options: { user: User | string },
  810. authOptions?: AuthOptions
  811. ): Promise<void>;
  812. followerQuery(): Query<this>;
  813. followeeQuery(): Query<this>;
  814. getFollowersAndFollowees(
  815. options?: { skip?: number; limit?: number },
  816. authOptions?: AuthOptions
  817. ): Promise<{ followers: User[]; followees: User[] }>;
  818. }
  819. export class Friendship {
  820. static request(
  821. friend: User | string,
  822. authOptions?: AuthOptions
  823. ): Promise<void>;
  824. static request(
  825. options: { friend: User | string; attributes?: object },
  826. authOptions?: AuthOptions
  827. ): Promise<void>;
  828. static acceptRequest(
  829. request: Object | string,
  830. authOptions?: AuthOptions
  831. ): Promise<void>;
  832. static acceptRequest(
  833. options: { request: Object | string; attributes?: object },
  834. authOptions?: AuthOptions
  835. ): Promise<void>;
  836. static declineRequest(
  837. request: Object | string,
  838. authOptions?: AuthOptions
  839. ): Promise<void>;
  840. }
  841. export class Captcha {
  842. url: string;
  843. captchaToken: string;
  844. validateToken: string;
  845. static request(
  846. options?: CaptchaOptions,
  847. authOptions?: AuthOptions
  848. ): Promise<Captcha>;
  849. refresh(): Promise<string>;
  850. verify(code: string): Promise<string>;
  851. bind(
  852. elements?: {
  853. textInput?: string | HTMLInputElement;
  854. image?: string | HTMLImageElement;
  855. verifyButton?: string | HTMLElement;
  856. },
  857. callbacks?: {
  858. success?: (validateToken: string) => any;
  859. error?: (error: Error) => any;
  860. }
  861. ): void;
  862. unbind(): void;
  863. }
  864. /**
  865. * @class AV.Conversation
  866. * <p>An AV.Conversation is a local representation of a LeanCloud realtime's
  867. * conversation. This class is a subclass of AV.Object, and retains the
  868. * same functionality of an AV.Object, but also extends it with various
  869. * conversation specific methods, like get members, creators of this conversation.
  870. * </p>
  871. *
  872. * @param {String} name The name of the Role to create.
  873. * @param {Boolean} [options.isSystem] Set this conversation as system conversation.
  874. * @param {Boolean} [options.isTransient] Set this conversation as transient conversation.
  875. */
  876. export class Conversation extends Object {
  877. constructor(
  878. name: string,
  879. options?: { isSytem?: boolean; isTransient?: boolean }
  880. );
  881. getCreator(): string;
  882. getLastMessageAt(): Date;
  883. getMembers(): string[];
  884. addMember(member: string): Conversation;
  885. getMutedMembers(): string[];
  886. getName(): string;
  887. isTransient(): boolean;
  888. isSystem(): boolean;
  889. send(
  890. fromClient: string,
  891. message: string | object,
  892. options?: { transient?: boolean; pushData?: object; toClients?: string[] },
  893. authOptions?: AuthOptions
  894. ): Promise<void>;
  895. broadcast(
  896. fromClient: string,
  897. message: string | object,
  898. options?: { pushData?: object; validTill?: number | Date },
  899. authOptions?: AuthOptions
  900. ): Promise<void>;
  901. }
  902. declare class Statistic {
  903. name: string;
  904. value: number;
  905. version?: number;
  906. }
  907. declare interface Ranking {
  908. value: number;
  909. user: User;
  910. rank: number;
  911. includedStatistics?: Statistic[];
  912. }
  913. declare interface UpdateStatisticsOptions extends AuthOptions {
  914. overwrite?: boolean;
  915. }
  916. declare interface LeaderboardArchive {
  917. statisticName: string;
  918. version: number;
  919. status: string;
  920. url: string;
  921. activatedAt: Date;
  922. deactivatedAt: Date;
  923. }
  924. export class Leaderboard {
  925. statisticName: string;
  926. order?: LeaderboardOrder;
  927. updateStrategy?: LeaderboardUpdateStrategy;
  928. versionChangeInterval?: LeaderboardVersionChangeInterval;
  929. version?: number;
  930. nextResetAt?: Date;
  931. createdAt?: Date;
  932. static createWithoutData(statisticName: string): Leaderboard;
  933. static createLeaderboard(
  934. options: {
  935. statisticName: string;
  936. order: LeaderboardOrder;
  937. versionChangeInterval?: LeaderboardVersionChangeInterval;
  938. updateStrategy?: LeaderboardUpdateStrategy;
  939. },
  940. authOptions?: AuthOptions
  941. ): Promise<Leaderboard>;
  942. static getLeaderboard(
  943. statisticName: string,
  944. authOptions?: AuthOptions
  945. ): Promise<Leaderboard>;
  946. static getStatistics(
  947. user: User,
  948. options?: { statisticNames?: string[] }
  949. ): Promise<Statistic[]>;
  950. static updateStatistics(
  951. user: User,
  952. statistics: { [name: string]: number },
  953. options?: UpdateStatisticsOptions
  954. ): Promise<Statistic[]>;
  955. static deleteStatistics(
  956. user: User,
  957. statisticNames: string[],
  958. authOptions?: AuthOptions
  959. ): Promise<void>;
  960. fetch(authOptions?: AuthOptions): Promise<Leaderboard>;
  961. count(
  962. options?: {
  963. version?: number;
  964. },
  965. authOptions?: AuthOptions
  966. ): Promise<Number>;
  967. getResults(
  968. options?: {
  969. skip?: number;
  970. limit?: number;
  971. selectUserKeys?: string | string[];
  972. includeUserKeys?: string | string[];
  973. includeStatistics?: string | string[];
  974. version?: number;
  975. },
  976. authOptions?: AuthOptions
  977. ): Promise<Ranking[]>;
  978. getResultsAroundUser(
  979. user: User,
  980. options?: {
  981. limit?: number;
  982. selectUserKeys?: string | string[];
  983. includeUserKeys?: string | string[];
  984. includeStatistics?: string | string[];
  985. version?: number;
  986. },
  987. authOptions?: AuthOptions
  988. ): Promise<Ranking[]>;
  989. getResultsAroundUser(
  990. options?: {
  991. limit?: number;
  992. selectUserKeys?: string | string[];
  993. includeUserKeys?: string | string[];
  994. includeStatistics?: string | string[];
  995. version?: number;
  996. },
  997. authOptions?: AuthOptions
  998. ): Promise<Ranking[]>;
  999. updateVersionChangeInterval(
  1000. versionChangeInterval: LeaderboardVersionChangeInterval,
  1001. authOptions?: AuthOptions
  1002. ): Promise<Leaderboard>;
  1003. updateUpdateStrategy(
  1004. updateStrategy: LeaderboardUpdateStrategy,
  1005. authOptions?: AuthOptions
  1006. ): Promise<Leaderboard>;
  1007. reset(authOptions?: AuthOptions): Promise<Leaderboard>;
  1008. destroy(authOptions?: AuthOptions): Promise<void>;
  1009. getArchives(
  1010. options?: {
  1011. skip?: number;
  1012. limit?: number;
  1013. },
  1014. authOptions?: AuthOptions
  1015. ): Promise<LeaderboardArchive>;
  1016. }
  1017. export enum LeaderboardOrder {
  1018. ASCENDING,
  1019. DESCENDING,
  1020. }
  1021. export enum LeaderboardUpdateStrategy {
  1022. BETTER,
  1023. LAST,
  1024. SUM,
  1025. }
  1026. export enum LeaderboardVersionChangeInterval {
  1027. NEVER,
  1028. DAY,
  1029. WEEK,
  1030. MONTH,
  1031. }
  1032. export class Error {
  1033. code: number;
  1034. message: string;
  1035. rawMessage?: string;
  1036. constructor(code: number, message: string);
  1037. /**
  1038. * Error code indicating some error other than those enumerated here.
  1039. */
  1040. static OTHER_CAUSE: -1;
  1041. /**
  1042. * Error code indicating that something has gone wrong with the server.
  1043. * If you get this error code, it is AV's fault.
  1044. */
  1045. static INTERNAL_SERVER_ERROR: 1;
  1046. /**
  1047. * Error code indicating the connection to the AV servers failed.
  1048. */
  1049. static CONNECTION_FAILED: 100;
  1050. /**
  1051. * Error code indicating the specified object doesn't exist.
  1052. */
  1053. static OBJECT_NOT_FOUND: 101;
  1054. /**
  1055. * Error code indicating you tried to query with a datatype that doesn't
  1056. * support it, like exact matching an array or object.
  1057. */
  1058. static INVALID_QUERY: 102;
  1059. /**
  1060. * Error code indicating a missing or invalid classname. Classnames are
  1061. * case-sensitive. They must start with a letter, and a-zA-Z0-9_ are the
  1062. * only valid characters.
  1063. */
  1064. static INVALID_CLASS_NAME: 103;
  1065. /**
  1066. * Error code indicating an unspecified object id.
  1067. */
  1068. static MISSING_OBJECT_ID: 104;
  1069. /**
  1070. * Error code indicating an invalid key name. Keys are case-sensitive. They
  1071. * must start with a letter, and a-zA-Z0-9_ are the only valid characters.
  1072. */
  1073. static INVALID_KEY_NAME: 105;
  1074. /**
  1075. * Error code indicating a malformed pointer. You should not see this unless
  1076. * you have been mucking about changing internal AV code.
  1077. */
  1078. static INVALID_POINTER: 106;
  1079. /**
  1080. * Error code indicating that badly formed JSON was received upstream. This
  1081. * either indicates you have done something unusual with modifying how
  1082. * things encode to JSON, or the network is failing badly.
  1083. */
  1084. static INVALID_JSON: 107;
  1085. /**
  1086. * Error code indicating that the feature you tried to access is only
  1087. * available internally for testing purposes.
  1088. */
  1089. static COMMAND_UNAVAILABLE: 108;
  1090. /**
  1091. * You must call AV.initialize before using the AV library.
  1092. */
  1093. static NOT_INITIALIZED: 109;
  1094. /**
  1095. * Error code indicating that a field was set to an inconsistent type.
  1096. */
  1097. static INCORRECT_TYPE: 111;
  1098. /**
  1099. * Error code indicating an invalid channel name. A channel name is either
  1100. * an empty string (the broadcast channel) or contains only a-zA-Z0-9_
  1101. * characters.
  1102. */
  1103. static INVALID_CHANNEL_NAME: 112;
  1104. /**
  1105. * Error code indicating that push is misconfigured.
  1106. */
  1107. static PUSH_MISCONFIGURED: 115;
  1108. /**
  1109. * Error code indicating that the object is too large.
  1110. */
  1111. static OBJECT_TOO_LARGE: 116;
  1112. /**
  1113. * Error code indicating that the operation isn't allowed for clients.
  1114. */
  1115. static OPERATION_FORBIDDEN: 119;
  1116. /**
  1117. * Error code indicating the result was not found in the cache.
  1118. */
  1119. static CACHE_MISS: 120;
  1120. /**
  1121. * Error code indicating that an invalid key was used in a nested
  1122. * JSONObject.
  1123. */
  1124. static INVALID_NESTED_KEY: 121;
  1125. /**
  1126. * Error code indicating that an invalid filename was used for AVFile.
  1127. * A valid file name contains only a-zA-Z0-9_. characters and is between 1
  1128. * and 128 characters.
  1129. */
  1130. static INVALID_FILE_NAME: 122;
  1131. /**
  1132. * Error code indicating an invalid ACL was provided.
  1133. */
  1134. static INVALID_ACL: 123;
  1135. /**
  1136. * Error code indicating that the request timed out on the server. Typically
  1137. * this indicates that the request is too expensive to run.
  1138. */
  1139. static TIMEOUT: 124;
  1140. /**
  1141. * Error code indicating that the email address was invalid.
  1142. */
  1143. static INVALID_EMAIL_ADDRESS: 125;
  1144. /**
  1145. * Error code indicating a missing content type.
  1146. */
  1147. static MISSING_CONTENT_TYPE: 126;
  1148. /**
  1149. * Error code indicating a missing content length.
  1150. */
  1151. static MISSING_CONTENT_LENGTH: 127;
  1152. /**
  1153. * Error code indicating an invalid content length.
  1154. */
  1155. static INVALID_CONTENT_LENGTH: 128;
  1156. /**
  1157. * Error code indicating a file that was too large.
  1158. */
  1159. static FILE_TOO_LARGE: 129;
  1160. /**
  1161. * Error code indicating an error saving a file.
  1162. */
  1163. static FILE_SAVE_ERROR: 130;
  1164. /**
  1165. * Error code indicating an error deleting a file.
  1166. */
  1167. static FILE_DELETE_ERROR: 153;
  1168. /**
  1169. * Error code indicating that a unique field was given a value that is
  1170. * already taken.
  1171. */
  1172. static DUPLICATE_VALUE: 137;
  1173. /**
  1174. * Error code indicating that a role's name is invalid.
  1175. */
  1176. static INVALID_ROLE_NAME: 139;
  1177. /**
  1178. * Error code indicating that an application quota was exceeded. Upgrade to
  1179. * resolve.
  1180. */
  1181. static EXCEEDED_QUOTA: 140;
  1182. /**
  1183. * Error code indicating that a Cloud Code script failed.
  1184. */
  1185. static SCRIPT_FAILED: 141;
  1186. /**
  1187. * Error code indicating that a Cloud Code validation failed.
  1188. */
  1189. static VALIDATION_ERROR: 142;
  1190. /**
  1191. * Error code indicating that invalid image data was provided.
  1192. */
  1193. static INVALID_IMAGE_DATA: 150;
  1194. /**
  1195. * Error code indicating an unsaved file.
  1196. */
  1197. static UNSAVED_FILE_ERROR: 151;
  1198. /**
  1199. * Error code indicating an invalid push time.
  1200. */
  1201. static INVALID_PUSH_TIME_ERROR: 152;
  1202. /**
  1203. * Error code indicating that the username is missing or empty.
  1204. */
  1205. static USERNAME_MISSING: 200;
  1206. /**
  1207. * Error code indicating that the password is missing or empty.
  1208. */
  1209. static PASSWORD_MISSING: 201;
  1210. /**
  1211. * Error code indicating that the username has already been taken.
  1212. */
  1213. static USERNAME_TAKEN: 202;
  1214. /**
  1215. * Error code indicating that the email has already been taken.
  1216. */
  1217. static EMAIL_TAKEN: 203;
  1218. /**
  1219. * Error code indicating that the email is missing, but must be specified.
  1220. */
  1221. static EMAIL_MISSING: 204;
  1222. /**
  1223. * Error code indicating that a user with the specified email was not found.
  1224. */
  1225. static EMAIL_NOT_FOUND: 205;
  1226. /**
  1227. * Error code indicating that a user object without a valid session could
  1228. * not be altered.
  1229. */
  1230. static SESSION_MISSING: 206;
  1231. /**
  1232. * Error code indicating that a user can only be created through signup.
  1233. */
  1234. static MUST_CREATE_USER_THROUGH_SIGNUP: 207;
  1235. /**
  1236. * Error code indicating that an an account being linked is already linked
  1237. * to another user.
  1238. */
  1239. static ACCOUNT_ALREADY_LINKED: 208;
  1240. /**
  1241. * Error code indicating that a user cannot be linked to an account because
  1242. * that account's id could not be found.
  1243. */
  1244. static LINKED_ID_MISSING: 250;
  1245. /**
  1246. * Error code indicating that a user with a linked (e.g. Facebook) account
  1247. * has an invalid session.
  1248. */
  1249. static INVALID_LINKED_SESSION: 251;
  1250. /**
  1251. * Error code indicating that a service being linked (e.g. Facebook or
  1252. * Twitter) is unsupported.
  1253. */
  1254. static UNSUPPORTED_SERVICE: 252;
  1255. /**
  1256. * Error code indicating a real error code is unavailable because
  1257. * we had to use an XDomainRequest object to allow CORS requests in
  1258. * Internet Explorer, which strips the body from HTTP responses that have
  1259. * a non-2XX status code.
  1260. */
  1261. static X_DOMAIN_REQUEST: 602;
  1262. }
  1263. /**
  1264. * @class
  1265. * A AV.Op is an atomic operation that can be applied to a field in a
  1266. * AV.Object. For example, calling <code>object.set("foo", "bar")</code>
  1267. * is an example of a AV.Op.Set. Calling <code>object.unset("foo")</code>
  1268. * is a AV.Op.Unset. These operations are stored in a AV.Object and
  1269. * sent to the server as part of <code>object.save()</code> operations.
  1270. * Instances of AV.Op should be immutable.
  1271. *
  1272. * You should not create subclasses of AV.Op or instantiate AV.Op
  1273. * directly.
  1274. */
  1275. export namespace Op {
  1276. interface BaseOperation extends IBaseObject {
  1277. objects(): any[];
  1278. }
  1279. interface Add extends BaseOperation {}
  1280. interface AddUnique extends BaseOperation {}
  1281. interface Increment extends IBaseObject {
  1282. amount: number;
  1283. }
  1284. interface Relation extends IBaseObject {
  1285. added(): Object[];
  1286. removed: Object[];
  1287. }
  1288. interface Set extends IBaseObject {
  1289. value(): any;
  1290. }
  1291. interface Unset extends IBaseObject {}
  1292. }
  1293. /**
  1294. * Contains functions to deal with Push in AV
  1295. * @name AV.Push
  1296. * @namespace
  1297. */
  1298. export namespace Push {
  1299. function send<T>(data: PushData, options?: AuthOptions): Promise<T>;
  1300. interface PushData {
  1301. prod?: 'dev' | 'prod';
  1302. channels?: string[];
  1303. push_time?: Date;
  1304. expiration_time?: Date;
  1305. expiration_interval?: number;
  1306. flow_control?: number;
  1307. where?: Query<Installation>;
  1308. cql?: string;
  1309. data?: any;
  1310. alert?: string;
  1311. badge?: string;
  1312. sound?: string;
  1313. title?: string;
  1314. }
  1315. }
  1316. export namespace Cloud {
  1317. function run(name: string, data?: any, options?: AuthOptions): Promise<any>;
  1318. function rpc(name: string, data?: any, options?: AuthOptions): Promise<any>;
  1319. function useMasterKey(): void;
  1320. function requestSmsCode(
  1321. data:
  1322. | string
  1323. | {
  1324. mobilePhoneNumber: string;
  1325. template?: string;
  1326. sign?: string;
  1327. smsType?: 'sms' | 'voice';
  1328. },
  1329. options?: SMSAuthOptions
  1330. ): Promise<void>;
  1331. function verifySmsCode(code: string, phone: string): Promise<void>;
  1332. function requestCaptcha(
  1333. options?: CaptchaOptions,
  1334. authOptions?: AuthOptions
  1335. ): Promise<Captcha>;
  1336. function verifyCaptcha(code: string, captchaToken: string): Promise<void>;
  1337. function getServerDate(): Promise<Date>;
  1338. }
  1339. export class Status {
  1340. id?: string;
  1341. createdAt?: Date;
  1342. updatedAt?: Date;
  1343. messageId?: number;
  1344. inboxType: string;
  1345. constructor(imageUrl?: string | null, message?: string | null);
  1346. constructor(data: Record<string, any>);
  1347. static sendStatusToFollowers(
  1348. status: Status,
  1349. options?: AuthOptions
  1350. ): Promise<Status>;
  1351. static sendPrivateStatus(
  1352. status: Status,
  1353. target: string,
  1354. options?: AuthOptions
  1355. ): Promise<Status>;
  1356. static countUnreadStatuses(
  1357. owner: User,
  1358. inboxType?: string,
  1359. options?: AuthOptions
  1360. ): Promise<{ total: number; unread: number }>;
  1361. static resetUnreadCount(
  1362. owner: User,
  1363. inboxType?: string,
  1364. options?: AuthOptions
  1365. ): Promise<any>;
  1366. static statusQuery(source?: User): Query<Object>;
  1367. static inboxQuery(owner?: User, inboxType?: string): InboxQuery;
  1368. get(key: string): any;
  1369. set(key: string, value: any): this;
  1370. destroy(options?: AuthOptions): Promise<any>;
  1371. toObject(): Object;
  1372. send(options?: AuthOptions): Promise<this>;
  1373. }
  1374. // @ts-ignore
  1375. export class InboxQuery extends Query<Status> {
  1376. sinceId(id: number): this;
  1377. maxId(id: number): this;
  1378. owner(owner: User): this;
  1379. inboxType(type: string): this;
  1380. }
  1381. interface ServerURLs {
  1382. api?: string;
  1383. engine?: string;
  1384. stats?: string;
  1385. push?: string;
  1386. rtm?: string;
  1387. }
  1388. export function init(options: {
  1389. appId: string;
  1390. appKey: string;
  1391. masterKey?: string;
  1392. hookKey?: string;
  1393. region?: string;
  1394. production?: boolean;
  1395. serverURL?: string | ServerURLs;
  1396. serverURLs?: string | ServerURLs;
  1397. disableCurrentUser?: boolean;
  1398. realtime?: Realtime;
  1399. }): void;
  1400. export function setServerURL(urls: string | ServerURLs): void;
  1401. export function setServerURLs(urls: string | ServerURLs): void;
  1402. export function setProduction(production: boolean): void;
  1403. export function setRequestTimeout(ms: number): void;
  1404. export function parseJSON(json: any): Object | File | any;
  1405. export function parse(text: string): Object | File | any;
  1406. export function stringify(target: Object | File | any): string | undefined;
  1407. export function request(options: {
  1408. method: string;
  1409. path: string;
  1410. query?: object;
  1411. data?: object;
  1412. authOptions?: AuthOptions;
  1413. service?: string;
  1414. version?: string;
  1415. }): Promise<any>;
  1416. export namespace debug {
  1417. function enable(): void;
  1418. function enable(namespaces: string): void;
  1419. function disable(): string;
  1420. }
  1421. export function setAdapters(adapters: Partial<Adapters>): void;