parse 5.0.0 → 5.1.0-alpha.10

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.
Files changed (139) hide show
  1. package/README.md +13 -0
  2. package/dist/parse.js +1462 -1051
  3. package/dist/parse.min.js +2 -2
  4. package/dist/parse.weapp.js +2361 -1086
  5. package/dist/parse.weapp.min.js +2 -2
  6. package/lib/browser/CoreManager.js +48 -171
  7. package/lib/browser/InstallationController.js +134 -23
  8. package/lib/browser/LiveQueryClient.js +43 -35
  9. package/lib/browser/LiveQuerySubscription.js +15 -5
  10. package/lib/browser/LocalDatastoreController.default.js +248 -0
  11. package/lib/browser/LocalDatastoreController.js +1 -246
  12. package/lib/browser/ObjectStateMutations.js +6 -5
  13. package/lib/browser/OfflineQuery.js +3 -2
  14. package/lib/browser/Parse.js +31 -7
  15. package/lib/browser/ParseACL.js +21 -11
  16. package/lib/browser/ParseFile.js +4 -0
  17. package/lib/browser/ParseHooks.js +2 -0
  18. package/lib/browser/ParseInstallation.js +274 -13
  19. package/lib/browser/ParseLiveQuery.js +32 -23
  20. package/lib/browser/ParseObject.js +45 -45
  21. package/lib/browser/ParseOp.js +21 -7
  22. package/lib/browser/ParseQuery.js +1 -0
  23. package/lib/browser/ParseRelation.js +12 -7
  24. package/lib/browser/ParseRole.js +2 -0
  25. package/lib/browser/ParseSession.js +1 -1
  26. package/lib/browser/ParseUser.js +52 -21
  27. package/lib/browser/RESTController.js +7 -2
  28. package/lib/browser/SingleInstanceStateController.js +2 -4
  29. package/lib/browser/Storage.js +1 -2
  30. package/lib/browser/StorageController.js +3 -0
  31. package/lib/browser/WebSocketController.js +13 -0
  32. package/lib/browser/arrayContainsObject.js +4 -3
  33. package/lib/browser/canBeSerialized.js +6 -4
  34. package/lib/browser/decode.js +8 -5
  35. package/lib/browser/encode.js +6 -4
  36. package/lib/browser/equals.js +4 -3
  37. package/lib/browser/unique.js +3 -2
  38. package/lib/browser/unsavedChildren.js +4 -2
  39. package/lib/browser/uuid.js +11 -5
  40. package/lib/node/CoreManager.js +48 -171
  41. package/lib/node/InstallationController.js +65 -21
  42. package/lib/node/LiveQueryClient.js +2 -5
  43. package/lib/node/LiveQuerySubscription.js +2 -2
  44. package/lib/node/LocalDatastoreController.default.js +67 -0
  45. package/lib/node/LocalDatastoreController.js +1 -65
  46. package/lib/node/ObjectStateMutations.js +8 -9
  47. package/lib/node/OfflineQuery.js +3 -2
  48. package/lib/node/Parse.js +31 -7
  49. package/lib/node/ParseACL.js +21 -11
  50. package/lib/node/ParseFile.js +4 -0
  51. package/lib/node/ParseHooks.js +2 -0
  52. package/lib/node/ParseInstallation.js +207 -7
  53. package/lib/node/ParseLiveQuery.js +2 -3
  54. package/lib/node/ParseObject.js +17 -17
  55. package/lib/node/ParseOp.js +21 -7
  56. package/lib/node/ParseQuery.js +1 -0
  57. package/lib/node/ParseRelation.js +14 -8
  58. package/lib/node/ParseRole.js +2 -0
  59. package/lib/node/ParseSession.js +1 -1
  60. package/lib/node/ParseUser.js +21 -19
  61. package/lib/node/RESTController.js +6 -2
  62. package/lib/node/SingleInstanceStateController.js +2 -8
  63. package/lib/node/Storage.js +1 -2
  64. package/lib/node/StorageController.js +3 -0
  65. package/lib/node/WebSocketController.js +10 -0
  66. package/lib/node/arrayContainsObject.js +4 -3
  67. package/lib/node/canBeSerialized.js +6 -4
  68. package/lib/node/decode.js +9 -5
  69. package/lib/node/encode.js +7 -4
  70. package/lib/node/equals.js +4 -3
  71. package/lib/node/unique.js +3 -2
  72. package/lib/node/unsavedChildren.js +4 -2
  73. package/lib/node/uuid.js +10 -8
  74. package/lib/react-native/CoreManager.js +39 -2
  75. package/lib/react-native/InstallationController.js +77 -9
  76. package/lib/react-native/LiveQueryClient.js +28 -20
  77. package/lib/react-native/LiveQuerySubscription.js +14 -5
  78. package/lib/react-native/LocalDatastoreController.default.js +91 -0
  79. package/lib/react-native/LocalDatastoreController.js +1 -91
  80. package/lib/react-native/ObjectStateMutations.js +6 -5
  81. package/lib/react-native/OfflineQuery.js +3 -2
  82. package/lib/react-native/Parse.js +23 -7
  83. package/lib/react-native/ParseACL.js +19 -11
  84. package/lib/react-native/ParseInstallation.js +115 -10
  85. package/lib/react-native/ParseLiveQuery.js +11 -2
  86. package/lib/react-native/ParseObject.js +36 -36
  87. package/lib/react-native/ParseOp.js +20 -6
  88. package/lib/react-native/ParseQuery.js +1 -0
  89. package/lib/react-native/ParseRelation.js +10 -7
  90. package/lib/react-native/ParseRole.js +2 -0
  91. package/lib/react-native/ParseUser.js +7 -8
  92. package/lib/react-native/RESTController.js +5 -2
  93. package/lib/react-native/SingleInstanceStateController.js +0 -2
  94. package/lib/react-native/Storage.js +1 -2
  95. package/lib/react-native/StorageController.js +1 -0
  96. package/lib/react-native/WebSocketController.js +5 -0
  97. package/lib/react-native/arrayContainsObject.js +3 -2
  98. package/lib/react-native/canBeSerialized.js +5 -3
  99. package/lib/react-native/decode.js +7 -5
  100. package/lib/react-native/encode.js +6 -4
  101. package/lib/react-native/equals.js +4 -3
  102. package/lib/react-native/unique.js +3 -2
  103. package/lib/react-native/unsavedChildren.js +3 -2
  104. package/lib/react-native/uuid.js +9 -4
  105. package/lib/weapp/CoreManager.js +48 -171
  106. package/lib/weapp/InstallationController.js +134 -23
  107. package/lib/weapp/LiveQueryClient.js +43 -35
  108. package/lib/weapp/LiveQuerySubscription.js +15 -5
  109. package/lib/weapp/LocalDatastoreController.default.js +248 -0
  110. package/lib/weapp/LocalDatastoreController.js +1 -246
  111. package/lib/weapp/ObjectStateMutations.js +6 -5
  112. package/lib/weapp/OfflineQuery.js +3 -2
  113. package/lib/weapp/Parse.js +31 -7
  114. package/lib/weapp/ParseACL.js +21 -11
  115. package/lib/weapp/ParseFile.js +4 -0
  116. package/lib/weapp/ParseHooks.js +2 -0
  117. package/lib/weapp/ParseInstallation.js +274 -13
  118. package/lib/weapp/ParseLiveQuery.js +32 -23
  119. package/lib/weapp/ParseObject.js +45 -45
  120. package/lib/weapp/ParseOp.js +21 -7
  121. package/lib/weapp/ParseQuery.js +1 -0
  122. package/lib/weapp/ParseRelation.js +12 -7
  123. package/lib/weapp/ParseRole.js +2 -0
  124. package/lib/weapp/ParseSession.js +1 -1
  125. package/lib/weapp/ParseUser.js +52 -21
  126. package/lib/weapp/RESTController.js +7 -2
  127. package/lib/weapp/SingleInstanceStateController.js +2 -4
  128. package/lib/weapp/Storage.js +1 -2
  129. package/lib/weapp/StorageController.js +3 -0
  130. package/lib/weapp/WebSocketController.js +13 -0
  131. package/lib/weapp/arrayContainsObject.js +4 -3
  132. package/lib/weapp/canBeSerialized.js +6 -4
  133. package/lib/weapp/decode.js +8 -5
  134. package/lib/weapp/encode.js +6 -4
  135. package/lib/weapp/equals.js +4 -3
  136. package/lib/weapp/unique.js +3 -2
  137. package/lib/weapp/unsavedChildren.js +4 -2
  138. package/lib/weapp/uuid.js +12 -5
  139. package/package.json +4 -2
