parse 4.0.0-alpha.1 → 4.0.0-alpha.11

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 (255) hide show
  1. package/LICENSE +167 -25
  2. package/NOTICE +10 -0
  3. package/README.md +6 -5
  4. package/dist/parse.js +12838 -21190
  5. package/dist/parse.min.js +7 -6
  6. package/dist/parse.weapp.js +7921 -17062
  7. package/dist/parse.weapp.min.js +7 -6
  8. package/lib/browser/Analytics.js +2 -27
  9. package/lib/browser/AnonymousUtils.js +6 -42
  10. package/lib/browser/Cloud.js +12 -77
  11. package/lib/browser/CloudCode.js +0 -3
  12. package/lib/browser/CoreManager.js +46 -191
  13. package/lib/browser/CryptoController.js +2 -16
  14. package/lib/browser/EventEmitter.js +1 -8
  15. package/lib/browser/EventuallyQueue.js +277 -824
  16. package/lib/browser/FacebookUtils.js +6 -42
  17. package/lib/browser/IndexedDBStorageController.js +3 -14
  18. package/lib/browser/InstallationController.js +2 -20
  19. package/lib/browser/LiveQueryClient.js +105 -213
  20. package/lib/browser/LiveQuerySubscription.js +10 -39
  21. package/lib/browser/LocalDatastore.js +451 -1081
  22. package/lib/browser/LocalDatastoreController.js +145 -602
  23. package/lib/browser/LocalDatastoreController.react-native.js +137 -573
  24. package/lib/browser/LocalDatastoreUtils.js +2 -19
  25. package/lib/browser/ObjectStateMutations.js +18 -121
  26. package/lib/browser/OfflineQuery.js +61 -222
  27. package/lib/browser/Parse.js +12 -115
  28. package/lib/browser/ParseACL.js +33 -148
  29. package/lib/browser/ParseCLP.js +96 -314
  30. package/lib/browser/ParseConfig.js +18 -95
  31. package/lib/browser/ParseError.js +63 -99
  32. package/lib/browser/ParseFile.js +128 -685
  33. package/lib/browser/ParseGeoPoint.js +23 -89
  34. package/lib/browser/ParseHooks.js +1 -34
  35. package/lib/browser/ParseInstallation.js +4 -32
  36. package/lib/browser/ParseLiveQuery.js +96 -505
  37. package/lib/browser/ParseObject.js +665 -1845
  38. package/lib/browser/ParseOp.js +41 -287
  39. package/lib/browser/ParsePolygon.js +13 -70
  40. package/lib/browser/ParseQuery.js +403 -1504
  41. package/lib/browser/ParseRelation.js +12 -68
  42. package/lib/browser/ParseRole.js +13 -75
  43. package/lib/browser/ParseSchema.js +49 -208
  44. package/lib/browser/ParseSession.js +11 -69
  45. package/lib/browser/ParseUser.js +274 -1127
  46. package/lib/browser/Push.js +7 -50
  47. package/lib/browser/RESTController.js +28 -157
  48. package/lib/browser/SingleInstanceStateController.js +19 -144
  49. package/lib/browser/Socket.weapp.js +0 -10
  50. package/lib/browser/Storage.js +10 -80
  51. package/lib/browser/StorageController.browser.js +4 -24
  52. package/lib/browser/StorageController.default.js +4 -24
  53. package/lib/browser/StorageController.react-native.js +6 -40
  54. package/lib/browser/StorageController.weapp.js +5 -23
  55. package/lib/browser/TaskQueue.js +1 -29
  56. package/lib/browser/UniqueInstanceStateController.js +19 -149
  57. package/lib/browser/Xhr.weapp.js +0 -17
  58. package/lib/browser/arrayContainsObject.js +2 -23
  59. package/lib/browser/canBeSerialized.js +3 -40
  60. package/lib/browser/decode.js +3 -40
  61. package/lib/browser/encode.js +9 -77
  62. package/lib/browser/equals.js +2 -34
  63. package/lib/browser/escape.js +1 -15
  64. package/lib/browser/isRevocableSession.js +2 -18
  65. package/lib/browser/parseDate.js +2 -20
  66. package/lib/browser/promiseUtils.js +3 -21
  67. package/lib/browser/unique.js +3 -24
  68. package/lib/browser/unsavedChildren.js +6 -57
  69. package/lib/browser/uuid.js +3 -1
  70. package/lib/node/Analytics.js +1 -25
  71. package/lib/node/AnonymousUtils.js +5 -44
  72. package/lib/node/Cloud.js +10 -73
  73. package/lib/node/CloudCode.js +0 -3
  74. package/lib/node/CoreManager.js +47 -227
  75. package/lib/node/CryptoController.js +2 -16
  76. package/lib/node/EventEmitter.js +1 -8
  77. package/lib/node/EventuallyQueue.js +16 -123
  78. package/lib/node/FacebookUtils.js +5 -44
  79. package/lib/node/IndexedDBStorageController.js +3 -19
  80. package/lib/node/InstallationController.js +2 -22
  81. package/lib/node/LiveQueryClient.js +72 -154
  82. package/lib/node/LiveQuerySubscription.js +7 -26
  83. package/lib/node/LocalDatastore.js +19 -182
  84. package/lib/node/LocalDatastoreController.js +6 -45
  85. package/lib/node/LocalDatastoreController.react-native.js +6 -52
  86. package/lib/node/LocalDatastoreUtils.js +1 -13
  87. package/lib/node/ObjectStateMutations.js +13 -100
  88. package/lib/node/OfflineQuery.js +27 -151
  89. package/lib/node/Parse.js +11 -108
  90. package/lib/node/ParseACL.js +32 -157
  91. package/lib/node/ParseCLP.js +69 -269
  92. package/lib/node/ParseConfig.js +16 -91
  93. package/lib/node/ParseError.js +61 -74
  94. package/lib/node/ParseFile.js +49 -212
  95. package/lib/node/ParseGeoPoint.js +21 -89
  96. package/lib/node/ParseHooks.js +0 -35
  97. package/lib/node/ParseInstallation.js +1 -17
  98. package/lib/node/ParseLiveQuery.js +10 -43
  99. package/lib/node/ParseObject.js +229 -964
  100. package/lib/node/ParseOp.js +31 -262
  101. package/lib/node/ParsePolygon.js +12 -69
  102. package/lib/node/ParseQuery.js +169 -888
  103. package/lib/node/ParseRelation.js +11 -68
  104. package/lib/node/ParseRole.js +10 -64
  105. package/lib/node/ParseSchema.js +46 -229
  106. package/lib/node/ParseSession.js +8 -57
  107. package/lib/node/ParseUser.js +107 -583
  108. package/lib/node/Push.js +4 -44
  109. package/lib/node/RESTController.js +18 -127
  110. package/lib/node/SingleInstanceStateController.js +17 -137
  111. package/lib/node/Socket.weapp.js +0 -7
  112. package/lib/node/Storage.js +10 -90
  113. package/lib/node/StorageController.browser.js +4 -30
  114. package/lib/node/StorageController.default.js +5 -28
  115. package/lib/node/StorageController.react-native.js +6 -47
  116. package/lib/node/StorageController.weapp.js +6 -28
  117. package/lib/node/TaskQueue.js +1 -24
  118. package/lib/node/UniqueInstanceStateController.js +16 -140
  119. package/lib/node/Xhr.weapp.js +0 -15
  120. package/lib/node/arrayContainsObject.js +1 -19
  121. package/lib/node/canBeSerialized.js +2 -35
  122. package/lib/node/decode.js +1 -33
  123. package/lib/node/encode.js +3 -61
  124. package/lib/node/equals.js +0 -27
  125. package/lib/node/escape.js +1 -13
  126. package/lib/node/isRevocableSession.js +1 -12
  127. package/lib/node/parseDate.js +1 -14
  128. package/lib/node/promiseUtils.js +2 -14
  129. package/lib/node/unique.js +1 -18
  130. package/lib/node/unsavedChildren.js +2 -45
  131. package/lib/node/uuid.js +6 -1
  132. package/lib/react-native/Analytics.js +0 -9
  133. package/lib/react-native/AnonymousUtils.js +0 -10
  134. package/lib/react-native/Cloud.js +0 -26
  135. package/lib/react-native/CoreManager.js +2 -6
  136. package/lib/react-native/CryptoController.js +0 -2
  137. package/lib/react-native/EventEmitter.js +0 -2
  138. package/lib/react-native/EventuallyQueue.js +156 -711
  139. package/lib/react-native/FacebookUtils.js +0 -22
  140. package/lib/react-native/IndexedDBStorageController.js +0 -1
  141. package/lib/react-native/InstallationController.js +0 -6
  142. package/lib/react-native/LiveQueryClient.js +46 -157
  143. package/lib/react-native/LiveQuerySubscription.js +3 -27
  144. package/lib/react-native/LocalDatastore.js +281 -948
  145. package/lib/react-native/LocalDatastoreController.js +71 -552
  146. package/lib/react-native/LocalDatastoreController.react-native.js +91 -526
  147. package/lib/react-native/LocalDatastoreUtils.js +0 -1
  148. package/lib/react-native/ObjectStateMutations.js +2 -65
  149. package/lib/react-native/OfflineQuery.js +25 -196
  150. package/lib/react-native/Parse.js +0 -65
  151. package/lib/react-native/ParseACL.js +0 -44
  152. package/lib/react-native/ParseCLP.js +23 -161
  153. package/lib/react-native/ParseConfig.js +0 -42
  154. package/lib/react-native/ParseError.js +1 -21
  155. package/lib/react-native/ParseFile.js +55 -529
  156. package/lib/react-native/ParseGeoPoint.js +0 -17
  157. package/lib/react-native/ParseHooks.js +0 -30
  158. package/lib/react-native/ParseInstallation.js +1 -23
  159. package/lib/react-native/ParseLiveQuery.js +55 -472
  160. package/lib/react-native/ParseObject.js +245 -1246
  161. package/lib/react-native/ParseOp.js +1 -138
  162. package/lib/react-native/ParsePolygon.js +0 -24
  163. package/lib/react-native/ParseQuery.js +182 -874
  164. package/lib/react-native/ParseRelation.js +0 -25
  165. package/lib/react-native/ParseRole.js +1 -36
  166. package/lib/react-native/ParseSchema.js +3 -54
  167. package/lib/react-native/ParseSession.js +1 -40
  168. package/lib/react-native/ParseUser.js +95 -773
  169. package/lib/react-native/Push.js +0 -16
  170. package/lib/react-native/RESTController.js +12 -109
  171. package/lib/react-native/SingleInstanceStateController.js +0 -44
  172. package/lib/react-native/Socket.weapp.js +0 -10
  173. package/lib/react-native/Storage.js +0 -24
  174. package/lib/react-native/StorageController.browser.js +0 -2
  175. package/lib/react-native/StorageController.default.js +0 -1
  176. package/lib/react-native/StorageController.react-native.js +0 -2
  177. package/lib/react-native/TaskQueue.js +0 -15
  178. package/lib/react-native/UniqueInstanceStateController.js +0 -47
  179. package/lib/react-native/Xhr.weapp.js +0 -16
  180. package/lib/react-native/arrayContainsObject.js +0 -5
  181. package/lib/react-native/canBeSerialized.js +0 -18
  182. package/lib/react-native/decode.js +0 -21
  183. package/lib/react-native/encode.js +0 -25
  184. package/lib/react-native/equals.js +0 -18
  185. package/lib/react-native/escape.js +0 -1
  186. package/lib/react-native/isRevocableSession.js +0 -1
  187. package/lib/react-native/parseDate.js +0 -3
  188. package/lib/react-native/promiseUtils.js +0 -13
  189. package/lib/react-native/unique.js +0 -4
  190. package/lib/react-native/unsavedChildren.js +0 -21
  191. package/lib/react-native/uuid.js +3 -1
  192. package/lib/weapp/Analytics.js +2 -27
  193. package/lib/weapp/AnonymousUtils.js +6 -42
  194. package/lib/weapp/Cloud.js +12 -77
  195. package/lib/weapp/CloudCode.js +0 -3
  196. package/lib/weapp/CoreManager.js +46 -191
  197. package/lib/weapp/CryptoController.js +2 -16
  198. package/lib/weapp/EventEmitter.js +1 -8
  199. package/lib/weapp/EventuallyQueue.js +277 -824
  200. package/lib/weapp/FacebookUtils.js +6 -42
  201. package/lib/weapp/IndexedDBStorageController.js +3 -14
  202. package/lib/weapp/InstallationController.js +2 -20
  203. package/lib/weapp/LiveQueryClient.js +105 -213
  204. package/lib/weapp/LiveQuerySubscription.js +10 -39
  205. package/lib/weapp/LocalDatastore.js +451 -1081
  206. package/lib/weapp/LocalDatastoreController.js +145 -602
  207. package/lib/weapp/LocalDatastoreController.react-native.js +137 -573
  208. package/lib/weapp/LocalDatastoreUtils.js +2 -19
  209. package/lib/weapp/ObjectStateMutations.js +18 -121
  210. package/lib/weapp/OfflineQuery.js +61 -222
  211. package/lib/weapp/Parse.js +12 -115
  212. package/lib/weapp/ParseACL.js +33 -148
  213. package/lib/weapp/ParseCLP.js +96 -314
  214. package/lib/weapp/ParseConfig.js +18 -95
  215. package/lib/weapp/ParseError.js +63 -99
  216. package/lib/weapp/ParseFile.js +129 -686
  217. package/lib/weapp/ParseGeoPoint.js +23 -89
  218. package/lib/weapp/ParseHooks.js +1 -34
  219. package/lib/weapp/ParseInstallation.js +4 -32
  220. package/lib/weapp/ParseLiveQuery.js +96 -505
  221. package/lib/weapp/ParseObject.js +665 -1845
  222. package/lib/weapp/ParseOp.js +41 -287
  223. package/lib/weapp/ParsePolygon.js +13 -70
  224. package/lib/weapp/ParseQuery.js +403 -1504
  225. package/lib/weapp/ParseRelation.js +12 -68
  226. package/lib/weapp/ParseRole.js +13 -75
  227. package/lib/weapp/ParseSchema.js +49 -208
  228. package/lib/weapp/ParseSession.js +11 -69
  229. package/lib/weapp/ParseUser.js +274 -1127
  230. package/lib/weapp/Push.js +7 -50
  231. package/lib/weapp/RESTController.js +28 -157
  232. package/lib/weapp/SingleInstanceStateController.js +19 -144
  233. package/lib/weapp/Socket.weapp.js +0 -10
  234. package/lib/weapp/Storage.js +10 -80
  235. package/lib/weapp/StorageController.browser.js +4 -24
  236. package/lib/weapp/StorageController.default.js +4 -24
  237. package/lib/weapp/StorageController.react-native.js +6 -40
  238. package/lib/weapp/StorageController.weapp.js +5 -23
  239. package/lib/weapp/TaskQueue.js +1 -29
  240. package/lib/weapp/UniqueInstanceStateController.js +19 -149
  241. package/lib/weapp/Xhr.weapp.js +0 -17
  242. package/lib/weapp/arrayContainsObject.js +2 -23
  243. package/lib/weapp/canBeSerialized.js +3 -40
  244. package/lib/weapp/decode.js +3 -40
  245. package/lib/weapp/encode.js +9 -77
  246. package/lib/weapp/equals.js +2 -34
  247. package/lib/weapp/escape.js +1 -15
  248. package/lib/weapp/isRevocableSession.js +2 -18
  249. package/lib/weapp/parseDate.js +2 -20
  250. package/lib/weapp/promiseUtils.js +3 -21
  251. package/lib/weapp/unique.js +3 -24
  252. package/lib/weapp/unsavedChildren.js +6 -57
  253. package/lib/weapp/uuid.js +1 -6
  254. package/package.json +35 -31
  255. package/PATENTS +0 -37
