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