parse 5.2.0-alpha.1 → 5.2.0-alpha.3

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 (247) hide show
  1. package/dist/parse.js +10519 -15246
  2. package/dist/parse.min.js +2 -2
  3. package/dist/parse.weapp.js +10499 -15371
  4. package/dist/parse.weapp.min.js +2 -2
  5. package/lib/browser/Analytics.js +7 -11
  6. package/lib/browser/AnonymousUtils.js +17 -22
  7. package/lib/browser/Cloud.js +23 -41
  8. package/lib/browser/CoreManager.js +71 -79
  9. package/lib/browser/CryptoController.js +14 -9
  10. package/lib/browser/EventEmitter.js +9 -2
  11. package/lib/browser/EventuallyQueue.js +156 -357
  12. package/lib/browser/FacebookUtils.js +23 -28
  13. package/lib/browser/IndexedDBStorageController.js +18 -14
  14. package/lib/browser/InstallationController.js +55 -121
  15. package/lib/browser/LiveQueryClient.js +312 -485
  16. package/lib/browser/LiveQuerySubscription.js +25 -28
  17. package/lib/browser/LocalDatastore.js +258 -624
  18. package/lib/browser/LocalDatastoreController.default.js +42 -226
  19. package/lib/browser/LocalDatastoreController.js +11 -1
  20. package/lib/browser/LocalDatastoreController.react-native.js +66 -160
  21. package/lib/browser/LocalDatastoreUtils.js +4 -7
  22. package/lib/browser/ObjectStateMutations.js +54 -96
  23. package/lib/browser/OfflineQuery.js +106 -198
  24. package/lib/browser/Parse.js +44 -60
  25. package/lib/browser/ParseACL.js +242 -288
  26. package/lib/browser/ParseCLP.js +372 -572
  27. package/lib/browser/ParseConfig.js +115 -138
  28. package/lib/browser/ParseError.js +85 -182
  29. package/lib/browser/ParseFile.js +294 -438
  30. package/lib/browser/ParseGeoPoint.js +121 -146
  31. package/lib/browser/ParseHooks.js +23 -25
  32. package/lib/browser/ParseInstallation.js +225 -367
  33. package/lib/browser/ParseLiveQuery.js +74 -148
  34. package/lib/browser/ParseObject.js +2014 -2621
  35. package/lib/browser/ParseOp.js +343 -484
  36. package/lib/browser/ParsePolygon.js +101 -120
  37. package/lib/browser/ParseQuery.js +1708 -2052
  38. package/lib/browser/ParseRelation.js +99 -118
  39. package/lib/browser/ParseRole.js +88 -140
  40. package/lib/browser/ParseSchema.js +372 -434
  41. package/lib/browser/ParseSession.js +62 -110
  42. package/lib/browser/ParseUser.js +941 -1284
  43. package/lib/browser/Push.js +15 -38
  44. package/lib/browser/RESTController.js +85 -124
  45. package/lib/browser/SingleInstanceStateController.js +57 -86
  46. package/lib/browser/Socket.weapp.js +50 -33
  47. package/lib/browser/Storage.js +23 -28
  48. package/lib/browser/StorageController.browser.js +16 -13
  49. package/lib/browser/StorageController.default.js +15 -14
  50. package/lib/browser/StorageController.js +14 -1
  51. package/lib/browser/StorageController.react-native.js +31 -30
  52. package/lib/browser/StorageController.weapp.js +19 -13
  53. package/lib/browser/TaskQueue.js +31 -43
  54. package/lib/browser/UniqueInstanceStateController.js +65 -86
  55. package/lib/browser/WebSocketController.js +11 -4
  56. package/lib/browser/Xhr.weapp.js +90 -78
  57. package/lib/browser/arrayContainsObject.js +3 -3
  58. package/lib/browser/canBeSerialized.js +10 -11
  59. package/lib/browser/decode.js +11 -11
  60. package/lib/browser/encode.js +11 -11
  61. package/lib/browser/equals.js +9 -10
  62. package/lib/browser/escape.js +2 -2
  63. package/lib/browser/isRevocableSession.js +1 -1
  64. package/lib/browser/parseDate.js +10 -10
  65. package/lib/browser/promiseUtils.js +19 -19
  66. package/lib/browser/unique.js +4 -4
  67. package/lib/browser/unsavedChildren.js +20 -21
  68. package/lib/browser/uuid.js +2 -4
  69. package/lib/node/Analytics.js +5 -9
  70. package/lib/node/AnonymousUtils.js +10 -15
  71. package/lib/node/Cloud.js +11 -11
  72. package/lib/node/CoreManager.js +59 -67
  73. package/lib/node/CryptoController.js +8 -3
  74. package/lib/node/EventEmitter.js +7 -1
  75. package/lib/node/EventuallyQueue.js +20 -39
  76. package/lib/node/FacebookUtils.js +4 -8
  77. package/lib/node/IndexedDBStorageController.js +14 -10
  78. package/lib/node/InstallationController.js +12 -13
  79. package/lib/node/LiveQueryClient.js +23 -21
  80. package/lib/node/LiveQuerySubscription.js +6 -7
  81. package/lib/node/LocalDatastore.js +23 -23
  82. package/lib/node/LocalDatastoreController.default.js +11 -12
  83. package/lib/node/LocalDatastoreController.js +14 -1
  84. package/lib/node/LocalDatastoreController.react-native.js +25 -21
  85. package/lib/node/LocalDatastoreUtils.js +4 -7
  86. package/lib/node/ObjectStateMutations.js +12 -22
  87. package/lib/node/OfflineQuery.js +37 -23
  88. package/lib/node/Parse.js +36 -50
  89. package/lib/node/ParseACL.js +21 -30
  90. package/lib/node/ParseCLP.js +38 -40
  91. package/lib/node/ParseConfig.js +10 -17
  92. package/lib/node/ParseError.js +460 -461
  93. package/lib/node/ParseFile.js +27 -47
  94. package/lib/node/ParseGeoPoint.js +16 -17
  95. package/lib/node/ParseHooks.js +16 -18
  96. package/lib/node/ParseInstallation.js +10 -11
  97. package/lib/node/ParseLiveQuery.js +9 -14
  98. package/lib/node/ParseObject.js +142 -173
  99. package/lib/node/ParseOp.js +35 -47
  100. package/lib/node/ParsePolygon.js +14 -20
  101. package/lib/node/ParseQuery.js +100 -123
  102. package/lib/node/ParseRelation.js +10 -19
  103. package/lib/node/ParseRole.js +10 -11
  104. package/lib/node/ParseSchema.js +29 -42
  105. package/lib/node/ParseSession.js +10 -11
  106. package/lib/node/ParseUser.js +76 -87
  107. package/lib/node/Push.js +7 -12
  108. package/lib/node/RESTController.js +24 -36
  109. package/lib/node/SingleInstanceStateController.js +41 -69
  110. package/lib/node/Socket.weapp.js +23 -2
  111. package/lib/node/Storage.js +14 -19
  112. package/lib/node/StorageController.browser.js +10 -8
  113. package/lib/node/StorageController.default.js +9 -9
  114. package/lib/node/StorageController.js +16 -1
  115. package/lib/node/StorageController.react-native.js +20 -20
  116. package/lib/node/StorageController.weapp.js +14 -8
  117. package/lib/node/TaskQueue.js +2 -3
  118. package/lib/node/UniqueInstanceStateController.js +43 -63
  119. package/lib/node/WebSocketController.js +15 -2
  120. package/lib/node/Xhr.weapp.js +11 -2
  121. package/lib/node/arrayContainsObject.js +4 -4
  122. package/lib/node/canBeSerialized.js +5 -5
  123. package/lib/node/decode.js +4 -4
  124. package/lib/node/encode.js +5 -5
  125. package/lib/node/equals.js +4 -4
  126. package/lib/node/escape.js +1 -1
  127. package/lib/node/isRevocableSession.js +1 -1
  128. package/lib/node/parseDate.js +1 -1
  129. package/lib/node/promiseUtils.js +7 -7
  130. package/lib/node/unique.js +5 -5
  131. package/lib/node/unsavedChildren.js +5 -5
  132. package/lib/node/uuid.js +2 -4
  133. package/lib/react-native/Analytics.js +2 -2
  134. package/lib/react-native/AnonymousUtils.js +3 -4
  135. package/lib/react-native/CoreManager.js +2 -3
  136. package/lib/react-native/CryptoController.js +6 -1
  137. package/lib/react-native/EventEmitter.js +6 -1
  138. package/lib/react-native/EventuallyQueue.js +1 -2
  139. package/lib/react-native/FacebookUtils.js +1 -2
  140. package/lib/react-native/IndexedDBStorageController.js +11 -5
  141. package/lib/react-native/InstallationController.js +1 -2
  142. package/lib/react-native/LiveQueryClient.js +8 -7
  143. package/lib/react-native/LiveQuerySubscription.js +2 -4
  144. package/lib/react-native/LocalDatastore.js +3 -3
  145. package/lib/react-native/LocalDatastoreController.default.js +1 -2
  146. package/lib/react-native/LocalDatastoreController.js +11 -1
  147. package/lib/react-native/LocalDatastoreController.react-native.js +11 -12
  148. package/lib/react-native/LocalDatastoreUtils.js +3 -6
  149. package/lib/react-native/OfflineQuery.js +25 -20
  150. package/lib/react-native/Parse.js +24 -38
  151. package/lib/react-native/ParseACL.js +4 -6
  152. package/lib/react-native/ParseCLP.js +2 -4
  153. package/lib/react-native/ParseConfig.js +4 -6
  154. package/lib/react-native/ParseError.js +13 -31
  155. package/lib/react-native/ParseFile.js +3 -4
  156. package/lib/react-native/ParseGeoPoint.js +2 -4
  157. package/lib/react-native/ParseInstallation.js +13 -30
  158. package/lib/react-native/ParseLiveQuery.js +2 -4
  159. package/lib/react-native/ParseObject.js +77 -87
  160. package/lib/react-native/ParseOp.js +41 -79
  161. package/lib/react-native/ParsePolygon.js +2 -4
  162. package/lib/react-native/ParseQuery.js +43 -45
  163. package/lib/react-native/ParseRelation.js +2 -4
  164. package/lib/react-native/ParseRole.js +13 -30
  165. package/lib/react-native/ParseSchema.js +3 -5
  166. package/lib/react-native/ParseSession.js +12 -29
  167. package/lib/react-native/ParseUser.js +24 -49
  168. package/lib/react-native/RESTController.js +10 -4
  169. package/lib/react-native/SingleInstanceStateController.js +23 -37
  170. package/lib/react-native/Socket.weapp.js +9 -4
  171. package/lib/react-native/Storage.js +1 -2
  172. package/lib/react-native/StorageController.browser.js +6 -1
  173. package/lib/react-native/StorageController.default.js +6 -1
  174. package/lib/react-native/StorageController.js +13 -1
  175. package/lib/react-native/StorageController.react-native.js +11 -6
  176. package/lib/react-native/StorageController.weapp.js +6 -1
  177. package/lib/react-native/TaskQueue.js +2 -4
  178. package/lib/react-native/UniqueInstanceStateController.js +23 -37
  179. package/lib/react-native/WebSocketController.js +9 -1
  180. package/lib/react-native/Xhr.weapp.js +9 -4
  181. package/lib/react-native/unsavedChildren.js +3 -3
  182. package/lib/react-native/uuid.js +1 -2
  183. package/lib/weapp/Analytics.js +7 -11
  184. package/lib/weapp/AnonymousUtils.js +17 -22
  185. package/lib/weapp/Cloud.js +23 -41
  186. package/lib/weapp/CoreManager.js +71 -79
  187. package/lib/weapp/CryptoController.js +14 -9
  188. package/lib/weapp/EventEmitter.js +9 -2
  189. package/lib/weapp/EventuallyQueue.js +156 -357
  190. package/lib/weapp/FacebookUtils.js +23 -28
  191. package/lib/weapp/IndexedDBStorageController.js +18 -14
  192. package/lib/weapp/InstallationController.js +55 -121
  193. package/lib/weapp/LiveQueryClient.js +312 -485
  194. package/lib/weapp/LiveQuerySubscription.js +25 -28
  195. package/lib/weapp/LocalDatastore.js +258 -624
  196. package/lib/weapp/LocalDatastoreController.default.js +42 -226
  197. package/lib/weapp/LocalDatastoreController.js +11 -1
  198. package/lib/weapp/LocalDatastoreController.react-native.js +66 -160
  199. package/lib/weapp/LocalDatastoreUtils.js +4 -7
  200. package/lib/weapp/ObjectStateMutations.js +54 -96
  201. package/lib/weapp/OfflineQuery.js +106 -198
  202. package/lib/weapp/Parse.js +44 -59
  203. package/lib/weapp/ParseACL.js +242 -288
  204. package/lib/weapp/ParseCLP.js +372 -572
  205. package/lib/weapp/ParseConfig.js +115 -138
  206. package/lib/weapp/ParseError.js +85 -182
  207. package/lib/weapp/ParseFile.js +295 -440
  208. package/lib/weapp/ParseGeoPoint.js +121 -146
  209. package/lib/weapp/ParseHooks.js +23 -25
  210. package/lib/weapp/ParseInstallation.js +225 -367
  211. package/lib/weapp/ParseLiveQuery.js +74 -148
  212. package/lib/weapp/ParseObject.js +2014 -2621
  213. package/lib/weapp/ParseOp.js +343 -484
  214. package/lib/weapp/ParsePolygon.js +101 -120
  215. package/lib/weapp/ParseQuery.js +1708 -2052
  216. package/lib/weapp/ParseRelation.js +99 -118
  217. package/lib/weapp/ParseRole.js +88 -140
  218. package/lib/weapp/ParseSchema.js +372 -434
  219. package/lib/weapp/ParseSession.js +62 -110
  220. package/lib/weapp/ParseUser.js +941 -1284
  221. package/lib/weapp/Push.js +15 -38
  222. package/lib/weapp/RESTController.js +86 -125
  223. package/lib/weapp/SingleInstanceStateController.js +57 -86
  224. package/lib/weapp/Socket.weapp.js +50 -33
  225. package/lib/weapp/Storage.js +23 -28
  226. package/lib/weapp/StorageController.browser.js +16 -13
  227. package/lib/weapp/StorageController.default.js +15 -14
  228. package/lib/weapp/StorageController.js +14 -1
  229. package/lib/weapp/StorageController.react-native.js +31 -30
  230. package/lib/weapp/StorageController.weapp.js +19 -13
  231. package/lib/weapp/TaskQueue.js +31 -43
  232. package/lib/weapp/UniqueInstanceStateController.js +65 -86
  233. package/lib/weapp/WebSocketController.js +11 -4
  234. package/lib/weapp/Xhr.weapp.js +90 -78
  235. package/lib/weapp/arrayContainsObject.js +3 -3
  236. package/lib/weapp/canBeSerialized.js +10 -11
  237. package/lib/weapp/decode.js +11 -11
  238. package/lib/weapp/encode.js +11 -11
  239. package/lib/weapp/equals.js +9 -10
  240. package/lib/weapp/escape.js +2 -2
  241. package/lib/weapp/isRevocableSession.js +1 -1
  242. package/lib/weapp/parseDate.js +10 -10
  243. package/lib/weapp/promiseUtils.js +19 -19
  244. package/lib/weapp/unique.js +4 -4
  245. package/lib/weapp/unsavedChildren.js +20 -21
  246. package/lib/weapp/uuid.js +6 -8
  247. package/package.json +24 -30
