parse 5.1.0-alpha.7 → 5.1.0-alpha.9

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.
@@ -1,40 +1,84 @@
1
1
  "use strict";
2
2
 
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _CoreManager = _interopRequireDefault(require("./CoreManager"));
3
8
  var _Storage = _interopRequireDefault(require("./Storage"));
9
+ var _ParseInstallation = _interopRequireDefault(require("./ParseInstallation"));
10
+ var _uuid = _interopRequireDefault(require("./uuid"));
4
11
  function _interopRequireDefault(obj) {
5
12
  return obj && obj.__esModule ? obj : {
6
13
  default: obj
7
14
  };
8
15
  }
9
- /**
10
- * @flow
11
- */
12
-
13
- const uuidv4 = require('./uuid');
14
- let iidCache = null;
16
+ const CURRENT_INSTALLATION_KEY = 'currentInstallation';
17
+ const CURRENT_INSTALLATION_ID_KEY = 'currentInstallationId';
18
+ let iidCache /*: string | null*/ = null;
19
+ let currentInstallationCache = null;
20
+ let currentInstallationCacheMatchesDisk = false;
15
21
  const InstallationController = {
16
- currentInstallationId() /*: Promise<string>*/{
22
+ async updateInstallationOnDisk(installation /*: ParseInstallation*/) /*: Promise<void>*/{
23
+ const path = _Storage.default.generatePath(CURRENT_INSTALLATION_KEY);
24
+ await _Storage.default.setItemAsync(path, JSON.stringify(installation.toJSON()));
25
+ this._setCurrentInstallationCache(installation);
26
+ },
27
+ async currentInstallationId() /*: Promise<string>*/{
17
28
  if (typeof iidCache === 'string') {
18
- return Promise.resolve(iidCache);
29
+ return iidCache;
30
+ }
31
+ const path = _Storage.default.generatePath(CURRENT_INSTALLATION_ID_KEY);
32
+ let iid = await _Storage.default.getItemAsync(path);
33
+ if (!iid) {
34
+ iid = (0, _uuid.default)();
35
+ return _Storage.default.setItemAsync(path, iid).then(() => {
36
+ iidCache = iid;
37
+ return iid;
38
+ });
19
39
  }
20
- const path = _Storage.default.generatePath('installationId');
21
- return _Storage.default.getItemAsync(path).then(iid => {
22
- if (!iid) {
23
- iid = uuidv4();
24
- return _Storage.default.setItemAsync(path, iid).then(() => {
25
- iidCache = iid;
26
- return iid;
27
- });
28
- }
29
- iidCache = iid;
30
- return iid;
31
- });
40
+ iidCache = iid;
41
+ return iid;
42
+ },
43
+ async currentInstallation() /*: Promise<ParseInstallation | null>*/{
44
+ if (currentInstallationCache) {
45
+ return currentInstallationCache;
46
+ }
47
+ if (currentInstallationCacheMatchesDisk) {
48
+ return null;
49
+ }
50
+ const path = _Storage.default.generatePath(CURRENT_INSTALLATION_KEY);
51
+ let installationData = await _Storage.default.getItemAsync(path);
52
+ currentInstallationCacheMatchesDisk = true;
53
+ if (installationData) {
54
+ installationData = JSON.parse(installationData);
55
+ installationData.className = '_Installation';
56
+ const current = _ParseInstallation.default.fromJSON(installationData);
57
+ currentInstallationCache = current;
58
+ return current;
59
+ }
60
+ const installationId = await this.currentInstallationId();
61
+ const installation = new _ParseInstallation.default();
62
+ installation.set('deviceType', _ParseInstallation.default.DEVICE_TYPES.WEB);
63
+ installation.set('installationId', installationId);
64
+ installation.set('parseVersion', _CoreManager.default.get('VERSION'));
65
+ currentInstallationCache = installation;
66
+ await _Storage.default.setItemAsync(path, JSON.stringify(installation.toJSON()));
67
+ return installation;
32
68
  },
33
69
  _clearCache() {
34
70
  iidCache = null;
71
+ currentInstallationCache = null;
72
+ currentInstallationCacheMatchesDisk = false;
35
73
  },
36
74
  _setInstallationIdCache(iid /*: string*/) {
37
75
  iidCache = iid;
76
+ },
77
+ _setCurrentInstallationCache(installation /*: ParseInstallation*/, matchesDisk /*: boolean*/ = true) {
78
+ currentInstallationCache = installation;
79
+ currentInstallationCacheMatchesDisk = matchesDisk;
38
80
  }
39
81
  };
40
- module.exports = InstallationController;
82
+ module.exports = InstallationController;
83
+ var _default = InstallationController;
84
+ exports.default = _default;
package/lib/node/Parse.js CHANGED
@@ -160,10 +160,11 @@ const Parse /*: ParseType*/ = {
160
160
  _CoreManager.default.setIfNeeded('EventEmitter', _EventEmitter.default);
161
161
  _CoreManager.default.setIfNeeded('LiveQuery', new _ParseLiveQuery.default());
162
162
  _CoreManager.default.setIfNeeded('CryptoController', _CryptoController.default);
163
+ _CoreManager.default.setIfNeeded('EventuallyQueue', _EventuallyQueue.default);
164
+ _CoreManager.default.setIfNeeded('InstallationController', _InstallationController.default);
163
165
  _CoreManager.default.setIfNeeded('LocalDatastoreController', _LocalDatastoreController.default);
164
166
  _CoreManager.default.setIfNeeded('StorageController', _StorageController.default);
165
167
  _CoreManager.default.setIfNeeded('WebSocketController', _WebSocketController.default);
166
- _CoreManager.default.setIfNeeded('EventuallyQueue', _EventuallyQueue.default);
167
168
  },
168
169
  /**
169
170
  * Call this method to set your AsyncStorage engine
@@ -397,7 +398,6 @@ const Parse /*: ParseType*/ = {
397
398
  return this.encryptedUser;
398
399
  }
399
400
  };
