parse 5.1.1-alpha.1 → 5.2.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/dist/parse.js +1411 -1216
  2. package/dist/parse.min.js +2 -2
  3. package/dist/parse.weapp.js +1414 -1219
  4. package/dist/parse.weapp.min.js +2 -2
  5. package/lib/browser/Cloud.js +7 -11
  6. package/lib/browser/CoreManager.js +1 -1
  7. package/lib/browser/EventuallyQueue.js +1 -1
  8. package/lib/browser/InstallationController.js +3 -3
  9. package/lib/browser/LiveQueryClient.js +102 -60
  10. package/lib/browser/LocalDatastore.js +189 -147
  11. package/lib/browser/LocalDatastoreController.default.js +14 -9
  12. package/lib/browser/LocalDatastoreController.react-native.js +14 -12
  13. package/lib/browser/LocalDatastoreUtils.js +0 -5
  14. package/lib/browser/ObjectStateMutations.js +57 -21
  15. package/lib/browser/Parse.js +2 -2
  16. package/lib/browser/ParseCLP.js +9 -17
  17. package/lib/browser/ParseFile.js +27 -31
  18. package/lib/browser/ParseGeoPoint.js +9 -3
  19. package/lib/browser/ParseHooks.js +13 -13
  20. package/lib/browser/ParseInstallation.js +14 -0
  21. package/lib/browser/ParseObject.js +15 -13
  22. package/lib/browser/ParseOp.js +17 -17
  23. package/lib/browser/ParsePolygon.js +1 -1
  24. package/lib/browser/ParseQuery.js +147 -149
  25. package/lib/browser/ParseRole.js +5 -9
  26. package/lib/browser/ParseSchema.js +1 -1
  27. package/lib/browser/ParseUser.js +66 -51
  28. package/lib/browser/Push.js +5 -10
  29. package/lib/browser/RESTController.js +1 -1
  30. package/lib/browser/SingleInstanceStateController.js +1 -1
  31. package/lib/browser/TaskQueue.js +10 -10
  32. package/lib/browser/UniqueInstanceStateController.js +1 -1
  33. package/lib/node/Cloud.js +7 -11
  34. package/lib/node/CoreManager.js +1 -1
  35. package/lib/node/EventuallyQueue.js +1 -1
  36. package/lib/node/InstallationController.js +3 -3
  37. package/lib/node/LiveQueryClient.js +14 -24
  38. package/lib/node/LocalDatastore.js +7 -11
  39. package/lib/node/LocalDatastoreController.default.js +12 -10
  40. package/lib/node/LocalDatastoreController.react-native.js +13 -12
  41. package/lib/node/LocalDatastoreUtils.js +0 -5
  42. package/lib/node/ObjectStateMutations.js +45 -19
  43. package/lib/node/Parse.js +2 -2
  44. package/lib/node/ParseCLP.js +8 -18
  45. package/lib/node/ParseFile.js +27 -40
  46. package/lib/node/ParseGeoPoint.js +9 -3
  47. package/lib/node/ParseHooks.js +13 -13
  48. package/lib/node/ParseInstallation.js +14 -0
  49. package/lib/node/ParseObject.js +15 -13
  50. package/lib/node/ParseOp.js +21 -21
  51. package/lib/node/ParsePolygon.js +1 -1
  52. package/lib/node/ParseQuery.js +84 -107
  53. package/lib/node/ParseRole.js +3 -8
  54. package/lib/node/ParseSchema.js +4 -4
  55. package/lib/node/ParseUser.js +42 -37
  56. package/lib/node/Push.js +3 -8
  57. package/lib/node/RESTController.js +1 -1
  58. package/lib/node/SingleInstanceStateController.js +1 -1
  59. package/lib/node/TaskQueue.js +9 -11
  60. package/lib/node/UniqueInstanceStateController.js +1 -1
  61. package/lib/react-native/Cloud.js +0 -1
  62. package/lib/react-native/CoreManager.js +1 -1
  63. package/lib/react-native/LiveQueryClient.js +49 -32
  64. package/lib/react-native/LocalDatastore.js +38 -14
  65. package/lib/react-native/LocalDatastoreController.default.js +7 -1
  66. package/lib/react-native/LocalDatastoreController.react-native.js +7 -1
  67. package/lib/react-native/ObjectStateMutations.js +30 -9
  68. package/lib/react-native/ParseCLP.js +3 -3
  69. package/lib/react-native/ParseFile.js +7 -6
  70. package/lib/react-native/ParseObject.js +4 -3
  71. package/lib/react-native/ParseQuery.js +45 -37
  72. package/lib/react-native/ParseRole.js +1 -1
  73. package/lib/react-native/ParseUser.js +22 -16
  74. package/lib/react-native/TaskQueue.js +8 -2
  75. package/lib/weapp/Cloud.js +7 -11
  76. package/lib/weapp/CoreManager.js +1 -1
  77. package/lib/weapp/EventuallyQueue.js +1 -1
  78. package/lib/weapp/InstallationController.js +3 -3
  79. package/lib/weapp/LiveQueryClient.js +102 -60
  80. package/lib/weapp/LocalDatastore.js +189 -147
  81. package/lib/weapp/LocalDatastoreController.default.js +14 -9
  82. package/lib/weapp/LocalDatastoreController.react-native.js +14 -12
  83. package/lib/weapp/LocalDatastoreUtils.js +0 -5
  84. package/lib/weapp/ObjectStateMutations.js +57 -21
  85. package/lib/weapp/Parse.js +2 -2
  86. package/lib/weapp/ParseCLP.js +9 -17
  87. package/lib/weapp/ParseFile.js +27 -31
  88. package/lib/weapp/ParseGeoPoint.js +9 -3
  89. package/lib/weapp/ParseHooks.js +13 -13
  90. package/lib/weapp/ParseInstallation.js +14 -0
  91. package/lib/weapp/ParseObject.js +15 -13
  92. package/lib/weapp/ParseOp.js +17 -17
  93. package/lib/weapp/ParsePolygon.js +1 -1
  94. package/lib/weapp/ParseQuery.js +147 -149
  95. package/lib/weapp/ParseRole.js +5 -9
  96. package/lib/weapp/ParseSchema.js +1 -1
  97. package/lib/weapp/ParseUser.js +66 -51
  98. package/lib/weapp/Push.js +5 -10
  99. package/lib/weapp/RESTController.js +1 -1
  100. package/lib/weapp/SingleInstanceStateController.js +1 -1
  101. package/lib/weapp/TaskQueue.js +10 -10
  102. package/lib/weapp/UniqueInstanceStateController.js +1 -1
  103. package/package.json +5 -6
