@@ -28,7 +28,7 @@ import * as UniqueInstanceStateController from './UniqueInstanceStateController'
2828import unsavedChildren from './unsavedChildren' ;
2929
3030import type { AttributeMap , OpsMap } from './ObjectStateMutations' ;
31- import type { RequestOptions , FullOptions } from './RESTController' ;
31+ import type { RequestOptions , FullOptions , BaseRequestOptions } from './RESTController' ;
3232import type ParseGeoPoint from './ParseGeoPoint' ;
3333import type ParsePolygon from './ParsePolygon' ;
3434
@@ -45,35 +45,63 @@ interface SaveParams {
4545 body : AttributeMap ;
4646}
4747
48- export type SaveOptions = FullOptions & {
48+ export interface SaveOptions extends BaseRequestOptions {
49+ /** If `false`, nested objects will not be saved (default is `true`). */
4950 cascadeSave ?: boolean ;
50- context ?: AttributeMap ;
5151 batchSize ?: number ;
5252 transaction ?: boolean ;
53- } ;
53+ }
5454
55- interface FetchOptions {
56- useMasterKey ?: boolean ;
57- sessionToken ?: string ;
55+ export interface FetchOptions extends BaseRequestOptions {
5856 include ?: string | string [ ] ;
59- context ?: AttributeMap ;
6057}
6158
6259export interface SetOptions {
6360 ignoreValidation ?: boolean ;
6461 unset ?: boolean ;
6562}
6663
64+ export type DestroyOptions = BaseRequestOptions ;
65+
66+ /** Options for destroyAll batch operation */
67+ export interface DestroyAllOptions extends BaseRequestOptions {
68+ /** batchSize: How many objects to yield in each batch (default: 20) */
69+ batchSize ?: number ;
70+ /** Set to true to enable transactions */
71+ transaction ?: boolean ;
72+ }
73+
74+ /** Options for saveAll batch operation */
75+ export interface SaveAllOptions extends BaseRequestOptions {
76+ /** batchSize: How many objects to yield in each batch (default: 20) */
77+ batchSize ?: number ;
78+ /** If `false`, nested objects will not be saved (default is `true`). */
79+ cascadeSave ?: boolean ;
80+ /** Set to true to enable transactions */
81+ transaction ?: boolean ;
82+ }
83+
84+ /** Options for fetchAll batch operation */
85+ export interface FetchAllOptions extends BaseRequestOptions {
86+ include ?: string | string [ ] ;
87+ }
88+
6789export type AttributeKey < T > = Extract < keyof T , string > ;
6890
6991export type Attributes = Record < string , any > ;
7092
71- interface JSONBaseAttributes {
93+ export interface JSONBaseAttributes {
7294 objectId : string ;
7395 createdAt : string ;
7496 updatedAt : string ;
7597}
7698
99+ export interface BaseAttributes {
100+ objectId : string ;
101+ createdAt : Date ;
102+ updatedAt : Date ;
103+ }
104+
77105interface CommonAttributes {
78106 ACL : ParseACL ;
79107}
@@ -82,7 +110,7 @@ type AtomicKey<T> = {
82110 [ K in keyof T ] : NonNullable < T [ K ] > extends any [ ] ? K : never ;
83111} ;
84112
85- type Encode < T > = T extends ParseObject
113+ export type Encode < T > = T extends ParseObject
86114 ? ReturnType < T [ 'toJSON' ] > | Pointer
87115 : T extends ParseACL | ParseGeoPoint | ParsePolygon | ParseRelation | ParseFile
88116 ? ReturnType < T [ 'toJSON' ] >
@@ -96,7 +124,7 @@ type Encode<T> = T extends ParseObject
96124 ? ToJSON < T >
97125 : T ;
98126
99- type ToJSON < T > = {
127+ export type ToJSON < T > = {
100128 [ K in keyof T ] : Encode < T [ K ] > ;
101129} ;
102130
@@ -1481,7 +1509,7 @@ class ParseObject<T extends Attributes = Attributes> {
14811509 * @returns {Promise } A promise that is fulfilled when the destroy
14821510 * completes.
14831511 */
1484- destroy ( options ?: RequestOptions ) : Promise < ParseObject | undefined > {
1512+ destroy ( options ?: DestroyOptions ) : Promise < ParseObject | undefined > {
14851513 if ( ! this . id ) {
14861514 return Promise . resolve ( undefined ) ;
14871515 }
@@ -1637,7 +1665,7 @@ class ParseObject<T extends Attributes = Attributes> {
16371665 * @static
16381666 * @returns {Parse.Object[] }
16391667 */
1640- static fetchAll < T extends ParseObject > ( list : T [ ] , options ?: RequestOptions ) : Promise < T [ ] > {
1668+ static fetchAll < T extends ParseObject > ( list : T [ ] , options ?: FetchAllOptions ) : Promise < T [ ] > {
16411669 const fetchOptions = ParseObject . _getRequestOptions ( options ) ;
16421670 return CoreManager . getObjectController ( ) . fetch ( list , true , fetchOptions ) as Promise < T [ ] > ;
16431671 }
@@ -1748,7 +1776,10 @@ class ParseObject<T extends Attributes = Attributes> {
17481776 * @static
17491777 * @returns {Parse.Object[] }
17501778 */
1751- static fetchAllIfNeeded < T extends ParseObject > ( list : T [ ] , options ?: FetchOptions ) : Promise < T [ ] > {
1779+ static fetchAllIfNeeded < T extends ParseObject > (
1780+ list : T [ ] ,
1781+ options ?: FetchAllOptions
1782+ ) : Promise < T [ ] > {
17521783 const fetchOptions = ParseObject . _getRequestOptions ( options ) ;
17531784 return CoreManager . getObjectController ( ) . fetch ( list , false , fetchOptions ) as Promise < T [ ] > ;
17541785 }
@@ -1824,9 +1855,9 @@ class ParseObject<T extends Attributes = Attributes> {
18241855 * @returns {Promise } A promise that is fulfilled when the destroyAll
18251856 * completes.
18261857 */
1827- static destroyAll ( list : ParseObject [ ] , options ?: SaveOptions ) {
1858+ static destroyAll < T extends ParseObject > ( list : T [ ] , options ?: DestroyAllOptions ) : Promise < T [ ] > {
18281859 const destroyOptions = ParseObject . _getRequestOptions ( options ) ;
1829- return CoreManager . getObjectController ( ) . destroy ( list , destroyOptions ) ;
1860+ return CoreManager . getObjectController ( ) . destroy ( list , destroyOptions ) as Promise < T [ ] > ;
18301861 }
18311862
18321863 /**
@@ -1858,7 +1889,7 @@ class ParseObject<T extends Attributes = Attributes> {
18581889 * @static
18591890 * @returns {Parse.Object[] }
18601891 */
1861- static saveAll < T extends ParseObject [ ] > ( list : T , options ?: SaveOptions ) : Promise < T > {
1892+ static saveAll < T extends ParseObject [ ] > ( list : T , options ?: SaveAllOptions ) : Promise < T > {
18621893 const saveOptions = ParseObject . _getRequestOptions ( options ) ;
18631894 return CoreManager . getObjectController ( ) . save ( list , saveOptions ) as any ;
18641895 }
@@ -2657,4 +2688,41 @@ const DefaultController = {
26572688CoreManager . setParseObject ( ParseObject ) ;
26582689CoreManager . setObjectController ( DefaultController ) ;
26592690
2691+ export interface ObjectStatic < T extends ParseObject = ParseObject > {
2692+ new ( ...args : any [ ] ) : T ;
2693+ createWithoutData ( id : string ) : T ;
2694+ destroyAll < U extends ParseObject > ( list : U [ ] , options ?: DestroyAllOptions ) : Promise < U [ ] > ;
2695+ extend ( className : string | { className : string } , protoProps ?: any , classProps ?: any ) : any ;
2696+ fetchAll < U extends ParseObject > ( list : U [ ] , options ?: FetchAllOptions ) : Promise < U [ ] > ;
2697+ fetchAllIfNeeded < U extends ParseObject > ( list : U [ ] , options ?: FetchAllOptions ) : Promise < U [ ] > ;
2698+ fetchAllIfNeededWithInclude < U extends ParseObject > (
2699+ list : U [ ] ,
2700+ keys : keyof U [ 'attributes' ] | ( keyof U [ 'attributes' ] ) [ ] ,
2701+ options ?: RequestOptions
2702+ ) : Promise < U [ ] > ;
2703+ fetchAllWithInclude < U extends ParseObject > (
2704+ list : U [ ] ,
2705+ keys : keyof U [ 'attributes' ] | ( keyof U [ 'attributes' ] ) [ ] ,
2706+ options ?: RequestOptions
2707+ ) : Promise < U [ ] > ;
2708+ fromJSON ( json : any , override ?: boolean , dirty ?: boolean ) : T ;
2709+ pinAll ( objects : ParseObject [ ] ) : Promise < void > ;
2710+ pinAllWithName ( name : string , objects : ParseObject [ ] ) : Promise < void > ;
2711+ registerSubclass ( className : string , clazz : new ( options ?: any ) => T ) : void ;
2712+ saveAll < U extends ParseObject [ ] > ( list : U , options ?: SaveAllOptions ) : Promise < U > ;
2713+ unPinAll ( objects : ParseObject [ ] ) : Promise < void > ;
2714+ unPinAllObjects ( ) : Promise < void > ;
2715+ unPinAllObjectsWithName ( name : string ) : Promise < void > ;
2716+ unPinAllWithName ( name : string , objects : ParseObject [ ] ) : Promise < void > ;
2717+ }
2718+
2719+ export interface ObjectConstructor extends ObjectStatic {
2720+ new < T extends Attributes > ( className : string , attributes : T , options ?: any ) : ParseObject < T > ;
2721+ new (
2722+ className ?: string | { className : string ; [ attr : string ] : any } ,
2723+ attributes ?: Attributes ,
2724+ options ?: any
2725+ ) : ParseObject ;
2726+ }
2727+
26602728export default ParseObject ;
0 commit comments