parse 4.0.0-alpha.1 → 4.0.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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 +34 -30
  255. package/PATENTS +0 -37
@@ -4,42 +4,25 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _CoreManager = _interopRequireDefault(require("./CoreManager"));
9
-
10
8
  function _interopRequireDefault(obj) {
11
9
  return obj && obj.__esModule ? obj : {
12
10
  default: obj
13
11
  };
14
12
  }
15
13
  /**
16
- * Copyright (c) 2015-present, Parse, LLC.
17
- * All rights reserved.
18
- *
19
- * This source code is licensed under the BSD-style license found in the
20
- * LICENSE file in the root directory of this source tree. An additional grant
21
- * of patent rights can be found in the PATENTS file in the same directory.
22
- *
23
14
  * @flow
24
15
  */
25
-
26
16
  /* global XMLHttpRequest, Blob */
27
17
 
28
-
29
18
  const ParseError = require('./ParseError').default;
30
-
31
19
  let XHR = null;
32
-
33
20
  if (typeof XMLHttpRequest !== 'undefined') {
34
21
  XHR = XMLHttpRequest;
35
22
  }
36
-
37
23
  /*:: type Base64 = { base64: string };*/
38
-
39
24
  /*:: type Uri = { uri: string };*/
40
-
41
25
  /*:: type FileData = Array<number> | Base64 | Blob | Uri;*/
42
-
43
26
  /*:: export type FileSource =
44
27
  | {
45
28
  format: 'file',
@@ -56,58 +39,40 @@ if (typeof XMLHttpRequest !== 'undefined') {
56
39
  uri: string,
57
40
  type: string,
58
41
  };*/