400
- _CoreManager.default.setInstallationController(_InstallationController.default);
401
401
  _CoreManager.default.setRESTController(_RESTController.default);
402
402
  Parse.initialize = Parse._initialize;
403
403
  Parse.Cloud = Parse.Cloud || {};
@@ -23,6 +23,10 @@ if (typeof XMLHttpRequest !== 'undefined') {
23
23
  /*:: type Base64 = { base64: string };*/
24
24
  /*:: type Uri = { uri: string };*/
25
25
  /*:: type FileData = Array<number> | Base64 | Blob | Uri;*/
26
+ /*:: export type FileSaveOptions = FullOptions & {
27
+ metadata?: { [key: string]: any },
28
+ tags?: { [key: string]: any },
29
+ };*/
26
30
  /*:: export type FileSource =
27
31
  | {
28
32
  format: 'file',
@@ -24,6 +24,8 @@ function _interopRequireDefault(obj) {
24
24
  default: obj
25
25
  };
26
26
  }
27
+ /*:: export type HookDeclaration = { functionName: string, url: string } | { className: string, triggerName: string, url: string };*/
28
+ /*:: export type HookDeleteArg = { functionName: string } | { className: string, triggerName: string };*/
27
29
  function getFunctions() {
28
30
  return _CoreManager.default.getHooksController().get('functions');
29
31
  }
@@ -4,25 +4,225 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+ var _CoreManager = _interopRequireDefault(require("./CoreManager"));
7
8
  var _ParseObject = _interopRequireDefault(require("./ParseObject"));
8
9
  function _interopRequireDefault(obj) {
9
10
  return obj && obj.__esModule ? obj : {
10
11
  default: obj
11
12
  };
12
13
  }
14
+ const DEVICE_TYPES /*: DeviceInterface*/ = {
15
+ IOS: 'ios',
16
+ MACOS: 'macos',
17
+ TVOS: 'tvos',
18
+ FCM: 'fcm',
19
+ ANDROID: 'android',
20
+ WEB: 'web'
21
+ };
22
+
13
23
  /**
14
- * @flow
24
+ * Parse.Installation is a local representation of installation data that can be saved and retrieved from the Parse cloud.
25
+ * This class is a subclass of a Parse.Object, and retains the same functionality of a Parse.Object, but also extends it with installation-specific features.
26
+ *
27
+ * <p>A valid Parse.Installation can only be instantiated via <code>Parse.Installation.currentInstallation()</code>
28
+ *
29
+ * Parse.Installation objects which have a valid <code>deviceToken</code> and are saved to the Parse cloud can be used to target push notifications.
30
+ * </p>
31
+ *
32
+ * @alias Parse.Installation
15
33
  */
16
- /*:: import type { AttributeMap } from './ObjectStateMutations';*/
17
- class Installation extends _ParseObject.default {
18
- constructor(attributes /*: ?AttributeMap*/) {
34
+ class ParseInstallation extends _ParseObject.default {
35
+ /**
36
+ * @param {object} attributes The initial set of data to store in the object.
37
+ */
38
+ constructor(attributes /*:: ?: AttributeMap*/) {
19
39
  super('_Installation');
20
40
  if (attributes && typeof attributes === 'object') {
21
- if (!this.set(attributes || {})) {
41
+ if (!this.set(attributes)) {
22
42
  throw new Error("Can't create an invalid Installation");
23
43
  }
24
44
  }
25
45
  }
46
+
47
+ /**
48
+ * A unique identifier for this installation’s client application. In iOS, this is the Bundle Identifier.
49
+ *
50
+ * @property {string} appIdentifier
51
+ * @static
52
+ */
53
+ get appIdentifier() {
54
+ return this.get('appIdentifier');
55
+ }
56
+
57
+ /**
58
+ * The version string of the client application to which this installation belongs.
59
+ *
60
+ * @property {string} appVersion
61
+ * @static
62
+ */
63
+ get appVersion() {
64
+ return this.get('appVersion');
65
+ }
66
+
67
+ /**
68
+ * The display name of the client application to which this installation belongs.
69
+ *
70
+ * @property {string} appName
71
+ * @static
72
+ */
73
+ get appName() {
74
+ return this.get('appName');
75
+ }
76
+
77
+ /**
78
+ * The current value of the icon badge for iOS apps.
79
+ * Changes to this value on the server will be used
80
+ * for future badge-increment push notifications.
81
+ *
82
+ * @property {number} badge
83
+ * @static
84
+ */
85
+ get badge() {
86
+ return this.get('badge');
87
+ }
88
+
89
+ /**
90
+ * An array of the channels to which a device is currently subscribed.
91
+ *
92
+ * @property {string[]} channels
93
+ * @static
94
+ */
95
+ get channels() {
96
+ return this.get('channels');
97
+ }
98
+
99
+ /**
100
+ * Token used to deliver push notifications to the device.
101
+ *
102
+ * @property {string} deviceToken
103
+ * @static
104
+ */
105
+ get deviceToken() {
106
+ return this.get('deviceToken');
107
+ }
108
+
109
+ /**
110
+ * The type of device, “ios”, “android”, “web”, etc.
111
+ *
112
+ * @property {string} deviceType
113
+ * @static
114
+ */
115
+ get deviceType() {
116
+ return this.get('deviceType');
117
+ }
118
+
119
+ /**
120
+ * Gets the GCM sender identifier for this installation
121
+ *
122
+ * @property {string} GCMSenderId
123
+ * @static
124
+ */
125
+ get GCMSenderId() {
126
+ return this.get('GCMSenderId');
127
+ }
128
+
129
+ /**
130
+ * Universally Unique Identifier (UUID) for the device used by Parse. It must be unique across all of an app’s installations.
131
+ *
132
+ * @property {string} installationId
133
+ * @static
134
+ */
135
+ get installationId() {
136
+ return this.get('installationId');
137
+ }
138
+
139
+ /**
140
+ * Gets the local identifier for this installation
141
+ *
142
+ * @property {string} localeIdentifier
143
+ * @static
144
+ */
145
+ get localeIdentifier() {
146
+ return this.get('localeIdentifier');
147
+ }
148
+
149
+ /**
150
+ * Gets the parse server version for this installation
151
+ *
152
+ * @property {string} parseVersion
153
+ * @static
154
+ */
155
+ get parseVersion() {
156
+ return this.get('parseVersion');
157
+ }
158
+
159
+ /**
160
+ * This field is reserved for directing Parse to the push delivery network to be used.
161
+ *
162
+ * @property {string} pushType
163
+ * @static
164
+ */
165
+ get pushType() {
166
+ return this.get('pushType');
167
+ }
168
+
169
+ /**
170
+ * Gets the time zone for this installation
171
+ *
172
+ * @property {string} timeZone
173
+ * @static
174
+ */
175
+ get timeZone() {
176
+ return this.get('timeZone');
177
+ }
178
+
179
+ /**
180
+ * Returns the device types for used for Push Notifications.
181
+ *
182
+ * <pre>
183
+ * Parse.Installation.DEVICE_TYPES.IOS
184
+ * Parse.Installation.DEVICE_TYPES.MACOS
185
+ * Parse.Installation.DEVICE_TYPES.TVOS
186
+ * Parse.Installation.DEVICE_TYPES.FCM
187
+ * Parse.Installation.DEVICE_TYPES.ANDROID
188
+ * Parse.Installation.DEVICE_TYPES.WEB
189
+ * </pre
190
+ *
191
+ * @property {Object} DEVICE_TYPES
192
+ * @static
193
+ */
194
+ static get DEVICE_TYPES() /*: DeviceInterface*/{
195
+ return DEVICE_TYPES;
196
+ }
197
+
198
+ /**
199
+ * Wrap the default save behavior with functionality to save to local storage.
200
+ *
201
+ * @param {...any} args
202
+ * @returns {Promise}
203
+ */
204
+ async save(...args) /*: Promise<ParseInstallation>*/{
205
+ await super.save.apply(this, args);
206
+ await _CoreManager.default.getInstallationController().updateInstallationOnDisk(this);
207
+ return this;
208
+ }
209
+
210
+ /**
211
+ * Get the current Parse.Installation from disk. If doesn't exists, create an new installation.
212
+ *
213
+ * <pre>
214
+ * const installation = await Parse.Installation.currentInstallation();
215
+ * installation.set('deviceToken', '123');
216
+ * await installation.save();
217
+ * </pre>
218
+ *
219
+ * @returns {Promise} A promise that resolves to the local installation object.
220
+ */
221
+ static currentInstallation() /*: Promise<ParseInstallation>*/{
222
+ return _CoreManager.default.getInstallationController().currentInstallation();
223
+ }
26
224
  }
27
- exports.default = Installation;
28
- _ParseObject.default.registerSubclass('_Installation', Installation);
225
+ _ParseObject.default.registerSubclass('_Installation', ParseInstallation);
226
+ module.exports = ParseInstallation;
227
+ var _default = ParseInstallation;
228
+ exports.default = _default;
@@ -473,10 +473,6 @@ class ParseObject {
473
473
  json[attr] = (0, _encode.default)(attrs[attr], false, false, seen, offline);
474
474
  }
475
475
  }
476
- const pending = this._getPendingOps();
477
- for (const attr in pending[0]) {
478
- json[attr] = pending[0][attr].toJSON(offline);
479
- }
480
476
  if (this.id) {
481
477
  json.objectId = this.id;
482
478
  }
@@ -62,7 +62,7 @@ class ParseSession extends _ParseObject.default {
62
62
  static current(options /*: FullOptions*/) {
63
63
  options = options || {};
64
64
  const controller = _CoreManager.default.getSessionController();
65
- const sessionOptions = {};
65
+ const sessionOptions /*: FullOptions*/ = {};
66
66
  if (options.hasOwnProperty('useMasterKey')) {
67
67
  sessionOptions.useMasterKey = options.useMasterKey;
68
68
  }
@@ -12,7 +12,7 @@ var config = {
12
12
  SERVER_AUTH_TOKEN: null,
13
13
  LIVEQUERY_SERVER_URL: null,
14
14
  ENCRYPTED_KEY: null,
15
- VERSION: 'js' + "5.1.0-alpha.7",
15
+ VERSION: 'js' + "5.1.0-alpha.9",
16
16
  APPLICATION_ID: null,
17
17
  JAVASCRIPT_KEY: null,
18
18
  MASTER_KEY: null,
@@ -85,11 +85,18 @@ var CoreManager = {
85
85
  requireMethods('FileController', ['saveFile', 'saveBase64'], controller);
86
86
  config['FileController'] = controller;
87
87
  },
88
+ setEventuallyQueue: function (controller) {
89
+ requireMethods('EventuallyQueue', ['poll', 'save', 'destroy'], controller);
90
+ config['EventuallyQueue'] = controller;
91
+ },
92
+ getEventuallyQueue: function () {
93
+ return config['EventuallyQueue'];
94
+ },
88
95
  getFileController: function () {
89
96
  return config['FileController'];
90
97
  },
91
98
  setInstallationController: function (controller) {
92
- requireMethods('InstallationController', ['currentInstallationId'], controller);
99
+ requireMethods('InstallationController', ['currentInstallationId', 'currentInstallation', 'updateInstallationOnDisk'], controller);
93
100
  config['InstallationController'] = controller;
94
101
  },
95
102
  getInstallationController: function () {
@@ -136,13 +143,6 @@ var CoreManager = {
136
143
  getRESTController: function () {
137
144
  return config['RESTController'];
138
145
  },
139
- setEventuallyQueue: function (controller) {
140
- requireMethods('EventuallyQueue', ['poll', 'save', 'destroy'], controller);
141
- config['EventuallyQueue'] = controller;
142
- },
143
- getEventuallyQueue: function () {
144
- return config['EventuallyQueue'];
145
- },
146
146
  setSchemaController: function (controller) {
147
147
  requireMethods('SchemaController', ['get', 'create', 'update', 'delete', 'send', 'purge'], controller);
148
148
  config['SchemaController'] = controller;
@@ -1,16 +1,39 @@
1
1
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ exports.default = void 0;
6
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
7
+ var _CoreManager = _interopRequireDefault(require("./CoreManager"));
2
8
  var _Storage = _interopRequireDefault(require("./Storage"));
3
- var uuidv4 = require('./uuid');
9
+ var _ParseInstallation = _interopRequireDefault(require("./ParseInstallation"));
10
+ var _uuid = _interopRequireDefault(require("./uuid"));
11
+ var CURRENT_INSTALLATION_KEY = 'currentInstallation';
12
+ var CURRENT_INSTALLATION_ID_KEY = 'currentInstallationId';
4
13
  var iidCache = null;
14
+ var currentInstallationCache = null;
15
+ var currentInstallationCacheMatchesDisk = false;
5
16
  var InstallationController = {
6
- currentInstallationId: function () {
7
- if (typeof iidCache === 'string') {
8
- return Promise.resolve(iidCache);
17
+ updateInstallationOnDisk: function () {
18
+ var _updateInstallationOnDisk = (0, _asyncToGenerator2.default)(function* (installation) {
19
+ var path = _Storage.default.generatePath(CURRENT_INSTALLATION_KEY);
20
+ yield _Storage.default.setItemAsync(path, JSON.stringify(installation.toJSON()));
21
+ this._setCurrentInstallationCache(installation);
22
+ });
23
+ function updateInstallationOnDisk() {
24
+ return _updateInstallationOnDisk.apply(this, arguments);
9
25
  }
10
- var path = _Storage.default.generatePath('installationId');
11
- return _Storage.default.getItemAsync(path).then(function (iid) {
26
+ return updateInstallationOnDisk;
27
+ }(),
28
+ currentInstallationId: function () {
29
+ var _currentInstallationId = (0, _asyncToGenerator2.default)(function* () {
30
+ if (typeof iidCache === 'string') {
31
+ return iidCache;
32
+ }
33
+ var path = _Storage.default.generatePath(CURRENT_INSTALLATION_ID_KEY);
34
+ var iid = yield _Storage.default.getItemAsync(path);
12
35
  if (!iid) {
13
- iid = uuidv4();
36
+ iid = (0, _uuid.default)();
14
37
  return _Storage.default.setItemAsync(path, iid).then(function () {
15
38
  iidCache = iid;
16
39
  return iid;
@@ -19,12 +42,57 @@ var InstallationController = {
19
42
  iidCache = iid;
20
43
  return iid;
21
44
  });
22
- },
45
+ function currentInstallationId() {
46
+ return _currentInstallationId.apply(this, arguments);
47
+ }
48
+ return currentInstallationId;
49
+ }(),
50
+ currentInstallation: function () {
51
+ var _currentInstallation = (0, _asyncToGenerator2.default)(function* () {
52
+ if (currentInstallationCache) {
53
+ return currentInstallationCache;
54
+ }
55
+ if (currentInstallationCacheMatchesDisk) {
56
+ return null;
57
+ }
58
+ var path = _Storage.default.generatePath(CURRENT_INSTALLATION_KEY);
59
+ var installationData = yield _Storage.default.getItemAsync(path);
60
+ currentInstallationCacheMatchesDisk = true;
61
+ if (installationData) {
62
+ installationData = JSON.parse(installationData);
63
+ installationData.className = '_Installation';
64
+ var current = _ParseInstallation.default.fromJSON(installationData);
65
+ currentInstallationCache = current;
66
+ return current;
67
+ }
68
+ var installationId = yield this.currentInstallationId();
69
+ var installation = new _ParseInstallation.default();
70
+ installation.set('deviceType', _ParseInstallation.default.DEVICE_TYPES.WEB);
71
+ installation.set('installationId', installationId);
72
+ installation.set('parseVersion', _CoreManager.default.get('VERSION'));
73
+ currentInstallationCache = installation;
74
+ yield _Storage.default.setItemAsync(path, JSON.stringify(installation.toJSON()));
75
+ return installation;
76
+ });
77
+ function currentInstallation() {
78
+ return _currentInstallation.apply(this, arguments);
79
+ }
80
+ return currentInstallation;
81
+ }(),
23
82
  _clearCache: function () {
24
83
  iidCache = null;
84
+ currentInstallationCache = null;
85
+ currentInstallationCacheMatchesDisk = false;
25
86
  },
26
87
  _setInstallationIdCache: function (iid) {
27
88
  iidCache = iid;
89
+ },
90
+ _setCurrentInstallationCache: function (installation) {
91
+ var matchesDisk = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
92
+ currentInstallationCache = installation;
93
+ currentInstallationCacheMatchesDisk = matchesDisk;
28
94
  }
29
95
  };
30
- module.exports = InstallationController;
96
+ module.exports = InstallationController;
97
+ var _default = InstallationController;
98
+ exports.default = _default;
@@ -133,10 +133,11 @@ var Parse = {
133
133
  _CoreManager.default.setIfNeeded('EventEmitter', _EventEmitter.default);
134
134
  _CoreManager.default.setIfNeeded('LiveQuery', new _ParseLiveQuery.default());
135
135
  _CoreManager.default.setIfNeeded('CryptoController', _CryptoController.default);
136
+ _CoreManager.default.setIfNeeded('EventuallyQueue', _EventuallyQueue.default);
137
+ _CoreManager.default.setIfNeeded('InstallationController', _InstallationController.default);
136
138
  _CoreManager.default.setIfNeeded('LocalDatastoreController', _LocalDatastoreController.default);
137
139
  _CoreManager.default.setIfNeeded('StorageController', _StorageController.default);
138
140
  _CoreManager.default.setIfNeeded('WebSocketController', _WebSocketController.default);
139
- _CoreManager.default.setIfNeeded('EventuallyQueue', _EventuallyQueue.default);
140
141
  },
141
142
  setAsyncStorage: function (storage) {
142
143
  _CoreManager.default.setAsyncStorage(storage);
@@ -272,7 +273,6 @@ var Parse = {
272
273
  return this.encryptedUser;
273
274
  }
274
275
  };
275
- _CoreManager.default.setInstallationController(_InstallationController.default);
276
276
  _CoreManager.default.setRESTController(_RESTController.default);
277
277
  Parse.Parse = Parse;
278
278
  module.exports = Parse;