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.
@@ -3,11 +3,14 @@ Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
5
  exports.default = void 0;
6
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
6
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
7
7
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
8
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
9
+ var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
8
10
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
9
11
  var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
10
12
  var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
13
+ var _CoreManager = _interopRequireDefault(require("./CoreManager"));
11
14
  var _ParseObject2 = _interopRequireDefault(require("./ParseObject"));
12
15
  function _createSuper(Derived) {
13
16
  var hasNativeReflectConstruct = _isNativeReflectConstruct();
@@ -34,21 +37,123 @@ function _isNativeReflectConstruct() {
34
37
  return false;
35
38
  }
36
39
  }
37
- var Installation = function (_ParseObject) {
38
- (0, _inherits2.default)(Installation, _ParseObject);
39
- var _super = _createSuper(Installation);
40
- function Installation(attributes) {
40
+ var DEVICE_TYPES = {
41
+ IOS: 'ios',
42
+ MACOS: 'macos',
43
+ TVOS: 'tvos',
44
+ FCM: 'fcm',
45
+ ANDROID: 'android',
46
+ WEB: 'web'
47
+ };
48
+ var ParseInstallation = function (_ParseObject) {
49
+ (0, _inherits2.default)(ParseInstallation, _ParseObject);
50
+ var _super = _createSuper(ParseInstallation);
51
+ function ParseInstallation(attributes) {
41
52
  var _this;
42
- (0, _classCallCheck2.default)(this, Installation);
53
+ (0, _classCallCheck2.default)(this, ParseInstallation);
43
54
  _this = _super.call(this, '_Installation');
44
55
  if (attributes && typeof attributes === 'object') {
45
- if (!_this.set(attributes || {})) {
56
+ if (!_this.set(attributes)) {
46
57
  throw new Error("Can't create an invalid Installation");
47
58
  }
48
59
  }
49
60
  return _this;
50
61
  }
51
- return (0, _createClass2.default)(Installation);
62
+ (0, _createClass2.default)(ParseInstallation, [{
63
+ key: "appIdentifier",
64
+ get: function () {
65
+ return this.get('appIdentifier');
66
+ }
67
+ }, {
68
+ key: "appVersion",
69
+ get: function () {
70
+ return this.get('appVersion');
71
+ }
72
+ }, {
73
+ key: "appName",
74
+ get: function () {
75
+ return this.get('appName');
76
+ }
77
+ }, {
78
+ key: "badge",
79
+ get: function () {
80
+ return this.get('badge');
81
+ }
82
+ }, {
83
+ key: "channels",
84
+ get: function () {
85
+ return this.get('channels');
86
+ }
87
+ }, {
88
+ key: "deviceToken",
89
+ get: function () {
90
+ return this.get('deviceToken');
91
+ }
92
+ }, {
93
+ key: "deviceType",
94
+ get: function () {
95
+ return this.get('deviceType');
96
+ }
97
+ }, {
98
+ key: "GCMSenderId",
99
+ get: function () {
100
+ return this.get('GCMSenderId');
101
+ }
102
+ }, {
103
+ key: "installationId",
104
+ get: function () {
105
+ return this.get('installationId');
106
+ }
107
+ }, {
108
+ key: "localeIdentifier",
109
+ get: function () {
110
+ return this.get('localeIdentifier');
111
+ }
112
+ }, {
113
+ key: "parseVersion",
114
+ get: function () {
115
+ return this.get('parseVersion');
116
+ }
117
+ }, {
118
+ key: "pushType",
119
+ get: function () {
120
+ return this.get('pushType');
121
+ }
122
+ }, {
123
+ key: "timeZone",
124
+ get: function () {
125
+ return this.get('timeZone');
126
+ }
127
+ }, {
128
+ key: "save",
129
+ value: function () {
130
+ var _save = (0, _asyncToGenerator2.default)(function* () {
131
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
132
+ args[_key] = arguments[_key];
133
+ }
134
+ yield (0, _get2.default)((0, _getPrototypeOf2.default)(ParseInstallation.prototype), "save", this).apply(this, args);
135
+ yield _CoreManager.default.getInstallationController().updateInstallationOnDisk(this);
136
+ return this;
137
+ });
138
+ function save() {
139
+ return _save.apply(this, arguments);
140
+ }
141
+ return save;
142
+ }()
143
+ }], [{
144
+ key: "DEVICE_TYPES",
145
+ get: function () {
146
+ return DEVICE_TYPES;
147
+ }
148
+ }, {
149
+ key: "currentInstallation",
150
+ value: function () {
151
+ return _CoreManager.default.getInstallationController().currentInstallation();
152
+ }
153
+ }]);
154
+ return ParseInstallation;
52
155
  }(_ParseObject2.default);
53
- exports.default = Installation;
54
- _ParseObject2.default.registerSubclass('_Installation', Installation);
156
+ _ParseObject2.default.registerSubclass('_Installation', ParseInstallation);
157
+ module.exports = ParseInstallation;
158
+ var _default = ParseInstallation;
159
+ exports.default = _default;
@@ -391,10 +391,6 @@ var ParseObject = function () {
391
391
  json[_attr5] = (0, _encode.default)(attrs[_attr5], false, false, seen, offline);
392
392
  }
393
393
  }
394
- var pending = this._getPendingOps();
395
- for (var _attr6 in pending[0]) {
396
- json[_attr6] = pending[0][_attr6].toJSON(offline);
397
- }
398
394
  if (this.id) {
399
395
  json.objectId = this.id;
400
396
  }
@@ -441,13 +437,13 @@ var ParseObject = function () {
441
437
  var pendingOps = this._getPendingOps();
442
438
  var keys = {};
443
439
  for (var i = 0; i < pendingOps.length; i++) {
444
- for (var _attr7 in pendingOps[i]) {
445
- keys[_attr7] = true;
440
+ for (var _attr6 in pendingOps[i]) {
441
+ keys[_attr6] = true;
446
442
  }
447
443
  }
448
444
  var dirtyObjects = this._getDirtyObjectAttributes();
449
- for (var _attr8 in dirtyObjects) {
450
- keys[_attr8] = true;
445
+ for (var _attr7 in dirtyObjects) {
446
+ keys[_attr7] = true;
451
447
  }
452
448
  return Object.keys(keys);
453
449
  }
@@ -570,11 +566,11 @@ var ParseObject = function () {
570
566
  }
571
567
  var currentAttributes = this.attributes;
572
568
  var newValues = {};
573
- for (var _attr9 in newOps) {
574
- if (newOps[_attr9] instanceof _ParseOp.RelationOp) {
575
- newValues[_attr9] = newOps[_attr9].applyTo(currentAttributes[_attr9], this, _attr9);
576
- } else if (!(newOps[_attr9] instanceof _ParseOp.UnsetOp)) {
577
- newValues[_attr9] = newOps[_attr9].applyTo(currentAttributes[_attr9]);
569
+ for (var _attr8 in newOps) {
570
+ if (newOps[_attr8] instanceof _ParseOp.RelationOp) {
571
+ newValues[_attr8] = newOps[_attr8].applyTo(currentAttributes[_attr8], this, _attr8);
572
+ } else if (!(newOps[_attr8] instanceof _ParseOp.UnsetOp)) {
573
+ newValues[_attr8] = newOps[_attr8].applyTo(currentAttributes[_attr8]);
578
574
  }
579
575
  }
580
576
  if (!options.ignoreValidation) {
@@ -589,9 +585,9 @@ var ParseObject = function () {
589
585
  var pendingOps = this._getPendingOps();
590
586
  var last = pendingOps.length - 1;
591
587
  var stateController = _CoreManager.default.getObjectStateController();
592
- for (var _attr10 in newOps) {
593
- var nextOp = newOps[_attr10].mergeWith(pendingOps[last][_attr10]);
594
- stateController.setPendingOp(this._getStateIdentifier(), _attr10, nextOp);
588
+ for (var _attr9 in newOps) {
589
+ var nextOp = newOps[_attr9].mergeWith(pendingOps[last][_attr9]);
590
+ stateController.setPendingOp(this._getStateIdentifier(), _attr9, nextOp);
595
591
  }
596
592
  return this;
597
593
  }
@@ -799,9 +795,9 @@ var ParseObject = function () {
799
795
  if (typeof this.constructor.readOnlyAttributes === 'function') {
800
796
  readonly = readonly.concat(this.constructor.readOnlyAttributes());
801
797
  }
802
- for (var _attr11 in attributes) {
803
- if (readonly.indexOf(_attr11) < 0) {
804
- erasable[_attr11] = true;
798
+ for (var _attr10 in attributes) {
799
+ if (readonly.indexOf(_attr10) < 0) {
800
+ erasable[_attr10] = true;
805
801
  }
806
802
  }
807
803
  return this.set(erasable, {
@@ -1136,11 +1132,11 @@ var ParseObject = function () {
1136
1132
  var constructor = classMap[json.className];
1137
1133
  var o = constructor ? new constructor(json.className) : new ParseObject(json.className);
1138
1134
  var otherAttributes = {};
1139
- for (var _attr12 in json) {
1140
- if (_attr12 !== 'className' && _attr12 !== '__type') {
1141
- otherAttributes[_attr12] = json[_attr12];
1135
+ for (var _attr11 in json) {
1136
+ if (_attr11 !== 'className' && _attr11 !== '__type') {
1137
+ otherAttributes[_attr11] = json[_attr11];
1142
1138
  if (dirty) {
1143
- o.set(_attr12, json[_attr12]);
1139
+ o.set(_attr11, json[_attr11]);
1144
1140
  }
1145
1141
  }
1146
1142
  }
@@ -8,181 +8,16 @@ _Object$defineProperty(exports, "__esModule", {
8
8
  exports.default = void 0;
9
9
  var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
10
10
  var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
11
- /*
12
- * @flow
13
- */
14
- /*:: import type { AttributeMap, ObjectCache, OpsMap, State } from './ObjectStateMutations';*/
15
- /*:: import type ParseFile from './ParseFile';*/
16
- /*:: import type { FileSource } from './ParseFile';*/
17
- /*:: import type { Op } from './ParseOp';*/
18
- /*:: import type ParseObject, {SaveOptions} from './ParseObject';*/
19
- /*:: import type { QueryJSON } from './ParseQuery';*/
20
- /*:: import type ParseUser from './ParseUser';*/
21
- /*:: import type { AuthData } from './ParseUser';*/
22
- /*:: import type { PushData } from './Push';*/
23
- /*:: import type { RequestOptions, FullOptions } from './RESTController';*/
24
- /*:: type AnalyticsController = {
25
- track: (name: string, dimensions: { [key: string]: string }) => Promise,
26
- };*/
27
- /*:: type CloudController = {
28
- run: (name: string, data: mixed, options: RequestOptions) => Promise,
29
- getJobsData: (options: RequestOptions) => Promise,
30
- startJob: (name: string, data: mixed, options: RequestOptions) => Promise,
31
- };*/
32
- /*:: type ConfigController = {
33
- current: () => Promise,
34
- get: () => Promise,
35
- save: (attrs: { [key: string]: any }) => Promise,
36
- };*/
37
- /*:: type CryptoController = {
38
- encrypt: (obj: any, secretKey: string) => string,
39
- decrypt: (encryptedText: string, secretKey: any) => string,
40
- };*/
41
- /*:: type FileController = {
42
- saveFile: (name: string, source: FileSource, options: FullOptions) => Promise,
43
- saveBase64: (name: string, source: FileSource, options: FullOptions) => Promise,
44
- download: (uri: string) => Promise,
45
- };*/
46
- /*:: type InstallationController = {
47
- currentInstallationId: () => Promise,
48
- };*/
49
- /*:: type ObjectController = {
50
- fetch: (
51
- object: ParseObject | Array<ParseObject>,
52
- forceFetch: boolean,
53
- options: RequestOptions
54
- ) => Promise,
55
- save: (object: ParseObject | Array<ParseObject | ParseFile>, options: RequestOptions) => Promise,
56
- destroy: (object: ParseObject | Array<ParseObject>, options: RequestOptions) => Promise,
57
- };*/
58
- /*:: type ObjectStateController = {
59
- getState: (obj: any) => ?State,
60
- initializeState: (obj: any, initial?: State) => State,
61
- removeState: (obj: any) => ?State,
62
- getServerData: (obj: any) => AttributeMap,
63
- setServerData: (obj: any, attributes: AttributeMap) => void,
64
- getPendingOps: (obj: any) => Array<OpsMap>,
65
- setPendingOp: (obj: any, attr: string, op: ?Op) => void,
66
- pushPendingState: (obj: any) => void,
67
- popPendingState: (obj: any) => OpsMap,
68
- mergeFirstPendingState: (obj: any) => void,
69
- getObjectCache: (obj: any) => ObjectCache,
70
- estimateAttribute: (obj: any, attr: string) => mixed,
71
- estimateAttributes: (obj: any) => AttributeMap,
72
- commitServerChanges: (obj: any, changes: AttributeMap) => void,
73
- enqueueTask: (obj: any, task: () => Promise) => Promise,
74
- clearAllState: () => void,
75
- duplicateState: (source: any, dest: any) => void,
76
- };*/
77
- /*:: type PushController = {
78
- send: (data: PushData) => Promise,
79
- };*/
80
- /*:: type QueryController = {
81
- find: (className: string, params: QueryJSON, options: RequestOptions) => Promise,
82
- aggregate: (className: string, params: any, options: RequestOptions) => Promise,
83
- };*/
84
- /*:: type EventuallyQueue = {
85
- save: (object: ParseObject, serverOptions: SaveOptions) => Promise,
86
- destroy: (object: ParseObject, serverOptions: RequestOptions) => Promise,
87
- poll: (ms: number) => void
88
- };*/
89
- /*:: type RESTController = {
90
- request: (method: string, path: string, data: mixed, options: RequestOptions) => Promise,
91
- ajax: (method: string, url: string, data: any, headers?: any, options: FullOptions) => Promise,
92
- };*/
93
- /*:: type SchemaController = {
94
- purge: (className: string) => Promise,
95
- get: (className: string, options: RequestOptions) => Promise,
96
- delete: (className: string, options: RequestOptions) => Promise,
97
- create: (className: string, params: any, options: RequestOptions) => Promise,
98
- update: (className: string, params: any, options: RequestOptions) => Promise,
99
- send(className: string, method: string, params: any, options: RequestOptions): Promise,
100
- };*/
101
- /*:: type SessionController = {
102
- getSession: (token: RequestOptions) => Promise,
103
- };*/
104
- /*:: type StorageController =
105
- | {
106
- async: 0,
107
- getItem: (path: string) => ?string,
108
- setItem: (path: string, value: string) => void,
109
- removeItem: (path: string) => void,
110
- getItemAsync?: (path: string) => Promise,
111
- setItemAsync?: (path: string, value: string) => Promise,
112
- removeItemAsync?: (path: string) => Promise,
113
- clear: () => void,
114
- }
115
- | {
116
- async: 1,
117
- getItem?: (path: string) => ?string,
118
- setItem?: (path: string, value: string) => void,
119
- removeItem?: (path: string) => void,
120
- getItemAsync: (path: string) => Promise,
121
- setItemAsync: (path: string, value: string) => Promise,
122
- removeItemAsync: (path: string) => Promise,
123
- clear: () => void,
124
- };*/
125
- /*:: type LocalDatastoreController = {
126
- fromPinWithName: (name: string) => ?any,
127
- pinWithName: (name: string, objects: any) => void,
128
- unPinWithName: (name: string) => void,
129
- getAllContents: () => ?any,
130
- clear: () => void,
131
- };*/
132
- /*:: type UserController = {
133
- setCurrentUser: (user: ParseUser) => Promise,
134
- currentUser: () => ?ParseUser,
135
- currentUserAsync: () => Promise,
136
- signUp: (user: ParseUser, attrs: AttributeMap, options: RequestOptions) => Promise,
137
- logIn: (user: ParseUser, options: RequestOptions) => Promise,
138
- become: (options: RequestOptions) => Promise,
139
- hydrate: (userJSON: AttributeMap) => Promise,
140
- logOut: (options: RequestOptions) => Promise,
141
- me: (options: RequestOptions) => Promise,
142
- requestPasswordReset: (email: string, options: RequestOptions) => Promise,
143
- updateUserOnDisk: (user: ParseUser) => Promise,
144
- upgradeToRevocableSession: (user: ParseUser, options: RequestOptions) => Promise,
145
- linkWith: (user: ParseUser, authData: AuthData) => Promise,
146
- removeUserFromDisk: () => Promise,
147
- verifyPassword: (username: string, password: string, options: RequestOptions) => Promise,
148
- requestEmailVerification: (email: string, options: RequestOptions) => Promise,
149
- };*/
150
- /*:: type HooksController = {
151
- get: (type: string, functionName?: string, triggerName?: string) => Promise,
152
- create: (hook: mixed) => Promise,
153
- delete: (hook: mixed) => Promise,
154
- update: (hook: mixed) => Promise,
155
- send: (method: string, path: string, body?: mixed) => Promise,
156
- };*/
157
- /*:: type WebSocketController = {
11
+ /** Based on https://github.com/react-native-async-storage/async-storage/blob/main/packages/default-storage-backend/src/types.ts */
12
+ /*:: export type WebSocketController = {
158
13
  onopen: () => void,
159
14
  onmessage: (message: any) => void,
160
- onclose: () => void,
15
+ onclose: (arg?: any) => void,
161
16
  onerror: (error: any) => void,
162
17
  send: (data: any) => void,
163
18
  close: () => void,
164
19
  };*/
165
- /*:: type Config = {
166
- AnalyticsController?: AnalyticsController,
167
- CloudController?: CloudController,
168
- ConfigController?: ConfigController,
169
- FileController?: FileController,
170
- InstallationController?: InstallationController,
171
- ObjectController?: ObjectController,
172
- ObjectStateController?: ObjectStateController,
173
- PushController?: PushController,
174
- QueryController?: QueryController,
175
- RESTController?: RESTController,
176
- SchemaController?: SchemaController,
177
- SessionController?: SessionController,
178
- StorageController?: StorageController,
179
- LocalDatastoreController?: LocalDatastoreController,
180
- UserController?: UserController,
181
- HooksController?: HooksController,
182
- WebSocketController?: WebSocketController,
183
- };*/
184
- var config /*: Config & { [key: string]: mixed }*/ = {
185
- // Defaults
20
+ var config /*: Config & { [key: string]: any }*/ = {
186
21
  IS_NODE: typeof process !== 'undefined' && !!process.versions && !!process.versions.node && !process.versions.electron,
187
22
  REQUEST_ATTEMPT_LIMIT: 5,
188
23
  REQUEST_BATCH_SIZE: 20,
@@ -192,7 +27,7 @@ var config /*: Config & { [key: string]: mixed }*/ = {
192
27
  SERVER_AUTH_TOKEN: null,
193
28
  LIVEQUERY_SERVER_URL: null,
194
29
  ENCRYPTED_KEY: null,
195
- VERSION: 'js' + "5.1.0-alpha.7",
30
+ VERSION: 'js' + "5.1.0-alpha.9",
196
31
  APPLICATION_ID: null,
197
32
  JAVASCRIPT_KEY: null,
198
33
  MASTER_KEY: null,
@@ -266,11 +101,18 @@ var CoreManager = {
266
101
  requireMethods('FileController', ['saveFile', 'saveBase64'], controller);
267
102
  config['FileController'] = controller;
268
103
  },
104
+ setEventuallyQueue: function (controller /*: EventuallyQueue*/) {
105
+ requireMethods('EventuallyQueue', ['poll', 'save', 'destroy'], controller);
106
+ config['EventuallyQueue'] = controller;
107
+ },
108
+ getEventuallyQueue: function () /*: EventuallyQueue*/{
109
+ return config['EventuallyQueue'];
110
+ },
269
111
  getFileController: function () /*: FileController*/{
270
112
  return config['FileController'];
271
113
  },
272
114
  setInstallationController: function (controller /*: InstallationController*/) {
273
- requireMethods('InstallationController', ['currentInstallationId'], controller);
115
+ requireMethods('InstallationController', ['currentInstallationId', 'currentInstallation', 'updateInstallationOnDisk'], controller);
274
116
  config['InstallationController'] = controller;
275
117
  },
276
118
  getInstallationController: function () /*: InstallationController*/{
@@ -317,13 +159,6 @@ var CoreManager = {
317
159
  getRESTController: function () /*: RESTController*/{
318
160
  return config['RESTController'];
319
161
  },
320
- setEventuallyQueue: function (controller /*: EventuallyQueue*/) {
321
- requireMethods('EventuallyQueue', ['poll', 'save', 'destroy'], controller);
322
- config['EventuallyQueue'] = controller;
323
- },
324
- getEventuallyQueue: function () /*: EventuallyQueue*/{
325
- return config['EventuallyQueue'];
326
- },
327
162
  setSchemaController: function (controller /*: SchemaController*/) {
328
163
  requireMethods('SchemaController', ['get', 'create', 'update', 'delete', 'send', 'purge'], controller);
329
164
  config['SchemaController'] = controller;
@@ -362,16 +197,16 @@ var CoreManager = {
362
197
  getStorageController: function () /*: StorageController*/{
363
198
  return config['StorageController'];
364
199
  },
365
- setAsyncStorage: function (storage /*: any*/) {
200
+ setAsyncStorage: function (storage /*: AsyncStorageType*/) {
366
201
  config['AsyncStorage'] = storage;
367
202
  },
368
203
  getAsyncStorage: function () {
369
204
  return config['AsyncStorage'];
370
205
  },
371
- setWebSocketController: function (controller /*: WebSocketController*/) {
206
+ setWebSocketController: function (controller /*: new (url: string | URL, protocols?: string | string[] | undefined) => WebSocketController*/) {
372
207
  config['WebSocketController'] = controller;
373
208
  },
374
- getWebSocketController: function () /*: WebSocketController*/{
209
+ getWebSocketController: function () /*: new (url: string | URL, protocols?: string | string[] | undefined) => WebSocketController*/{
375
210
  return config['WebSocketController'];
376
211
  },
377
212
  setUserController: function (controller /*: UserController*/) {
@@ -381,11 +216,11 @@ var CoreManager = {
381
216
  getUserController: function () /*: UserController*/{
382
217
  return config['UserController'];
383
218
  },
384
- setLiveQueryController: function (controller /*: any*/) {
219
+ setLiveQueryController: function (controller /*: LiveQueryControllerType*/) {
385
220
  requireMethods('LiveQueryController', ['setDefaultLiveQueryClient', 'getDefaultLiveQueryClient', '_clearCachedDefaultClient'], controller);
386
221
  config['LiveQueryController'] = controller;
387
222
  },
388
- getLiveQueryController: function () /*: any*/{
223
+ getLiveQueryController: function () /*: LiveQueryControllerType*/{
389
224
  return config['LiveQueryController'];
390
225
  },
391
226
  setHooksController: function (controller /*: HooksController*/) {
@@ -1,37 +1,148 @@
1
1
  "use strict";
2
2
 
3
+ var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
3
4
  var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
4
- var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
5
+ _Object$defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+ var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs3/regenerator"));
10
+ var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/json/stringify"));
11
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncToGenerator"));
12
+ var _CoreManager = _interopRequireDefault(require("./CoreManager"));
5
13
  var _Storage = _interopRequireDefault(require("./Storage"));
6
- /**
7
- * @flow
8
- */
9
-
10
- var uuidv4 = require('./uuid');
11
- var iidCache = null;
14
+ var _ParseInstallation = _interopRequireDefault(require("./ParseInstallation"));
15
+ var _uuid = _interopRequireDefault(require("./uuid"));
16
+ var CURRENT_INSTALLATION_KEY = 'currentInstallation';
17
+ var CURRENT_INSTALLATION_ID_KEY = 'currentInstallationId';
18
+ var iidCache /*: string | null*/ = null;
19
+ var currentInstallationCache = null;
20
+ var currentInstallationCacheMatchesDisk = false;
12
21
  var InstallationController = {
22
+ updateInstallationOnDisk: function (installation /*: ParseInstallation*/) /*: Promise<void>*/{
23
+ var _this = this;
24
+ return (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
25
+ var path;
26
+ return _regenerator.default.wrap(function (_context) {
27
+ while (1) switch (_context.prev = _context.next) {
28
+ case 0:
29
+ path = _Storage.default.generatePath(CURRENT_INSTALLATION_KEY);
30
+ _context.next = 3;
31
+ return _Storage.default.setItemAsync(path, (0, _stringify.default)(installation.toJSON()));
32
+ case 3:
33
+ _this._setCurrentInstallationCache(installation);
34
+ case 4:
35
+ case "end":
36
+ return _context.stop();
37
+ }
38
+ }, _callee);
39
+ }))();
40
+ },
13
41
  currentInstallationId: function () /*: Promise<string>*/{
14
- if (typeof iidCache === 'string') {
15
- return _promise.default.resolve(iidCache);
16
- }
17
- var path = _Storage.default.generatePath('installationId');
18
- return _Storage.default.getItemAsync(path).then(function (iid) {
19
- if (!iid) {
20
- iid = uuidv4();
21
- return _Storage.default.setItemAsync(path, iid).then(function () {
22
- iidCache = iid;
23
- return iid;
24
- });
25
- }
26
- iidCache = iid;
27
- return iid;
28
- });
42
+ return (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
43
+ var path, iid;
44
+ return _regenerator.default.wrap(function (_context2) {
45
+ while (1) switch (_context2.prev = _context2.next) {
46
+ case 0:
47
+ if (!(typeof iidCache === 'string')) {
48
+ _context2.next = 2;
49
+ break;
50
+ }
51
+ return _context2.abrupt("return", iidCache);
52
+ case 2:
53
+ path = _Storage.default.generatePath(CURRENT_INSTALLATION_ID_KEY);
54
+ _context2.next = 5;
55
+ return _Storage.default.getItemAsync(path);
56
+ case 5:
57
+ iid = _context2.sent;
58
+ if (iid) {
59
+ _context2.next = 9;
60
+ break;
61
+ }
62
+ iid = (0, _uuid.default)();
63
+ return _context2.abrupt("return", _Storage.default.setItemAsync(path, iid).then(function () {
64
+ iidCache = iid;
65
+ return iid;
66
+ }));
67
+ case 9:
68
+ iidCache = iid;
69
+ return _context2.abrupt("return", iid);
70
+ case 11:
71
+ case "end":
72
+ return _context2.stop();
73
+ }
74
+ }, _callee2);
75
+ }))();
76
+ },
77
+ currentInstallation: function () /*: Promise<ParseInstallation | null>*/{
78
+ var _this2 = this;
79
+ return (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
80
+ var path, installationData, current, installationId, installation;
81
+ return _regenerator.default.wrap(function (_context3) {
82
+ while (1) switch (_context3.prev = _context3.next) {
83
+ case 0:
84
+ if (!currentInstallationCache) {
85
+ _context3.next = 2;
86
+ break;
87
+ }
88
+ return _context3.abrupt("return", currentInstallationCache);
89
+ case 2:
90
+ if (!currentInstallationCacheMatchesDisk) {
91
+ _context3.next = 4;
92
+ break;
93
+ }
94
+ return _context3.abrupt("return", null);
95
+ case 4:
96
+ path = _Storage.default.generatePath(CURRENT_INSTALLATION_KEY);
97
+ _context3.next = 7;
98
+ return _Storage.default.getItemAsync(path);
99
+ case 7:
100
+ installationData = _context3.sent;
101
+ currentInstallationCacheMatchesDisk = true;
102
+ if (!installationData) {
103
+ _context3.next = 15;
104
+ break;
105
+ }
106
+ installationData = JSON.parse(installationData);
107
+ installationData.className = '_Installation';
108
+ current = _ParseInstallation.default.fromJSON(installationData);
109
+ currentInstallationCache = current;
110
+ return _context3.abrupt("return", current);
111
+ case 15:
112
+ _context3.next = 17;
113
+ return _this2.currentInstallationId();
114
+ case 17:
115
+ installationId = _context3.sent;
116
+ installation = new _ParseInstallation.default();
117
+ installation.set('deviceType', _ParseInstallation.default.DEVICE_TYPES.WEB);
118
+ installation.set('installationId', installationId);
119
+ installation.set('parseVersion', _CoreManager.default.get('VERSION'));
120
+ currentInstallationCache = installation;
121
+ _context3.next = 25;
122
+ return _Storage.default.setItemAsync(path, (0, _stringify.default)(installation.toJSON()));
123
+ case 25:
124
+ return _context3.abrupt("return", installation);
125
+ case 26:
126
+ case "end":
127
+ return _context3.stop();
128
+ }
129
+ }, _callee3);
130
+ }))();
29
131
  },
30
132
  _clearCache: function () {
31
133
  iidCache = null;
134
+ currentInstallationCache = null;
135
+ currentInstallationCacheMatchesDisk = false;
32
136
  },
33
137
  _setInstallationIdCache: function (iid /*: string*/) {
34
138
  iidCache = iid;
139
+ },
140
+ _setCurrentInstallationCache: function (installation /*: ParseInstallation*/) {
141
+ var matchesDisk /*: boolean*/ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
142
+ currentInstallationCache = installation;
143
+ currentInstallationCacheMatchesDisk = matchesDisk;
35
144
  }
36
145
  };
37
- module.exports = InstallationController;
146
+ module.exports = InstallationController;
147
+ var _default = InstallationController;
148
+ exports.default = _default;