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.
- package/dist/parse.js +17994 -26193
- package/dist/parse.min.js +2 -2
- package/dist/parse.weapp.js +8738 -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 +128 -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 +49 -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 +3 -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 +129 -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,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
|
-
*
|
|
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
|
-
}
|
|
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
|
-
});
|
|
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
|
-
|
|
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: {
|
|
443
|
+
metadata: {
|
|
444
|
+
...options.metadata
|
|
580
445
|
},
|
|
581
|
-
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;
|