59
- function b64Digit(number
60
- /*: number*/
61
- )
62
- /*: string*/
63
- {
42
+ function b64Digit(number /*: number*/) /*: string*/{
64
43
  if (number < 26) {
65
44
  return String.fromCharCode(65 + number);
66
45
  }
67
-
68
46
  if (number < 52) {
69
47
  return String.fromCharCode(97 + (number - 26));
70
48
  }
71
-
72
49
  if (number < 62) {
73
50
  return String.fromCharCode(48 + (number - 52));
74
51
  }
75
-
76
52
  if (number === 62) {
77
53
  return '+';
78
54
  }
79
-
80
55
  if (number === 63) {
81
56
  return '/';
82
57
  }
83
-
84
58
  throw new TypeError('Tried to encode large digit ' + number + ' in base64.');
85
59
  }
60
+
86
61
  /**
87
62
  * A Parse.File is a local representation of a file that is saved to the Parse
88
63
  * cloud.
89
64
  *
90
65
  * @alias Parse.File
91
66
  */
92
-
93
-
94
67
  class ParseFile {
95
68
  /*:: _name: string;*/
96
-
97
69
  /*:: _url: ?string;*/
98
-
99
70
  /*:: _source: FileSource;*/
100
-
101
71
  /*:: _previousSave: ?Promise<ParseFile>;*/
102
-
103
72
  /*:: _data: ?string;*/
104
-
105
73
  /*:: _requestTask: ?any;*/
106
-
107
74
  /*:: _metadata: ?Object;*/
108
-
109
75
  /*:: _tags: ?Object;*/
110
-
111
76
  /**
112
77
  * @param name {String} The file's name. This will be prefixed by a unique
113
78
  * value once the file has finished saving. The file name must begin with
@@ -138,22 +103,11 @@ class ParseFile {
138
103
  * @param metadata {Object} Optional key value pairs to be stored with file object
139
104
  * @param tags {Object} Optional key value pairs to be stored with file object
140
105
  */
141
- constructor(name
142
- /*: string*/
143
- , data
144
- /*:: ?: FileData*/
145
- , type
146
- /*:: ?: string*/
147
- , metadata
148
- /*:: ?: Object*/
149
- , tags
150
- /*:: ?: Object*/
151
- ) {
106
+ constructor(name /*: string*/, data /*:: ?: FileData*/, type /*:: ?: string*/, metadata /*:: ?: Object*/, tags /*:: ?: Object*/) {
152
107
  const specifiedType = type || '';
153
108
  this._name = name;
154
109
  this._metadata = metadata || {};
155
110
  this._tags = tags || {};
156
-
157
111
  if (data !== undefined) {
158
112
  if (Array.isArray(data)) {
159
113
  this._data = ParseFile.encodeBase64(data);
@@ -188,6 +142,7 @@ class ParseFile {
188
142
  }
189
143
  }
190
144
  }
145
+
191
146
  /**
192
147
  * Return the data for the file, downloading it if not already present.
193
148
  * Data is present if initialized with Byte Array, Base64 or Saved with Uri.
@@ -195,27 +150,21 @@ class ParseFile {
195
150
  *
196
151
  * @returns {Promise} Promise that is resolve with base64 data
197
152
  */
198
-
199
-
200
- async getData()
201
- /*: Promise<String>*/
202
- {
153
+ async getData() /*: Promise<String>*/{
203
154
  if (this._data) {
204
155
  return this._data;
205
156
  }
206
-
207
157
  if (!this._url) {
208
158
  throw new Error('Cannot retrieve data for unsaved ParseFile.');
209
159
  }
210
-
211
160
  const controller = _CoreManager.default.getFileController();
212
-
213
161
  const result = await controller.download(this._url, {
214
162
  requestTask: task => this._requestTask = task
215
163
  });
216
164
  this._data = result.base64;
217
165
  return this._data;
218
166
  }
167
+
219
168
  /**
220
169
  * Gets the name of the file. Before save is called, this is the filename
221
170
  * given by the user. After save is called, that name gets prefixed with a
@@ -223,68 +172,52 @@ class ParseFile {
223
172
  *
224
173
  * @returns {string}
225
174
  */
226
-
227
-
228
- name()
229
- /*: string*/
230
- {
175
+ name() /*: string*/{
231
176
  return this._name;
232
177
  }
178
+
233
179
  /**
234
180
  * Gets the url of the file. It is only available after you save the file or
235
181
  * after you get the file from a Parse.Object.
236
182
  *
237
183
  * @param {object} options An object to specify url options
238
- * @returns {string}
184
+ * @returns {string | undefined}
239
185
  */
240
-
241
-
242
- url(options
243
- /*:: ?: { forceSecure?: boolean }*/
244
- )
245
- /*: ?string*/
246
- {
186
+ url(options /*:: ?: { forceSecure?: boolean }*/) /*: ?string*/{
247
187
  options = options || {};
248
-
249
188
  if (!this._url) {
250
189
  return;
251
190
  }
252
-
253
191
  if (options.forceSecure) {
254
192
  return this._url.replace(/^http:\/\//i, 'https://');
255
193
  } else {
256
194
  return this._url;
257
195
  }
258
196
  }
197
+
259
198
  /**
260
199
  * Gets the metadata of the file.
261
200
  *
262
201
  * @returns {object}
263
202
  */
264
-
265
-
266
- metadata()
267
- /*: Object*/
268
- {
203
+ metadata() /*: Object*/{
269
204
  return this._metadata;
270
205
  }
206
+
271
207
  /**
272
208
  * Gets the tags of the file.
273
209
  *
274
210
  * @returns {object}
275
211
  */
276
-
277
-
278
- tags()
279
- /*: Object*/
280
- {
212
+ tags() /*: Object*/{
281
213
  return this._tags;
282
214
  }
215
+
283
216
  /**
284
217
  * Saves the file to the Parse cloud.
285
218
  *
286
219
  * @param {object} options
287
- * * Valid options are:<ul>
220
+ * Valid options are:<ul>
288
221
  * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
289
222
  * be used for this request.
290
223
  * <li>sessionToken: A valid session token, used for making a request on
@@ -301,22 +234,14 @@ class ParseFile {
301
234
  * });
302
235
  * </pre>
303
236
  * </ul>
304
- * @returns {Promise} Promise that is resolved when the save finishes.
237
+ * @returns {Promise | undefined} Promise that is resolved when the save finishes.
305
238
  */
306
-
307
-
308
- save(options
309
- /*:: ?: FullOptions*/
310
- ) {
239
+ save(options /*:: ?: FullOptions*/) /*: ?Promise*/{
311
240
  options = options || {};
312
-
313
241
  options.requestTask = task => this._requestTask = task;
314
-
315
242
  options.metadata = this._metadata;
316
243
  options.tags = this._tags;
317
-
318
244
  const controller = _CoreManager.default.getFileController();
319
-
320
245
  if (!this._previousSave) {
321
246
  if (this._source.format === 'file') {
322
247
  this._previousSave = controller.saveFile(this._name, this._source, options).then(res => {
@@ -331,7 +256,6 @@ class ParseFile {
331
256
  if (!(result && result.base64)) {
332
257
  return {};
333
258
  }
334
-
335
259
  const newSource = {
336
260
  format: 'base64',
337
261
  base64: result.base64,
@@ -355,169 +279,124 @@ class ParseFile {
355
279
  });
356
280
  }
357
281
  }
358
-
359
282
  if (this._previousSave) {
360
283
  return this._previousSave;
361
284
  }
362
285
  }
286
+
363
287
  /**
364
288
  * Aborts the request if it has already been sent.
365
289
  */
366
-
367
-
368
290
  cancel() {
369
291
  if (this._requestTask && typeof this._requestTask.abort === 'function') {
370
292
  this._requestTask.abort();
371
293
  }
372
-
373
294
  this._requestTask = null;
374
295
  }
296
+
375
297
  /**
376
298
  * Deletes the file from the Parse cloud.
377
299
  * In Cloud Code and Node only with Master Key.
378
300
  *
379
301
  * @param {object} options
380
- * * Valid options are:<ul>
302
+ * Valid options are:<ul>
381
303
  * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
382
304
  * be used for this request.
383
305
  * <pre>
384
306
  * @returns {Promise} Promise that is resolved when the delete finishes.
385
307
  */
386
-
387
-
388
- destroy(options
389
- /*:: ?: FullOptions*/
390
- = {}) {
308
+ destroy(options /*:: ?: FullOptions*/ = {}) {
391
309
  if (!this._name) {
392
310
  throw new ParseError(ParseError.FILE_DELETE_UNNAMED_ERROR, 'Cannot delete an unnamed file.');
393
311
  }
394
-
395
312
  const destroyOptions = {
396
313
  useMasterKey: true
397
314
  };
398
-
399
315
  if (options.hasOwnProperty('useMasterKey')) {
400
316
  destroyOptions.useMasterKey = options.useMasterKey;
401
317
  }
402
-
403
318
  const controller = _CoreManager.default.getFileController();
404
-
405
319
  return controller.deleteFile(this._name, destroyOptions).then(() => {
406
320
  this._data = null;
407
321
  this._requestTask = null;
408
322
  return this;
409
323
  });
410
324
  }
411
-
412
- toJSON()
413
- /*: { name: ?string, url: ?string }*/
414
- {
325
+ toJSON() /*: { name: ?string, url: ?string }*/{
415
326
  return {
416
327
  __type: 'File',
417
328
  name: this._name,
418
329
  url: this._url
419
330
  };
420
331
  }
421
-
422
- equals(other
423
- /*: mixed*/
424
- )
425
- /*: boolean*/
426
- {
332
+ equals(other /*: mixed*/) /*: boolean*/{
427
333
  if (this === other) {
428
334
  return true;
429
- } // Unsaved Files are never equal, since they will be saved to different URLs
430
-
431
-
335
+ }
336
+ // Unsaved Files are never equal, since they will be saved to different URLs
432
337
  return other instanceof ParseFile && this.name() === other.name() && this.url() === other.url() && typeof this.url() !== 'undefined';
433
338
  }
339
+
434
340
  /**
435
341
  * Sets metadata to be saved with file object. Overwrites existing metadata
436
342
  *
437
343
  * @param {object} metadata Key value pairs to be stored with file object
438
344
  */
439
-
440
-
441
- setMetadata(metadata
442
- /*: any*/
443
- ) {
345
+ setMetadata(metadata /*: any*/) {
444
346
  if (metadata && typeof metadata === 'object') {
445
347
  Object.keys(metadata).forEach(key => {
446
348
  this.addMetadata(key, metadata[key]);
447
349
  });
448
350
  }
449
351
  }
352
+
450
353
  /**
451
354
  * Sets metadata to be saved with file object. Adds to existing metadata.
452
355
  *
453
356
  * @param {string} key key to store the metadata
454
357
  * @param {*} value metadata
455
358
  */
456
-
457
-
458
- addMetadata(key
459
- /*: string*/
460
- , value
461
- /*: any*/
462
- ) {
359
+ addMetadata(key /*: string*/, value /*: any*/) {
463
360
  if (typeof key === 'string') {
464
361
  this._metadata[key] = value;
465
362
  }
466
363
  }
364
+
467
365
  /**
468
366
  * Sets tags to be saved with file object. Overwrites existing tags
469
367
  *
470
368
  * @param {object} tags Key value pairs to be stored with file object
471
369
  */
472
-
473
-
474
- setTags(tags
475
- /*: any*/
476
- ) {
370
+ setTags(tags /*: any*/) {
477
371
  if (tags && typeof tags === 'object') {
478
372
  Object.keys(tags).forEach(key => {
479
373
  this.addTag(key, tags[key]);
480
374
  });
481
375
  }
482
376
  }
377
+
483
378
  /**
484
379
  * Sets tags to be saved with file object. Adds to existing tags.
485
380
  *
486
381
  * @param {string} key key to store tags
487
382
  * @param {*} value tag
488
383
  */
489
-
490
-
491
- addTag(key
492
- /*: string*/
493
- , value
494
- /*: string*/
495
- ) {
384
+ addTag(key /*: string*/, value /*: string*/) {
496
385
  if (typeof key === 'string') {
497
386
  this._tags[key] = value;
498
387
  }
499
388
  }
500
-
501
- static fromJSON(obj)
502
- /*: ParseFile*/
503
- {
389
+ static fromJSON(obj) /*: ParseFile*/{
504
390
  if (obj.__type !== 'File') {
505
391
  throw new TypeError('JSON object does not represent a ParseFile');
506
392
  }
507
-
508
393
  const file = new ParseFile(obj.name);
509
394
  file._url = obj.url;
510
395
  return file;
511
396
  }
512
-
513
- static encodeBase64(bytes
514
- /*: Array<number>*/
515
- )
516
- /*: string*/
517
- {
397
+ static encodeBase64(bytes /*: Array<number>*/) /*: string*/{
518
398
  const chunks = [];
519
399
  chunks.length = Math.ceil(bytes.length / 3);
520
-
521
400
  for (let i = 0; i < chunks.length; i++) {
522
401
  const b1 = bytes[i * 3];
523
402
  const b2 = bytes[i * 3 + 1] || 0;
@@ -526,39 +405,26 @@ class ParseFile {
526
405
  const has3 = i * 3 + 2 < bytes.length;
527
406
  chunks[i] = [b64Digit(b1 >> 2 & 0x3f), b64Digit(b1 << 4 & 0x30 | b2 >> 4 & 0x0f), has2 ? b64Digit(b2 << 2 & 0x3c | b3 >> 6 & 0x03) : '=', has3 ? b64Digit(b3 & 0x3f) : '='].join('');
528
407
  }
529
-
530
408
  return chunks.join('');
531
409
  }
532
-
533
410
  }
534
-
535
411
  const DefaultController = {
536
- saveFile: async function (name
537
- /*: string*/
538
- , source
539
- /*: FileSource*/
540
- , options
541
- /*:: ?: FullOptions*/
542
- ) {
412
+ saveFile: async function (name /*: string*/, source /*: FileSource*/, options /*:: ?: FullOptions*/) {
543
413
  if (source.format !== 'file') {
544
414
  throw new Error('saveFile can only be used with File-type sources.');
545
415
  }
546
-
547
416
  const base64Data = await new Promise((res, rej) => {
548
417
  // eslint-disable-next-line no-undef
549
418
  const reader = new FileReader();
550
-
551
419
  reader.onload = () => res(reader.result);
552
-
553
420
  reader.onerror = error => rej(error);
554
-
555
421
  reader.readAsDataURL(source.file);
556
- }); // we only want the data after the comma
422
+ });
423
+ // we only want the data after the comma
557
424
  // For example: "data:application/pdf;base64,JVBERi0xLjQKJ..." we would only want "JVBERi0xLjQKJ..."
558
-
559
- const [first, second] = base64Data.split(','); // in the event there is no 'data:application/pdf;base64,' at the beginning of the base64 string
425
+ const [first, second] = base64Data.split(',');
426
+ // in the event there is no 'data:application/pdf;base64,' at the beginning of the base64 string
560
427
  // use the entire string instead
561
-
562
428
  const data = second ? second : first;
563
429
  const newSource = {
564
430
  format: 'base64',
@@ -567,35 +433,26 @@ const DefaultController = {
567
433
  };
568
434
  return await DefaultController.saveBase64(name, newSource, options);
569
435
  },
570
- saveBase64: function (name
571
- /*: string*/
572
- , source
573
- /*: FileSource*/
574
- , options
575
- /*:: ?: FullOptions*/
576
- ) {
436
+ saveBase64: function (name /*: string*/, source /*: FileSource*/, options /*:: ?: FullOptions*/) {
577
437
  if (source.format !== 'base64') {
578
438
  throw new Error('saveBase64 can only be used with Base64-type sources.');
579
439
  }
580
-
581
- const data
582
- /*: { base64: any, _ContentType?: any, fileData: Object }*/
583
- = {
440
+ const data /*: { base64: any, _ContentType?: any, fileData: Object }*/ = {
584
441
  base64: source.base64,
585
442
  fileData: {
586
- metadata: { ...options.metadata
443
+ metadata: {
444
+ ...options.metadata
587
445
  },
588
- tags: { ...options.tags
446
+ tags: {
447
+ ...options.tags
589
448
  }
590
449
  }
591
450
  };
592
451
  delete options.metadata;
593
452
  delete options.tags;
594
-
595
453
  if (source.type) {
596
454
  data._ContentType = source.type;
597
455
  }
598
-
599
456
  return _CoreManager.default.getRESTController().request('POST', 'files/' + name, data, options);
600
457
  },
601
458
  download: function (uri, options) {
@@ -628,50 +485,37 @@ const DefaultController = {
628
485
  const xhr = new XHR();
629
486
  xhr.open('GET', uri, true);
630
487
  xhr.responseType = 'arraybuffer';
631
-
632
488
  xhr.onerror = function (e) {
633
489
  reject(e);
634
490
  };
635
-
636
491
  xhr.onreadystatechange = function () {
637
492
  if (xhr.readyState !== xhr.DONE) {
638
493
  return;
639
494
  }
640
-
641
495
  if (!this.response) {
642
496
  return resolve({});
643
497
  }
644
-
645
498
  const bytes = new Uint8Array(this.response);
646
499
  resolve({
647
500
  base64: ParseFile.encodeBase64(bytes),
648
501
  contentType: xhr.getResponseHeader('content-type')
649
502
  });
650
503
  };
651
-
652
504
  options.requestTask(xhr);
653
505
  xhr.send();
654
506
  });
655
507
  },
656
- deleteFile: function (name
657
- /*: string*/
658
- , options
659
- /*:: ?: FullOptions*/
660
- ) {
508
+ deleteFile: function (name /*: string*/, options /*:: ?: FullOptions*/) {
661
509
  const headers = {
662
510
  'X-Parse-Application-ID': _CoreManager.default.get('APPLICATION_ID')
663
511
  };
664
-
665
512
  if (options.useMasterKey) {
666
513
  headers['X-Parse-Master-Key'] = _CoreManager.default.get('MASTER_KEY');
667
514
  }
668
-
669
515
  let url = _CoreManager.default.get('SERVER_URL');
670
-
671
516
  if (url[url.length - 1] !== '/') {
672
517
  url += '/';
673
518
  }
674
-
675
519
  url += 'files/' + name;
676
520
  return _CoreManager.default.getRESTController().ajax('DELETE', url, '', headers).catch(response => {
677
521
  // TODO: return JSON object in server
@@ -682,21 +526,14 @@ const DefaultController = {
682
526
  }
683
527
  });
684
528
  },
685
-
686
- _setXHR(xhr
687
- /*: any*/
688
- ) {
529
+ _setXHR(xhr /*: any*/) {
689
530
  XHR = xhr;
690
531
  },
691
-
692
532
  _getXHR() {
693
533
  return XHR;
694
534
  }
695
-
696
535
  };
697
-
698
536
  _CoreManager.default.setFileController(DefaultController);
699
-
700
537
  var _default = ParseFile;
701
538
  exports.default = _default;
702
539
  exports.b64Digit = b64Digit;