parse 5.1.0-alpha.1 → 5.1.0-alpha.11

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.
Files changed (143) hide show
  1. package/README.md +13 -0
  2. package/dist/parse.js +1464 -1051
  3. package/dist/parse.min.js +2 -2
  4. package/dist/parse.weapp.js +2367 -1090
  5. package/dist/parse.weapp.min.js +2 -2
  6. package/lib/browser/CoreManager.js +48 -171
  7. package/lib/browser/InstallationController.js +134 -23
  8. package/lib/browser/LiveQueryClient.js +43 -35
  9. package/lib/browser/LiveQuerySubscription.js +15 -5
  10. package/lib/browser/LocalDatastoreController.default.js +248 -0
  11. package/lib/browser/LocalDatastoreController.js +1 -246
  12. package/lib/browser/ObjectStateMutations.js +6 -5
  13. package/lib/browser/OfflineQuery.js +3 -2
  14. package/lib/browser/Parse.js +31 -7
  15. package/lib/browser/ParseACL.js +21 -11
  16. package/lib/browser/ParseFile.js +4 -0
  17. package/lib/browser/ParseGeoPoint.js +12 -8
  18. package/lib/browser/ParseHooks.js +2 -0
  19. package/lib/browser/ParseInstallation.js +274 -13
  20. package/lib/browser/ParseLiveQuery.js +32 -23
  21. package/lib/browser/ParseObject.js +37 -40
  22. package/lib/browser/ParseOp.js +21 -7
  23. package/lib/browser/ParseQuery.js +1 -0
  24. package/lib/browser/ParseRelation.js +12 -7
  25. package/lib/browser/ParseRole.js +2 -0
  26. package/lib/browser/ParseSession.js +1 -1
  27. package/lib/browser/ParseUser.js +51 -15
  28. package/lib/browser/RESTController.js +6 -5
  29. package/lib/browser/SingleInstanceStateController.js +2 -4
  30. package/lib/browser/Storage.js +1 -2
  31. package/lib/browser/StorageController.js +3 -0
  32. package/lib/browser/WebSocketController.js +13 -0
  33. package/lib/browser/arrayContainsObject.js +4 -3
  34. package/lib/browser/canBeSerialized.js +6 -4
  35. package/lib/browser/decode.js +8 -5
  36. package/lib/browser/encode.js +6 -4
  37. package/lib/browser/equals.js +4 -3
  38. package/lib/browser/unique.js +3 -2
  39. package/lib/browser/unsavedChildren.js +4 -2
  40. package/lib/browser/uuid.js +11 -5
  41. package/lib/node/CoreManager.js +48 -171
  42. package/lib/node/InstallationController.js +65 -21
  43. package/lib/node/LiveQueryClient.js +2 -5
  44. package/lib/node/LiveQuerySubscription.js +2 -2
  45. package/lib/node/LocalDatastoreController.default.js +67 -0
  46. package/lib/node/LocalDatastoreController.js +1 -65
  47. package/lib/node/ObjectStateMutations.js +8 -9
  48. package/lib/node/OfflineQuery.js +3 -2
  49. package/lib/node/Parse.js +31 -7
  50. package/lib/node/ParseACL.js +21 -11
  51. package/lib/node/ParseFile.js +4 -0
  52. package/lib/node/ParseGeoPoint.js +11 -11
  53. package/lib/node/ParseHooks.js +2 -0
  54. package/lib/node/ParseInstallation.js +207 -7
  55. package/lib/node/ParseLiveQuery.js +2 -3
  56. package/lib/node/ParseObject.js +9 -12
  57. package/lib/node/ParseOp.js +21 -7
  58. package/lib/node/ParseQuery.js +1 -0
  59. package/lib/node/ParseRelation.js +14 -8
  60. package/lib/node/ParseRole.js +2 -0
  61. package/lib/node/ParseSession.js +1 -1
  62. package/lib/node/ParseUser.js +20 -13
  63. package/lib/node/RESTController.js +5 -5
  64. package/lib/node/SingleInstanceStateController.js +2 -8
  65. package/lib/node/Storage.js +1 -2
  66. package/lib/node/StorageController.js +3 -0
  67. package/lib/node/WebSocketController.js +10 -0
  68. package/lib/node/arrayContainsObject.js +4 -3
  69. package/lib/node/canBeSerialized.js +6 -4
  70. package/lib/node/decode.js +9 -5
  71. package/lib/node/encode.js +7 -4
  72. package/lib/node/equals.js +4 -3
  73. package/lib/node/unique.js +3 -2
  74. package/lib/node/unsavedChildren.js +4 -2
  75. package/lib/node/uuid.js +10 -8
  76. package/lib/react-native/CoreManager.js +39 -2
  77. package/lib/react-native/InstallationController.js +77 -9
  78. package/lib/react-native/LiveQueryClient.js +28 -20
  79. package/lib/react-native/LiveQuerySubscription.js +14 -5
  80. package/lib/react-native/LocalDatastoreController.default.js +91 -0
  81. package/lib/react-native/LocalDatastoreController.js +1 -91
  82. package/lib/react-native/ObjectStateMutations.js +6 -5
  83. package/lib/react-native/OfflineQuery.js +3 -2
  84. package/lib/react-native/Parse.js +23 -7
  85. package/lib/react-native/ParseACL.js +19 -11
  86. package/lib/react-native/ParseGeoPoint.js +5 -3
  87. package/lib/react-native/ParseInstallation.js +115 -10
  88. package/lib/react-native/ParseLiveQuery.js +11 -2
  89. package/lib/react-native/ParseObject.js +28 -31
  90. package/lib/react-native/ParseOp.js +20 -6
  91. package/lib/react-native/ParseQuery.js +1 -0
  92. package/lib/react-native/ParseRelation.js +10 -7
  93. package/lib/react-native/ParseRole.js +2 -0
  94. package/lib/react-native/ParseUser.js +6 -2
  95. package/lib/react-native/RESTController.js +5 -5
  96. package/lib/react-native/SingleInstanceStateController.js +0 -2
  97. package/lib/react-native/Storage.js +1 -2
  98. package/lib/react-native/StorageController.js +1 -0
  99. package/lib/react-native/WebSocketController.js +5 -0
  100. package/lib/react-native/arrayContainsObject.js +3 -2
  101. package/lib/react-native/canBeSerialized.js +5 -3
  102. package/lib/react-native/decode.js +7 -5
  103. package/lib/react-native/encode.js +6 -4
  104. package/lib/react-native/equals.js +4 -3
  105. package/lib/react-native/unique.js +3 -2
  106. package/lib/react-native/unsavedChildren.js +3 -2
  107. package/lib/react-native/uuid.js +9 -4
  108. package/lib/weapp/CoreManager.js +48 -171
  109. package/lib/weapp/InstallationController.js +134 -23
  110. package/lib/weapp/LiveQueryClient.js +43 -35
  111. package/lib/weapp/LiveQuerySubscription.js +15 -5
  112. package/lib/weapp/LocalDatastoreController.default.js +248 -0
  113. package/lib/weapp/LocalDatastoreController.js +1 -246
  114. package/lib/weapp/ObjectStateMutations.js +6 -5
  115. package/lib/weapp/OfflineQuery.js +3 -2
  116. package/lib/weapp/Parse.js +31 -7
  117. package/lib/weapp/ParseACL.js +21 -11
  118. package/lib/weapp/ParseFile.js +4 -0
  119. package/lib/weapp/ParseGeoPoint.js +12 -8
  120. package/lib/weapp/ParseHooks.js +2 -0
  121. package/lib/weapp/ParseInstallation.js +274 -13
  122. package/lib/weapp/ParseLiveQuery.js +32 -23
  123. package/lib/weapp/ParseObject.js +37 -40
  124. package/lib/weapp/ParseOp.js +21 -7
  125. package/lib/weapp/ParseQuery.js +1 -0
  126. package/lib/weapp/ParseRelation.js +12 -7
  127. package/lib/weapp/ParseRole.js +2 -0
  128. package/lib/weapp/ParseSession.js +1 -1
  129. package/lib/weapp/ParseUser.js +51 -15
  130. package/lib/weapp/RESTController.js +6 -5
  131. package/lib/weapp/SingleInstanceStateController.js +2 -4
  132. package/lib/weapp/Storage.js +1 -2
  133. package/lib/weapp/StorageController.js +3 -0
  134. package/lib/weapp/WebSocketController.js +13 -0
  135. package/lib/weapp/arrayContainsObject.js +4 -3
  136. package/lib/weapp/canBeSerialized.js +6 -4
  137. package/lib/weapp/decode.js +8 -5
  138. package/lib/weapp/encode.js +6 -4
  139. package/lib/weapp/equals.js +4 -3
  140. package/lib/weapp/unique.js +3 -2
  141. package/lib/weapp/unsavedChildren.js +4 -2
  142. package/lib/weapp/uuid.js +12 -5
  143. package/package.json +3 -1