@@ -111,20 +111,6 @@ const generateInterval = k => {
111
111
  * @alias Parse.LiveQueryClient
112
112
  */
113
113
  class LiveQueryClient {
114
- /*:: attempts: number;*/
115
- /*:: id: number;*/
116
- /*:: requestId: number;*/
117
- /*:: applicationId: string;*/
118
- /*:: serverURL: string;*/
119
- /*:: javascriptKey: ?string;*/
120
- /*:: masterKey: ?string;*/
121
- /*:: sessionToken: ?string;*/
122
- /*:: installationId: ?string;*/
123
- /*:: additionalProperties: boolean;*/
124
- /*:: connectPromise: Promise;*/
125
- /*:: subscriptions: Map;*/
126
- /*:: socket: any;*/
127
- /*:: state: string;*/
128
114
  /**
129
115
  * @param {object} options
130
116
  * @param {string} options.applicationId - applicationId of your Parse app
@@ -181,11 +167,11 @@ class LiveQueryClient {
181
167
  * <a href="https://github.com/parse-community/parse-server/wiki/Parse-LiveQuery-Protocol-Specification">here</a> for more details. The subscription you get is the same subscription you get
182
168
  * from our Standard API.
183
169
  *
184
- * @param {object} query - the ParseQuery you want to subscribe to
170
+ * @param {ParseQuery} query - the ParseQuery you want to subscribe to
185
171
  * @param {string} sessionToken (optional)
186
172
  * @returns {LiveQuerySubscription | undefined}
187
173
  */
188
- subscribe(query /*: Object*/, sessionToken /*: ?string*/) /*: LiveQuerySubscription*/{
174
+ subscribe(query /*: ParseQuery*/, sessionToken /*:: ?: string*/) /*: LiveQuerySubscription | undefined*/{
189
175
  var _queryJSON$keys, _queryJSON$watch;
190
176
  if (!query) {
191
177
  return;
@@ -203,7 +189,8 @@ class LiveQueryClient {
203
189
  where,
204
190
  keys,
205
191
  watch
206
- }
192
+ },
193
+ sessionToken: undefined
207
194
  };
208
195
  if (sessionToken) {
209
196
  subscribeRequest.sessionToken = sessionToken;
@@ -225,7 +212,7 @@ class LiveQueryClient {
225
212
  * @param {object} subscription - subscription you would like to unsubscribe from.
226
213
  * @returns {Promise | undefined}
227
214
  */
228
- unsubscribe(subscription /*: Object*/) /*: ?Promise*/{
215
+ async unsubscribe(subscription /*: LiveQuerySubscription*/) /*: Promise<void>*/{
229
216
  if (!subscription) {
230
217
  return;
231
218
  }
@@ -265,7 +252,8 @@ class LiveQueryClient {
265
252
  this._handleWebSocketMessage(event);
266
253
  };
267
254
  this.socket.onclose = event => {
268
- this.socket.closingPromise.resolve(event);
255
+ var _this$socket$closingP;
256
+ (_this$socket$closingP = this.socket.closingPromise) === null || _this$socket$closingP === void 0 ? void 0 : _this$socket$closingP.resolve(event);
269
257
  this._handleWebSocketClose();
270
258
  };
271
259
  this.socket.onerror = error => {
@@ -287,7 +275,8 @@ class LiveQueryClient {
287
275
  className,
288
276
  where,
289
277
  fields
290
- }
278
+ },
279
+ sessionToken: undefined
291
280
  };
292
281
  if (sessionToken) {
293
282
  subscribeRequest.sessionToken = sessionToken;
@@ -304,7 +293,7 @@ class LiveQueryClient {
304
293
  *
305
294
  * @returns {Promise | undefined} CloseEvent {@link https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close_event}
306
295
  */
307
- close() /*: ?Promise*/{
296
+ async close() /*: Promise<void>*/{
308
297
  var _this$socket, _this$socket2;
309
298
  if (this.state === CLIENT_STATE.INITIALIZED || this.state === CLIENT_STATE.DISCONNECTED) {
310
299
  return;
@@ -336,7 +325,8 @@ class LiveQueryClient {
336
325
  applicationId: this.applicationId,
337
326
  javascriptKey: this.javascriptKey,
338
327
  masterKey: this.masterKey,
339
- sessionToken: this.sessionToken
328
+ sessionToken: this.sessionToken,
329
+ installationId: undefined
340
330
  };
341
331
  if (this.additionalProperties) {
342
332
  connectRequest.installationId = this.installationId;
@@ -348,9 +338,9 @@ class LiveQueryClient {
348
338
  if (typeof data === 'string') {
349
339
  data = JSON.parse(data);
350
340
  }
351
- let subscription = null;
341
+ let subscription /*: null | LiveQuerySubscription*/ = null;
352
342
  if (data.requestId) {
353
- subscription = this.subscriptions.get(data.requestId);
343
+ subscription = this.subscriptions.get(data.requestId) || null;
354
344
  }
355
345
  const response = {
356
346
  clientId: data.clientId,
@@ -12,10 +12,6 @@ function _interopRequireDefault(obj) {
12
12
  default: obj
13
13
  };
14
14
  }
15
- /**
16
- * @flow
17
- */
18
- /*:: import type ParseObject from './ParseObject';*/
19
15
  /**
20
16
  * Provides a local datastore which can be used to store and retrieve <code>Parse.Object</code>. <br />
21
17
  * To enable this functionality, call <code>Parse.enableLocalDatastore()</code>.
@@ -39,28 +35,28 @@ function _interopRequireDefault(obj) {
39
35
  const LocalDatastore = {
40
36
  isEnabled: false,
41
37
  isSyncing: false,
42
- fromPinWithName(name /*: string*/) /*: Promise<Array<Object>>*/{
38
+ fromPinWithName(name /*: string*/) /*: Promise<Array<any>>*/{
43
39
  const controller = _CoreManager.default.getLocalDatastoreController();
44
40
  return controller.fromPinWithName(name);
45
41
  },
46
- pinWithName(name /*: string*/, value /*: any*/) /*: Promise<void>*/{
42
+ async pinWithName(name /*: string*/, value /*: any*/) /*: Promise<void>*/{
47
43
  const controller = _CoreManager.default.getLocalDatastoreController();
48
44
  return controller.pinWithName(name, value);
49
45
  },
50
- unPinWithName(name /*: string*/) /*: Promise<void>*/{
46
+ async unPinWithName(name /*: string*/) /*: Promise<void>*/{
51
47
  const controller = _CoreManager.default.getLocalDatastoreController();
52
48
  return controller.unPinWithName(name);
53
49
  },
54
- _getAllContents() /*: Promise<Object>*/{
50
+ _getAllContents() /*: Promise<any>*/{
55
51
  const controller = _CoreManager.default.getLocalDatastoreController();
56
52
  return controller.getAllContents();
57
53
  },
58
54
  // Use for testing
59
- _getRawStorage() /*: Promise<Object>*/{
55
+ async _getRawStorage() /*: Promise<any>*/{
60
56
  const controller = _CoreManager.default.getLocalDatastoreController();
61
57
  return controller.getRawStorage();
62
58
  },
63
- _clear() /*: Promise<void>*/{
59
+ async _clear() /*: Promise<void>*/{
64
60
  const controller = _CoreManager.default.getLocalDatastoreController();
65
61
  return controller.clear();
66
62
  },
@@ -360,7 +356,7 @@ const LocalDatastore = {
360
356
  const objectId = object.objectId || object._getId();
361
357
  return `${_LocalDatastoreUtils.OBJECT_PREFIX}${object.className}_${objectId}`;
362
358
  },
363
- getPinName(pinName /*: ?string*/) {
359
+ getPinName(pinName /*:: ?: string*/) {
364
360
  if (!pinName || pinName === _LocalDatastoreUtils.DEFAULT_PIN) {
365
361
  return _LocalDatastoreUtils.DEFAULT_PIN;
366
362
  }
@@ -1,5 +1,9 @@
1
1
  "use strict";
2
2
 
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
3
7
  var _LocalDatastoreUtils = require("./LocalDatastoreUtils");
4
8
  var _Storage = _interopRequireDefault(require("./Storage"));
5
9
  function _interopRequireDefault(obj) {
@@ -7,12 +11,8 @@ function _interopRequireDefault(obj) {
7
11
  default: obj
8
12
  };
9
13
  }
10
- /**
11
- * @flow
12
- */
13
-
14
14
  const LocalDatastoreController = {
15
- async fromPinWithName(name /*: string*/) /*: Array<Object>*/{
15
+ async fromPinWithName(name /*: string*/) /*: Promise<Array<any>>*/{
16
16
  const values = await _Storage.default.getItemAsync(name);
17
17
  if (!values) {
18
18
  return [];
@@ -27,7 +27,7 @@ const LocalDatastoreController = {
27
27
  unPinWithName(name /*: string*/) {
28
28
  return _Storage.default.removeItemAsync(name);
29
29
  },
30
- async getAllContents() /*: Object*/{
30
+ async getAllContents() /*: Promise<any>*/{
31
31
  const keys = await _Storage.default.getAllKeysAsync();
32
32
  return keys.reduce(async (previousPromise, key) => {
33
33
  const LDS = await previousPromise;
@@ -43,7 +43,7 @@ const LocalDatastoreController = {
43
43
  }, Promise.resolve({}));
44
44
  },
45
45
  // Used for testing
46
- async getRawStorage() /*: Object*/{
46
+ async getRawStorage() /*: Promise<any>*/{
47
47
  const keys = await _Storage.default.getAllKeysAsync();
48
48
  return keys.reduce(async (previousPromise, key) => {
49
49
  const LDS = await previousPromise;
@@ -52,9 +52,9 @@ const LocalDatastoreController = {
52
52
  return LDS;
53
53
  }, Promise.resolve({}));
54
54
  },
55
- async clear() /*: Promise*/{
55
+ async clear() /*: Promise<any>*/{
56
56
  const keys = await _Storage.default.getAllKeysAsync();
57
- const toRemove = [];
57
+ const toRemove /*: string[]*/ = [];
58
58
  for (const key of keys) {
59
59
  if ((0, _LocalDatastoreUtils.isLocalDatastoreKey)(key)) {
60
60
  toRemove.push(key);
@@ -64,4 +64,6 @@ const LocalDatastoreController = {
64
64
  return Promise.all(promises);
65
65
  }
66
66
  };
67
- module.exports = LocalDatastoreController;
67
+ module.exports = LocalDatastoreController;
68
+ var _default = LocalDatastoreController;
69
+ exports.default = _default;
@@ -1,14 +1,13 @@
1
1
  "use strict";
2
2
 
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
3
7
  var _LocalDatastoreUtils = require("./LocalDatastoreUtils");
4
- /**
5
- * @flow
6
- * @private
7
- */
8
-
9
8
  const RNStorage = require('./StorageController.react-native');
10
9
  const LocalDatastoreController = {
11
- async fromPinWithName(name /*: string*/) /*: Promise<Array<Object>>*/{
10
+ async fromPinWithName(name /*: string*/) /*: Promise<Array<any>>*/{
12
11
  const values = await RNStorage.getItemAsync(name);
13
12
  if (!values) {
14
13
  return [];
@@ -28,9 +27,9 @@ const LocalDatastoreController = {
28
27
  unPinWithName(name /*: string*/) /*: Promise<void>*/{
29
28
  return RNStorage.removeItemAsync(name);
30
29
  },
31
- async getAllContents() /*: Promise<Object>*/{
30
+ async getAllContents() /*: Promise<any>*/{
32
31
  const keys = await RNStorage.getAllKeysAsync();
33
- const batch = [];
32
+ const batch /*: string[]*/ = [];
34
33
  for (let i = 0; i < keys.length; i += 1) {
35
34
  const key = keys[i];
36
35
  if ((0, _LocalDatastoreUtils.isLocalDatastoreKey)(key)) {
@@ -38,7 +37,7 @@ const LocalDatastoreController = {
38
37
  }
39
38
  }
40
39
  const LDS = {};
41
- let results = [];
40
+ let results /*: any[]*/ = [];
42
41
  try {
43
42
  results = await RNStorage.multiGet(batch);
44
43
  } catch (error) {
@@ -56,7 +55,7 @@ const LocalDatastoreController = {
56
55
  return LDS;
57
56
  },
58
57
  // Used for testing
59
- async getRawStorage() /*: Promise<Object>*/{
58
+ async getRawStorage() /*: Promise<any>*/{
60
59
  const keys = await RNStorage.getAllKeysAsync();
61
60
  const storage = {};
62
61
  const results = await RNStorage.multiGet(keys);
@@ -68,7 +67,7 @@ const LocalDatastoreController = {
68
67
  },
69
68
  async clear() /*: Promise<void>*/{
70
69
  const keys = await RNStorage.getAllKeysAsync();
71
- const batch = [];
70
+ const batch /*: string[]*/ = [];
72
71
  for (let i = 0; i < keys.length; i += 1) {
73
72
  const key = keys[i];
74
73
  if ((0, _LocalDatastoreUtils.isLocalDatastoreKey)(key)) {
@@ -78,4 +77,6 @@ const LocalDatastoreController = {
78
77
  return RNStorage.multiRemove(batch).catch(error => console.error('Error clearing local datastore: ', error));
79
78
  }
80
79
  };
81
- module.exports = LocalDatastoreController;
80
+ module.exports = LocalDatastoreController;
81
+ var _default = LocalDatastoreController;
82
+ exports.default = _default;
@@ -5,11 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.PIN_PREFIX = exports.OBJECT_PREFIX = exports.DEFAULT_PIN = void 0;
7
7
  exports.isLocalDatastoreKey = isLocalDatastoreKey;
8
- /**
9
- * @flow
10
- * @private
11
- */
12
-
13
8
  const DEFAULT_PIN = '_default';
14
9
  exports.DEFAULT_PIN = DEFAULT_PIN;
15
10
  const PIN_PREFIX = 'parsePin_';
@@ -23,10 +23,6 @@ function _interopRequireDefault(obj) {
23
23
  default: obj
24
24
  };
25
25
  }
26
- /**
27
- * @flow
28
- */
29
- /*:: import type { Op } from './ParseOp';*/
30
26
  /*:: export type AttributeMap = { [attr: string]: any };*/
31
27
  /*:: export type OpsMap = { [attr: string]: Op };*/
32
28
  /*:: export type ObjectCache = { [attr: string]: string };*/
@@ -55,7 +51,7 @@ function setServerData(serverData /*: AttributeMap*/, attributes /*: AttributeMa
55
51
  }
56
52
  }
57
53
  }
58
- function setPendingOp(pendingOps /*: Array<OpsMap>*/, attr /*: string*/, op /*: ?Op*/) {
54
+ function setPendingOp(pendingOps /*: Array<OpsMap>*/, attr /*: string*/, op /*:: ?: Op*/) {
59
55
  const last = pendingOps.length - 1;
60
56
  if (op) {
61
57
  pendingOps[last][attr] = op;
@@ -87,7 +83,7 @@ function mergeFirstPendingState(pendingOps /*: Array<OpsMap>*/) {
87
83
  }
88
84
  }
89
85
  }
90
- function estimateAttribute(serverData /*: AttributeMap*/, pendingOps /*: Array<OpsMap>*/, object /*: ParseObject*/, attr /*: string*/) /*: mixed*/{
86
+ function estimateAttribute(serverData /*: AttributeMap*/, pendingOps /*: Array<OpsMap>*/, object /*: ParseObject*/, attr /*: string*/) /*: any*/{
91
87
  let value = serverData[attr];
92
88
  for (let i = 0; i < pendingOps.length; i++) {
93
89
  if (pendingOps[i][attr]) {
@@ -115,18 +111,27 @@ function estimateAttributes(serverData /*: AttributeMap*/, pendingOps /*: Array<
115
111
  }
116
112
  } else {
117
113
  if (attr.includes('.')) {
118
- // convert a.b.c into { a: { b: { c: value } } }
114
+ // similar to nestedSet function
119
115
  const fields = attr.split('.');
120
116
  const last = fields[fields.length - 1];
121
117
  let object = data;
122
118
  for (let i = 0; i < fields.length - 1; i++) {
123
119
  const key = fields[i];
124
120
  if (!(key in object)) {
125
- object[key] = {};
121
+ const nextKey = fields[i + 1];
122
+ if (!isNaN(nextKey)) {
123
+ object[key] = [];
124
+ } else {
125
+ object[key] = {};
126
+ }
126
127
  } else {
127
- object[key] = {
128
- ...object[key]
129
- };
128
+ if (Array.isArray(object[key])) {
129
+ object[key] = [...object[key]];
130
+ } else {
131
+ object[key] = {
132
+ ...object[key]
133
+ };
134
+ }
130
135
  }
131
136
  object = object[key];
132
137
  }
@@ -139,24 +144,45 @@ function estimateAttributes(serverData /*: AttributeMap*/, pendingOps /*: Array<
139
144
  }
140
145
  return data;
141
146
  }
147
+
148
+ /**
149
+ * Allows setting properties/variables deep in an object.
150
+ * Converts a.b into { a: { b: value } } for dot notation on Objects
151
+ * Converts a.0.b into { a: [{ b: value }] } for dot notation on Arrays
152
+ *
153
+ * @param obj The object to assign the value to
154
+ * @param key The key to assign. If it's in a deeper path, then use dot notation (`prop1.prop2.prop3`)
155
+ * Note that intermediate object(s) in the nested path are automatically created if they don't exist.
156
+ * @param value The value to assign. If it's an `undefined` then the key is deleted.
157
+ */
142
158
  function nestedSet(obj, key, value) {
143
- const path = key.split('.');
144
- for (let i = 0; i < path.length - 1; i++) {
145
- if (!(path[i] in obj)) {
146
- obj[path[i]] = {};
159
+ const paths = key.split('.');
160
+ for (let i = 0; i < paths.length - 1; i++) {
161
+ const path = paths[i];
162
+ if (!(path in obj)) {
163
+ const nextPath = paths[i + 1];
164
+ if (!isNaN(nextPath)) {
165
+ obj[path] = [];
166
+ } else {
167
+ obj[path] = {};
168
+ }
147
169
  }
148
- obj = obj[path[i]];
170
+ obj = obj[path];
149
171
  }
150
172
  if (typeof value === 'undefined') {
151
- delete obj[path[path.length - 1]];
173
+ delete obj[paths[paths.length - 1]];
152
174
  } else {
153
- obj[path[path.length - 1]] = value;
175
+ obj[paths[paths.length - 1]] = value;
154
176
  }
155
177
  }
156
178
  function commitServerChanges(serverData /*: AttributeMap*/, objectCache /*: ObjectCache*/, changes /*: AttributeMap*/) {
157
179
  const ParseObject = _CoreManager.default.getParseObject();
158
180
  for (const attr in changes) {
159
- const val = changes[attr];
181
+ let val = changes[attr];
182
+ // Check for JSON array { '0': { something }, '1': { something } }
183
+ if (val && typeof val === 'object' && !Array.isArray(val) && Object.keys(val).length > 0 && Object.keys(val).some(k => !isNaN(parseInt(k)))) {
184
+ val = Object.values(val);
185
+ }
160
186
  nestedSet(serverData, attr, val);
161
187
  if (val && typeof val === 'object' && !(val instanceof ParseObject) && !(val instanceof _ParseFile.default) && !(val instanceof _ParseRelation.default)) {
162
188
  const json = (0, _encode.default)(val, false, true);
package/lib/node/Parse.js CHANGED
@@ -92,7 +92,7 @@ function _interopRequireDefault(obj) {
92
92
  * @global
93
93
  * @class
94
94
  * @hideconstructor
95
- */
95
+ */
96
96
 
97
97
  const Parse /*: ParseType*/ = {
98
98
  ACL: _ParseACL.default,
@@ -340,7 +340,7 @@ const Parse /*: ParseType*/ = {
340
340
  * @param [ms] Milliseconds to ping the server. Default 2000ms
341
341
  * @static
342
342
  */
343
- enableLocalDatastore(polling = true, ms /*: number*/ = 2000) {
343
+ enableLocalDatastore(polling = true, ms = 2000) {
344
344
  if (!this.applicationId) {
345
345
  console.log("'enableLocalDataStore' must be called after 'initialize'");
346
346
  return;
@@ -11,16 +11,9 @@ function _interopRequireDefault(obj) {
11
11
  default: obj
12
12
  };
13
13
  }
14
- /**
15
- * @flow
16
- */
17
- /*:: type Entity = Entity;*/
18
- /*:: type UsersMap = { [userId: string]: boolean | any };*/
19
- /*:: export type PermissionsMap = { [permission: string]: UsersMap };*/
14
+ /*:: export type PermissionsMap = { writeUserFields?: string[], readUserFields?: string[] } & { [permission: string]: UsersMap };*/
20
15
  const PUBLIC_KEY = '*';
21
- const VALID_PERMISSIONS /*: Map<string, UsersMap>*/ = new Map(
22
- /*:: <string, UsersMap>*/
23
- );
16
+ const VALID_PERMISSIONS /*: Map<string, UsersMap>*/ = new Map();
24
17
  VALID_PERMISSIONS.set('get', {});
25
18
  VALID_PERMISSIONS.set('find', {});
26
19
  VALID_PERMISSIONS.set('count', {});
@@ -28,9 +21,7 @@ VALID_PERMISSIONS.set('create', {});
28
21
  VALID_PERMISSIONS.set('update', {});
29
22
  VALID_PERMISSIONS.set('delete', {});
30
23
  VALID_PERMISSIONS.set('addField', {});
31
- const VALID_PERMISSIONS_EXTENDED /*: Map<string, UsersMap>*/ = new Map(
32
- /*:: <string, UsersMap>*/
33
- );
24
+ const VALID_PERMISSIONS_EXTENDED /*: Map<string, UsersMap>*/ = new Map();
34
25
  VALID_PERMISSIONS_EXTENDED.set('protectedFields', {});
35
26
 
36
27
  /**
@@ -126,7 +117,6 @@ VALID_PERMISSIONS_EXTENDED.set('protectedFields', {});
126
117
  * @alias Parse.CLP
127
118
  */
128
119
  class ParseCLP {
129
- /*:: permissionsMap: PermissionsMap;*/
130
120
  /**
131
121
  * @param {(Parse.User | Parse.Role | object)} userId The user to initialize the CLP for
132
122
  */
@@ -312,7 +302,7 @@ class ParseCLP {
312
302
  }
313
303
  return permissions;
314
304
  }
315
- _setArrayAccess(permission /*: string*/, userId /*: Entity*/, fields /*: string*/) {
305
+ _setArrayAccess(permission /*: string*/, userId /*: Entity*/, fields /*: string[]*/) {
316
306
  userId = this._parseEntity(userId);
317
307
  const permissions = this.permissionsMap[permission][userId];
318
308
  if (!permissions) {
@@ -339,8 +329,8 @@ class ParseCLP {
339
329
  throw new TypeError(`${operation}.pointerFields must be an array of strings or undefined.`);
340
330
  }
341
331
  }
342
- _getGroupPointerPermissions(operation /*: string*/) /*: string[]*/{
343
- return this.permissionsMap[operation];
332
+ _getGroupPointerPermissions(operation /*: 'readUserFields' | 'writeUserFields'*/) /*: string[]*/{
333
+ return this.permissionsMap[operation] || [];
344
334
  }
345
335
 
346
336
  /**
@@ -356,7 +346,7 @@ class ParseCLP {
356
346
  * @returns {string[]} User pointer fields
357
347
  */
358
348
  getReadUserFields() /*: string[]*/{
359
- return this._getGroupPointerPermissions('readUserFields');
349
+ return this._getGroupPointerPermissions('readUserFields') || [];
360
350
  }
361
351
 
362
352
  /**
@@ -372,7 +362,7 @@ class ParseCLP {
372
362
  * @returns {string[]} User pointer fields
373
363
  */
374
364
  getWriteUserFields() /*: string[]*/{
375
- return this._getGroupPointerPermissions('writeUserFields');
365
+ return this._getGroupPointerPermissions('writeUserFields') || [];
376
366
  }
377
367
 
378
368
  /**