@@ -7,24 +7,20 @@ _Object$defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.default = void 0;
9
9
  var _ParseUser = _interopRequireDefault(require("./ParseUser"));
10
- /**
11
- * @flow-weak
12
- */
13
10
  /* global FB */
14
11
 
15
- var initialized = false;
16
- var requestedPermissions;
17
- var initOptions;
18
- var provider = {
19
- authenticate: function (options) {
20
- var _this = this;
12
+ let initialized = false;
13
+ let requestedPermissions;
14
+ let initOptions;
15
+ const provider = {
16
+ authenticate(options) {
21
17
  if (typeof FB === 'undefined') {
22
18
  options.error(this, 'Facebook SDK not found.');
23
19
  }
24
- FB.login(function (response) {
20
+ FB.login(response => {
25
21
  if (response.authResponse) {
26
22
  if (options.success) {
27
- options.success(_this, {
23
+ options.success(this, {
28
24
  id: response.authResponse.userID,
29
25
  access_token: response.authResponse.accessToken,
30
26
  expiration_date: new Date(response.authResponse.expiresIn * 1000 + new Date().getTime()).toJSON()
@@ -32,18 +28,18 @@ var provider = {
32
28
  }
33
29
  } else {
34
30
  if (options.error) {
35
- options.error(_this, response);
31
+ options.error(this, response);
36
32
  }
37
33
  }
38
34
  }, {
39
35
  scope: requestedPermissions
40
36
  });
41
37
  },
42
- restoreAuthentication: function (authData) {
38
+ restoreAuthentication(authData) {
43
39
  if (authData) {
44
- var newOptions = {};
40
+ const newOptions = {};
45
41
  if (initOptions) {
46
- for (var key in initOptions) {
42
+ for (const key in initOptions) {
47
43
  newOptions[key] = initOptions[key];
48
44
  }
49
45
  }
@@ -54,7 +50,7 @@ var provider = {
54
50
  // Most of the time, the users will match -- it's only in cases where
55
51
  // the FB SDK knows of a different user than the one being restored
56
52
  // from a Parse User that logged in with username/password.
57
- var existingResponse = FB.getAuthResponse();
53
+ const existingResponse = FB.getAuthResponse();
58
54
  if (existingResponse && existingResponse.userID !== authData.id) {
59
55
  FB.logout();
60
56
  }
@@ -62,10 +58,10 @@ var provider = {
62
58
  }
63
59
  return true;
64
60
  },
65
- getAuthType: function () {
61
+ getAuthType() {
66
62
  return 'facebook';
67
63
  },
68
- deauthenticate: function () {
64
+ deauthenticate() {
69
65
  this.restoreAuthentication(null);
70
66
  }
71
67
  };
@@ -77,7 +73,7 @@ var provider = {
77
73
  * @static
78
74
  * @hideconstructor
79
75
  */
80
- var FacebookUtils = {
76
+ const FacebookUtils = {
81
77
  /**
82
78
  * Initializes Parse Facebook integration. Call this function after you
83
79
  * have loaded the Facebook Javascript SDK with the same parameters
@@ -96,18 +92,18 @@ var FacebookUtils = {
96
92
  * interferes with Parse Facebook integration. Call FB.getLoginStatus()
97
93
  * explicitly if this behavior is required by your application.
98
94
  */
99
- init: function (options) {
95
+ init(options) {
100
96
  if (typeof FB === 'undefined') {
101
97
  throw new Error('The Facebook JavaScript SDK must be loaded before calling init.');
102
98
  }
103
99
  initOptions = {};
104
100
  if (options) {
105
- for (var key in options) {
101
+ for (const key in options) {
106
102
  initOptions[key] = options[key];
107
103
  }
108
104
  }
109
105
  if (initOptions.status && typeof console !== 'undefined') {
110
- var warn = console.warn || console.log || function () {}; // eslint-disable-line no-console
106
+ const warn = console.warn || console.log || function () {}; // eslint-disable-line no-console
111
107
  warn.call(console, 'The "status" flag passed into' + ' FB.init, when set to true, can interfere with Parse Facebook' + ' integration, so it has been suppressed. Please call' + ' FB.getLoginStatus() explicitly if you require this behavior.');
112
108
  }
113
109
  initOptions.status = false;
@@ -125,7 +121,7 @@ var FacebookUtils = {
125
121
  * @returns {boolean} <code>true</code> if the user has their account
126
122
  * linked to Facebook.
127
123
  */
128
- isLinked: function (user) {
124
+ isLinked(user) {
129
125
  return user._isLinked('facebook');
130
126
  },
131
127
  /**
@@ -152,7 +148,7 @@ var FacebookUtils = {
152
148
  * @param {object} options MasterKey / SessionToken. Alternatively can be used for authData if permissions is a string
153
149
  * @returns {Promise}
154
150
  */
155
- logIn: function (permissions, options) {
151
+ logIn(permissions, options) {
156
152
  if (!permissions || typeof permissions === 'string') {
157
153
  if (!initialized) {
158
154
  throw new Error('You must initialize FacebookUtils before calling logIn.');
@@ -190,7 +186,7 @@ var FacebookUtils = {
190
186
  * @param {object} options MasterKey / SessionToken. Alternatively can be used for authData if permissions is a string
191
187
  * @returns {Promise}
192
188
  */
193
- link: function (user, permissions, options) {
189
+ link(user, permissions, options) {
194
190
  if (!permissions || typeof permissions === 'string') {
195
191
  if (!initialized) {
196
192
  throw new Error('You must initialize FacebookUtils before calling link.');
@@ -220,9 +216,8 @@ var FacebookUtils = {
220
216
  return user._unlinkFrom('facebook', options);
221
217
  },
222
218
  // Used for testing purposes
223
- _getAuthProvider: function () {
219
+ _getAuthProvider() {
224
220
  return provider;
225
221
  }
226
222
  };
227
- var _default = FacebookUtils;
228
- exports.default = _default;
223
+ var _default = exports.default = FacebookUtils;
@@ -1,39 +1,43 @@
1
1
  "use strict";
2
2
 
3
3
  var _keysInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/keys");
4
+ var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
5
+ _Object$defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
4
9
  var _idbKeyval = require("idb-keyval");
5
- /**
6
- * @flow
7
- */
8
10
  /* global window */
9
11
 
12
+ let IndexedDBStorageController;
10
13
  if (typeof window !== 'undefined' && window.indexedDB) {
11
14
  try {
12
- var ParseStore = (0, _idbKeyval.createStore)('parseDB', 'parseStore');
13
- var IndexedDBStorageController = {
15
+ const ParseStore = (0, _idbKeyval.createStore)('parseDB', 'parseStore');
16
+ IndexedDBStorageController = {
14
17
  async: 1,
15
- getItemAsync: function (path /*: string*/) {
18
+ getItemAsync(path) {
16
19
  return (0, _idbKeyval.get)(path, ParseStore);
17
20
  },
18
- setItemAsync: function (path /*: string*/, value /*: string*/) {
21
+ setItemAsync(path, value) {
19
22
  return (0, _idbKeyval.set)(path, value, ParseStore);
20
23
  },
21
- removeItemAsync: function (path /*: string*/) {
24
+ removeItemAsync(path) {
22
25
  return (0, _idbKeyval.del)(path, ParseStore);
23
26
  },
24
- getAllKeysAsync: function () {
27
+ getAllKeysAsync() {
25
28
  return (0, _keysInstanceProperty(_idbKeyval))(ParseStore);
26
29
  },
27
- clear: function () {
30
+ clear() {
28
31
  return (0, _idbKeyval.clear)(ParseStore);
29
32
  }
30
33
  };
31
- module.exports = IndexedDBStorageController;
32
34
  } catch (_) {
33
35
  // IndexedDB not accessible
34
- module.exports = undefined;
36
+ IndexedDBStorageController = undefined;
35
37
  }
36
38
  } else {
37
39
  // IndexedDB not supported
38
- module.exports = undefined;
39
- }
40
+ IndexedDBStorageController = undefined;
41
+ }
42
+ module.exports = IndexedDBStorageController;
43
+ var _default = exports.default = IndexedDBStorageController;
@@ -6,143 +6,77 @@ _Object$defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports.default = void 0;
9
- var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs3/regenerator"));
10
9
  var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/json/stringify"));
11
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncToGenerator"));
12
10
  var _CoreManager = _interopRequireDefault(require("./CoreManager"));
13
11
  var _Storage = _interopRequireDefault(require("./Storage"));
14
12
  var _ParseInstallation = _interopRequireDefault(require("./ParseInstallation"));
15
13
  var _uuid = _interopRequireDefault(require("./uuid"));
16
- var CURRENT_INSTALLATION_KEY = 'currentInstallation';
17
- var CURRENT_INSTALLATION_ID_KEY = 'currentInstallationId';
18
- var iidCache /*: string | null*/ = null;
19
- var currentInstallationCache /*: ParseInstallation | null*/ = null;
20
- var currentInstallationCacheMatchesDisk = false;
21
- var InstallationController = {
22
- updateInstallationOnDisk: function (installation /*: ParseInstallation*/) /*: Promise<void>*/{
23
- var _this = this;
24
- return (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
25
- var path;
26
- return _regenerator.default.wrap(function (_context) {
27
- while (1) switch (_context.prev = _context.next) {
28
- case 0:
29
- path = _Storage.default.generatePath(CURRENT_INSTALLATION_KEY);
30
- _context.next = 3;
31
- return _Storage.default.setItemAsync(path, (0, _stringify.default)(installation.toJSON()));
32
- case 3:
33
- _this._setCurrentInstallationCache(installation);
34
- case 4:
35
- case "end":
36
- return _context.stop();
37
- }
38
- }, _callee);
39
- }))();
14
+ const CURRENT_INSTALLATION_KEY = 'currentInstallation';
15
+ const CURRENT_INSTALLATION_ID_KEY = 'currentInstallationId';
16
+ let iidCache = null;
17
+ let currentInstallationCache = null;
18
+ let currentInstallationCacheMatchesDisk = false;
19
+ const InstallationController = {
20
+ async updateInstallationOnDisk(installation) {
21
+ const path = _Storage.default.generatePath(CURRENT_INSTALLATION_KEY);
22
+ await _Storage.default.setItemAsync(path, (0, _stringify.default)(installation.toJSON()));
23
+ this._setCurrentInstallationCache(installation);
40
24
  },
41
- currentInstallationId: function () /*: Promise<string>*/{
42
- return (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
43
- var path, iid;
44
- return _regenerator.default.wrap(function (_context2) {
45
- while (1) switch (_context2.prev = _context2.next) {
46
- case 0:
47
- if (!(typeof iidCache === 'string')) {
48
- _context2.next = 2;
49
- break;
50
- }
51
- return _context2.abrupt("return", iidCache);
52
- case 2:
53
- path = _Storage.default.generatePath(CURRENT_INSTALLATION_ID_KEY);
54
- _context2.next = 5;
55
- return _Storage.default.getItemAsync(path);
56
- case 5:
57
- iid = _context2.sent;
58
- if (iid) {
59
- _context2.next = 9;
60
- break;
61
- }
62
- iid = (0, _uuid.default)();
63
- return _context2.abrupt("return", _Storage.default.setItemAsync(path, iid).then(function () {
64
- iidCache = iid;
65
- return iid;
66
- }));
67
- case 9:
68
- iidCache = iid;
69
- return _context2.abrupt("return", iid);
70
- case 11:
71
- case "end":
72
- return _context2.stop();
73
- }
74
- }, _callee2);
75
- }))();
25
+ async currentInstallationId() {
26
+ if (typeof iidCache === 'string') {
27
+ return iidCache;
28
+ }
29
+ const path = _Storage.default.generatePath(CURRENT_INSTALLATION_ID_KEY);
30
+ let iid = await _Storage.default.getItemAsync(path);
31
+ if (!iid) {
32
+ iid = (0, _uuid.default)();
33
+ return _Storage.default.setItemAsync(path, iid).then(() => {
34
+ iidCache = iid;
35
+ return iid;
36
+ });
37
+ }
38
+ iidCache = iid;
39
+ return iid;
76
40
  },
77
- currentInstallation: function () /*: Promise<ParseInstallation | null>*/{
78
- var _this2 = this;
79
- return (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
80
- var path, installationData, current, installationId, installation;
81
- return _regenerator.default.wrap(function (_context3) {
82
- while (1) switch (_context3.prev = _context3.next) {
83
- case 0:
84
- if (!currentInstallationCache) {
85
- _context3.next = 2;
86
- break;
87
- }
88
- return _context3.abrupt("return", currentInstallationCache);
89
- case 2:
90
- if (!currentInstallationCacheMatchesDisk) {
91
- _context3.next = 4;
92
- break;
93
- }
94
- return _context3.abrupt("return", null);
95
- case 4:
96
- path = _Storage.default.generatePath(CURRENT_INSTALLATION_KEY);
97
- _context3.next = 7;
98
- return _Storage.default.getItemAsync(path);
99
- case 7:
100
- installationData /*: any*/ = _context3.sent;
101
- currentInstallationCacheMatchesDisk = true;
102
- if (!installationData) {
103
- _context3.next = 15;
104
- break;
105
- }
106
- installationData = JSON.parse(installationData);
107
- installationData.className = '_Installation';
108
- current = _ParseInstallation.default.fromJSON(installationData);
109
- currentInstallationCache = current;
110
- return _context3.abrupt("return", current);
111
- case 15:
112
- _context3.next = 17;
113
- return _this2.currentInstallationId();
114
- case 17:
115
- installationId = _context3.sent;
116
- installation = new _ParseInstallation.default();
117
- installation.set('deviceType', _ParseInstallation.default.DEVICE_TYPES.WEB);
118
- installation.set('installationId', installationId);
119
- installation.set('parseVersion', _CoreManager.default.get('VERSION'));
120
- currentInstallationCache = installation;
121
- _context3.next = 25;
122
- return _Storage.default.setItemAsync(path, (0, _stringify.default)(installation.toJSON()));
123
- case 25:
124
- return _context3.abrupt("return", installation);
125
- case 26:
126
- case "end":
127
- return _context3.stop();
128
- }
129
- }, _callee3);
130
- }))();
41
+ async currentInstallation() {
42
+ if (currentInstallationCache) {
43
+ return currentInstallationCache;
44
+ }
45
+ if (currentInstallationCacheMatchesDisk) {
46
+ return null;
47
+ }
48
+ const path = _Storage.default.generatePath(CURRENT_INSTALLATION_KEY);
49
+ let installationData = await _Storage.default.getItemAsync(path);
50
+ currentInstallationCacheMatchesDisk = true;
51
+ if (installationData) {
52
+ installationData = JSON.parse(installationData);
53
+ installationData.className = '_Installation';
54
+ const current = _ParseInstallation.default.fromJSON(installationData);
55
+ currentInstallationCache = current;
56
+ return current;
57
+ }
58
+ const installationId = await this.currentInstallationId();
59
+ const installation = new _ParseInstallation.default();
60
+ installation.set('deviceType', _ParseInstallation.default.DEVICE_TYPES.WEB);
61
+ installation.set('installationId', installationId);
62
+ installation.set('parseVersion', _CoreManager.default.get('VERSION'));
63
+ currentInstallationCache = installation;
64
+ await _Storage.default.setItemAsync(path, (0, _stringify.default)(installation.toJSON()));
65
+ return installation;
131
66
  },
132
- _clearCache: function () {
67
+ _clearCache() {
133
68
  iidCache = null;
134
69
  currentInstallationCache = null;
135
70
  currentInstallationCacheMatchesDisk = false;
136
71
  },
137
- _setInstallationIdCache: function (iid /*: string*/) {
72
+ _setInstallationIdCache(iid) {
138
73
  iidCache = iid;
139
74
  },
140
- _setCurrentInstallationCache: function (installation /*: ParseInstallation*/) {
141
- var matchesDisk = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
75
+ _setCurrentInstallationCache(installation) {
76
+ let matchesDisk = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
142
77
  currentInstallationCache = installation;
143
78
  currentInstallationCacheMatchesDisk = matchesDisk;
144
79
  }
145
80
  };
146
81
  module.exports = InstallationController;
147
- var _default = InstallationController;
148
- exports.default = _default;
82
+ var _default = exports.default = InstallationController;