@@ -8,176 +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 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 RESTController = {
85
- request: (method: string, path: string, data: mixed, options: RequestOptions) => Promise,
86
- ajax: (method: string, url: string, data: any, headers?: any, options: FullOptions) => Promise,
87
- };*/
88
- /*:: type SchemaController = {
89
- purge: (className: string) => Promise,
90
- get: (className: string, options: RequestOptions) => Promise,
91
- delete: (className: string, options: RequestOptions) => Promise,
92
- create: (className: string, params: any, options: RequestOptions) => Promise,
93
- update: (className: string, params: any, options: RequestOptions) => Promise,
94
- send(className: string, method: string, params: any, options: RequestOptions): Promise,
95
- };*/
96
- /*:: type SessionController = {
97
- getSession: (token: RequestOptions) => Promise,
98
- };*/
99
- /*:: type StorageController =
100
- | {
101
- async: 0,
102
- getItem: (path: string) => ?string,
103
- setItem: (path: string, value: string) => void,
104
- removeItem: (path: string) => void,
105
- getItemAsync?: (path: string) => Promise,
106
- setItemAsync?: (path: string, value: string) => Promise,
107
- removeItemAsync?: (path: string) => Promise,
108
- clear: () => void,
109
- }
110
- | {
111
- async: 1,
112
- getItem?: (path: string) => ?string,
113
- setItem?: (path: string, value: string) => void,
114
- removeItem?: (path: string) => void,
115
- getItemAsync: (path: string) => Promise,
116
- setItemAsync: (path: string, value: string) => Promise,
117
- removeItemAsync: (path: string) => Promise,
118
- clear: () => void,
119
- };*/
120
- /*:: type LocalDatastoreController = {
121
- fromPinWithName: (name: string) => ?any,
122
- pinWithName: (name: string, objects: any) => void,
123
- unPinWithName: (name: string) => void,
124
- getAllContents: () => ?any,
125
- clear: () => void,
126
- };*/
127
- /*:: type UserController = {
128
- setCurrentUser: (user: ParseUser) => Promise,
129
- currentUser: () => ?ParseUser,
130
- currentUserAsync: () => Promise,
131
- signUp: (user: ParseUser, attrs: AttributeMap, options: RequestOptions) => Promise,
132
- logIn: (user: ParseUser, options: RequestOptions) => Promise,
133
- become: (options: RequestOptions) => Promise,
134
- hydrate: (userJSON: AttributeMap) => Promise,
135
- logOut: (options: RequestOptions) => Promise,
136
- me: (options: RequestOptions) => Promise,
137
- requestPasswordReset: (email: string, options: RequestOptions) => Promise,
138
- updateUserOnDisk: (user: ParseUser) => Promise,
139
- upgradeToRevocableSession: (user: ParseUser, options: RequestOptions) => Promise,
140
- linkWith: (user: ParseUser, authData: AuthData) => Promise,
141
- removeUserFromDisk: () => Promise,
142
- verifyPassword: (username: string, password: string, options: RequestOptions) => Promise,
143
- requestEmailVerification: (email: string, options: RequestOptions) => Promise,
144
- };*/
145
- /*:: type HooksController = {
146
- get: (type: string, functionName?: string, triggerName?: string) => Promise,
147
- create: (hook: mixed) => Promise,
148
- delete: (hook: mixed) => Promise,
149
- update: (hook: mixed) => Promise,
150
- send: (method: string, path: string, body?: mixed) => Promise,
151
- };*/
152
- /*:: 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 = {
153
13
  onopen: () => void,
154
14
  onmessage: (message: any) => void,
155
- onclose: () => void,
15
+ onclose: (arg?: any) => void,
156
16
  onerror: (error: any) => void,
157
17
  send: (data: any) => void,
158
18
  close: () => void,
159
19
  };*/
