parse 4.0.0-alpha.1 → 4.0.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +167 -25
- package/NOTICE +10 -0
- package/README.md +6 -5
- package/dist/parse.js +12838 -21190
- package/dist/parse.min.js +7 -6
- package/dist/parse.weapp.js +7921 -17062
- package/dist/parse.weapp.min.js +7 -6
- package/lib/browser/Analytics.js +2 -27
- package/lib/browser/AnonymousUtils.js +6 -42
- package/lib/browser/Cloud.js +12 -77
- package/lib/browser/CloudCode.js +0 -3
- package/lib/browser/CoreManager.js +46 -191
- package/lib/browser/CryptoController.js +2 -16
- package/lib/browser/EventEmitter.js +1 -8
- package/lib/browser/EventuallyQueue.js +277 -824
- package/lib/browser/FacebookUtils.js +6 -42
- package/lib/browser/IndexedDBStorageController.js +3 -14
- package/lib/browser/InstallationController.js +2 -20
- package/lib/browser/LiveQueryClient.js +105 -213
- package/lib/browser/LiveQuerySubscription.js +10 -39
- package/lib/browser/LocalDatastore.js +451 -1081
- package/lib/browser/LocalDatastoreController.js +145 -602
- package/lib/browser/LocalDatastoreController.react-native.js +137 -573
- package/lib/browser/LocalDatastoreUtils.js +2 -19
- package/lib/browser/ObjectStateMutations.js +18 -121
- package/lib/browser/OfflineQuery.js +61 -222
- package/lib/browser/Parse.js +12 -115
- package/lib/browser/ParseACL.js +33 -148
- package/lib/browser/ParseCLP.js +96 -314
- package/lib/browser/ParseConfig.js +18 -95
- package/lib/browser/ParseError.js +63 -99
- package/lib/browser/ParseFile.js +128 -685
- package/lib/browser/ParseGeoPoint.js +23 -89
- package/lib/browser/ParseHooks.js +1 -34
- package/lib/browser/ParseInstallation.js +4 -32
- package/lib/browser/ParseLiveQuery.js +96 -505
- package/lib/browser/ParseObject.js +665 -1845
- package/lib/browser/ParseOp.js +41 -287
- package/lib/browser/ParsePolygon.js +13 -70
- package/lib/browser/ParseQuery.js +403 -1504
- package/lib/browser/ParseRelation.js +12 -68
- package/lib/browser/ParseRole.js +13 -75
- package/lib/browser/ParseSchema.js +49 -208
- package/lib/browser/ParseSession.js +11 -69
- package/lib/browser/ParseUser.js +274 -1127
- package/lib/browser/Push.js +7 -50
- package/lib/browser/RESTController.js +28 -157
- package/lib/browser/SingleInstanceStateController.js +19 -144
- package/lib/browser/Socket.weapp.js +0 -10
- package/lib/browser/Storage.js +10 -80
- package/lib/browser/StorageController.browser.js +4 -24
- package/lib/browser/StorageController.default.js +4 -24
- package/lib/browser/StorageController.react-native.js +6 -40
- package/lib/browser/StorageController.weapp.js +5 -23
- package/lib/browser/TaskQueue.js +1 -29
- package/lib/browser/UniqueInstanceStateController.js +19 -149
- package/lib/browser/Xhr.weapp.js +0 -17
- package/lib/browser/arrayContainsObject.js +2 -23
- package/lib/browser/canBeSerialized.js +3 -40
- package/lib/browser/decode.js +3 -40
- package/lib/browser/encode.js +9 -77
- package/lib/browser/equals.js +2 -34
- package/lib/browser/escape.js +1 -15
- package/lib/browser/isRevocableSession.js +2 -18
- package/lib/browser/parseDate.js +2 -20
- package/lib/browser/promiseUtils.js +3 -21
- package/lib/browser/unique.js +3 -24
- package/lib/browser/unsavedChildren.js +6 -57
- package/lib/browser/uuid.js +3 -1
- package/lib/node/Analytics.js +1 -25
- package/lib/node/AnonymousUtils.js +5 -44
- package/lib/node/Cloud.js +10 -73
- package/lib/node/CloudCode.js +0 -3
- package/lib/node/CoreManager.js +47 -227
- package/lib/node/CryptoController.js +2 -16
- package/lib/node/EventEmitter.js +1 -8
- package/lib/node/EventuallyQueue.js +16 -123
- package/lib/node/FacebookUtils.js +5 -44
- package/lib/node/IndexedDBStorageController.js +3 -19
- package/lib/node/InstallationController.js +2 -22
- package/lib/node/LiveQueryClient.js +72 -154
- package/lib/node/LiveQuerySubscription.js +7 -26
- package/lib/node/LocalDatastore.js +19 -182
- package/lib/node/LocalDatastoreController.js +6 -45
- package/lib/node/LocalDatastoreController.react-native.js +6 -52
- package/lib/node/LocalDatastoreUtils.js +1 -13
- package/lib/node/ObjectStateMutations.js +13 -100
- package/lib/node/OfflineQuery.js +27 -151
- package/lib/node/Parse.js +11 -108
- package/lib/node/ParseACL.js +32 -157
- package/lib/node/ParseCLP.js +69 -269
- package/lib/node/ParseConfig.js +16 -91
- package/lib/node/ParseError.js +61 -74
- package/lib/node/ParseFile.js +49 -212
- package/lib/node/ParseGeoPoint.js +21 -89
- package/lib/node/ParseHooks.js +0 -35
- package/lib/node/ParseInstallation.js +1 -17
- package/lib/node/ParseLiveQuery.js +10 -43
- package/lib/node/ParseObject.js +229 -964
- package/lib/node/ParseOp.js +31 -262
- package/lib/node/ParsePolygon.js +12 -69
- package/lib/node/ParseQuery.js +169 -888
- package/lib/node/ParseRelation.js +11 -68
- package/lib/node/ParseRole.js +10 -64
- package/lib/node/ParseSchema.js +46 -229
- package/lib/node/ParseSession.js +8 -57
- package/lib/node/ParseUser.js +107 -583
- package/lib/node/Push.js +4 -44
- package/lib/node/RESTController.js +18 -127
- package/lib/node/SingleInstanceStateController.js +17 -137
- package/lib/node/Socket.weapp.js +0 -7
- package/lib/node/Storage.js +10 -90
- package/lib/node/StorageController.browser.js +4 -30
- package/lib/node/StorageController.default.js +5 -28
- package/lib/node/StorageController.react-native.js +6 -47
- package/lib/node/StorageController.weapp.js +6 -28
- package/lib/node/TaskQueue.js +1 -24
- package/lib/node/UniqueInstanceStateController.js +16 -140
- package/lib/node/Xhr.weapp.js +0 -15
- package/lib/node/arrayContainsObject.js +1 -19
- package/lib/node/canBeSerialized.js +2 -35
- package/lib/node/decode.js +1 -33
- package/lib/node/encode.js +3 -61
- package/lib/node/equals.js +0 -27
- package/lib/node/escape.js +1 -13
- package/lib/node/isRevocableSession.js +1 -12
- package/lib/node/parseDate.js +1 -14
- package/lib/node/promiseUtils.js +2 -14
- package/lib/node/unique.js +1 -18
- package/lib/node/unsavedChildren.js +2 -45
- package/lib/node/uuid.js +6 -1
- package/lib/react-native/Analytics.js +0 -9
- package/lib/react-native/AnonymousUtils.js +0 -10
- package/lib/react-native/Cloud.js +0 -26
- package/lib/react-native/CoreManager.js +2 -6
- package/lib/react-native/CryptoController.js +0 -2
- package/lib/react-native/EventEmitter.js +0 -2
- package/lib/react-native/EventuallyQueue.js +156 -711
- package/lib/react-native/FacebookUtils.js +0 -22
- package/lib/react-native/IndexedDBStorageController.js +0 -1
- package/lib/react-native/InstallationController.js +0 -6
- package/lib/react-native/LiveQueryClient.js +46 -157
- package/lib/react-native/LiveQuerySubscription.js +3 -27
- package/lib/react-native/LocalDatastore.js +281 -948
- package/lib/react-native/LocalDatastoreController.js +71 -552
- package/lib/react-native/LocalDatastoreController.react-native.js +91 -526
- package/lib/react-native/LocalDatastoreUtils.js +0 -1
- package/lib/react-native/ObjectStateMutations.js +2 -65
- package/lib/react-native/OfflineQuery.js +25 -196
- package/lib/react-native/Parse.js +0 -65
- package/lib/react-native/ParseACL.js +0 -44
- package/lib/react-native/ParseCLP.js +23 -161
- package/lib/react-native/ParseConfig.js +0 -42
- package/lib/react-native/ParseError.js +1 -21
- package/lib/react-native/ParseFile.js +55 -529
- package/lib/react-native/ParseGeoPoint.js +0 -17
- package/lib/react-native/ParseHooks.js +0 -30
- package/lib/react-native/ParseInstallation.js +1 -23
- package/lib/react-native/ParseLiveQuery.js +55 -472
- package/lib/react-native/ParseObject.js +245 -1246
- package/lib/react-native/ParseOp.js +1 -138
- package/lib/react-native/ParsePolygon.js +0 -24
- package/lib/react-native/ParseQuery.js +182 -874
- package/lib/react-native/ParseRelation.js +0 -25
- package/lib/react-native/ParseRole.js +1 -36
- package/lib/react-native/ParseSchema.js +3 -54
- package/lib/react-native/ParseSession.js +1 -40
- package/lib/react-native/ParseUser.js +95 -773
- package/lib/react-native/Push.js +0 -16
- package/lib/react-native/RESTController.js +12 -109
- package/lib/react-native/SingleInstanceStateController.js +0 -44
- package/lib/react-native/Socket.weapp.js +0 -10
- package/lib/react-native/Storage.js +0 -24
- package/lib/react-native/StorageController.browser.js +0 -2
- package/lib/react-native/StorageController.default.js +0 -1
- package/lib/react-native/StorageController.react-native.js +0 -2
- package/lib/react-native/TaskQueue.js +0 -15
- package/lib/react-native/UniqueInstanceStateController.js +0 -47
- package/lib/react-native/Xhr.weapp.js +0 -16
- package/lib/react-native/arrayContainsObject.js +0 -5
- package/lib/react-native/canBeSerialized.js +0 -18
- package/lib/react-native/decode.js +0 -21
- package/lib/react-native/encode.js +0 -25
- package/lib/react-native/equals.js +0 -18
- package/lib/react-native/escape.js +0 -1
- package/lib/react-native/isRevocableSession.js +0 -1
- package/lib/react-native/parseDate.js +0 -3
- package/lib/react-native/promiseUtils.js +0 -13
- package/lib/react-native/unique.js +0 -4
- package/lib/react-native/unsavedChildren.js +0 -21
- package/lib/react-native/uuid.js +3 -1
- package/lib/weapp/Analytics.js +2 -27
- package/lib/weapp/AnonymousUtils.js +6 -42
- package/lib/weapp/Cloud.js +12 -77
- package/lib/weapp/CloudCode.js +0 -3
- package/lib/weapp/CoreManager.js +46 -191
- package/lib/weapp/CryptoController.js +2 -16
- package/lib/weapp/EventEmitter.js +1 -8
- package/lib/weapp/EventuallyQueue.js +277 -824
- package/lib/weapp/FacebookUtils.js +6 -42
- package/lib/weapp/IndexedDBStorageController.js +3 -14
- package/lib/weapp/InstallationController.js +2 -20
- package/lib/weapp/LiveQueryClient.js +105 -213
- package/lib/weapp/LiveQuerySubscription.js +10 -39
- package/lib/weapp/LocalDatastore.js +451 -1081
- package/lib/weapp/LocalDatastoreController.js +145 -602
- package/lib/weapp/LocalDatastoreController.react-native.js +137 -573
- package/lib/weapp/LocalDatastoreUtils.js +2 -19
- package/lib/weapp/ObjectStateMutations.js +18 -121
- package/lib/weapp/OfflineQuery.js +61 -222
- package/lib/weapp/Parse.js +12 -115
- package/lib/weapp/ParseACL.js +33 -148
- package/lib/weapp/ParseCLP.js +96 -314
- package/lib/weapp/ParseConfig.js +18 -95
- package/lib/weapp/ParseError.js +63 -99
- package/lib/weapp/ParseFile.js +129 -686
- package/lib/weapp/ParseGeoPoint.js +23 -89
- package/lib/weapp/ParseHooks.js +1 -34
- package/lib/weapp/ParseInstallation.js +4 -32
- package/lib/weapp/ParseLiveQuery.js +96 -505
- package/lib/weapp/ParseObject.js +665 -1845
- package/lib/weapp/ParseOp.js +41 -287
- package/lib/weapp/ParsePolygon.js +13 -70
- package/lib/weapp/ParseQuery.js +403 -1504
- package/lib/weapp/ParseRelation.js +12 -68
- package/lib/weapp/ParseRole.js +13 -75
- package/lib/weapp/ParseSchema.js +49 -208
- package/lib/weapp/ParseSession.js +11 -69
- package/lib/weapp/ParseUser.js +274 -1127
- package/lib/weapp/Push.js +7 -50
- package/lib/weapp/RESTController.js +28 -157
- package/lib/weapp/SingleInstanceStateController.js +19 -144
- package/lib/weapp/Socket.weapp.js +0 -10
- package/lib/weapp/Storage.js +10 -80
- package/lib/weapp/StorageController.browser.js +4 -24
- package/lib/weapp/StorageController.default.js +4 -24
- package/lib/weapp/StorageController.react-native.js +6 -40
- package/lib/weapp/StorageController.weapp.js +5 -23
- package/lib/weapp/TaskQueue.js +1 -29
- package/lib/weapp/UniqueInstanceStateController.js +19 -149
- package/lib/weapp/Xhr.weapp.js +0 -17
- package/lib/weapp/arrayContainsObject.js +2 -23
- package/lib/weapp/canBeSerialized.js +3 -40
- package/lib/weapp/decode.js +3 -40
- package/lib/weapp/encode.js +9 -77
- package/lib/weapp/equals.js +2 -34
- package/lib/weapp/escape.js +1 -15
- package/lib/weapp/isRevocableSession.js +2 -18
- package/lib/weapp/parseDate.js +2 -20
- package/lib/weapp/promiseUtils.js +3 -21
- package/lib/weapp/unique.js +3 -24
- package/lib/weapp/unsavedChildren.js +6 -57
- package/lib/weapp/uuid.js +1 -6
- package/package.json +35 -31
- package/PATENTS +0 -37
package/lib/node/ParseFile.js
CHANGED
|
@@ -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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
}
|
|
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
|
-
});
|
|
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
|
-
|
|
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: {
|
|
443
|
+
metadata: {
|
|
444
|
+
...options.metadata
|
|
587
445
|
},
|
|
588
|
-
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;
|