parse 8.1.1-alpha.2 → 8.1.1-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,24 +1,22 @@
1
1
  import ParseGeoPoint from './ParseGeoPoint';
2
2
  import ParseObject from './ParseObject';
3
3
  import type LiveQuerySubscription from './LiveQuerySubscription';
4
- import type { FullOptions } from './RESTController';
5
- import type { Pointer } from './ParseObject';
6
- type BatchOptions = FullOptions & {
4
+ import type { BaseRequestOptions } from './RESTController';
5
+ import type { Pointer, BaseAttributes } from './ParseObject';
6
+ export interface BatchOptions extends BaseRequestOptions {
7
7
  batchSize?: number;
8
- useMasterKey?: boolean;
9
- useMaintenanceKey?: boolean;
10
- sessionToken?: string;
11
- context?: Record<string, any>;
12
8
  json?: boolean;
13
- };
9
+ }
14
10
  export type WhereClause = Record<string, any>;
15
- interface QueryOptions {
16
- useMasterKey?: boolean;
17
- sessionToken?: string;
18
- context?: Record<string, any>;
11
+ export interface QueryOptions extends BaseRequestOptions {
19
12
  json?: boolean;
20
13
  }
21
- interface FullTextQueryOptions {
14
+ export type FindOptions = QueryOptions;
15
+ /** CountOptions - no json since count() returns a number, not objects */
16
+ export type CountOptions = BaseRequestOptions;
17
+ export type GetOptions = QueryOptions;
18
+ export type FirstOptions = QueryOptions;
19
+ export interface FullTextOptions {
22
20
  language?: string;
23
21
  caseSensitive?: boolean;
24
22
  diacriticSensitive?: boolean;
@@ -41,11 +39,6 @@ export interface QueryJSON {
41
39
  subqueryReadPreference?: string;
42
40
  comment?: string;
43
41
  }
44
- interface BaseAttributes {
45
- createdAt: Date;
46
- objectId: string;
47
- updatedAt: Date;
48
- }
49
42
  /**
50
43
  * Creates a new parse Parse.Query for the given Parse.Object subclass.
51
44
  *
@@ -209,7 +202,7 @@ declare class ParseQuery<T extends ParseObject = ParseObject> {
209
202
  * @returns {Promise} A promise that is resolved with the result when
210
203
  * the query completes.
211
204
  */
212
- get(objectId: string, options?: QueryOptions): Promise<T>;
205
+ get(objectId: string, options?: GetOptions): Promise<T>;
213
206
  /**
214
207
  * Retrieves a list of ParseObjects that satisfy this query.
215
208
  *
@@ -225,7 +218,7 @@ declare class ParseQuery<T extends ParseObject = ParseObject> {
225
218
  * @returns {Promise} A promise that is resolved with the results when
226
219
  * the query completes.
227
220
  */
228
- find(options?: QueryOptions): Promise<T[]>;
221
+ find(options?: FindOptions): Promise<T[]>;
229
222
  /**
230
223
  * Retrieves a complete list of ParseObjects that satisfy this query.
231
224
  * Using `eachBatch` under the hood to fetch all the valid objects.
@@ -257,10 +250,7 @@ declare class ParseQuery<T extends ParseObject = ParseObject> {
257
250
  * @returns {Promise} A promise that is resolved with the count when
258
251
  * the query completes.
259
252
  */
260
- count(options?: {
261
- useMasterKey?: boolean;
262
- sessionToken?: string;
263
- }): Promise<number>;
253
+ count(options?: CountOptions): Promise<number>;
264
254
  /**
265
255
  * Executes a distinct query and returns unique values
266
256
  *
@@ -291,7 +281,7 @@ declare class ParseQuery<T extends ParseObject = ParseObject> {
291
281
  * @returns {Promise} A promise that is resolved with the object when
292
282
  * the query completes.
293
283
  */
294
- first(options?: QueryOptions): Promise<T | undefined>;
284
+ first(options?: FirstOptions): Promise<T | undefined>;
295
285
  /**
296
286
  * Iterates over objects matching a query, calling a callback for each batch.
297
287
  * If the callback returns a promise, the iteration will not continue until
@@ -625,7 +615,7 @@ declare class ParseQuery<T extends ParseObject = ParseObject> {
625
615
  * @param {boolean} options.diacriticSensitive A boolean flag to enable or disable diacritic sensitive search.
626
616
  * @returns {Parse.Query} Returns the query, so you can chain this call.
627
617
  */
628
- fullText<K extends keyof T['attributes'] | keyof BaseAttributes>(key: K, value: string, options?: FullTextQueryOptions): this;
618
+ fullText<K extends keyof T['attributes'] | keyof BaseAttributes>(key: K, value: string, options?: FullTextOptions): this;
629
619
  /**
630
620
  * Method to sort the full text search by text score
631
621
  *
@@ -7,22 +7,24 @@ import type ParseRelation from './ParseRelation';
7
7
  import type { PermissionsMap } from './ParseCLP';
8
8
  import type { Pointer } from './ParseObject';
9
9
  type Bytes = string;
10
- type TYPE = 'String' | 'Number' | 'Bytes' | 'Boolean' | 'Date' | 'File' | 'GeoPoint' | 'Polygon' | 'Array' | 'Object' | 'Pointer' | 'Relation';
11
- type AttrType<T extends ParseObject, V> = Extract<{
10
+ export type FieldType = TYPE;
11
+ export type TYPE = 'String' | 'Number' | 'Bytes' | 'Boolean' | 'Date' | 'File' | 'GeoPoint' | 'Polygon' | 'Array' | 'Object' | 'Pointer' | 'Relation';
12
+ export type AttrType<T extends ParseObject, V> = Extract<{
12
13
  [K in keyof T['attributes']]: T['attributes'][K] extends V ? K : never;
13
14
  }[keyof T['attributes']], string>;
14
- interface FieldOptions<T extends string | number | boolean | Bytes | Date | ParseFile | ParseGeoPoint | ParsePolygon | any[] | object | Pointer | ParseRelation = any> {
15
+ export type SupportedFieldTypes = string | number | boolean | Bytes | Date | ParseFile | ParseGeoPoint | ParsePolygon | any[] | object | Pointer | ParseRelation;
16
+ export interface FieldOptions<T extends SupportedFieldTypes = any> {
15
17
  required?: boolean | undefined;
16
18
  defaultValue?: T | undefined;
17
19
  targetClass?: string | undefined;
18
20
  }
19
- type Index = Record<string, number | string>;
20
- interface CLPField {
21
+ export type Index = Record<string, number | string>;
22
+ export interface CLPField {
21
23
  '*'?: boolean | undefined;
22
24
  requiresAuthentication?: boolean | undefined;
23
25
  [userIdOrRoleName: string]: boolean | undefined;
24
26
  }
25
- interface CLP {
27
+ export interface CLP {
26
28
  find?: CLPField | undefined;
27
29
  get?: CLPField | undefined;
28
30
  count?: CLPField | undefined;
@@ -34,7 +36,7 @@ interface CLP {
34
36
  writeUserFields?: string[] | undefined;
35
37
  protectedFields?: Record<string, string[]>;
36
38
  }
37
- interface RestSchema {
39
+ export interface RestSchema {
38
40
  className: string;
39
41
  fields: Record<string, {
40
42
  type: string;
@@ -10,6 +10,10 @@ export interface AuthProvider {
10
10
  getAuthType(): string;
11
11
  deauthenticate?(): void;
12
12
  }
13
+ export interface SignUpOptions {
14
+ useMasterKey?: boolean;
15
+ installationId?: string;
16
+ }
13
17
  /**
14
18
  * <p>A Parse.User object is a local representation of a user persisted to the
15
19
  * Parse cloud. This class is a subclass of a Parse.Object, and retains the
@@ -194,7 +198,7 @@ declare class ParseUser<T extends Attributes = Attributes> extends ParseObject<T
194
198
  * @returns {Promise} A promise that is fulfilled when the signup
195
199
  * finishes.
196
200
  */
197
- signUp(attrs?: Attributes | null, options?: FullOptions & {
201
+ signUp(attrs?: Attributes | null, options?: SignUpOptions & {
198
202
  context?: Attributes;
199
203
  }): Promise<ParseUser>;
200
204
  /**
package/types/Push.d.ts CHANGED
@@ -10,6 +10,8 @@ export interface PushData {
10
10
  data?: any;
11
11
  channels?: string[];
12
12
  }
13
+ /** Options for Push.send operation */
14
+ export type SendOptions = FullOptions;
13
15
  /**
14
16
  * Contains functions to deal with Push in Parse.
15
17
  *
@@ -1,3 +1,11 @@
1
+ /** Base options for all Parse requests that go through _getRequestOptions */
2
+ export interface BaseRequestOptions {
3
+ useMasterKey?: boolean;
4
+ useMaintenanceKey?: boolean;
5
+ sessionToken?: string;
6
+ installationId?: string;
7
+ context?: Record<string, unknown>;
8
+ }
1
9
  export interface RequestOptions {
2
10
  useMasterKey?: boolean;
3
11
  useMaintenanceKey?: boolean;
package/types/index.d.ts CHANGED
@@ -32,9 +32,15 @@ import Schema from './ParseSchema';
32
32
  import Session from './ParseSession';
33
33
  import Storage from './Storage';
34
34
  import User from './ParseUser';
35
+ import LiveQuerySubscription from './LiveQuerySubscription';
35
36
 
36
- export type { AuthProvider, AuthData } from './ParseUser';
37
- export type { Pointer } from './ParseObject';
37
+ export type { AuthProvider, AuthData, SignUpOptions } from './ParseUser';
38
+ export type { Pointer, Attributes, BaseAttributes, JSONBaseAttributes, ObjectStatic, ObjectConstructor, FetchOptions, SaveOptions, SetOptions, DestroyOptions, DestroyAllOptions, SaveAllOptions, FetchAllOptions, Encode, ToJSON } from './ParseObject';
39
+ export type { PushData, SendOptions } from './Push';
40
+ export type { FullOptions, RequestOptions } from './RESTController';
41
+ export type { RestSchema, TYPE } from './ParseSchema';
42
+ export type { FindOptions, QueryOptions, QueryJSON, WhereClause, FullTextOptions, BatchOptions, CountOptions, GetOptions, FirstOptions } from './ParseQuery';
43
+ export { LiveQuerySubscription };
38
44
  export {
39
45
  ACL,
40
46
  Analytics,
@@ -64,3 +70,42 @@ export {
64
70
  IndexedDB,
65
71
  Hooks,
66
72
  };
73
+
74
+ // ============================================================================
75
+ // Namespace re-exports for backward compatibility
76
+ // These enable Parse.Object.FetchOptions, Parse.Query.FindOptions etc.
77
+ // ============================================================================
78
+
79
+ export namespace Object {
80
+ export type DestroyOptions = import('./ParseObject').DestroyOptions;
81
+ export type DestroyAllOptions = import('./ParseObject').DestroyAllOptions;
82
+ export type FetchOptions = import('./ParseObject').FetchOptions;
83
+ export type FetchAllOptions = import('./ParseObject').FetchAllOptions;
84
+ export type SaveOptions = import('./ParseObject').SaveOptions;
85
+ export type SaveAllOptions = import('./ParseObject').SaveAllOptions;
86
+ export type SetOptions = import('./ParseObject').SetOptions;
87
+ export type Encode<T> = import('./ParseObject').Encode<T>;
88
+ export type ToJSON<T> = import('./ParseObject').ToJSON<T>;
89
+ }
90
+
91
+ export namespace Query {
92
+ export type FindOptions = import('./ParseQuery').FindOptions;
93
+ export type QueryOptions = import('./ParseQuery').QueryOptions;
94
+ export type FullTextOptions = import('./ParseQuery').FullTextOptions;
95
+ export type BatchOptions = import('./ParseQuery').BatchOptions;
96
+ export type CountOptions = import('./ParseQuery').CountOptions;
97
+ export type GetOptions = import('./ParseQuery').GetOptions;
98
+ export type FirstOptions = import('./ParseQuery').FirstOptions;
99
+ }
100
+
101
+ export namespace Schema {
102
+ export type TYPE = import('./ParseSchema').TYPE;
103
+ export type FieldType = import('./ParseSchema').FieldType;
104
+ export type FieldOptions<
105
+ T extends import('./ParseSchema').SupportedFieldTypes = any
106
+ > = import('./ParseSchema').FieldOptions<T>;
107
+ export type Index = import('./ParseSchema').Index;
108
+ export type CLP = import('./ParseSchema').CLP;
109
+ export type CLPField = import('./ParseSchema').CLPField;
110
+ export type AttrType<T extends import('./ParseObject').default, V> = import('./ParseSchema').AttrType<T, V>;
111
+ }
package/types/tests.ts CHANGED
@@ -633,6 +633,21 @@ async function test_cloud_functions() {
633
633
  }
634
634
  });
635
635
 
636
+ ParseNode.Cloud.beforeSave('MyCustomClass', (request): void => {
637
+ request.object;
638
+ });
639
+
640
+ // Tests to allow for Parse.Object subclasses with non-optional constructor params.
641
+ class ArgObject extends Parse.Object<{ a: string }> {
642
+ constructor(arg: { a: string }) {
643
+ super('ArgObject', arg);
644
+ }
645
+ }
646
+ ParseNode.Cloud.beforeSave(ArgObject, request => {
647
+ // $ExpectType ArgObject
648
+ request.object;
649
+ });
650
+
636
651
  ParseNode.Cloud.beforeFind('MyCustomClass', request => {
637
652
  request.query;
638
653
  request.user;
@@ -2355,6 +2370,7 @@ function testEventuallyQueue() {
2355
2370
  }
2356
2371
  }
2357
2372
 
2373
+ // TODO: Add missing LiveQuery types (LiveQuerySubscription, etc.)
2358
2374
  function LiveQueryEvents() {
2359
2375
  function testLiveQueryEvents() {
2360
2376
  Parse.LiveQuery.on('open', () => {});
@@ -2383,3 +2399,89 @@ function testInitialize() {
2383
2399
  // Node - 1 param (should also work since javaScriptKey is optional in node)
2384
2400
  ParseNode.initialize('appId');
2385
2401
  }
2402
+ // Test Parse.* and namespace type exports
2403
+ async function test_type_exports() {
2404
+ // Parse.Object.* namespace
2405
+ const objDestroyOpts: Parse.Object.DestroyOptions = { useMasterKey: true, sessionToken: 'token' };
2406
+ const objDestroyAllOpts: Parse.Object.DestroyAllOptions = { batchSize: 100, useMasterKey: true };
2407
+ const objFetchOpts: Parse.Object.FetchOptions = { useMasterKey: true, include: ['rel'] };
2408
+ const objFetchAllOpts: Parse.Object.FetchAllOptions = { useMasterKey: true };
2409
+ const objSaveOpts: Parse.Object.SaveOptions = { useMasterKey: true, cascadeSave: false, context: {} };
2410
+ const objSaveAllOpts: Parse.Object.SaveAllOptions = { batchSize: 50, useMasterKey: true };
2411
+ const objSetOpts: Parse.Object.SetOptions = { ignoreValidation: true };
2412
+ type ObjEncode = Parse.Object.Encode<Date>;
2413
+ type ObjToJSON = Parse.Object.ToJSON<{ name: string }>;
2414
+
2415
+ // Parse.Query.* namespace
2416
+ const queryOpts: Parse.Query.QueryOptions = { useMasterKey: true, sessionToken: 'token', json: true };
2417
+ const queryFindOpts: Parse.Query.FindOptions = { useMasterKey: true, context: {} };
2418
+ const queryBatchOpts: Parse.Query.BatchOptions = { batchSize: 100, useMasterKey: true };
2419
+ const queryFullTextOpts: Parse.Query.FullTextOptions = { language: 'en', caseSensitive: false };
2420
+
2421
+ // Parse.Schema.* namespace
2422
+ const schemaTypes: Parse.Schema.TYPE[] = ['String', 'Number', 'Boolean', 'Date', 'File', 'GeoPoint', 'Polygon', 'Array', 'Object', 'Pointer', 'Relation', 'Bytes'];
2423
+
2424
+ // Direct Parse.* exports
2425
+ const destroyOpts: Parse.DestroyOptions = { useMasterKey: true };
2426
+ const fetchOpts: Parse.FetchOptions = { useMasterKey: true, include: ['rel'] };
2427
+ const saveOpts: Parse.SaveOptions = { useMasterKey: true, cascadeSave: true };
2428
+ const setOpts: Parse.SetOptions = { ignoreValidation: false };
2429
+ const destroyAllOpts: Parse.DestroyAllOptions = { batchSize: 100 };
2430
+ const saveAllOpts: Parse.SaveAllOptions = { batchSize: 50 };
2431
+ const fetchAllOpts: Parse.FetchAllOptions = { useMasterKey: true };
2432
+ const findOpts: Parse.FindOptions = { useMasterKey: true, json: true };
2433
+ const batchOpts: Parse.BatchOptions = { batchSize: 100 };
2434
+ const fullTextOpts: Parse.FullTextOptions = { language: 'en' };
2435
+ const typeVal: Parse.TYPE = 'String';
2436
+ type DirectEncode = Parse.Encode<Date>;
2437
+ type DirectToJSON = Parse.ToJSON<{ x: number }>;
2438
+
2439
+ // Core types
2440
+ const pointer: Parse.Pointer = { __type: 'Pointer', className: 'Test', objectId: 'abc' };
2441
+ const attrs: Parse.Attributes = { score: 100 };
2442
+ const baseAttrs: Parse.BaseAttributes = { createdAt: new Date(), updatedAt: new Date(), objectId: 'abc' };
2443
+ const jsonBaseAttrs: Parse.JSONBaseAttributes = { createdAt: '2023-01-01T00:00:00Z', updatedAt: '2023-01-01T00:00:00Z', objectId: 'abc' };
2444
+ const whereClause: Parse.WhereClause = { score: { $gt: 100 } };
2445
+ const queryJson: Parse.QueryJSON = { where: {}, limit: 10 };
2446
+ const fullOpts: Parse.FullOptions = { useMasterKey: true };
2447
+ const reqOpts: Parse.RequestOptions = { useMasterKey: true, batchSize: 50 };
2448
+ const authProvider: Parse.AuthProvider = { authenticate: () => {}, getAuthType: () => 'custom', restoreAuthentication: () => true };
2449
+ const authData: Parse.AuthData = { id: 'user-id' };
2450
+ const signUpOpts: Parse.SignUpOptions = { useMasterKey: true };
2451
+ const restSchema: Parse.RestSchema = { className: 'Test', fields: {}, classLevelPermissions: {} };
2452
+ const pushData: Parse.PushData = { channels: ['news'], data: { alert: 'Hello' } };
2453
+ const sendOpts: Parse.SendOptions = { useMasterKey: true };
2454
+ const cloudRunOpts: Parse.Cloud.RunOptions = { useMasterKey: true, context: {} };
2455
+ const subscription: Parse.LiveQuerySubscription = await new Parse.Query('Test').subscribe();
2456
+
2457
+ class MyClass extends Parse.Object {
2458
+ constructor() {
2459
+ super('MyClass');
2460
+ }
2461
+ }
2462
+ // ObjectStatic with generic subclasses
2463
+ const objectStatic: Parse.ObjectStatic = MyClass;
2464
+ function doCreateWithoutData<T extends Parse.Object>(clz: Parse.ObjectStatic<T>, id: string): T {
2465
+ return clz.createWithoutData(id);
2466
+ }
2467
+ // $ExpectType MyClass
2468
+ const myClsObj = doCreateWithoutData(MyClass, '1');
2469
+
2470
+ // Verify types work with actual methods
2471
+ const obj = new Parse.Object('Test');
2472
+ const query = new Parse.Query('Test');
2473
+
2474
+ await obj.save(null, saveOpts);
2475
+ await obj.fetch(fetchOpts);
2476
+ await obj.destroy(destroyOpts);
2477
+ obj.set('key', 'value', setOpts);
2478
+ await Parse.Object.saveAll([obj], saveAllOpts);
2479
+ await Parse.Object.destroyAll([obj], destroyAllOpts);
2480
+ await Parse.Object.fetchAll([obj], fetchAllOpts);
2481
+ await query.find(findOpts);
2482
+ await query.first(findOpts);
2483
+ await query.count(findOpts);
2484
+ await query.each(() => {}, batchOpts);
2485
+ await query.eachBatch(() => {}, batchOpts);
2486
+ query.fullText('field', 'term', fullTextOpts);
2487
+ }