160
- /*:: type Config = {
161
- AnalyticsController?: AnalyticsController,
162
- CloudController?: CloudController,
163
- ConfigController?: ConfigController,
164
- FileController?: FileController,
165
- InstallationController?: InstallationController,
166
- ObjectController?: ObjectController,
167
- ObjectStateController?: ObjectStateController,
168
- PushController?: PushController,
169
- QueryController?: QueryController,
170
- RESTController?: RESTController,
171
- SchemaController?: SchemaController,
172
- SessionController?: SessionController,
173
- StorageController?: StorageController,
174
- LocalDatastoreController?: LocalDatastoreController,
175
- UserController?: UserController,
176
- HooksController?: HooksController,
177
- WebSocketController?: WebSocketController,
178
- };*/
179
- var config /*: Config & { [key: string]: mixed }*/ = {
180
- // Defaults
20
+ var config /*: Config & { [key: string]: any }*/ = {
181
21
  IS_NODE: typeof process !== 'undefined' && !!process.versions && !!process.versions.node && !process.versions.electron,
182
22
  REQUEST_ATTEMPT_LIMIT: 5,
183
23
  REQUEST_BATCH_SIZE: 20,
@@ -187,7 +27,7 @@ var config /*: Config & { [key: string]: mixed }*/ = {
187
27
  SERVER_AUTH_TOKEN: null,
188
28
  LIVEQUERY_SERVER_URL: null,
189
29
  ENCRYPTED_KEY: null,
190
- VERSION: 'js' + "5.1.0-alpha.1",
30
+ VERSION: 'js' + "5.1.0-alpha.11",
191
31
  APPLICATION_ID: null,
192
32
  JAVASCRIPT_KEY: null,
193
33
  MASTER_KEY: null,
@@ -261,11 +101,18 @@ var CoreManager = {
261
101
  requireMethods('FileController', ['saveFile', 'saveBase64'], controller);
262
102
  config['FileController'] = controller;
263
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
+ },
264
111
  getFileController: function () /*: FileController*/{
265
112
  return config['FileController'];
266
113
  },
267
114
  setInstallationController: function (controller /*: InstallationController*/) {
268
- requireMethods('InstallationController', ['currentInstallationId'], controller);
115
+ requireMethods('InstallationController', ['currentInstallationId', 'currentInstallation', 'updateInstallationOnDisk'], controller);
269
116
  config['InstallationController'] = controller;
270
117
  },
271
118
  getInstallationController: function () /*: InstallationController*/{
@@ -350,16 +197,16 @@ var CoreManager = {
350
197
  getStorageController: function () /*: StorageController*/{
351
198
  return config['StorageController'];
352
199
  },
353
- setAsyncStorage: function (storage /*: any*/) {
200
+ setAsyncStorage: function (storage /*: AsyncStorageType*/) {
354
201
  config['AsyncStorage'] = storage;
355
202
  },
356
203
  getAsyncStorage: function () {
357
204
  return config['AsyncStorage'];
358
205
  },
359
- setWebSocketController: function (controller /*: WebSocketController*/) {
206
+ setWebSocketController: function (controller /*: new (url: string | URL, protocols?: string | string[] | undefined) => WebSocketController*/) {
360
207
  config['WebSocketController'] = controller;
361
208
  },
362
- getWebSocketController: function () /*: WebSocketController*/{
209
+ getWebSocketController: function () /*: new (url: string | URL, protocols?: string | string[] | undefined) => WebSocketController*/{
363
210
  return config['WebSocketController'];
364
211
  },
365
212
  setUserController: function (controller /*: UserController*/) {
@@ -369,11 +216,11 @@ var CoreManager = {
369
216
  getUserController: function () /*: UserController*/{
370
217
  return config['UserController'];
371
218
  },
372
- setLiveQueryController: function (controller /*: any*/) {
219
+ setLiveQueryController: function (controller /*: LiveQueryControllerType*/) {
373
220
  requireMethods('LiveQueryController', ['setDefaultLiveQueryClient', 'getDefaultLiveQueryClient', '_clearCachedDefaultClient'], controller);
374
221
  config['LiveQueryController'] = controller;
375
222
  },
376
- getLiveQueryController: function () /*: any*/{
223
+ getLiveQueryController: function () /*: LiveQueryControllerType*/{
377
224
  return config['LiveQueryController'];
378
225
  },
379
226
  setHooksController: function (controller /*: HooksController*/) {
@@ -382,6 +229,36 @@ var CoreManager = {
382
229
  },
383
230
  getHooksController: function () /*: HooksController*/{
384
231
  return config['HooksController'];
232
+ },
233
+ setParseOp: function (op /*: ParseOp*/) {
234
+ config['ParseOp'] = op;
235
+ },
236
+ getParseOp: function () {
237
+ return config['ParseOp'];
238
+ },
239
+ setParseObject: function (object /*: ParseObject*/) {
240
+ config['ParseObject'] = object;
241
+ },
242
+ getParseObject: function () /*: ParseObject*/{
243
+ return config['ParseObject'];
244
+ },
245
+ setParseQuery: function (query /*: ParseQuery*/) {
246
+ config['ParseQuery'] = query;
247
+ },
248
+ getParseQuery: function () {
249
+ return config['ParseQuery'];
250
+ },
251
+ setParseRole: function (role /*: ParseRole*/) {
252
+ config['ParseRole'] = role;
253
+ },
254
+ getParseRole: function () /*: ParseRole*/{
255
+ return config['ParseRole'];
256
+ },
257
+ setParseUser: function (user /*: ParseUser*/) {
258
+ config['ParseUser'] = user;
259
+ },
260
+ getParseUser: function () /*: ParseUser*/{
261
+ return config['ParseUser'];
385
262
  }
386
263
  };
387
264
  module.exports = CoreManager;
@@ -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;
@@ -13,13 +13,13 @@ _Object$defineProperty(exports, "__esModule", {
13
13
  exports.default = void 0;
14
14
  var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
15
15
  var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/map"));
16
+ var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
16
17
  var _keys = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/keys"));
17
18
  var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/json/stringify"));
18
19
  var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
19
20
  var _values = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/values"));
20
21
  var _setTimeout2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/set-timeout"));
21
22
  var _bind = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/bind"));
22
- var _typeof2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/typeof"));
23
23
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/classCallCheck"));
24
24
  var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/createClass"));
25
25
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
@@ -80,10 +80,10 @@ function _createForOfIteratorHelper(o, allowArrayLike) {
80
80
  };
81
81
  }
82
82
  function _unsupportedIterableToArray(o, minLen) {
83
- var _context6;
83
+ var _context7;
84
84
  if (!o) return;
85
85
  if (typeof o === "string") return _arrayLikeToArray(o, minLen);
86
- var n = _sliceInstanceProperty(_context6 = Object.prototype.toString.call(o)).call(_context6, 8, -1);
86
+ var n = _sliceInstanceProperty(_context7 = Object.prototype.toString.call(o)).call(_context7, 8, -1);
87
87
  if (n === "Object" && o.constructor) n = o.constructor.name;
88
88
  if (n === "Map" || n === "Set") return _Array$from(o);
89
89
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
@@ -92,7 +92,7 @@ function _arrayLikeToArray(arr, len) {
92
92
  if (len == null || len > arr.length) len = arr.length;
93
93
  for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
94
94
  return arr2;
95
- } /* global WebSocket */
95
+ }
96
96
  // The LiveQuery client inner state
97
97
  var CLIENT_STATE = {
98
98
  INITIALIZED: 'initialized',
@@ -200,6 +200,7 @@ var LiveQueryClient = /*#__PURE__*/function () {
200
200
  * @param {string} options.installationId (optional)
201
201
  */
202
202
  function LiveQueryClient(_ref) {
203
+ var _this = this;
203
204
  var applicationId = _ref.applicationId,
204
205
  serverURL = _ref.serverURL,
205
206
  javascriptKey = _ref.javascriptKey,
@@ -240,8 +241,16 @@ var LiveQueryClient = /*#__PURE__*/function () {
240
241
  this.state = CLIENT_STATE.INITIALIZED;
241
242
  var EventEmitter = _CoreManager.default.getEventEmitter();
242
243
  this.emitter = new EventEmitter();
243
- this.on = this.emitter.on;
244
- this.emit = this.emitter.emit;
244
+ this.on = function (eventName, listener) {
245
+ return _this.emitter.on(eventName, listener);
246
+ };
247
+ this.emit = function (eventName) {
248
+ var _this$emitter, _context;
249
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
250
+ args[_key - 1] = arguments[_key];
251
+ }
252
+ return (_this$emitter = _this.emitter).emit.apply(_this$emitter, (0, _concat.default)(_context = [eventName]).call(_context, args));
253
+ };
245
254
  // adding listener so process does not crash
246
255
  // best practice is for developer to register their own listener
247
256
  this.on('error', function () {});
@@ -271,7 +280,7 @@ var LiveQueryClient = /*#__PURE__*/function () {
271
280
  value: function (query /*: Object*/, sessionToken /*: ?string*/) /*: LiveQuerySubscription*/{
272
281
  var _queryJSON$keys,
273
282
  _queryJSON$watch,
274
- _this = this;
283
+ _this2 = this;
275
284
  if (!query) {
276
285
  return;
277
286
  }
@@ -297,7 +306,7 @@ var LiveQueryClient = /*#__PURE__*/function () {
297
306
  this.subscriptions.set(this.requestId, subscription);
298
307
  this.requestId += 1;
299
308
  this.connectPromise.then(function () {
300
- _this.socket.send((0, _stringify.default)(subscribeRequest));
309
+ _this2.socket.send((0, _stringify.default)(subscribeRequest));
301
310
  }).catch(function (error) {
302
311
  subscription.subscribePromise.reject(error);
303
312
  });
@@ -313,7 +322,7 @@ var LiveQueryClient = /*#__PURE__*/function () {
313
322
  }, {
314
323
  key: "unsubscribe",
315
324
  value: function (subscription /*: Object*/) /*: ?Promise*/{
316
- var _this2 = this;
325
+ var _this3 = this;
317
326
  if (!subscription) {
318
327
  return;
319
328
  }
@@ -322,7 +331,7 @@ var LiveQueryClient = /*#__PURE__*/function () {
322
331
  requestId: subscription.id
323
332
  };
324
333
  return this.connectPromise.then(function () {
325
- return _this2.socket.send((0, _stringify.default)(unsubscribeRequest));
334
+ return _this3.socket.send((0, _stringify.default)(unsubscribeRequest));
326
335
  }).then(function () {
327
336
  return subscription.unsubscribePromise;
328
337
  });
@@ -336,7 +345,7 @@ var LiveQueryClient = /*#__PURE__*/function () {
336
345
  }, {
337
346
  key: "open",
338
347
  value: function () {
339
- var _this3 = this;
348
+ var _this4 = this;
340
349
  var WebSocketImplementation = _CoreManager.default.getWebSocketController();
341
350
  if (!WebSocketImplementation) {
342
351
  this.emit(CLIENT_EMMITER_TYPES.ERROR, 'Can not find WebSocket implementation');
@@ -350,25 +359,25 @@ var LiveQueryClient = /*#__PURE__*/function () {
350
359
 
351
360
  // Bind WebSocket callbacks
352
361
  this.socket.onopen = function () {
353
- _this3._handleWebSocketOpen();
362
+ _this4._handleWebSocketOpen();
354
363
  };
355
364
  this.socket.onmessage = function (event) {
356
- _this3._handleWebSocketMessage(event);
365
+ _this4._handleWebSocketMessage(event);
357
366
  };
358
367
  this.socket.onclose = function (event) {
359
- _this3.socket.closingPromise.resolve(event);
360
- _this3._handleWebSocketClose();
368
+ _this4.socket.closingPromise.resolve(event);
369
+ _this4._handleWebSocketClose();
361
370
  };
362
371
  this.socket.onerror = function (error) {
363
- _this3._handleWebSocketError(error);
372
+ _this4._handleWebSocketError(error);
364
373
  };
365
374
  }
366
375
  }, {
367
376
  key: "resubscribe",
368
377
  value: function () {
369
- var _context,
370
- _this4 = this;
371
- (0, _forEach.default)(_context = this.subscriptions).call(_context, function (subscription, requestId) {
378
+ var _context2,
379
+ _this5 = this;
380
+ (0, _forEach.default)(_context2 = this.subscriptions).call(_context2, function (subscription, requestId) {
372
381
  var query = subscription.query;
373
382
  var queryJSON = query.toJSON();
374
383
  var where = queryJSON.where;
@@ -387,8 +396,8 @@ var LiveQueryClient = /*#__PURE__*/function () {
387
396
  if (sessionToken) {
388
397
  subscribeRequest.sessionToken = sessionToken;
389
398
  }
390
- _this4.connectPromise.then(function () {
391
- _this4.socket.send((0, _stringify.default)(subscribeRequest));
399
+ _this5.connectPromise.then(function () {
400
+ _this5.socket.send((0, _stringify.default)(subscribeRequest));
392
401
  });
393
402
  });
394
403
  }
@@ -402,14 +411,14 @@ var LiveQueryClient = /*#__PURE__*/function () {
402
411
  }, {
403
412
  key: "close",
404
413
  value: function () /*: ?Promise*/{
405
- var _this$socket, _this$socket2, _context2;
414
+ var _this$socket, _this$socket2, _context3;
406
415
  if (this.state === CLIENT_STATE.INITIALIZED || this.state === CLIENT_STATE.DISCONNECTED) {
407
416
  return;
408
417
  }
409
418
  this.state = CLIENT_STATE.DISCONNECTED;
410
419
  (_this$socket = this.socket) === null || _this$socket === void 0 ? void 0 : _this$socket.close();
411
420
  // Notify each subscription about the close
412
- var _iterator = _createForOfIteratorHelper((0, _values.default)(_context2 = this.subscriptions).call(_context2)),
421
+ var _iterator = _createForOfIteratorHelper((0, _values.default)(_context3 = this.subscriptions).call(_context3)),
413
422
  _step;
414
423
  try {
415
424
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
@@ -556,14 +565,14 @@ var LiveQueryClient = /*#__PURE__*/function () {
556
565
  }, {
557
566
  key: "_handleWebSocketClose",
558
567
  value: function () {
559
- var _context3;
568
+ var _context4;
560
569
  if (this.state === CLIENT_STATE.DISCONNECTED) {
561
570
  return;
562
571
  }
563
572
  this.state = CLIENT_STATE.CLOSED;
564
573
  this.emit(CLIENT_EMMITER_TYPES.CLOSE);
565
574
  // Notify each subscription about the close
566
- var _iterator2 = _createForOfIteratorHelper((0, _values.default)(_context3 = this.subscriptions).call(_context3)),
575
+ var _iterator2 = _createForOfIteratorHelper((0, _values.default)(_context4 = this.subscriptions).call(_context4)),
567
576
  _step2;
568
577
  try {
569
578
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
@@ -580,9 +589,9 @@ var LiveQueryClient = /*#__PURE__*/function () {
580
589
  }, {
581
590
  key: "_handleWebSocketError",
582
591
  value: function (error /*: any*/) {
583
- var _context4;
592
+ var _context5;
584
593
  this.emit(CLIENT_EMMITER_TYPES.ERROR, error);
585
- var _iterator3 = _createForOfIteratorHelper((0, _values.default)(_context4 = this.subscriptions).call(_context4)),
594
+ var _iterator3 = _createForOfIteratorHelper((0, _values.default)(_context5 = this.subscriptions).call(_context5)),
586
595
  _step3;
587
596
  try {
588
597
  for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
@@ -599,8 +608,8 @@ var LiveQueryClient = /*#__PURE__*/function () {
599
608
  }, {
600
609
  key: "_handleReconnect",
601
610
  value: function () {
602
- var _context5,
603
- _this5 = this;
611
+ var _context6,
612
+ _this6 = this;
604
613
  // if closed or currently reconnecting we stop attempting to reconnect
605
614
  if (this.state === CLIENT_STATE.DISCONNECTED) {
606
615
  return;
@@ -616,15 +625,14 @@ var LiveQueryClient = /*#__PURE__*/function () {
616
625
  if (this.reconnectHandle) {
617
626
  clearTimeout(this.reconnectHandle);
618
627
  }
619
- this.reconnectHandle = (0, _setTimeout2.default)((0, _bind.default)(_context5 = function () {
620
- _this5.attempts++;
621
- _this5.connectPromise = (0, _promiseUtils.resolvingPromise)();
622
- _this5.open();
623
- }).call(_context5, this), time);
628
+ this.reconnectHandle = (0, _setTimeout2.default)((0, _bind.default)(_context6 = function () {
629
+ _this6.attempts++;
630
+ _this6.connectPromise = (0, _promiseUtils.resolvingPromise)();
631
+ _this6.open();
632
+ }).call(_context6, this), time);
624
633
  }
625
634
  }]);
626
635
  return LiveQueryClient;
627
636
  }();
628
- _CoreManager.default.setWebSocketController(require('./Socket.weapp'));
629
637
  var _default = LiveQueryClient;
630
638
  exports.default = _default;