parse 4.0.1 → 4.1.0-alpha.2
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/dist/parse.js +17995 -26193
- package/dist/parse.min.js +2 -2
- package/dist/parse.weapp.js +8739 -17728
- package/dist/parse.weapp.min.js +2 -2
- package/lib/browser/Analytics.js +2 -20
- package/lib/browser/AnonymousUtils.js +6 -35
- package/lib/browser/Cloud.js +12 -70
- package/lib/browser/CloudCode.js +0 -3
- package/lib/browser/CoreManager.js +46 -184
- package/lib/browser/CryptoController.js +2 -16
- package/lib/browser/EventEmitter.js +1 -1
- package/lib/browser/EventuallyQueue.js +277 -824
- package/lib/browser/FacebookUtils.js +6 -35
- package/lib/browser/IndexedDBStorageController.js +3 -14
- package/lib/browser/InstallationController.js +2 -13
- package/lib/browser/LiveQueryClient.js +87 -204
- 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 -12
- package/lib/browser/ObjectStateMutations.js +18 -121
- package/lib/browser/OfflineQuery.js +42 -222
- package/lib/browser/Parse.js +12 -106
- package/lib/browser/ParseACL.js +33 -141
- package/lib/browser/ParseCLP.js +96 -314
- package/lib/browser/ParseConfig.js +18 -88
- package/lib/browser/ParseError.js +63 -90
- package/lib/browser/ParseFile.js +129 -685
- package/lib/browser/ParseGeoPoint.js +23 -82
- 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 +628 -1840
- package/lib/browser/ParseOp.js +41 -287
- package/lib/browser/ParsePolygon.js +13 -63
- package/lib/browser/ParseQuery.js +404 -1505
- package/lib/browser/ParseRelation.js +12 -61
- package/lib/browser/ParseRole.js +13 -75
- package/lib/browser/ParseSchema.js +49 -201
- package/lib/browser/ParseSession.js +11 -69
- package/lib/browser/ParseUser.js +274 -1127
- package/lib/browser/Push.js +7 -43
- package/lib/browser/RESTController.js +18 -140
- package/lib/browser/SingleInstanceStateController.js +19 -137
- package/lib/browser/Socket.weapp.js +2 -12
- package/lib/browser/Storage.js +10 -73
- package/lib/browser/StorageController.browser.js +4 -17
- package/lib/browser/StorageController.default.js +4 -17
- package/lib/browser/StorageController.react-native.js +6 -33
- package/lib/browser/StorageController.weapp.js +5 -16
- package/lib/browser/TaskQueue.js +1 -22
- package/lib/browser/UniqueInstanceStateController.js +19 -142
- package/lib/browser/Xhr.weapp.js +0 -17
- package/lib/browser/arrayContainsObject.js +2 -16
- package/lib/browser/canBeSerialized.js +3 -33
- package/lib/browser/decode.js +3 -33
- package/lib/browser/encode.js +9 -70
- package/lib/browser/equals.js +2 -25
- package/lib/browser/escape.js +1 -8
- package/lib/browser/isRevocableSession.js +2 -11
- package/lib/browser/parseDate.js +2 -13
- package/lib/browser/promiseUtils.js +3 -21
- package/lib/browser/unique.js +3 -17
- package/lib/browser/unsavedChildren.js +6 -50
- package/lib/browser/uuid.js +3 -1
- package/lib/node/Analytics.js +1 -18
- package/lib/node/AnonymousUtils.js +5 -37
- package/lib/node/Cloud.js +10 -66
- package/lib/node/CloudCode.js +0 -3
- package/lib/node/CoreManager.js +47 -220
- package/lib/node/CryptoController.js +2 -16
- package/lib/node/EventEmitter.js +1 -1
- package/lib/node/EventuallyQueue.js +16 -123
- package/lib/node/FacebookUtils.js +5 -37
- package/lib/node/IndexedDBStorageController.js +3 -19
- package/lib/node/InstallationController.js +2 -15
- package/lib/node/LiveQueryClient.js +56 -136
- package/lib/node/LiveQuerySubscription.js +7 -16
- package/lib/node/LocalDatastore.js +19 -175
- package/lib/node/LocalDatastoreController.js +6 -38
- package/lib/node/LocalDatastoreController.react-native.js +6 -45
- package/lib/node/LocalDatastoreUtils.js +1 -6
- package/lib/node/ObjectStateMutations.js +13 -93
- package/lib/node/OfflineQuery.js +20 -152
- package/lib/node/Parse.js +11 -99
- package/lib/node/ParseACL.js +32 -150
- package/lib/node/ParseCLP.js +69 -262
- package/lib/node/ParseConfig.js +16 -84
- package/lib/node/ParseError.js +61 -65
- package/lib/node/ParseFile.js +50 -205
- package/lib/node/ParseGeoPoint.js +21 -82
- package/lib/node/ParseHooks.js +0 -35
- package/lib/node/ParseInstallation.js +1 -10
- package/lib/node/ParseLiveQuery.js +10 -36
- package/lib/node/ParseObject.js +193 -939
- package/lib/node/ParseOp.js +31 -255
- package/lib/node/ParsePolygon.js +12 -62
- package/lib/node/ParseQuery.js +170 -882
- package/lib/node/ParseRelation.js +11 -61
- package/lib/node/ParseRole.js +10 -57
- package/lib/node/ParseSchema.js +46 -222
- package/lib/node/ParseSession.js +8 -50
- package/lib/node/ParseUser.js +107 -576
- package/lib/node/Push.js +4 -37
- package/lib/node/RESTController.js +8 -110
- package/lib/node/SingleInstanceStateController.js +17 -130
- package/lib/node/Socket.weapp.js +2 -9
- package/lib/node/Storage.js +10 -83
- package/lib/node/StorageController.browser.js +4 -23
- package/lib/node/StorageController.default.js +5 -21
- package/lib/node/StorageController.react-native.js +6 -40
- package/lib/node/StorageController.weapp.js +6 -21
- package/lib/node/TaskQueue.js +1 -17
- package/lib/node/UniqueInstanceStateController.js +16 -133
- package/lib/node/Xhr.weapp.js +0 -15
- package/lib/node/arrayContainsObject.js +1 -12
- package/lib/node/canBeSerialized.js +2 -28
- package/lib/node/decode.js +1 -26
- package/lib/node/encode.js +3 -54
- package/lib/node/equals.js +0 -18
- package/lib/node/escape.js +1 -6
- package/lib/node/isRevocableSession.js +1 -5
- package/lib/node/parseDate.js +1 -7
- package/lib/node/promiseUtils.js +2 -14
- package/lib/node/unique.js +1 -11
- package/lib/node/unsavedChildren.js +2 -38
- 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 +1 -5
- package/lib/react-native/CryptoController.js +0 -2
- package/lib/react-native/EventEmitter.js +0 -2
- package/lib/react-native/EventuallyQueue.js +4 -52
- 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 +24 -101
- package/lib/react-native/LiveQuerySubscription.js +3 -27
- package/lib/react-native/LocalDatastore.js +6 -113
- package/lib/react-native/LocalDatastoreController.js +0 -21
- package/lib/react-native/LocalDatastoreController.react-native.js +4 -31
- package/lib/react-native/LocalDatastoreUtils.js +0 -1
- package/lib/react-native/ObjectStateMutations.js +0 -34
- package/lib/react-native/OfflineQuery.js +2 -137
- package/lib/react-native/Parse.js +0 -65
- package/lib/react-native/ParseACL.js +0 -44
- package/lib/react-native/ParseCLP.js +32 -96
- package/lib/react-native/ParseConfig.js +0 -42
- package/lib/react-native/ParseError.js +1 -21
- package/lib/react-native/ParseFile.js +4 -72
- 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 +3 -25
- package/lib/react-native/ParseObject.js +4 -371
- package/lib/react-native/ParseOp.js +1 -138
- package/lib/react-native/ParsePolygon.js +0 -24
- package/lib/react-native/ParseQuery.js +6 -262
- package/lib/react-native/ParseRelation.js +0 -25
- package/lib/react-native/ParseRole.js +1 -36
- package/lib/react-native/ParseSchema.js +0 -51
- package/lib/react-native/ParseSession.js +1 -40
- package/lib/react-native/ParseUser.js +1 -224
- package/lib/react-native/Push.js +0 -16
- package/lib/react-native/RESTController.js +1 -70
- package/lib/react-native/SingleInstanceStateController.js +0 -44
- package/lib/react-native/Socket.weapp.js +2 -12
- 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 -20
- package/lib/weapp/AnonymousUtils.js +6 -35
- package/lib/weapp/Cloud.js +12 -70
- package/lib/weapp/CloudCode.js +0 -3
- package/lib/weapp/CoreManager.js +46 -184
- package/lib/weapp/CryptoController.js +2 -16
- package/lib/weapp/EventEmitter.js +1 -1
- package/lib/weapp/EventuallyQueue.js +277 -824
- package/lib/weapp/FacebookUtils.js +6 -35
- package/lib/weapp/IndexedDBStorageController.js +3 -14
- package/lib/weapp/InstallationController.js +2 -13
- package/lib/weapp/LiveQueryClient.js +87 -204
- 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 -12
- package/lib/weapp/ObjectStateMutations.js +18 -121
- package/lib/weapp/OfflineQuery.js +42 -222
- package/lib/weapp/Parse.js +12 -106
- package/lib/weapp/ParseACL.js +33 -141
- package/lib/weapp/ParseCLP.js +96 -314
- package/lib/weapp/ParseConfig.js +18 -88
- package/lib/weapp/ParseError.js +63 -90
- package/lib/weapp/ParseFile.js +130 -686
- package/lib/weapp/ParseGeoPoint.js +23 -82
- 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 +628 -1840
- package/lib/weapp/ParseOp.js +41 -287
- package/lib/weapp/ParsePolygon.js +13 -63
- package/lib/weapp/ParseQuery.js +404 -1505
- package/lib/weapp/ParseRelation.js +12 -61
- package/lib/weapp/ParseRole.js +13 -75
- package/lib/weapp/ParseSchema.js +49 -201
- package/lib/weapp/ParseSession.js +11 -69
- package/lib/weapp/ParseUser.js +274 -1127
- package/lib/weapp/Push.js +7 -43
- package/lib/weapp/RESTController.js +18 -140
- package/lib/weapp/SingleInstanceStateController.js +19 -137
- package/lib/weapp/Socket.weapp.js +2 -12
- package/lib/weapp/Storage.js +10 -73
- package/lib/weapp/StorageController.browser.js +4 -17
- package/lib/weapp/StorageController.default.js +4 -17
- package/lib/weapp/StorageController.react-native.js +6 -33
- package/lib/weapp/StorageController.weapp.js +5 -16
- package/lib/weapp/TaskQueue.js +1 -22
- package/lib/weapp/UniqueInstanceStateController.js +19 -142
- package/lib/weapp/Xhr.weapp.js +0 -17
- package/lib/weapp/arrayContainsObject.js +2 -16
- package/lib/weapp/canBeSerialized.js +3 -33
- package/lib/weapp/decode.js +3 -33
- package/lib/weapp/encode.js +9 -70
- package/lib/weapp/equals.js +2 -25
- package/lib/weapp/escape.js +1 -8
- package/lib/weapp/isRevocableSession.js +2 -11
- package/lib/weapp/parseDate.js +2 -13
- package/lib/weapp/promiseUtils.js +3 -21
- package/lib/weapp/unique.js +3 -17
- package/lib/weapp/unsavedChildren.js +6 -50
- package/lib/weapp/uuid.js +1 -6
- package/package.json +45 -43
package/lib/node/ParseFile.js
CHANGED
|
@@ -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
|
-
*
|
|
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,125 @@ 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') {
|
|
292
|
+
this._requestTask._aborted = true;
|
|
363
293
|
this._requestTask.abort();
|
|
364
294
|
}
|
|
365
|
-
|
|
366
295
|
this._requestTask = null;
|
|
367
296
|
}
|
|
297
|
+
|
|
368
298
|
/**
|
|
369
299
|
* Deletes the file from the Parse cloud.
|
|
370
300
|
* In Cloud Code and Node only with Master Key.
|
|
371
301
|
*
|
|
372
302
|
* @param {object} options
|
|
373
|
-
*
|
|
303
|
+
* Valid options are:<ul>
|
|
374
304
|
* <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
|
|
375
305
|
* be used for this request.
|
|
376
306
|
* <pre>
|
|
377
307
|
* @returns {Promise} Promise that is resolved when the delete finishes.
|
|
378
308
|
*/
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
destroy(options
|
|
382
|
-
/*:: ?: FullOptions*/
|
|
383
|
-
= {}) {
|
|
309
|
+
destroy(options /*:: ?: FullOptions*/ = {}) {
|
|
384
310
|
if (!this._name) {
|
|
385
311
|
throw new ParseError(ParseError.FILE_DELETE_UNNAMED_ERROR, 'Cannot delete an unnamed file.');
|
|
386
312
|
}
|
|
387
|
-
|
|
388
313
|
const destroyOptions = {
|
|
389
314
|
useMasterKey: true
|
|
390
315
|
};
|
|
391
|
-
|
|
392
316
|
if (options.hasOwnProperty('useMasterKey')) {
|
|
393
317
|
destroyOptions.useMasterKey = options.useMasterKey;
|
|
394
318
|
}
|
|
395
|
-
|
|
396
319
|
const controller = _CoreManager.default.getFileController();
|
|
397
|
-
|
|
398
320
|
return controller.deleteFile(this._name, destroyOptions).then(() => {
|
|
399
321
|
this._data = null;
|
|
400
322
|
this._requestTask = null;
|
|
401
323
|
return this;
|
|
402
324
|
});
|
|
403
325
|
}
|
|
404
|
-
|
|
405
|
-
toJSON()
|
|
406
|
-
/*: { name: ?string, url: ?string }*/
|
|
407
|
-
{
|
|
326
|
+
toJSON() /*: { name: ?string, url: ?string }*/{
|
|
408
327
|
return {
|
|
409
328
|
__type: 'File',
|
|
410
329
|
name: this._name,
|
|
411
330
|
url: this._url
|
|
412
331
|
};
|
|
413
332
|
}
|
|
414
|
-
|
|
415
|
-
equals(other
|
|
416
|
-
/*: mixed*/
|
|
417
|
-
)
|
|
418
|
-
/*: boolean*/
|
|
419
|
-
{
|
|
333
|
+
equals(other /*: mixed*/) /*: boolean*/{
|
|
420
334
|
if (this === other) {
|
|
421
335
|
return true;
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
|
|
336
|
+
}
|
|
337
|
+
// Unsaved Files are never equal, since they will be saved to different URLs
|
|
425
338
|
return other instanceof ParseFile && this.name() === other.name() && this.url() === other.url() && typeof this.url() !== 'undefined';
|
|
426
339
|
}
|
|
340
|
+
|
|
427
341
|
/**
|
|
428
342
|
* Sets metadata to be saved with file object. Overwrites existing metadata
|
|
429
343
|
*
|
|
430
344
|
* @param {object} metadata Key value pairs to be stored with file object
|
|
431
345
|
*/
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
setMetadata(metadata
|
|
435
|
-
/*: any*/
|
|
436
|
-
) {
|
|
346
|
+
setMetadata(metadata /*: any*/) {
|
|
437
347
|
if (metadata && typeof metadata === 'object') {
|
|
438
348
|
Object.keys(metadata).forEach(key => {
|
|
439
349
|
this.addMetadata(key, metadata[key]);
|
|
440
350
|
});
|
|
441
351
|
}
|
|
442
352
|
}
|
|
353
|
+
|
|
443
354
|
/**
|
|
444
355
|
* Sets metadata to be saved with file object. Adds to existing metadata.
|
|
445
356
|
*
|
|
446
357
|
* @param {string} key key to store the metadata
|
|
447
358
|
* @param {*} value metadata
|
|
448
359
|
*/
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
addMetadata(key
|
|
452
|
-
/*: string*/
|
|
453
|
-
, value
|
|
454
|
-
/*: any*/
|
|
455
|
-
) {
|
|
360
|
+
addMetadata(key /*: string*/, value /*: any*/) {
|
|
456
361
|
if (typeof key === 'string') {
|
|
457
362
|
this._metadata[key] = value;
|
|
458
363
|
}
|
|
459
364
|
}
|
|
365
|
+
|
|
460
366
|
/**
|
|
461
367
|
* Sets tags to be saved with file object. Overwrites existing tags
|
|
462
368
|
*
|
|
463
369
|
* @param {object} tags Key value pairs to be stored with file object
|
|
464
370
|
*/
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
setTags(tags
|
|
468
|
-
/*: any*/
|
|
469
|
-
) {
|
|
371
|
+
setTags(tags /*: any*/) {
|
|
470
372
|
if (tags && typeof tags === 'object') {
|
|
471
373
|
Object.keys(tags).forEach(key => {
|
|
472
374
|
this.addTag(key, tags[key]);
|
|
473
375
|
});
|
|
474
376
|
}
|
|
475
377
|
}
|
|
378
|
+
|
|
476
379
|
/**
|
|
477
380
|
* Sets tags to be saved with file object. Adds to existing tags.
|
|
478
381
|
*
|
|
479
382
|
* @param {string} key key to store tags
|
|
480
383
|
* @param {*} value tag
|
|
481
384
|
*/
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
addTag(key
|
|
485
|
-
/*: string*/
|
|
486
|
-
, value
|
|
487
|
-
/*: string*/
|
|
488
|
-
) {
|
|
385
|
+
addTag(key /*: string*/, value /*: string*/) {
|
|
489
386
|
if (typeof key === 'string') {
|
|
490
387
|
this._tags[key] = value;
|
|
491
388
|
}
|
|
492
389
|
}
|
|
493
|
-
|
|
494
|
-
static fromJSON(obj)
|
|
495
|
-
/*: ParseFile*/
|
|
496
|
-
{
|
|
390
|
+
static fromJSON(obj) /*: ParseFile*/{
|
|
497
391
|
if (obj.__type !== 'File') {
|
|
498
392
|
throw new TypeError('JSON object does not represent a ParseFile');
|
|
499
393
|
}
|
|
500
|
-
|
|
501
394
|
const file = new ParseFile(obj.name);
|
|
502
395
|
file._url = obj.url;
|
|
503
396
|
return file;
|
|
504
397
|
}
|
|
505
|
-
|
|
506
|
-
static encodeBase64(bytes
|
|
507
|
-
/*: Array<number>*/
|
|
508
|
-
)
|
|
509
|
-
/*: string*/
|
|
510
|
-
{
|
|
398
|
+
static encodeBase64(bytes /*: Array<number>*/) /*: string*/{
|
|
511
399
|
const chunks = [];
|
|
512
400
|
chunks.length = Math.ceil(bytes.length / 3);
|
|
513
|
-
|
|
514
401
|
for (let i = 0; i < chunks.length; i++) {
|
|
515
402
|
const b1 = bytes[i * 3];
|
|
516
403
|
const b2 = bytes[i * 3 + 1] || 0;
|
|
@@ -519,39 +406,26 @@ class ParseFile {
|
|
|
519
406
|
const has3 = i * 3 + 2 < bytes.length;
|
|
520
407
|
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
408
|
}
|
|
522
|
-
|
|
523
409
|
return chunks.join('');
|
|
524
410
|
}
|
|
525
|
-
|
|
526
411
|
}
|
|
527
|
-
|
|
528
412
|
const DefaultController = {
|
|
529
|
-
saveFile: async function (name
|
|
530
|
-
/*: string*/
|
|
531
|
-
, source
|
|
532
|
-
/*: FileSource*/
|
|
533
|
-
, options
|
|
534
|
-
/*:: ?: FullOptions*/
|
|
535
|
-
) {
|
|
413
|
+
saveFile: async function (name /*: string*/, source /*: FileSource*/, options /*:: ?: FullOptions*/) {
|
|
536
414
|
if (source.format !== 'file') {
|
|
537
415
|
throw new Error('saveFile can only be used with File-type sources.');
|
|
538
416
|
}
|
|
539
|
-
|
|
540
417
|
const base64Data = await new Promise((res, rej) => {
|
|
541
418
|
// eslint-disable-next-line no-undef
|
|
542
419
|
const reader = new FileReader();
|
|
543
|
-
|
|
544
420
|
reader.onload = () => res(reader.result);
|
|
545
|
-
|
|
546
421
|
reader.onerror = error => rej(error);
|
|
547
|
-
|
|
548
422
|
reader.readAsDataURL(source.file);
|
|
549
|
-
});
|
|
423
|
+
});
|
|
424
|
+
// we only want the data after the comma
|
|
550
425
|
// For example: "data:application/pdf;base64,JVBERi0xLjQKJ..." we would only want "JVBERi0xLjQKJ..."
|
|
551
|
-
|
|
552
|
-
|
|
426
|
+
const [first, second] = base64Data.split(',');
|
|
427
|
+
// in the event there is no 'data:application/pdf;base64,' at the beginning of the base64 string
|
|
553
428
|
// use the entire string instead
|
|
554
|
-
|
|
555
429
|
const data = second ? second : first;
|
|
556
430
|
const newSource = {
|
|
557
431
|
format: 'base64',
|
|
@@ -560,35 +434,26 @@ const DefaultController = {
|
|
|
560
434
|
};
|
|
561
435
|
return await DefaultController.saveBase64(name, newSource, options);
|
|
562
436
|
},
|
|
563
|
-
saveBase64: function (name
|
|
564
|
-
/*: string*/
|
|
565
|
-
, source
|
|
566
|
-
/*: FileSource*/
|
|
567
|
-
, options
|
|
568
|
-
/*:: ?: FullOptions*/
|
|
569
|
-
) {
|
|
437
|
+
saveBase64: function (name /*: string*/, source /*: FileSource*/, options /*:: ?: FullOptions*/) {
|
|
570
438
|
if (source.format !== 'base64') {
|
|
571
439
|
throw new Error('saveBase64 can only be used with Base64-type sources.');
|
|
572
440
|
}
|
|
573
|
-
|
|
574
|
-
const data
|
|
575
|
-
/*: { base64: any, _ContentType?: any, fileData: Object }*/
|
|
576
|
-
= {
|
|
441
|
+
const data /*: { base64: any, _ContentType?: any, fileData: Object }*/ = {
|
|
577
442
|
base64: source.base64,
|
|
578
443
|
fileData: {
|
|
579
|
-
metadata: {
|
|
444
|
+
metadata: {
|
|
445
|
+
...options.metadata
|
|
580
446
|
},
|
|
581
|
-
tags: {
|
|
447
|
+
tags: {
|
|
448
|
+
...options.tags
|
|
582
449
|
}
|
|
583
450
|
}
|
|
584
451
|
};
|
|
585
452
|
delete options.metadata;
|
|
586
453
|
delete options.tags;
|
|
587
|
-
|
|
588
454
|
if (source.type) {
|
|
589
455
|
data._ContentType = source.type;
|
|
590
456
|
}
|
|
591
|
-
|
|
592
457
|
return _CoreManager.default.getRESTController().request('POST', 'files/' + name, data, options);
|
|
593
458
|
},
|
|
594
459
|
download: function (uri, options) {
|
|
@@ -621,50 +486,37 @@ const DefaultController = {
|
|
|
621
486
|
const xhr = new XHR();
|
|
622
487
|
xhr.open('GET', uri, true);
|
|
623
488
|
xhr.responseType = 'arraybuffer';
|
|
624
|
-
|
|
625
489
|
xhr.onerror = function (e) {
|
|
626
490
|
reject(e);
|
|
627
491
|
};
|
|
628
|
-
|
|
629
492
|
xhr.onreadystatechange = function () {
|
|
630
493
|
if (xhr.readyState !== xhr.DONE) {
|
|
631
494
|
return;
|
|
632
495
|
}
|
|
633
|
-
|
|
634
496
|
if (!this.response) {
|
|
635
497
|
return resolve({});
|
|
636
498
|
}
|
|
637
|
-
|
|
638
499
|
const bytes = new Uint8Array(this.response);
|
|
639
500
|
resolve({
|
|
640
501
|
base64: ParseFile.encodeBase64(bytes),
|
|
641
502
|
contentType: xhr.getResponseHeader('content-type')
|
|
642
503
|
});
|
|
643
504
|
};
|
|
644
|
-
|
|
645
505
|
options.requestTask(xhr);
|
|
646
506
|
xhr.send();
|
|
647
507
|
});
|
|
648
508
|
},
|
|
649
|
-
deleteFile: function (name
|
|
650
|
-
/*: string*/
|
|
651
|
-
, options
|
|
652
|
-
/*:: ?: FullOptions*/
|
|
653
|
-
) {
|
|
509
|
+
deleteFile: function (name /*: string*/, options /*:: ?: FullOptions*/) {
|
|
654
510
|
const headers = {
|
|
655
511
|
'X-Parse-Application-ID': _CoreManager.default.get('APPLICATION_ID')
|
|
656
512
|
};
|
|
657
|
-
|
|
658
513
|
if (options.useMasterKey) {
|
|
659
514
|
headers['X-Parse-Master-Key'] = _CoreManager.default.get('MASTER_KEY');
|
|
660
515
|
}
|
|
661
|
-
|
|
662
516
|
let url = _CoreManager.default.get('SERVER_URL');
|
|
663
|
-
|
|
664
517
|
if (url[url.length - 1] !== '/') {
|
|
665
518
|
url += '/';
|
|
666
519
|
}
|
|
667
|
-
|
|
668
520
|
url += 'files/' + name;
|
|
669
521
|
return _CoreManager.default.getRESTController().ajax('DELETE', url, '', headers).catch(response => {
|
|
670
522
|
// TODO: return JSON object in server
|
|
@@ -675,21 +527,14 @@ const DefaultController = {
|
|
|
675
527
|
}
|
|
676
528
|
});
|
|
677
529
|
},
|
|
678
|
-
|
|
679
|
-
_setXHR(xhr
|
|
680
|
-
/*: any*/
|
|
681
|
-
) {
|
|
530
|
+
_setXHR(xhr /*: any*/) {
|
|
682
531
|
XHR = xhr;
|
|
683
532
|
},
|
|
684
|
-
|
|
685
533
|
_getXHR() {
|
|
686
534
|
return XHR;
|
|
687
535
|
}
|
|
688
|
-
|
|
689
536
|
};
|
|
690
|
-
|
|
691
537
|
_CoreManager.default.setFileController(DefaultController);
|
|
692
|
-
|
|
693
538
|
var _default = ParseFile;
|
|
694
539
|
exports.default = _default;
|
|
695
540
|
exports.b64Digit = b64Digit;
|