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,24 +1,14 @@
1
1
  "use strict";
2
2
 
3
3
  var _CoreManager = _interopRequireDefault(require("./CoreManager"));
4
-
5
4
  var _ParseQuery = _interopRequireDefault(require("./ParseQuery"));
6
-
7
5
  var _LocalDatastoreUtils = require("./LocalDatastoreUtils");
8
-
9
6
  function _interopRequireDefault(obj) {
10
7
  return obj && obj.__esModule ? obj : {
11
8
  default: obj
12
9
  };
13
10
  }
14
11
  /**
15
- * Copyright (c) 2015-present, Parse, LLC.
16
- * All rights reserved.
17
- *
18
- * This source code is licensed under the BSD-style license found in the
19
- * LICENSE file in the root directory of this source tree. An additional grant
20
- * of patent rights can be found in the PATENTS file in the same directory.
21
- *
22
12
  * @flow
23
13
  */
24
14
 
@@ -42,130 +32,73 @@ function _interopRequireDefault(obj) {
42
32
  * @class Parse.LocalDatastore
43
33
  * @static
44
34
  */
45
-
46
-
47
35
  const LocalDatastore = {
48
36
  isEnabled: false,
49
37
  isSyncing: false,
50
-
51
- fromPinWithName(name
52
- /*: string*/
53
- )
54
- /*: Promise<Array<Object>>*/
55
- {
38
+ fromPinWithName(name /*: string*/) /*: Promise<Array<Object>>*/{
56
39
  const controller = _CoreManager.default.getLocalDatastoreController();
57
-
58
40
  return controller.fromPinWithName(name);
59
41
  },
60
-
61
- pinWithName(name
62
- /*: string*/
63
- , value
64
- /*: any*/
65
- )
66
- /*: Promise<void>*/
67
- {
42
+ pinWithName(name /*: string*/, value /*: any*/) /*: Promise<void>*/{
68
43
  const controller = _CoreManager.default.getLocalDatastoreController();
69
-
70
44
  return controller.pinWithName(name, value);
71
45
  },
72
-
73
- unPinWithName(name
74
- /*: string*/
75
- )
76
- /*: Promise<void>*/
77
- {
46
+ unPinWithName(name /*: string*/) /*: Promise<void>*/{
78
47
  const controller = _CoreManager.default.getLocalDatastoreController();
79
-
80
48
  return controller.unPinWithName(name);
81
49
  },
82
-
83
- _getAllContents()
84
- /*: Promise<Object>*/
85
- {
50
+ _getAllContents() /*: Promise<Object>*/{
86
51
  const controller = _CoreManager.default.getLocalDatastoreController();
87
-
88
52
  return controller.getAllContents();
89
53
  },
90
-
91
54
  // Use for testing
92
- _getRawStorage()
93
- /*: Promise<Object>*/
94
- {
55
+ _getRawStorage() /*: Promise<Object>*/{
95
56
  const controller = _CoreManager.default.getLocalDatastoreController();
96
-
97
57
  return controller.getRawStorage();
98
58
  },
99
-
100
- _clear()
101
- /*: Promise<void>*/
102
- {
59
+ _clear() /*: Promise<void>*/{
103
60
  const controller = _CoreManager.default.getLocalDatastoreController();
104
-
105
61
  return controller.clear();
106
62
  },
107
-
108
63
  // Pin the object and children recursively
109
64
  // Saves the object and children key to Pin Name
110
- async _handlePinAllWithName(name
111
- /*: string*/
112
- , objects
113
- /*: Array<ParseObject>*/
114
- )
115
- /*: Promise<void>*/
116
- {
65
+ async _handlePinAllWithName(name /*: string*/, objects /*: Array<ParseObject>*/) /*: Promise<void>*/{
117
66
  const pinName = this.getPinName(name);
118
67
  const toPinPromises = [];
119
68
  const objectKeys = [];
120
-
121
69
  for (const parent of objects) {
122
70
  const children = this._getChildren(parent);
123
-
124
71
  const parentKey = this.getKeyForObject(parent);
125
-
126
72
  const json = parent._toFullJSON(undefined, true);
127
-
128
73
  if (parent._localId) {
129
74
  json._localId = parent._localId;
130
75
  }
131
-
132
76
  children[parentKey] = json;
133
-
134
77
  for (const objectKey in children) {
135
78
  objectKeys.push(objectKey);
136
79
  toPinPromises.push(this.pinWithName(objectKey, [children[objectKey]]));
137
80
  }
138
81
  }
139
-
140
82
  const fromPinPromise = this.fromPinWithName(pinName);
141
83
  const [pinned] = await Promise.all([fromPinPromise, toPinPromises]);
142
84
  const toPin = [...new Set([...(pinned || []), ...objectKeys])];
143
85
  return this.pinWithName(pinName, toPin);
144
86
  },
145
-
146
87
  // Removes object and children keys from pin name
147
88
  // Keeps the object and children pinned
148
- async _handleUnPinAllWithName(name
149
- /*: string*/
150
- , objects
151
- /*: Array<ParseObject>*/
152
- ) {
89
+ async _handleUnPinAllWithName(name /*: string*/, objects /*: Array<ParseObject>*/) {
153
90
  const localDatastore = await this._getAllContents();
154
91
  const pinName = this.getPinName(name);
155
92
  const promises = [];
156
93
  let objectKeys = [];
157
-
158
94
  for (const parent of objects) {
159
95
  const children = this._getChildren(parent);
160
-
161
96
  const parentKey = this.getKeyForObject(parent);
162
97
  objectKeys.push(parentKey, ...Object.keys(children));
163
98
  }
164
-
165
99
  objectKeys = [...new Set(objectKeys)];
166
100
  let pinned = localDatastore[pinName] || [];
167
101
  pinned = pinned.filter(item => !objectKeys.includes(item));
168
-
169
102
  if (pinned.length == 0) {
170
103
  promises.push(this.unPinWithName(pinName));
171
104
  delete localDatastore[pinName];
@@ -173,141 +106,100 @@ const LocalDatastore = {
173
106
  promises.push(this.pinWithName(pinName, pinned));
174
107
  localDatastore[pinName] = pinned;
175
108
  }
176
-
177
109
  for (const objectKey of objectKeys) {
178
110
  let hasReference = false;
179
-
180
111
  for (const key in localDatastore) {
181
112
  if (key === _LocalDatastoreUtils.DEFAULT_PIN || key.startsWith(_LocalDatastoreUtils.PIN_PREFIX)) {
182
113
  const pinnedObjects = localDatastore[key] || [];
183
-
184
114
  if (pinnedObjects.includes(objectKey)) {
185
115
  hasReference = true;
186
116
  break;
187
117
  }
188
118
  }
189
119
  }
190
-
191
120
  if (!hasReference) {
192
121
  promises.push(this.unPinWithName(objectKey));
193
122
  }
194
123
  }
195
-
196
124
  return Promise.all(promises);
197
125
  },
198
-
199
126
  // Retrieve all pointer fields from object recursively
200
- _getChildren(object
201
- /*: ParseObject*/
202
- ) {
127
+ _getChildren(object /*: ParseObject*/) {
203
128
  const encountered = {};
204
-
205
129
  const json = object._toFullJSON(undefined, true);
206
-
207
130
  for (const key in json) {
208
131
  if (json[key] && json[key].__type && json[key].__type === 'Object') {
209
132
  this._traverse(json[key], encountered);
210
133
  }
211
134
  }
212
-
213
135
  return encountered;
214
136
  },
215
-
216
- _traverse(object
217
- /*: any*/
218
- , encountered
219
- /*: any*/
220
- ) {
137
+ _traverse(object /*: any*/, encountered /*: any*/) {
221
138
  if (!object.objectId) {
222
139
  return;
223
140
  } else {
224
141
  const objectKey = this.getKeyForObject(object);
225
-
226
142
  if (encountered[objectKey]) {
227
143
  return;
228
144
  }
229
-
230
145
  encountered[objectKey] = object;
231
146
  }
232
-
233
147
  for (const key in object) {
234
148
  let json = object[key];
235
-
236
149
  if (!object[key]) {
237
150
  json = object;
238
151
  }
239
-
240
152
  if (json.__type && json.__type === 'Object') {
241
153
  this._traverse(json, encountered);
242
154
  }
243
155
  }
244
156
  },
245
-
246
157
  // Transform keys in pin name to objects
247
- async _serializeObjectsFromPinName(name
248
- /*: string*/
249
- ) {
158
+ async _serializeObjectsFromPinName(name /*: string*/) {
250
159
  const localDatastore = await this._getAllContents();
251
160
  const allObjects = [];
252
-
253
161
  for (const key in localDatastore) {
254
162
  if (key.startsWith(_LocalDatastoreUtils.OBJECT_PREFIX)) {
255
163
  allObjects.push(localDatastore[key][0]);
256
164
  }
257
165
  }
258
-
259
166
  if (!name) {
260
167
  return allObjects;
261
168
  }
262
-
263
169
  const pinName = this.getPinName(name);
264
170
  const pinned = localDatastore[pinName];
265
-
266
171
  if (!Array.isArray(pinned)) {
267
172
  return [];
268
173
  }
269
-
270
174
  const promises = pinned.map(objectKey => this.fromPinWithName(objectKey));
271
175
  let objects = await Promise.all(promises);
272
176
  objects = [].concat(...objects);
273
177
  return objects.filter(object => object != null);
274
178
  },
275
-
276
179
  // Replaces object pointers with pinned pointers
277
180
  // The object pointers may contain old data
278
181
  // Uses Breadth First Search Algorithm
279
- async _serializeObject(objectKey
280
- /*: string*/
281
- , localDatastore
282
- /*: any*/
283
- ) {
182
+ async _serializeObject(objectKey /*: string*/, localDatastore /*: any*/) {
284
183
  let LDS = localDatastore;
285
-
286
184
  if (!LDS) {
287
185
  LDS = await this._getAllContents();
288
186
  }
289
-
290
187
  if (!LDS[objectKey] || LDS[objectKey].length === 0) {
291
188
  return null;
292
189
  }
293
-
294
190
  const root = LDS[objectKey][0];
295
191
  const queue = [];
296
192
  const meta = {};
297
193
  let uniqueId = 0;
298
194
  meta[uniqueId] = root;
299
195
  queue.push(uniqueId);
300
-
301
196
  while (queue.length !== 0) {
302
197
  const nodeId = queue.shift();
303
198
  const subTreeRoot = meta[nodeId];
304
-
305
199
  for (const field in subTreeRoot) {
306
200
  const value = subTreeRoot[field];
307
-
308
201
  if (value.__type && value.__type === 'Object') {
309
202
  const key = this.getKeyForObject(value);
310
-
311
203
  if (LDS[key] && LDS[key].length > 0) {
312
204
  const pointer = LDS[key][0];
313
205
  uniqueId++;
@@ -318,59 +210,41 @@ const LocalDatastore = {
318
210
  }
319
211
  }
320
212
  }
321
-
322
213
  return root;
323
214
  },
324
-
325
215
  // Called when an object is save / fetched
326
216
  // Update object pin value
327
- async _updateObjectIfPinned(object
328
- /*: ParseObject*/
329
- )
330
- /*: Promise<void>*/
331
- {
217
+ async _updateObjectIfPinned(object /*: ParseObject*/) /*: Promise<void>*/{
332
218
  if (!this.isEnabled) {
333
219
  return;
334
220
  }
335
-
336
221
  const objectKey = this.getKeyForObject(object);
337
222
  const pinned = await this.fromPinWithName(objectKey);
338
-
339
223
  if (!pinned || pinned.length === 0) {
340
224
  return;
341
225
  }
342
-
343
226
  return this.pinWithName(objectKey, [object._toFullJSON()]);
344
227
  },
345
-
346
228
  // Called when object is destroyed
347
229
  // Unpin object and remove all references from pin names
348
230
  // TODO: Destroy children?
349
- async _destroyObjectIfPinned(object
350
- /*: ParseObject*/
351
- ) {
231
+ async _destroyObjectIfPinned(object /*: ParseObject*/) {
352
232
  if (!this.isEnabled) {
353
233
  return;
354
234
  }
355
-
356
235
  const localDatastore = await this._getAllContents();
357
236
  const objectKey = this.getKeyForObject(object);
358
237
  const pin = localDatastore[objectKey];
359
-
360
238
  if (!pin) {
361
239
  return;
362
240
  }
363
-
364
241
  const promises = [this.unPinWithName(objectKey)];
365
242
  delete localDatastore[objectKey];
366
-
367
243
  for (const key in localDatastore) {
368
244
  if (key === _LocalDatastoreUtils.DEFAULT_PIN || key.startsWith(_LocalDatastoreUtils.PIN_PREFIX)) {
369
245
  let pinned = localDatastore[key] || [];
370
-
371
246
  if (pinned.includes(objectKey)) {
372
247
  pinned = pinned.filter(item => item !== objectKey);
373
-
374
248
  if (pinned.length == 0) {
375
249
  promises.push(this.unPinWithName(key));
376
250
  delete localDatastore[key];
@@ -381,35 +255,24 @@ const LocalDatastore = {
381
255
  }
382
256
  }
383
257
  }
384
-
385
258
  return Promise.all(promises);
386
259
  },
387
-
388
260
  // Update pin and references of the unsaved object
389
- async _updateLocalIdForObject(localId
390
- /*: string*/
391
- , object
392
- /*: ParseObject*/
393
- ) {
261
+ async _updateLocalIdForObject(localId /*: string*/, object /*: ParseObject*/) {
394
262
  if (!this.isEnabled) {
395
263
  return;
396
264
  }
397
-
398
265
  const localKey = `${_LocalDatastoreUtils.OBJECT_PREFIX}${object.className}_${localId}`;
399
266
  const objectKey = this.getKeyForObject(object);
400
267
  const unsaved = await this.fromPinWithName(localKey);
401
-
402
268
  if (!unsaved || unsaved.length === 0) {
403
269
  return;
404
270
  }
405
-
406
271
  const promises = [this.unPinWithName(localKey), this.pinWithName(objectKey, unsaved)];
407
272
  const localDatastore = await this._getAllContents();
408
-
409
273
  for (const key in localDatastore) {
410
274
  if (key === _LocalDatastoreUtils.DEFAULT_PIN || key.startsWith(_LocalDatastoreUtils.PIN_PREFIX)) {
411
275
  let pinned = localDatastore[key] || [];
412
-
413
276
  if (pinned.includes(localKey)) {
414
277
  pinned = pinned.filter(item => item !== localKey);
415
278
  pinned.push(objectKey);
@@ -418,10 +281,8 @@ const LocalDatastore = {
418
281
  }
419
282
  }
420
283
  }
421
-
422
284
  return Promise.all(promises);
423
285
  },
424
-
425
286
  /**
426
287
  * Updates Local Datastore from Server
427
288
  *
@@ -437,57 +298,46 @@ const LocalDatastore = {
437
298
  if (!this.checkIfEnabled() || this.isSyncing) {
438
299
  return;
439
300
  }
440
-
441
301
  const localDatastore = await this._getAllContents();
442
302
  const keys = [];
443
-
444
303
  for (const key in localDatastore) {
445
304
  if (key.startsWith(_LocalDatastoreUtils.OBJECT_PREFIX)) {
446
305
  keys.push(key);
447
306
  }
448
307
  }
449
-
450
308
  if (keys.length === 0) {
451
309
  return;
452
310
  }
453
-
454
311
  this.isSyncing = true;
455
312
  const pointersHash = {};
456
-
457
313
  for (const key of keys) {
458
314
  // Ignore the OBJECT_PREFIX
459
- let [,, className, objectId] = key.split('_'); // User key is split into [ 'Parse', 'LDS', '', 'User', 'objectId' ]
315
+ let [,, className, objectId] = key.split('_');
460
316
 
317
+ // User key is split into [ 'Parse', 'LDS', '', 'User', 'objectId' ]
461
318
  if (key.split('_').length === 5 && key.split('_')[3] === 'User') {
462
319
  className = '_User';
463
320
  objectId = key.split('_')[4];
464
321
  }
465
-
466
322
  if (objectId.startsWith('local')) {
467
323
  continue;
468
324
  }
469
-
470
325
  if (!(className in pointersHash)) {
471
326
  pointersHash[className] = new Set();
472
327
  }
473
-
474
328
  pointersHash[className].add(objectId);
475
329
  }
476
-
477
330
  const queryPromises = Object.keys(pointersHash).map(className => {
478
331
  const objectIds = Array.from(pointersHash[className]);
479
332
  const query = new _ParseQuery.default(className);
480
333
  query.limit(objectIds.length);
481
-
482
334
  if (objectIds.length === 1) {
483
335
  query.equalTo('objectId', objectIds[0]);
484
336
  } else {
485
337
  query.containedIn('objectId', objectIds);
486
338
  }
487
-
488
339
  return query.find();
489
340
  });
490
-
491
341
  try {
492
342
  const responses = await Promise.all(queryPromises);
493
343
  const objects = [].concat.apply([], responses);
@@ -502,36 +352,23 @@ const LocalDatastore = {
502
352
  this.isSyncing = false;
503
353
  }
504
354
  },
505
-
506
- getKeyForObject(object
507
- /*: any*/
508
- ) {
355
+ getKeyForObject(object /*: any*/) {
509
356
  const objectId = object.objectId || object._getId();
510
-
511
357
  return `${_LocalDatastoreUtils.OBJECT_PREFIX}${object.className}_${objectId}`;
512
358
  },
513
-
514
- getPinName(pinName
515
- /*: ?string*/
516
- ) {
359
+ getPinName(pinName /*: ?string*/) {
517
360
  if (!pinName || pinName === _LocalDatastoreUtils.DEFAULT_PIN) {
518
361
  return _LocalDatastoreUtils.DEFAULT_PIN;
519
362
  }
520
-
521
363
  return _LocalDatastoreUtils.PIN_PREFIX + pinName;
522
364
  },
523
-
524
365
  checkIfEnabled() {
525
366
  if (!this.isEnabled) {
526
367
  console.error('Parse.enableLocalDatastore() must be called first');
527
368
  }
528
-
529
369
  return this.isEnabled;
530
370
  }
531
-
532
371
  };
533
372
  module.exports = LocalDatastore;
534
-
535
373
  _CoreManager.default.setLocalDatastoreController(require('./LocalDatastoreController'));
536
-
537
374
  _CoreManager.default.setLocalDatastore(LocalDatastore);
@@ -1,82 +1,49 @@
1
1
  "use strict";
2
2
 
3
3
  var _LocalDatastoreUtils = require("./LocalDatastoreUtils");
4
-
5
4
  var _Storage = _interopRequireDefault(require("./Storage"));
6
-
7
5
  function _interopRequireDefault(obj) {
8
6
  return obj && obj.__esModule ? obj : {
9
7
  default: obj
10
8
  };
11
9
  }
12
10
  /**
13
- * Copyright (c) 2015-present, Parse, LLC.
14
- * All rights reserved.
15
- *
16
- * This source code is licensed under the BSD-style license found in the
17
- * LICENSE file in the root directory of this source tree. An additional grant
18
- * of patent rights can be found in the PATENTS file in the same directory.
19
- *
20
11
  * @flow
21
12
  */
22
13
 
23
-
24
14
  const LocalDatastoreController = {
25
- async fromPinWithName(name
26
- /*: string*/
27
- )
28
- /*: Array<Object>*/
29
- {
15
+ async fromPinWithName(name /*: string*/) /*: Array<Object>*/{
30
16
  const values = await _Storage.default.getItemAsync(name);
31
-
32
17
  if (!values) {
33
18
  return [];
34
19
  }
35
-
36
20
  const objects = JSON.parse(values);
37
21
  return objects;
38
22
  },
39
-
40
- pinWithName(name
41
- /*: string*/
42
- , value
43
- /*: any*/
44
- ) {
23
+ pinWithName(name /*: string*/, value /*: any*/) {
45
24
  const values = JSON.stringify(value);
46
25
  return _Storage.default.setItemAsync(name, values);
47
26
  },
48
-
49
- unPinWithName(name
50
- /*: string*/
51
- ) {
27
+ unPinWithName(name /*: string*/) {
52
28
  return _Storage.default.removeItemAsync(name);
53
29
  },
54
-
55
- async getAllContents()
56
- /*: Object*/
57
- {
30
+ async getAllContents() /*: Object*/{
58
31
  const keys = await _Storage.default.getAllKeysAsync();
59
32
  return keys.reduce(async (previousPromise, key) => {
60
33
  const LDS = await previousPromise;
61
-
62
34
  if ((0, _LocalDatastoreUtils.isLocalDatastoreKey)(key)) {
63
35
  const value = await _Storage.default.getItemAsync(key);
64
-
65
36
  try {
66
37
  LDS[key] = JSON.parse(value);
67
38
  } catch (error) {
68
39
  console.error('Error getAllContents: ', error);
69
40
  }
70
41
  }
71
-
72
42
  return LDS;
73
43
  }, Promise.resolve({}));
74
44
  },
75
-
76
45
  // Used for testing
77
- async getRawStorage()
78
- /*: Object*/
79
- {
46
+ async getRawStorage() /*: Object*/{
80
47
  const keys = await _Storage.default.getAllKeysAsync();
81
48
  return keys.reduce(async (previousPromise, key) => {
82
49
  const LDS = await previousPromise;
@@ -85,22 +52,16 @@ const LocalDatastoreController = {
85
52
  return LDS;
86
53
  }, Promise.resolve({}));
87
54
  },
88
-
89
- async clear()
90
- /*: Promise*/
91
- {
55
+ async clear() /*: Promise*/{
92
56
  const keys = await _Storage.default.getAllKeysAsync();
93
57
  const toRemove = [];
94
-
95
58
  for (const key of keys) {
96
59
  if ((0, _LocalDatastoreUtils.isLocalDatastoreKey)(key)) {
97
60
  toRemove.push(key);
98
61
  }
99
62
  }
100
-
101
63
  const promises = toRemove.map(this.unPinWithName);
102
64
  return Promise.all(promises);
103
65
  }
104
-
105
66
  };
106
67
  module.exports = LocalDatastoreController;