parse 4.0.1 → 4.1.0-alpha.1

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