@@ -8,15 +8,16 @@ _Object$defineProperty(exports, "__esModule", {
8
8
  exports.default = canBeSerialized;
9
9
  var _isArray = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array"));
10
10
  var _typeof2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/typeof"));
11
+ var _CoreManager = _interopRequireDefault(require("./CoreManager"));
11
12
  var _ParseFile = _interopRequireDefault(require("./ParseFile"));
12
- var _ParseObject = _interopRequireDefault(require("./ParseObject"));
13
13
  var _ParseRelation = _interopRequireDefault(require("./ParseRelation"));
14
14
  /**
15
15
  * @flow
16
16
  */
17
-
17
+ /*:: import type ParseObject from './ParseObject';*/
18
18
  function canBeSerialized(obj /*: ParseObject*/) /*: boolean*/{
19
- if (!(obj instanceof _ParseObject.default)) {
19
+ var ParseObject = _CoreManager.default.getParseObject();
20
+ if (!(obj instanceof ParseObject)) {
20
21
  return true;
21
22
  }
22
23
  var attributes = obj.attributes;
@@ -35,7 +36,8 @@ function canBeSerializedHelper(value /*: any*/) /*: boolean*/{
35
36
  if (value instanceof _ParseRelation.default) {
36
37
  return true;
37
38
  }
38
- if (value instanceof _ParseObject.default) {
39
+ var ParseObject = _CoreManager.default.getParseObject();
40
+ if (value instanceof ParseObject) {
39
41
  return !!value.id;
40
42
  }
41
43
  if (value instanceof _ParseFile.default) {
@@ -9,16 +9,16 @@ exports.default = decode;
9
9
  var _isArray = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array"));
10
10
  var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
11
11
  var _typeof2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/typeof"));
12
+ var _CoreManager = _interopRequireDefault(require("./CoreManager"));
12
13
  var _ParseACL = _interopRequireDefault(require("./ParseACL"));
13
14
  var _ParseFile = _interopRequireDefault(require("./ParseFile"));
14
15
  var _ParseGeoPoint = _interopRequireDefault(require("./ParseGeoPoint"));
15
16
  var _ParsePolygon = _interopRequireDefault(require("./ParsePolygon"));
16
- var _ParseObject = _interopRequireDefault(require("./ParseObject"));
17
- var _ParseOp = require("./ParseOp");
18
17
  var _ParseRelation = _interopRequireDefault(require("./ParseRelation"));
19
18
  /**
20
19
  * @flow
21
20
  */
21
+
22
22
  // eslint-disable-line no-unused-vars
23
23
 
24
24
  function decode(value /*: any*/) /*: any*/{
@@ -33,13 +33,16 @@ function decode(value /*: any*/) /*: any*/{
33
33
  return dup;
34
34
  }
35
35
  if (typeof value.__op === 'string') {
36
- return (0, _ParseOp.opFromJSON)(value);
36
+ var _CoreManager$getParse = _CoreManager.default.getParseOp(),
37
+ opFromJSON = _CoreManager$getParse.opFromJSON;
38
+ return opFromJSON(value);
37
39
  }
40
+ var ParseObject = _CoreManager.default.getParseObject();
38
41
  if (value.__type === 'Pointer' && value.className) {
39
- return _ParseObject.default.fromJSON(value);
42
+ return ParseObject.fromJSON(value);
40
43
  }
41
44
  if (value.__type === 'Object' && value.className) {
42
- return _ParseObject.default.fromJSON(value);
45
+ return ParseObject.fromJSON(value);
43
46
  }
44
47
  if (value.__type === 'Relation') {
45
48
  // The parent and key fields will be populated by the parent
@@ -13,19 +13,19 @@ var _startsWith = _interopRequireDefault(require("@babel/runtime-corejs3/core-js
13
13
  var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
14
14
  var _isArray = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array"));
15
15
  var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
16
+ var _CoreManager = _interopRequireDefault(require("./CoreManager"));
16
17
  var _ParseACL = _interopRequireDefault(require("./ParseACL"));
17
18
  var _ParseFile = _interopRequireDefault(require("./ParseFile"));
18
19
  var _ParseGeoPoint = _interopRequireDefault(require("./ParseGeoPoint"));
19
20
  var _ParsePolygon = _interopRequireDefault(require("./ParsePolygon"));
20
- var _ParseObject = _interopRequireDefault(require("./ParseObject"));
21
- var _ParseOp = require("./ParseOp");
22
21
  var _ParseRelation = _interopRequireDefault(require("./ParseRelation"));
23
22
  /**
24
23
  * @flow
25
24
  */
26
25
 
27
26
  function encode(value /*: mixed*/, disallowObjects /*: boolean*/, forcePointers /*: boolean*/, seen /*: Array<mixed>*/, offline /*: boolean*/) /*: any*/{
28
- if (value instanceof _ParseObject.default) {
27
+ var ParseObject = _CoreManager.default.getParseObject();
28
+ if (value instanceof ParseObject) {
29
29
  if (disallowObjects) {
30
30
  throw new Error('Parse Objects not allowed here');
31
31
  }
@@ -40,7 +40,9 @@ function encode(value /*: mixed*/, disallowObjects /*: boolean*/, forcePointers
40
40
  seen = (0, _concat.default)(seen).call(seen, seenEntry);
41
41
  return value._toFullJSON(seen, offline);
42
42
  }
43
- if (value instanceof _ParseOp.Op || value instanceof _ParseACL.default || value instanceof _ParseGeoPoint.default || value instanceof _ParsePolygon.default || value instanceof _ParseRelation.default) {
43
+ var _CoreManager$getParse = _CoreManager.default.getParseOp(),
44
+ Op = _CoreManager$getParse.Op;
45
+ if (value instanceof Op || value instanceof _ParseACL.default || value instanceof _ParseGeoPoint.default || value instanceof _ParsePolygon.default || value instanceof _ParseRelation.default) {
44
46
  return value.toJSON();
45
47
  }
46
48
  if (value instanceof _ParseFile.default) {
@@ -9,10 +9,10 @@ exports.default = equals;
9
9
  var _isArray = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array"));
10
10
  var _keys = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/keys"));
11
11
  var _typeof2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/typeof"));
12
+ var _CoreManager = _interopRequireDefault(require("./CoreManager"));
12
13
  var _ParseACL = _interopRequireDefault(require("./ParseACL"));
13
14
  var _ParseFile = _interopRequireDefault(require("./ParseFile"));
14
15
  var _ParseGeoPoint = _interopRequireDefault(require("./ParseGeoPoint"));
15
- var _ParseObject = _interopRequireDefault(require("./ParseObject"));
16
16
  function equals(a, b) {
17
17
  var toString = Object.prototype.toString;
18
18
  if (toString.call(a) === '[object Date]' || toString.call(b) === '[object Date]') {
@@ -41,10 +41,11 @@ function equals(a, b) {
41
41
  }
42
42
  return true;
43
43
  }
44
- if (a instanceof _ParseACL.default || a instanceof _ParseFile.default || a instanceof _ParseGeoPoint.default || a instanceof _ParseObject.default) {
44
+ var ParseObject = _CoreManager.default.getParseObject();
45
+ if (a instanceof _ParseACL.default || a instanceof _ParseFile.default || a instanceof _ParseGeoPoint.default || a instanceof ParseObject) {
45
46
  return a.equals(b);
46
47
  }
47
- if (b instanceof _ParseObject.default) {
48
+ if (b instanceof ParseObject) {
48
49
  if (a.__type === 'Object' || a.__type === 'Pointer') {
49
50
  return a.objectId === b.id && a.className === b.className;
50
51
  }
@@ -9,7 +9,7 @@ exports.default = unique;
9
9
  var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
10
10
  var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
11
11
  var _arrayContainsObject = _interopRequireDefault(require("./arrayContainsObject"));
12
- var _ParseObject = _interopRequireDefault(require("./ParseObject"));
12
+ var _CoreManager = _interopRequireDefault(require("./CoreManager"));
13
13
  /**
14
14
  * @flow
15
15
  */
@@ -17,7 +17,8 @@ var _ParseObject = _interopRequireDefault(require("./ParseObject"));
17
17
  function unique /*:: <T>*/(arr /*: Array<T>*/) /*: Array<T>*/{
18
18
  var uniques = [];
19
19
  (0, _forEach.default)(arr).call(arr, function (value) {
20
- if (value instanceof _ParseObject.default) {
20
+ var ParseObject = _CoreManager.default.getParseObject();
21
+ if (value instanceof ParseObject) {
21
22
  if (!(0, _arrayContainsObject.default)(uniques, value)) {
22
23
  uniques.push(value);
23
24
  }
@@ -11,12 +11,13 @@ var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-st
11
11
  var _isArray = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array"));
12
12
  var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
13
13
  var _typeof2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/typeof"));
14
+ var _CoreManager = _interopRequireDefault(require("./CoreManager"));
14
15
  var _ParseFile = _interopRequireDefault(require("./ParseFile"));
15
- var _ParseObject = _interopRequireDefault(require("./ParseObject"));
16
16
  var _ParseRelation = _interopRequireDefault(require("./ParseRelation"));
17
17
  /**
18
18
  * @flow
19
19
  */
20
+ /*:: import type ParseObject from './ParseObject';*/
20
21
  /*:: type EncounterMap = {
21
22
  objects: { [identifier: string]: ParseObject | boolean },
22
23
  files: Array<ParseFile>,
@@ -51,7 +52,8 @@ function unsavedChildren(obj /*: ParseObject*/, allowDeepUnsaved /*:: ?: boolean
51
52
  return (0, _concat.default)(unsaved).call(unsaved, encountered.files);
52
53
  }
53
54
  function traverse(obj /*: ParseObject*/, encountered /*: EncounterMap*/, shouldThrow /*: boolean*/, allowDeepUnsaved /*: boolean*/) {
54
- if (obj instanceof _ParseObject.default) {
55
+ var ParseObject = _CoreManager.default.getParseObject();
56
+ if (obj instanceof ParseObject) {
55
57
  if (!obj.id && shouldThrow) {
56
58
  throw new Error('Cannot create a pointer to an unsaved Object.');
57
59
  }
@@ -1,7 +1,13 @@
1
1
  "use strict";
2
2
 
3
- var uuid = null;
4
- var _require = require('uuid'),
5
- v4 = _require.v4;
6
- uuid = v4;
7
- module.exports = uuid;
3
+ var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
4
+ _Object$defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _uuid = require("uuid");
9
+ var uuid /*: () => string*/ = null;
10
+ uuid = _uuid.v4;
11
+ module.exports = uuid;
12
+ var _default = uuid;
13
+ exports.default = _default;
@@ -4,176 +4,16 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- /*
8
- * @flow
9
- */
10
- /*:: import type { AttributeMap, ObjectCache, OpsMap, State } from './ObjectStateMutations';*/
11
- /*:: import type ParseFile from './ParseFile';*/
12
- /*:: import type { FileSource } from './ParseFile';*/
13
- /*:: import type { Op } from './ParseOp';*/
14
- /*:: import type ParseObject from './ParseObject';*/
15
- /*:: import type { QueryJSON } from './ParseQuery';*/
16
- /*:: import type ParseUser from './ParseUser';*/
17
- /*:: import type { AuthData } from './ParseUser';*/
18
- /*:: import type { PushData } from './Push';*/
19
- /*:: import type { RequestOptions, FullOptions } from './RESTController';*/
20
- /*:: type AnalyticsController = {
21
- track: (name: string, dimensions: { [key: string]: string }) => Promise,
22
- };*/
23
- /*:: type CloudController = {
24
- run: (name: string, data: mixed, options: RequestOptions) => Promise,
25
- getJobsData: (options: RequestOptions) => Promise,
26
- startJob: (name: string, data: mixed, options: RequestOptions) => Promise,
27
- };*/
28
- /*:: type ConfigController = {
29
- current: () => Promise,
30
- get: () => Promise,
31
- save: (attrs: { [key: string]: any }) => Promise,
32
- };*/
33
- /*:: type CryptoController = {
34
- encrypt: (obj: any, secretKey: string) => string,
35
- decrypt: (encryptedText: string, secretKey: any) => string,
36
- };*/
37
- /*:: type FileController = {
38
- saveFile: (name: string, source: FileSource, options: FullOptions) => Promise,
39
- saveBase64: (name: string, source: FileSource, options: FullOptions) => Promise,
40
- download: (uri: string) => Promise,
41
- };*/
42
- /*:: type InstallationController = {
43
- currentInstallationId: () => Promise,
44
- };*/
45
- /*:: type ObjectController = {
46
- fetch: (
47
- object: ParseObject | Array<ParseObject>,
48
- forceFetch: boolean,
49
- options: RequestOptions
50
- ) => Promise,
51
- save: (object: ParseObject | Array<ParseObject | ParseFile>, options: RequestOptions) => Promise,
52
- destroy: (object: ParseObject | Array<ParseObject>, options: RequestOptions) => Promise,
53
- };*/
54
- /*:: type ObjectStateController = {
55
- getState: (obj: any) => ?State,
56
- initializeState: (obj: any, initial?: State) => State,
57
- removeState: (obj: any) => ?State,
58
- getServerData: (obj: any) => AttributeMap,
59
- setServerData: (obj: any, attributes: AttributeMap) => void,
60
- getPendingOps: (obj: any) => Array<OpsMap>,
61
- setPendingOp: (obj: any, attr: string, op: ?Op) => void,
62
- pushPendingState: (obj: any) => void,
63
- popPendingState: (obj: any) => OpsMap,
64
- mergeFirstPendingState: (obj: any) => void,
65
- getObjectCache: (obj: any) => ObjectCache,
66
- estimateAttribute: (obj: any, attr: string) => mixed,
67
- estimateAttributes: (obj: any) => AttributeMap,
68
- commitServerChanges: (obj: any, changes: AttributeMap) => void,
69
- enqueueTask: (obj: any, task: () => Promise) => Promise,
70
- clearAllState: () => void,
71
- duplicateState: (source: any, dest: any) => void,
72
- };*/
73
- /*:: type PushController = {
74
- send: (data: PushData) => Promise,
75
- };*/
76
- /*:: type QueryController = {
77
- find: (className: string, params: QueryJSON, options: RequestOptions) => Promise,
78
- aggregate: (className: string, params: any, options: RequestOptions) => Promise,
79
- };*/
80
- /*:: type RESTController = {
81
- request: (method: string, path: string, data: mixed, options: RequestOptions) => Promise,
82
- ajax: (method: string, url: string, data: any, headers?: any, options: FullOptions) => Promise,
83
- };*/
84
- /*:: type SchemaController = {
85
- purge: (className: string) => Promise,
86
- get: (className: string, options: RequestOptions) => Promise,
87
- delete: (className: string, options: RequestOptions) => Promise,
88
- create: (className: string, params: any, options: RequestOptions) => Promise,
89
- update: (className: string, params: any, options: RequestOptions) => Promise,
90
- send(className: string, method: string, params: any, options: RequestOptions): Promise,
91
- };*/
92
- /*:: type SessionController = {
93
- getSession: (token: RequestOptions) => Promise,
94
- };*/
95
- /*:: type StorageController =
96
- | {
97
- async: 0,
98
- getItem: (path: string) => ?string,
99
- setItem: (path: string, value: string) => void,
100
- removeItem: (path: string) => void,
101
- getItemAsync?: (path: string) => Promise,
102
- setItemAsync?: (path: string, value: string) => Promise,
103
- removeItemAsync?: (path: string) => Promise,
104
- clear: () => void,
105
- }
106
- | {
107
- async: 1,
108
- getItem?: (path: string) => ?string,
109
- setItem?: (path: string, value: string) => void,
110
- removeItem?: (path: string) => void,
111
- getItemAsync: (path: string) => Promise,
112
- setItemAsync: (path: string, value: string) => Promise,
113
- removeItemAsync: (path: string) => Promise,
114
- clear: () => void,
115
- };*/
116
- /*:: type LocalDatastoreController = {
117
- fromPinWithName: (name: string) => ?any,
118
- pinWithName: (name: string, objects: any) => void,
119
- unPinWithName: (name: string) => void,
120
- getAllContents: () => ?any,
121
- clear: () => void,
122
- };*/
123
- /*:: type UserController = {
124
- setCurrentUser: (user: ParseUser) => Promise,
125
- currentUser: () => ?ParseUser,
126
- currentUserAsync: () => Promise,
127
- signUp: (user: ParseUser, attrs: AttributeMap, options: RequestOptions) => Promise,
128
- logIn: (user: ParseUser, options: RequestOptions) => Promise,
129
- become: (options: RequestOptions) => Promise,
130
- hydrate: (userJSON: AttributeMap) => Promise,
131
- logOut: (options: RequestOptions) => Promise,
132
- me: (options: RequestOptions) => Promise,
133
- requestPasswordReset: (email: string, options: RequestOptions) => Promise,
134
- updateUserOnDisk: (user: ParseUser) => Promise,
135
- upgradeToRevocableSession: (user: ParseUser, options: RequestOptions) => Promise,
136
- linkWith: (user: ParseUser, authData: AuthData) => Promise,
137
- removeUserFromDisk: () => Promise,
138
- verifyPassword: (username: string, password: string, options: RequestOptions) => Promise,
139
- requestEmailVerification: (email: string, options: RequestOptions) => Promise,
140
- };*/
141
- /*:: type HooksController = {
142
- get: (type: string, functionName?: string, triggerName?: string) => Promise,
143
- create: (hook: mixed) => Promise,
144
- delete: (hook: mixed) => Promise,
145
- update: (hook: mixed) => Promise,
146
- send: (method: string, path: string, body?: mixed) => Promise,
147
- };*/
148
- /*:: type WebSocketController = {
7
+ /** Based on https://github.com/react-native-async-storage/async-storage/blob/main/packages/default-storage-backend/src/types.ts */
8
+ /*:: export type WebSocketController = {
149
9
  onopen: () => void,
150
10
  onmessage: (message: any) => void,
151
- onclose: () => void,
11
+ onclose: (arg?: any) => void,
152
12
  onerror: (error: any) => void,
153
13
  send: (data: any) => void,
154
14
  close: () => void,
155
15
  };*/
156
- /*:: type Config = {
157
- AnalyticsController?: AnalyticsController,
158
- CloudController?: CloudController,
159
- ConfigController?: ConfigController,
160
- FileController?: FileController,
161
- InstallationController?: InstallationController,
162
- ObjectController?: ObjectController,
163
- ObjectStateController?: ObjectStateController,
164
- PushController?: PushController,
165
- QueryController?: QueryController,
166
- RESTController?: RESTController,
167
- SchemaController?: SchemaController,
168
- SessionController?: SessionController,
169
- StorageController?: StorageController,
170
- LocalDatastoreController?: LocalDatastoreController,
171
- UserController?: UserController,
172
- HooksController?: HooksController,
173
- WebSocketController?: WebSocketController,
174
- };*/
175
- const config /*: Config & { [key: string]: mixed }*/ = {
176
- // Defaults
16
+ const config /*: Config & { [key: string]: any }*/ = {
177
17
  IS_NODE: typeof process !== 'undefined' && !!process.versions && !!process.versions.node && !process.versions.electron,
178
18
  REQUEST_ATTEMPT_LIMIT: 5,
179
19
  REQUEST_BATCH_SIZE: 20,
@@ -183,7 +23,7 @@ const config /*: Config & { [key: string]: mixed }*/ = {
183
23
  SERVER_AUTH_TOKEN: null,
184
24
  LIVEQUERY_SERVER_URL: null,
185
25
  ENCRYPTED_KEY: null,
186
- VERSION: 'js' + "5.0.0",
26
+ VERSION: 'js' + "5.1.0-alpha.10",
187
27
  APPLICATION_ID: null,
188
28
  JAVASCRIPT_KEY: null,
189
29
  MASTER_KEY: null,
@@ -258,11 +98,18 @@ const CoreManager = {
258
98
  requireMethods('FileController', ['saveFile', 'saveBase64'], controller);
259
99
  config['FileController'] = controller;
260
100
  },
101
+ setEventuallyQueue(controller /*: EventuallyQueue*/) {
102
+ requireMethods('EventuallyQueue', ['poll', 'save', 'destroy'], controller);
103
+ config['EventuallyQueue'] = controller;
104
+ },
105
+ getEventuallyQueue() /*: EventuallyQueue*/{
106
+ return config['EventuallyQueue'];
107
+ },
261
108
  getFileController() /*: FileController*/{
262
109
  return config['FileController'];
263
110
  },
264
111
  setInstallationController(controller /*: InstallationController*/) {
265
- requireMethods('InstallationController', ['currentInstallationId'], controller);
112
+ requireMethods('InstallationController', ['currentInstallationId', 'currentInstallation', 'updateInstallationOnDisk'], controller);
266
113
  config['InstallationController'] = controller;
267
114
  },
268
115
  getInstallationController() /*: InstallationController*/{
@@ -347,16 +194,16 @@ const CoreManager = {
347
194
  getStorageController() /*: StorageController*/{
348
195
  return config['StorageController'];
349
196
  },
350
- setAsyncStorage(storage /*: any*/) {
197
+ setAsyncStorage(storage /*: AsyncStorageType*/) {
351
198
  config['AsyncStorage'] = storage;
352
199
  },
353
200
  getAsyncStorage() {
354
201
  return config['AsyncStorage'];
355
202
  },
356
- setWebSocketController(controller /*: WebSocketController*/) {
203
+ setWebSocketController(controller /*: new (url: string | URL, protocols?: string | string[] | undefined) => WebSocketController*/) {
357
204
  config['WebSocketController'] = controller;
358
205
  },
359
- getWebSocketController() /*: WebSocketController*/{
206
+ getWebSocketController() /*: new (url: string | URL, protocols?: string | string[] | undefined) => WebSocketController*/{
360
207
  return config['WebSocketController'];
361
208
  },
362
209
  setUserController(controller /*: UserController*/) {
@@ -366,11 +213,11 @@ const CoreManager = {
366
213
  getUserController() /*: UserController*/{
367
214
  return config['UserController'];
368
215
  },
369
- setLiveQueryController(controller /*: any*/) {
216
+ setLiveQueryController(controller /*: LiveQueryControllerType*/) {
370
217
  requireMethods('LiveQueryController', ['setDefaultLiveQueryClient', 'getDefaultLiveQueryClient', '_clearCachedDefaultClient'], controller);
371
218
  config['LiveQueryController'] = controller;
372
219
  },
373
- getLiveQueryController() /*: any*/{
220
+ getLiveQueryController() /*: LiveQueryControllerType*/{
374
221
  return config['LiveQueryController'];
375
222
  },
376
223
  setHooksController(controller /*: HooksController*/) {
@@ -379,6 +226,36 @@ const CoreManager = {
379
226
  },
380
227
  getHooksController() /*: HooksController*/{
381
228
  return config['HooksController'];
229
+ },
230
+ setParseOp(op /*: ParseOp*/) {
231
+ config['ParseOp'] = op;
232
+ },
233
+ getParseOp() {
234
+ return config['ParseOp'];
235
+ },
236
+ setParseObject(object /*: ParseObject*/) {
237
+ config['ParseObject'] = object;
238
+ },
239
+ getParseObject() /*: ParseObject*/{
240
+ return config['ParseObject'];
241
+ },
242
+ setParseQuery(query /*: ParseQuery*/) {
243
+ config['ParseQuery'] = query;
244
+ },
245
+ getParseQuery() {
246
+ return config['ParseQuery'];
247
+ },
248
+ setParseRole(role /*: ParseRole*/) {
249
+ config['ParseRole'] = role;
250
+ },
251
+ getParseRole() /*: ParseRole*/{
252
+ return config['ParseRole'];
253
+ },
254
+ setParseUser(user /*: ParseUser*/) {
255
+ config['ParseUser'] = user;
256
+ },
257
+ getParseUser() /*: ParseUser*/{
258
+ return config['ParseUser'];
382
259
  }
383
260
  };
384
261
  module.exports = CoreManager;
@@ -1,40 +1,84 @@
1
1
  "use strict";
2
2
 
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _CoreManager = _interopRequireDefault(require("./CoreManager"));
3
8
  var _Storage = _interopRequireDefault(require("./Storage"));
9
+ var _ParseInstallation = _interopRequireDefault(require("./ParseInstallation"));
10
+ var _uuid = _interopRequireDefault(require("./uuid"));
4
11
  function _interopRequireDefault(obj) {
5
12
  return obj && obj.__esModule ? obj : {
6
13
  default: obj
7
14
  };
8
15
  }
9
- /**
10
- * @flow
11
- */
12
-
13
- const uuidv4 = require('./uuid');
14
- let iidCache = null;
16
+ const CURRENT_INSTALLATION_KEY = 'currentInstallation';
17
+ const CURRENT_INSTALLATION_ID_KEY = 'currentInstallationId';
18
+ let iidCache /*: string | null*/ = null;
19
+ let currentInstallationCache = null;
20
+ let currentInstallationCacheMatchesDisk = false;
15
21
  const InstallationController = {
16
- currentInstallationId() /*: Promise<string>*/{
22
+ async updateInstallationOnDisk(installation /*: ParseInstallation*/) /*: Promise<void>*/{
23
+ const path = _Storage.default.generatePath(CURRENT_INSTALLATION_KEY);
24
+ await _Storage.default.setItemAsync(path, JSON.stringify(installation.toJSON()));
25
+ this._setCurrentInstallationCache(installation);
26
+ },
27
+ async currentInstallationId() /*: Promise<string>*/{
17
28
  if (typeof iidCache === 'string') {
18
- return Promise.resolve(iidCache);
29
+ return iidCache;
30
+ }
31
+ const path = _Storage.default.generatePath(CURRENT_INSTALLATION_ID_KEY);
32
+ let iid = await _Storage.default.getItemAsync(path);
33
+ if (!iid) {
34
+ iid = (0, _uuid.default)();
35
+ return _Storage.default.setItemAsync(path, iid).then(() => {
36
+ iidCache = iid;
37
+ return iid;
38
+ });
19
39
  }
20
- const path = _Storage.default.generatePath('installationId');
21
- return _Storage.default.getItemAsync(path).then(iid => {
22
- if (!iid) {
23
- iid = uuidv4();
24
- return _Storage.default.setItemAsync(path, iid).then(() => {
25
- iidCache = iid;
26
- return iid;
27
- });
28
- }
29
- iidCache = iid;
30
- return iid;
31
- });
40
+ iidCache = iid;
41
+ return iid;
42
+ },
43
+ async currentInstallation() /*: Promise<ParseInstallation | null>*/{
44
+ if (currentInstallationCache) {
45
+ return currentInstallationCache;
46
+ }
47
+ if (currentInstallationCacheMatchesDisk) {
48
+ return null;
49
+ }
50
+ const path = _Storage.default.generatePath(CURRENT_INSTALLATION_KEY);
51
+ let installationData = await _Storage.default.getItemAsync(path);
52
+ currentInstallationCacheMatchesDisk = true;
53
+ if (installationData) {
54
+ installationData = JSON.parse(installationData);
55
+ installationData.className = '_Installation';
56
+ const current = _ParseInstallation.default.fromJSON(installationData);
57
+ currentInstallationCache = current;
58
+ return current;
59
+ }
60
+ const installationId = await this.currentInstallationId();
61
+ const installation = new _ParseInstallation.default();
62
+ installation.set('deviceType', _ParseInstallation.default.DEVICE_TYPES.WEB);
63
+ installation.set('installationId', installationId);
64
+ installation.set('parseVersion', _CoreManager.default.get('VERSION'));
65
+ currentInstallationCache = installation;
66
+ await _Storage.default.setItemAsync(path, JSON.stringify(installation.toJSON()));
67
+ return installation;
32
68
  },
33
69
  _clearCache() {
34
70
  iidCache = null;
71
+ currentInstallationCache = null;
72
+ currentInstallationCacheMatchesDisk = false;
35
73
  },
36
74
  _setInstallationIdCache(iid /*: string*/) {
37
75
  iidCache = iid;
76
+ },
77
+ _setCurrentInstallationCache(installation /*: ParseInstallation*/, matchesDisk /*: boolean*/ = true) {
78
+ currentInstallationCache = installation;
79
+ currentInstallationCacheMatchesDisk = matchesDisk;
38
80
  }
39
81
  };
40
- module.exports = InstallationController;
82
+ module.exports = InstallationController;
83
+ var _default = InstallationController;
84
+ exports.default = _default;
@@ -14,8 +14,6 @@ function _interopRequireDefault(obj) {
14
14
  default: obj
15
15
  };
16
16
  }
17
- /* global WebSocket */
18
-
19
17
  // The LiveQuery client inner state
20
18
  const CLIENT_STATE = {
21
19
  INITIALIZED: 'initialized',
@@ -163,8 +161,8 @@ class LiveQueryClient {
163
161
  this.state = CLIENT_STATE.INITIALIZED;
164
162
  const EventEmitter = _CoreManager.default.getEventEmitter();
165
163
  this.emitter = new EventEmitter();
166
- this.on = this.emitter.on;
167
- this.emit = this.emitter.emit;
164
+ this.on = (eventName, listener) => this.emitter.on(eventName, listener);
165
+ this.emit = (eventName, ...args) => this.emitter.emit(eventName, ...args);
168
166
  // adding listener so process does not crash
169
167
  // best practice is for developer to register their own listener
170
168
  this.on('error', () => {});
@@ -481,6 +479,5 @@ class LiveQueryClient {
481
479
  }).bind(this), time);
482
480
  }
483
481
  }
484
- _CoreManager.default.setWebSocketController(require('ws'));
485
482
  var _default = LiveQueryClient;
486
483
  exports.default = _default;
@@ -108,8 +108,8 @@ class Subscription {
108
108
  this.subscribed = false;
109
109
  const EventEmitter = _CoreManager.default.getEventEmitter();
110
110
  this.emitter = new EventEmitter();
111
- this.on = this.emitter.on;
112
- this.emit = this.emitter.emit;
111
+ this.on = (eventName, listener) => this.emitter.on(eventName, listener);
112
+ this.emit = (eventName, ...args) => this.emitter.emit(eventName, ...args);
113
113
  // adding listener so process does not crash
114
114
  // best practice is for developer to register their own listener
115
115
  this.on('error', () => {});