@@ -1,23 +1,18 @@
1
1
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
3
  value: true
5
4
  });
6
5
  exports.default = void 0;
7
-
8
6
  var _ParseUser = _interopRequireDefault(require("./ParseUser"));
9
-
10
7
  var initialized = false;
11
8
  var requestedPermissions;
12
9
  var initOptions;
13
10
  var provider = {
14
11
  authenticate: function (options) {
15
12
  var _this = this;
16
-
17
13
  if (typeof FB === 'undefined') {
18
14
  options.error(this, 'Facebook SDK not found.');
19
15
  }
20
-
21
16
  FB.login(function (response) {
22
17
  if (response.authResponse) {
23
18
  if (options.success) {
@@ -39,23 +34,18 @@ var provider = {
39
34
  restoreAuthentication: function (authData) {
40
35
  if (authData) {
41
36
  var newOptions = {};
42
-
43
37
  if (initOptions) {
44
38
  for (var key in initOptions) {
45
39
  newOptions[key] = initOptions[key];
46
40
  }
47
41
  }
48
-
49
42
  newOptions.status = false;
50
43
  var existingResponse = FB.getAuthResponse();
51
-
52
44
  if (existingResponse && existingResponse.userID !== authData.id) {
53
45
  FB.logout();
54
46
  }
55
-
56
47
  FB.init(newOptions);
57
48
  }
58
-
59
49
  return true;
60
50
  },
61
51
  getAuthType: function () {
@@ -70,26 +60,19 @@ var FacebookUtils = {
70
60
  if (typeof FB === 'undefined') {
71
61
  throw new Error('The Facebook JavaScript SDK must be loaded before calling init.');
72
62
  }
73
-
74
63
  initOptions = {};
75
-
76
64
  if (options) {
77
65
  for (var key in options) {
78
66
  initOptions[key] = options[key];
79
67
  }
80
68
  }
81
-
82
69
  if (initOptions.status && typeof console !== 'undefined') {
83
70
  var warn = console.warn || console.log || function () {};
84
-
85
71
  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.');
86
72
  }
87
-
88
73
  initOptions.status = false;
89
74
  FB.init(initOptions);
90
-
91
75
  _ParseUser.default._registerAuthenticationProvider(provider);
92
-
93
76
  initialized = true;
94
77
  },
95
78
  isLinked: function (user) {
@@ -100,11 +83,9 @@ var FacebookUtils = {
100
83
  if (!initialized) {
101
84
  throw new Error('You must initialize FacebookUtils before calling logIn.');
102
85
  }
103
-
104
86
  requestedPermissions = permissions;
105
87
  return _ParseUser.default.logInWith('facebook', options);
106
88
  }
107
-
108
89
  return _ParseUser.default.logInWith('facebook', {
109
90
  authData: permissions
110
91
  }, options);
@@ -114,11 +95,9 @@ var FacebookUtils = {
114
95
  if (!initialized) {
115
96
  throw new Error('You must initialize FacebookUtils before calling link.');
116
97
  }
117
-
118
98
  requestedPermissions = permissions;
119
99
  return user.linkWith('facebook', options);
120
100
  }
121
-
122
101
  return user.linkWith('facebook', {
123
102
  authData: permissions
124
103
  }, options);
@@ -127,7 +106,6 @@ var FacebookUtils = {
127
106
  if (!initialized) {
128
107
  throw new Error('You must initialize FacebookUtils before calling unlink.');
129
108
  }
130
-
131
109
  return user._unlinkFrom('facebook', options);
132
110
  },
133
111
  _getAuthProvider: function () {
@@ -1,5 +1,4 @@
1
1
  var _idbKeyval = require("idb-keyval");
2
-
3
2
  if (typeof window !== 'undefined' && window.indexedDB) {
4
3
  var ParseStore = (0, _idbKeyval.createStore)('parseDB', 'parseStore');
5
4
  var IndexedDBStorageController = {
@@ -1,18 +1,13 @@
1
1
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
2
-
3
2
  var _Storage = _interopRequireDefault(require("./Storage"));
4
-
5
3
  var uuidv4 = require('./uuid');
6
-
7
4
  var iidCache = null;
8
5
  var InstallationController = {
9
6
  currentInstallationId: function () {
10
7
  if (typeof iidCache === 'string') {
11
8
  return Promise.resolve(iidCache);
12
9
  }
13
-
14
10
  var path = _Storage.default.generatePath('installationId');
15
-
16
11
  return _Storage.default.getItemAsync(path).then(function (iid) {
17
12
  if (!iid) {
18
13
  iid = uuidv4();
@@ -21,7 +16,6 @@ var InstallationController = {
21
16
  return iid;
22
17
  });
23
18
  }
24
-
25
19
  iidCache = iid;
26
20
  return iid;
27
21
  });
@@ -1,93 +1,37 @@
1
1
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
3
  value: true
5
4
  });
6
5
  exports.default = void 0;
7
-
8
6
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
-
10
7
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
-
12
8
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
13
-
14
9
  var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
15
-
16
10
  var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
17
-
18
11
  var _CoreManager = _interopRequireDefault(require("./CoreManager"));
19
-
20
12
  var _EventEmitter2 = _interopRequireDefault(require("./EventEmitter"));
21
-
22
13
  var _ParseObject = _interopRequireDefault(require("./ParseObject"));
23
-
24
14
  var _LiveQuerySubscription = _interopRequireDefault(require("./LiveQuerySubscription"));
25
-
26
15
  var _promiseUtils = require("./promiseUtils");
27
-
28
- function _createForOfIteratorHelperLoose(o, allowArrayLike) {
29
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
30
- if (it) return (it = it.call(o)).next.bind(it);
31
-
32
- if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
33
- if (it) o = it;
34
- var i = 0;
35
- return function () {
36
- if (i >= o.length) return {
37
- done: true
38
- };
39
- return {
40
- done: false,
41
- value: o[i++]
42
- };
43
- };
44
- }
45
-
46
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
47
- }
48
-
49
- function _unsupportedIterableToArray(o, minLen) {
50
- if (!o) return;
51
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
52
- var n = Object.prototype.toString.call(o).slice(8, -1);
53
- if (n === "Object" && o.constructor) n = o.constructor.name;
54
- if (n === "Map" || n === "Set") return Array.from(o);
55
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
56
- }
57
-
58
- function _arrayLikeToArray(arr, len) {
59
- if (len == null || len > arr.length) len = arr.length;
60
-
61
- for (var i = 0, arr2 = new Array(len); i < len; i++) {
62
- arr2[i] = arr[i];
63
- }
64
-
65
- return arr2;
66
- }
67
-
16
+ var _ParseError = _interopRequireDefault(require("./ParseError"));
68
17
  function _createSuper(Derived) {
69
18
  var hasNativeReflectConstruct = _isNativeReflectConstruct();
70
-
71
19
  return function () {
72
20
  var Super = (0, _getPrototypeOf2.default)(Derived),
73
- result;
74
-
21
+ result;
75
22
  if (hasNativeReflectConstruct) {
76
23
  var NewTarget = (0, _getPrototypeOf2.default)(this).constructor;
77
24
  result = Reflect.construct(Super, arguments, NewTarget);
78
25
  } else {
79
26
  result = Super.apply(this, arguments);
80
27
  }
81
-
82
28
  return (0, _possibleConstructorReturn2.default)(this, result);
83
29
  };
84
30
  }
85
-
86
31
  function _isNativeReflectConstruct() {
87
32
  if (typeof Reflect === "undefined" || !Reflect.construct) return false;
88
33
  if (Reflect.construct.sham) return false;
89
34
  if (typeof Proxy === "function") return true;
90
-
91
35
  try {
92
36
  Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
93
37
  return true;
@@ -95,7 +39,6 @@ function _isNativeReflectConstruct() {
95
39
  return false;
96
40
  }
97
41
  }
98
-
99
42
  var CLIENT_STATE = {
100
43
  INITIALIZED: 'initialized',
101
44
  CONNECTING: 'connecting',
@@ -136,32 +79,25 @@ var SUBSCRIPTION_EMMITER_TYPES = {
136
79
  LEAVE: 'leave',
137
80
  DELETE: 'delete'
138
81
  };
139
-
140
82
  var generateInterval = function (k) {
141
83
  return Math.random() * Math.min(30, Math.pow(2, k) - 1) * 1000;
142
84
  };
143
-
144
85
  var LiveQueryClient = function (_EventEmitter) {
145
86
  (0, _inherits2.default)(LiveQueryClient, _EventEmitter);
146
-
147
87
  var _super = _createSuper(LiveQueryClient);
148
-
149
88
  function LiveQueryClient(_ref) {
150
89
  var _this;
151
-
152
90
  var applicationId = _ref.applicationId,
153
- serverURL = _ref.serverURL,
154
- javascriptKey = _ref.javascriptKey,
155
- masterKey = _ref.masterKey,
156
- sessionToken = _ref.sessionToken,
157
- installationId = _ref.installationId;
91
+ serverURL = _ref.serverURL,
92
+ javascriptKey = _ref.javascriptKey,
93
+ masterKey = _ref.masterKey,
94
+ sessionToken = _ref.sessionToken,
95
+ installationId = _ref.installationId;
158
96
  (0, _classCallCheck2.default)(this, LiveQueryClient);
159
97
  _this = _super.call(this);
160
-
161
98
  if (!serverURL || serverURL.indexOf('ws') !== 0) {
162
99
  throw new Error('You need to set a proper Parse LiveQuery server url before using LiveQueryClient');
163
100
  }
164
-
165
101
  _this.reconnectHandle = null;
166
102
  _this.attempts = 1;
167
103
  _this.id = 0;
@@ -176,12 +112,9 @@ var LiveQueryClient = function (_EventEmitter) {
176
112
  _this.connectPromise = (0, _promiseUtils.resolvingPromise)();
177
113
  _this.subscriptions = new Map();
178
114
  _this.state = CLIENT_STATE.INITIALIZED;
179
-
180
115
  _this.on('error', function () {});
181
-
182
116
  return _this;
183
117
  }
184
-
185
118
  (0, _createClass2.default)(LiveQueryClient, [{
186
119
  key: "shouldOpen",
187
120
  value: function () {
@@ -191,11 +124,9 @@ var LiveQueryClient = function (_EventEmitter) {
191
124
  key: "subscribe",
192
125
  value: function (query, sessionToken) {
193
126
  var _this2 = this;
194
-
195
127
  if (!query) {
196
128
  return;
197
129
  }
198
-
199
130
  var className = query.className;
200
131
  var queryJSON = query.toJSON();
201
132
  var where = queryJSON.where;
@@ -209,16 +140,16 @@ var LiveQueryClient = function (_EventEmitter) {
209
140
  fields: fields
210
141
  }
211
142
  };
212
-
213
143
  if (sessionToken) {
214
144
  subscribeRequest.sessionToken = sessionToken;
215
145
  }
216
-
217
146
  var subscription = new _LiveQuerySubscription.default(this.requestId, query, sessionToken);
218
147
  this.subscriptions.set(this.requestId, subscription);
219
148
  this.requestId += 1;
220
149
  this.connectPromise.then(function () {
221
150
  _this2.socket.send(JSON.stringify(subscribeRequest));
151
+ }).catch(function (error) {
152
+ subscription.subscribePromise.reject(error);
222
153
  });
223
154
  return subscription;
224
155
  }
@@ -226,50 +157,41 @@ var LiveQueryClient = function (_EventEmitter) {
226
157
  key: "unsubscribe",
227
158
  value: function (subscription) {
228
159
  var _this3 = this;
229
-
230
160
  if (!subscription) {
231
161
  return;
232
162
  }
233
-
234
- this.subscriptions.delete(subscription.id);
235
163
  var unsubscribeRequest = {
236
164
  op: OP_TYPES.UNSUBSCRIBE,
237
165
  requestId: subscription.id
238
166
  };
239
- this.connectPromise.then(function () {
240
- _this3.socket.send(JSON.stringify(unsubscribeRequest));
167
+ return this.connectPromise.then(function () {
168
+ return _this3.socket.send(JSON.stringify(unsubscribeRequest));
169
+ }).then(function () {
170
+ return subscription.unsubscribePromise;
241
171
  });
242
172
  }
243
173
  }, {
244
174
  key: "open",
245
175
  value: function () {
246
176
  var _this4 = this;
247
-
248
177
  var WebSocketImplementation = _CoreManager.default.getWebSocketController();
249
-
250
178
  if (!WebSocketImplementation) {
251
179
  this.emit(CLIENT_EMMITER_TYPES.ERROR, 'Can not find WebSocket implementation');
252
180
  return;
253
181
  }
254
-
255
182
  if (this.state !== CLIENT_STATE.RECONNECTING) {
256
183
  this.state = CLIENT_STATE.CONNECTING;
257
184
  }
258
-
259
185
  this.socket = new WebSocketImplementation(this.serverURL);
260
-
261
186
  this.socket.onopen = function () {
262
187
  _this4._handleWebSocketOpen();
263
188
  };
264
-
265
189
  this.socket.onmessage = function (event) {
266
190
  _this4._handleWebSocketMessage(event);
267
191
  };
268
-
269
192
  this.socket.onclose = function () {
270
193
  _this4._handleWebSocketClose();
271
194
  };
272
-
273
195
  this.socket.onerror = function (error) {
274
196
  _this4._handleWebSocketError(error);
275
197
  };
@@ -278,7 +200,6 @@ var LiveQueryClient = function (_EventEmitter) {
278
200
  key: "resubscribe",
279
201
  value: function () {
280
202
  var _this5 = this;
281
-
282
203
  this.subscriptions.forEach(function (subscription, requestId) {
283
204
  var query = subscription.query;
284
205
  var queryJSON = query.toJSON();
@@ -295,11 +216,9 @@ var LiveQueryClient = function (_EventEmitter) {
295
216
  fields: fields
296
217
  }
297
218
  };
298
-
299
219
  if (sessionToken) {
300
220
  subscribeRequest.sessionToken = sessionToken;
301
221
  }
302
-
303
222
  _this5.connectPromise.then(function () {
304
223
  _this5.socket.send(JSON.stringify(subscribeRequest));
305
224
  });
@@ -311,18 +230,13 @@ var LiveQueryClient = function (_EventEmitter) {
311
230
  if (this.state === CLIENT_STATE.INITIALIZED || this.state === CLIENT_STATE.DISCONNECTED) {
312
231
  return;
313
232
  }
314
-
315
233
  this.state = CLIENT_STATE.DISCONNECTED;
316
234
  this.socket.close();
317
-
318
- for (var _iterator = _createForOfIteratorHelperLoose(this.subscriptions.values()), _step; !(_step = _iterator()).done;) {
319
- var subscription = _step.value;
235
+ for (var subscription of this.subscriptions.values()) {
320
236
  subscription.subscribed = false;
321
237
  subscription.emit(SUBSCRIPTION_EMMITER_TYPES.CLOSE);
322
238
  }
323
-
324
239
  this._handleReset();
325
-
326
240
  this.emit(CLIENT_EMMITER_TYPES.CLOSE);
327
241
  }
328
242
  }, {
@@ -345,45 +259,36 @@ var LiveQueryClient = function (_EventEmitter) {
345
259
  masterKey: this.masterKey,
346
260
  sessionToken: this.sessionToken
347
261
  };
348
-
349
262
  if (this.additionalProperties) {
350
263
  connectRequest.installationId = this.installationId;
351
264
  }
352
-
353
265
  this.socket.send(JSON.stringify(connectRequest));
354
266
  }
355
267
  }, {
356
268
  key: "_handleWebSocketMessage",
357
269
  value: function (event) {
358
270
  var data = event.data;
359
-
360
271
  if (typeof data === 'string') {
361
272
  data = JSON.parse(data);
362
273
  }
363
-
364
274
  var subscription = null;
365
-
366
275
  if (data.requestId) {
367
276
  subscription = this.subscriptions.get(data.requestId);
368
277
  }
369
-
370
278
  var response = {
371
279
  clientId: data.clientId,
372
280
  installationId: data.installationId
373
281
  };
374
-
375
282
  switch (data.op) {
376
283
  case OP_EVENTS.CONNECTED:
377
284
  if (this.state === CLIENT_STATE.RECONNECTING) {
378
285
  this.resubscribe();
379
286
  }
380
-
381
287
  this.emit(CLIENT_EMMITER_TYPES.OPEN);
382
288
  this.id = data.clientId;
383
289
  this.connectPromise.resolve();
384
290
  this.state = CLIENT_STATE.CONNECTED;
385
291
  break;
386
-
387
292
  case OP_EVENTS.SUBSCRIBED:
388
293
  if (subscription) {
389
294
  subscription.subscribed = true;
@@ -392,67 +297,65 @@ var LiveQueryClient = function (_EventEmitter) {
392
297
  return subscription.emit(SUBSCRIPTION_EMMITER_TYPES.OPEN, response);
393
298
  }, 200);
394
299
  }
395
-
396
300
  break;
397
-
398
301
  case OP_EVENTS.ERROR:
399
- if (data.requestId) {
400
- if (subscription) {
401
- subscription.subscribePromise.resolve();
402
- setTimeout(function () {
403
- return subscription.emit(SUBSCRIPTION_EMMITER_TYPES.ERROR, data.error);
404
- }, 200);
302
+ {
303
+ var parseError = new _ParseError.default(data.code, data.error);
304
+ if (!this.id) {
305
+ this.connectPromise.reject(parseError);
306
+ this.state = CLIENT_STATE.DISCONNECTED;
405
307
  }
406
- } else {
407
- this.emit(CLIENT_EMMITER_TYPES.ERROR, data.error);
408
- }
409
-
410
- if (data.error === 'Additional properties not allowed') {
411
- this.additionalProperties = false;
412
- }
413
-
414
- if (data.reconnect) {
415
- this._handleReconnect();
308
+ if (data.requestId) {
309
+ if (subscription) {
310
+ subscription.subscribePromise.reject(parseError);
311
+ setTimeout(function () {
312
+ return subscription.emit(SUBSCRIPTION_EMMITER_TYPES.ERROR, data.error);
313
+ }, 200);
314
+ }
315
+ } else {
316
+ this.emit(CLIENT_EMMITER_TYPES.ERROR, data.error);
317
+ }
318
+ if (data.error === 'Additional properties not allowed') {
319
+ this.additionalProperties = false;
320
+ }
321
+ if (data.reconnect) {
322
+ this._handleReconnect();
323
+ }
324
+ break;
416
325
  }
417
-
418
- break;
419
-
420
326
  case OP_EVENTS.UNSUBSCRIBED:
421
- break;
422
-
327
+ {
328
+ if (subscription) {
329
+ this.subscriptions.delete(data.requestId);
330
+ subscription.subscribed = false;
331
+ subscription.unsubscribePromise.resolve();
332
+ }
333
+ break;
334
+ }
423
335
  default:
424
336
  {
425
337
  if (!subscription) {
426
338
  break;
427
339
  }
428
-
429
340
  var override = false;
430
-
431
341
  if (data.original) {
432
342
  override = true;
433
343
  delete data.original.__type;
434
-
435
344
  for (var field in data.original) {
436
345
  if (!(field in data.object)) {
437
346
  data.object[field] = undefined;
438
347
  }
439
348
  }
440
-
441
349
  data.original = _ParseObject.default.fromJSON(data.original, false);
442
350
  }
443
-
444
351
  delete data.object.__type;
445
-
446
352
  var parseObject = _ParseObject.default.fromJSON(data.object, !(subscription.query && subscription.query._select) ? override : false);
447
-
448
353
  if (data.original) {
449
354
  subscription.emit(data.op, parseObject, data.original, response);
450
355
  } else {
451
356
  subscription.emit(data.op, parseObject, response);
452
357
  }
453
-
454
358
  var localDatastore = _CoreManager.default.getLocalDatastore();
455
-
456
359
  if (override && localDatastore.isEnabled) {
457
360
  localDatastore._updateObjectIfPinned(parseObject).then(function () {});
458
361
  }
@@ -465,57 +368,43 @@ var LiveQueryClient = function (_EventEmitter) {
465
368
  if (this.state === CLIENT_STATE.DISCONNECTED) {
466
369
  return;
467
370
  }
468
-
469
371
  this.state = CLIENT_STATE.CLOSED;
470
372
  this.emit(CLIENT_EMMITER_TYPES.CLOSE);
471
-
472
- for (var _iterator2 = _createForOfIteratorHelperLoose(this.subscriptions.values()), _step2; !(_step2 = _iterator2()).done;) {
473
- var subscription = _step2.value;
373
+ for (var subscription of this.subscriptions.values()) {
474
374
  subscription.emit(SUBSCRIPTION_EMMITER_TYPES.CLOSE);
475
375
  }
476
-
477
376
  this._handleReconnect();
478
377
  }
479
378
  }, {
480
379
  key: "_handleWebSocketError",
481
380
  value: function (error) {
482
381
  this.emit(CLIENT_EMMITER_TYPES.ERROR, error);
483
-
484
- for (var _iterator3 = _createForOfIteratorHelperLoose(this.subscriptions.values()), _step3; !(_step3 = _iterator3()).done;) {
485
- var subscription = _step3.value;
382
+ for (var subscription of this.subscriptions.values()) {
486
383
  subscription.emit(SUBSCRIPTION_EMMITER_TYPES.ERROR, error);
487
384
  }
488
-
489
385
  this._handleReconnect();
490
386
  }
491
387
  }, {
492
388
  key: "_handleReconnect",
493
389
  value: function () {
494
390
  var _this6 = this;
495
-
496
391
  if (this.state === CLIENT_STATE.DISCONNECTED) {
497
392
  return;
498
393
  }
499
-
500
394
  this.state = CLIENT_STATE.RECONNECTING;
501
395
  var time = generateInterval(this.attempts);
502
-
503
396
  if (this.reconnectHandle) {
504
397
  clearTimeout(this.reconnectHandle);
505
398
  }
506
-
507
399
  this.reconnectHandle = setTimeout(function () {
508
400
  _this6.attempts++;
509
401
  _this6.connectPromise = (0, _promiseUtils.resolvingPromise)();
510
-
511
402
  _this6.open();
512
403
  }.bind(this), time);
513
404
  }
514
405
  }]);
515
406
  return LiveQueryClient;
516
407
  }(_EventEmitter2.default);
517
-
518
408
  _CoreManager.default.setWebSocketController(WebSocket);
519
-
520
409
  var _default = LiveQueryClient;
521
410
  exports.default = _default;