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