parse 8.1.1-alpha.3 → 8.1.1-alpha.5

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.
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
@@ -1888,6 +1888,8 @@ function testQuery() {
1888
1888
  attribute2: number;
1889
1889
  attribute3: AnotherSubClass;
1890
1890
  attribute4: string[];
1891
+ attribute5?: AnotherSubClass[];
1892
+ attribute6?: string[];
1891
1893
  }> {}
1892
1894
  const query = new Parse.Query(MySubClass);
1893
1895
 
@@ -1997,6 +1999,22 @@ function testQuery() {
1997
1999
  // $ExpectType ParseQuery<MySubClass>
1998
2000
  query.equalTo('attribute4', ['a_string_value']);
1999
2001
 
2002
+
2003
+ // Optional object[] (e.g. prop?: ClassName[] ): allow matching a single element (array contains object), and allow matching the full array
2004
+ // $ExpectType ParseQuery<MySubClass>
2005
+ query.equalTo('attribute5', new AnotherSubClass());
2006
+ // $ExpectType ParseQuery<MySubClass>
2007
+ query.equalTo('attribute5', [new AnotherSubClass()]);
2008
+ // Since there is no `$ExpectNotError` thing, this line is instead used to at least prove that there is no regression for type safety for `Array of object` fields
2009
+ // $ExpectError
2010
+ query.equalTo('attribute5', new MySubClass());
2011
+
2012
+ // Optional string[] (e.g. prop?: string[] ): allow matching a single element (array contains string), and allow matching the full array
2013
+ // $ExpectType ParseQuery<MySubClass>
2014
+ query.equalTo('attribute6', 'a_string_value');
2015
+ // $ExpectType ParseQuery<MySubClass>
2016
+ query.equalTo('attribute6', ['a_string_value']);
2017
+
2000
2018
  // $ExpectType ParseQuery<MySubClass>
2001
2019
  query.notEqualTo('attribute4', 'a_string_value');
2002
2020
  // $ExpectType ParseQuery<MySubClass>
@@ -2011,6 +2029,12 @@ function testQuery() {
2011
2029
  // $ExpectError
2012
2030
  query.notEqualTo('attribute4', [5]);
2013
2031
 
2032
+ // Optional string[]: reject invalid element types
2033
+ // $ExpectError
2034
+ query.equalTo('attribute6', 5);
2035
+ // $ExpectError
2036
+ query.notEqualTo('attribute6', 5);
2037
+
2014
2038
  // $ExpectType ParseQuery<MySubClass>
2015
2039
  query.exists('attribute1');
2016
2040
  // $ExpectError
@@ -2370,6 +2394,7 @@ function testEventuallyQueue() {
2370
2394
  }
2371
2395
  }
2372
2396
 
2397
+ // TODO: Add missing LiveQuery types (LiveQuerySubscription, etc.)
2373
2398
  function LiveQueryEvents() {
2374
2399
  function testLiveQueryEvents() {
2375
2400
  Parse.LiveQuery.on('open', () => {});
@@ -2398,3 +2423,89 @@ function testInitialize() {
2398
2423
  // Node - 1 param (should also work since javaScriptKey is optional in node)
2399
2424
  ParseNode.initialize('appId');
2400
2425
  }
2426
+ // Test Parse.* and namespace type exports
2427
+ async function test_type_exports() {
2428
+ // Parse.Object.* namespace
2429
+ const objDestroyOpts: Parse.Object.DestroyOptions = { useMasterKey: true, sessionToken: 'token' };
2430
+ const objDestroyAllOpts: Parse.Object.DestroyAllOptions = { batchSize: 100, useMasterKey: true };
2431
+ const objFetchOpts: Parse.Object.FetchOptions = { useMasterKey: true, include: ['rel'] };
2432
+ const objFetchAllOpts: Parse.Object.FetchAllOptions = { useMasterKey: true };
2433
+ const objSaveOpts: Parse.Object.SaveOptions = { useMasterKey: true, cascadeSave: false, context: {} };
2434
+ const objSaveAllOpts: Parse.Object.SaveAllOptions = { batchSize: 50, useMasterKey: true };
2435
+ const objSetOpts: Parse.Object.SetOptions = { ignoreValidation: true };
2436
+ type ObjEncode = Parse.Object.Encode<Date>;
2437
+ type ObjToJSON = Parse.Object.ToJSON<{ name: string }>;
2438
+
2439
+ // Parse.Query.* namespace
2440
+ const queryOpts: Parse.Query.QueryOptions = { useMasterKey: true, sessionToken: 'token', json: true };
2441
+ const queryFindOpts: Parse.Query.FindOptions = { useMasterKey: true, context: {} };
2442
+ const queryBatchOpts: Parse.Query.BatchOptions = { batchSize: 100, useMasterKey: true };
2443
+ const queryFullTextOpts: Parse.Query.FullTextOptions = { language: 'en', caseSensitive: false };
2444
+
2445
+ // Parse.Schema.* namespace
2446
+ const schemaTypes: Parse.Schema.TYPE[] = ['String', 'Number', 'Boolean', 'Date', 'File', 'GeoPoint', 'Polygon', 'Array', 'Object', 'Pointer', 'Relation', 'Bytes'];
2447
+
2448
+ // Direct Parse.* exports
2449
+ const destroyOpts: Parse.DestroyOptions = { useMasterKey: true };
2450
+ const fetchOpts: Parse.FetchOptions = { useMasterKey: true, include: ['rel'] };
2451
+ const saveOpts: Parse.SaveOptions = { useMasterKey: true, cascadeSave: true };
2452
+ const setOpts: Parse.SetOptions = { ignoreValidation: false };
2453
+ const destroyAllOpts: Parse.DestroyAllOptions = { batchSize: 100 };
2454
+ const saveAllOpts: Parse.SaveAllOptions = { batchSize: 50 };
2455
+ const fetchAllOpts: Parse.FetchAllOptions = { useMasterKey: true };
2456
+ const findOpts: Parse.FindOptions = { useMasterKey: true, json: true };
2457
+ const batchOpts: Parse.BatchOptions = { batchSize: 100 };
2458
+ const fullTextOpts: Parse.FullTextOptions = { language: 'en' };
2459
+ const typeVal: Parse.TYPE = 'String';
2460
+ type DirectEncode = Parse.Encode<Date>;
2461
+ type DirectToJSON = Parse.ToJSON<{ x: number }>;
2462
+
2463
+ // Core types
2464
+ const pointer: Parse.Pointer = { __type: 'Pointer', className: 'Test', objectId: 'abc' };
2465
+ const attrs: Parse.Attributes = { score: 100 };
2466
+ const baseAttrs: Parse.BaseAttributes = { createdAt: new Date(), updatedAt: new Date(), objectId: 'abc' };
2467
+ const jsonBaseAttrs: Parse.JSONBaseAttributes = { createdAt: '2023-01-01T00:00:00Z', updatedAt: '2023-01-01T00:00:00Z', objectId: 'abc' };
2468
+ const whereClause: Parse.WhereClause = { score: { $gt: 100 } };
2469
+ const queryJson: Parse.QueryJSON = { where: {}, limit: 10 };
2470
+ const fullOpts: Parse.FullOptions = { useMasterKey: true };
2471
+ const reqOpts: Parse.RequestOptions = { useMasterKey: true, batchSize: 50 };
2472
+ const authProvider: Parse.AuthProvider = { authenticate: () => {}, getAuthType: () => 'custom', restoreAuthentication: () => true };
2473
+ const authData: Parse.AuthData = { id: 'user-id' };
2474
+ const signUpOpts: Parse.SignUpOptions = { useMasterKey: true };
2475
+ const restSchema: Parse.RestSchema = { className: 'Test', fields: {}, classLevelPermissions: {} };
2476
+ const pushData: Parse.PushData = { channels: ['news'], data: { alert: 'Hello' } };
2477
+ const sendOpts: Parse.SendOptions = { useMasterKey: true };
2478
+ const cloudRunOpts: Parse.Cloud.RunOptions = { useMasterKey: true, context: {} };
2479
+ const subscription: Parse.LiveQuerySubscription = await new Parse.Query('Test').subscribe();
2480
+
2481
+ class MyClass extends Parse.Object {
2482
+ constructor() {
2483
+ super('MyClass');
2484
+ }
2485
+ }
2486
+ // ObjectStatic with generic subclasses
2487
+ const objectStatic: Parse.ObjectStatic = MyClass;
2488
+ function doCreateWithoutData<T extends Parse.Object>(clz: Parse.ObjectStatic<T>, id: string): T {
2489
+ return clz.createWithoutData(id);
2490
+ }
2491
+ // $ExpectType MyClass
2492
+ const myClsObj = doCreateWithoutData(MyClass, '1');
2493
+
2494
+ // Verify types work with actual methods
2495
+ const obj = new Parse.Object('Test');
2496
+ const query = new Parse.Query('Test');
2497
+
2498
+ await obj.save(null, saveOpts);
2499
+ await obj.fetch(fetchOpts);
2500
+ await obj.destroy(destroyOpts);
2501
+ obj.set('key', 'value', setOpts);
2502
+ await Parse.Object.saveAll([obj], saveAllOpts);
2503
+ await Parse.Object.destroyAll([obj], destroyAllOpts);
2504
+ await Parse.Object.fetchAll([obj], fetchAllOpts);
2505
+ await query.find(findOpts);
2506
+ await query.first(findOpts);
2507
+ await query.count(findOpts);
2508
+ await query.each(() => {}, batchOpts);
2509
+ await query.eachBatch(() => {}, batchOpts);
2510
+ query.fullText('field', 'term', fullTextOpts);
2511
+ }