parse 5.2.0-alpha.1 → 5.2.0-alpha.3

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 (247) hide show
  1. package/dist/parse.js +10519 -15246
  2. package/dist/parse.min.js +2 -2
  3. package/dist/parse.weapp.js +10499 -15371
  4. package/dist/parse.weapp.min.js +2 -2
  5. package/lib/browser/Analytics.js +7 -11
  6. package/lib/browser/AnonymousUtils.js +17 -22
  7. package/lib/browser/Cloud.js +23 -41
  8. package/lib/browser/CoreManager.js +71 -79
  9. package/lib/browser/CryptoController.js +14 -9
  10. package/lib/browser/EventEmitter.js +9 -2
  11. package/lib/browser/EventuallyQueue.js +156 -357
  12. package/lib/browser/FacebookUtils.js +23 -28
  13. package/lib/browser/IndexedDBStorageController.js +18 -14
  14. package/lib/browser/InstallationController.js +55 -121
  15. package/lib/browser/LiveQueryClient.js +312 -485
  16. package/lib/browser/LiveQuerySubscription.js +25 -28
  17. package/lib/browser/LocalDatastore.js +258 -624
  18. package/lib/browser/LocalDatastoreController.default.js +42 -226
  19. package/lib/browser/LocalDatastoreController.js +11 -1
  20. package/lib/browser/LocalDatastoreController.react-native.js +66 -160
  21. package/lib/browser/LocalDatastoreUtils.js +4 -7
  22. package/lib/browser/ObjectStateMutations.js +54 -96
  23. package/lib/browser/OfflineQuery.js +106 -198
  24. package/lib/browser/Parse.js +44 -60
  25. package/lib/browser/ParseACL.js +242 -288
  26. package/lib/browser/ParseCLP.js +372 -572
  27. package/lib/browser/ParseConfig.js +115 -138
  28. package/lib/browser/ParseError.js +85 -182
  29. package/lib/browser/ParseFile.js +294 -438
  30. package/lib/browser/ParseGeoPoint.js +121 -146
  31. package/lib/browser/ParseHooks.js +23 -25
  32. package/lib/browser/ParseInstallation.js +225 -367
  33. package/lib/browser/ParseLiveQuery.js +74 -148
  34. package/lib/browser/ParseObject.js +2014 -2621
  35. package/lib/browser/ParseOp.js +343 -484
  36. package/lib/browser/ParsePolygon.js +101 -120
  37. package/lib/browser/ParseQuery.js +1708 -2052
  38. package/lib/browser/ParseRelation.js +99 -118
  39. package/lib/browser/ParseRole.js +88 -140
  40. package/lib/browser/ParseSchema.js +372 -434
  41. package/lib/browser/ParseSession.js +62 -110
  42. package/lib/browser/ParseUser.js +941 -1284
  43. package/lib/browser/Push.js +15 -38
  44. package/lib/browser/RESTController.js +85 -124
  45. package/lib/browser/SingleInstanceStateController.js +57 -86
  46. package/lib/browser/Socket.weapp.js +50 -33
  47. package/lib/browser/Storage.js +23 -28
  48. package/lib/browser/StorageController.browser.js +16 -13
  49. package/lib/browser/StorageController.default.js +15 -14
  50. package/lib/browser/StorageController.js +14 -1
  51. package/lib/browser/StorageController.react-native.js +31 -30
  52. package/lib/browser/StorageController.weapp.js +19 -13
  53. package/lib/browser/TaskQueue.js +31 -43
  54. package/lib/browser/UniqueInstanceStateController.js +65 -86
  55. package/lib/browser/WebSocketController.js +11 -4
  56. package/lib/browser/Xhr.weapp.js +90 -78
  57. package/lib/browser/arrayContainsObject.js +3 -3
  58. package/lib/browser/canBeSerialized.js +10 -11
  59. package/lib/browser/decode.js +11 -11
  60. package/lib/browser/encode.js +11 -11
  61. package/lib/browser/equals.js +9 -10
  62. package/lib/browser/escape.js +2 -2
  63. package/lib/browser/isRevocableSession.js +1 -1
  64. package/lib/browser/parseDate.js +10 -10
  65. package/lib/browser/promiseUtils.js +19 -19
  66. package/lib/browser/unique.js +4 -4
  67. package/lib/browser/unsavedChildren.js +20 -21
  68. package/lib/browser/uuid.js +2 -4
  69. package/lib/node/Analytics.js +5 -9
  70. package/lib/node/AnonymousUtils.js +10 -15
  71. package/lib/node/Cloud.js +11 -11
  72. package/lib/node/CoreManager.js +59 -67
  73. package/lib/node/CryptoController.js +8 -3
  74. package/lib/node/EventEmitter.js +7 -1
  75. package/lib/node/EventuallyQueue.js +20 -39
  76. package/lib/node/FacebookUtils.js +4 -8
  77. package/lib/node/IndexedDBStorageController.js +14 -10
  78. package/lib/node/InstallationController.js +12 -13
  79. package/lib/node/LiveQueryClient.js +23 -21
  80. package/lib/node/LiveQuerySubscription.js +6 -7
  81. package/lib/node/LocalDatastore.js +23 -23
  82. package/lib/node/LocalDatastoreController.default.js +11 -12
  83. package/lib/node/LocalDatastoreController.js +14 -1
  84. package/lib/node/LocalDatastoreController.react-native.js +25 -21
  85. package/lib/node/LocalDatastoreUtils.js +4 -7
  86. package/lib/node/ObjectStateMutations.js +12 -22
  87. package/lib/node/OfflineQuery.js +37 -23
  88. package/lib/node/Parse.js +36 -50
  89. package/lib/node/ParseACL.js +21 -30
  90. package/lib/node/ParseCLP.js +38 -40
  91. package/lib/node/ParseConfig.js +10 -17
  92. package/lib/node/ParseError.js +460 -461
  93. package/lib/node/ParseFile.js +27 -47
  94. package/lib/node/ParseGeoPoint.js +16 -17
  95. package/lib/node/ParseHooks.js +16 -18
  96. package/lib/node/ParseInstallation.js +10 -11
  97. package/lib/node/ParseLiveQuery.js +9 -14
  98. package/lib/node/ParseObject.js +142 -173
  99. package/lib/node/ParseOp.js +35 -47
  100. package/lib/node/ParsePolygon.js +14 -20
  101. package/lib/node/ParseQuery.js +100 -123
  102. package/lib/node/ParseRelation.js +10 -19
  103. package/lib/node/ParseRole.js +10 -11
  104. package/lib/node/ParseSchema.js +29 -42
  105. package/lib/node/ParseSession.js +10 -11
  106. package/lib/node/ParseUser.js +76 -87
  107. package/lib/node/Push.js +7 -12
  108. package/lib/node/RESTController.js +24 -36
  109. package/lib/node/SingleInstanceStateController.js +41 -69
  110. package/lib/node/Socket.weapp.js +23 -2
  111. package/lib/node/Storage.js +14 -19
  112. package/lib/node/StorageController.browser.js +10 -8
  113. package/lib/node/StorageController.default.js +9 -9
  114. package/lib/node/StorageController.js +16 -1
  115. package/lib/node/StorageController.react-native.js +20 -20
  116. package/lib/node/StorageController.weapp.js +14 -8
  117. package/lib/node/TaskQueue.js +2 -3
  118. package/lib/node/UniqueInstanceStateController.js +43 -63
  119. package/lib/node/WebSocketController.js +15 -2
  120. package/lib/node/Xhr.weapp.js +11 -2
  121. package/lib/node/arrayContainsObject.js +4 -4
  122. package/lib/node/canBeSerialized.js +5 -5
  123. package/lib/node/decode.js +4 -4
  124. package/lib/node/encode.js +5 -5
  125. package/lib/node/equals.js +4 -4
  126. package/lib/node/escape.js +1 -1
  127. package/lib/node/isRevocableSession.js +1 -1
  128. package/lib/node/parseDate.js +1 -1
  129. package/lib/node/promiseUtils.js +7 -7
  130. package/lib/node/unique.js +5 -5
  131. package/lib/node/unsavedChildren.js +5 -5
  132. package/lib/node/uuid.js +2 -4
  133. package/lib/react-native/Analytics.js +2 -2
  134. package/lib/react-native/AnonymousUtils.js +3 -4
  135. package/lib/react-native/CoreManager.js +2 -3
  136. package/lib/react-native/CryptoController.js +6 -1
  137. package/lib/react-native/EventEmitter.js +6 -1
  138. package/lib/react-native/EventuallyQueue.js +1 -2
  139. package/lib/react-native/FacebookUtils.js +1 -2
  140. package/lib/react-native/IndexedDBStorageController.js +11 -5
  141. package/lib/react-native/InstallationController.js +1 -2
  142. package/lib/react-native/LiveQueryClient.js +8 -7
  143. package/lib/react-native/LiveQuerySubscription.js +2 -4
  144. package/lib/react-native/LocalDatastore.js +3 -3
  145. package/lib/react-native/LocalDatastoreController.default.js +1 -2
  146. package/lib/react-native/LocalDatastoreController.js +11 -1
  147. package/lib/react-native/LocalDatastoreController.react-native.js +11 -12
  148. package/lib/react-native/LocalDatastoreUtils.js +3 -6
  149. package/lib/react-native/OfflineQuery.js +25 -20
  150. package/lib/react-native/Parse.js +24 -38
  151. package/lib/react-native/ParseACL.js +4 -6
  152. package/lib/react-native/ParseCLP.js +2 -4
  153. package/lib/react-native/ParseConfig.js +4 -6
  154. package/lib/react-native/ParseError.js +13 -31
  155. package/lib/react-native/ParseFile.js +3 -4
  156. package/lib/react-native/ParseGeoPoint.js +2 -4
  157. package/lib/react-native/ParseInstallation.js +13 -30
  158. package/lib/react-native/ParseLiveQuery.js +2 -4
  159. package/lib/react-native/ParseObject.js +77 -87
  160. package/lib/react-native/ParseOp.js +41 -79
  161. package/lib/react-native/ParsePolygon.js +2 -4
  162. package/lib/react-native/ParseQuery.js +43 -45
  163. package/lib/react-native/ParseRelation.js +2 -4
  164. package/lib/react-native/ParseRole.js +13 -30
  165. package/lib/react-native/ParseSchema.js +3 -5
  166. package/lib/react-native/ParseSession.js +12 -29
  167. package/lib/react-native/ParseUser.js +24 -49
  168. package/lib/react-native/RESTController.js +10 -4
  169. package/lib/react-native/SingleInstanceStateController.js +23 -37
  170. package/lib/react-native/Socket.weapp.js +9 -4
  171. package/lib/react-native/Storage.js +1 -2
  172. package/lib/react-native/StorageController.browser.js +6 -1
  173. package/lib/react-native/StorageController.default.js +6 -1
  174. package/lib/react-native/StorageController.js +13 -1
  175. package/lib/react-native/StorageController.react-native.js +11 -6
  176. package/lib/react-native/StorageController.weapp.js +6 -1
  177. package/lib/react-native/TaskQueue.js +2 -4
  178. package/lib/react-native/UniqueInstanceStateController.js +23 -37
  179. package/lib/react-native/WebSocketController.js +9 -1
  180. package/lib/react-native/Xhr.weapp.js +9 -4
  181. package/lib/react-native/unsavedChildren.js +3 -3
  182. package/lib/react-native/uuid.js +1 -2
  183. package/lib/weapp/Analytics.js +7 -11
  184. package/lib/weapp/AnonymousUtils.js +17 -22
  185. package/lib/weapp/Cloud.js +23 -41
  186. package/lib/weapp/CoreManager.js +71 -79
  187. package/lib/weapp/CryptoController.js +14 -9
  188. package/lib/weapp/EventEmitter.js +9 -2
  189. package/lib/weapp/EventuallyQueue.js +156 -357
  190. package/lib/weapp/FacebookUtils.js +23 -28
  191. package/lib/weapp/IndexedDBStorageController.js +18 -14
  192. package/lib/weapp/InstallationController.js +55 -121
  193. package/lib/weapp/LiveQueryClient.js +312 -485
  194. package/lib/weapp/LiveQuerySubscription.js +25 -28
  195. package/lib/weapp/LocalDatastore.js +258 -624
  196. package/lib/weapp/LocalDatastoreController.default.js +42 -226
  197. package/lib/weapp/LocalDatastoreController.js +11 -1
  198. package/lib/weapp/LocalDatastoreController.react-native.js +66 -160
  199. package/lib/weapp/LocalDatastoreUtils.js +4 -7
  200. package/lib/weapp/ObjectStateMutations.js +54 -96
  201. package/lib/weapp/OfflineQuery.js +106 -198
  202. package/lib/weapp/Parse.js +44 -59
  203. package/lib/weapp/ParseACL.js +242 -288
  204. package/lib/weapp/ParseCLP.js +372 -572
  205. package/lib/weapp/ParseConfig.js +115 -138
  206. package/lib/weapp/ParseError.js +85 -182
  207. package/lib/weapp/ParseFile.js +295 -440
  208. package/lib/weapp/ParseGeoPoint.js +121 -146
  209. package/lib/weapp/ParseHooks.js +23 -25
  210. package/lib/weapp/ParseInstallation.js +225 -367
  211. package/lib/weapp/ParseLiveQuery.js +74 -148
  212. package/lib/weapp/ParseObject.js +2014 -2621
  213. package/lib/weapp/ParseOp.js +343 -484
  214. package/lib/weapp/ParsePolygon.js +101 -120
  215. package/lib/weapp/ParseQuery.js +1708 -2052
  216. package/lib/weapp/ParseRelation.js +99 -118
  217. package/lib/weapp/ParseRole.js +88 -140
  218. package/lib/weapp/ParseSchema.js +372 -434
  219. package/lib/weapp/ParseSession.js +62 -110
  220. package/lib/weapp/ParseUser.js +941 -1284
  221. package/lib/weapp/Push.js +15 -38
  222. package/lib/weapp/RESTController.js +86 -125
  223. package/lib/weapp/SingleInstanceStateController.js +57 -86
  224. package/lib/weapp/Socket.weapp.js +50 -33
  225. package/lib/weapp/Storage.js +23 -28
  226. package/lib/weapp/StorageController.browser.js +16 -13
  227. package/lib/weapp/StorageController.default.js +15 -14
  228. package/lib/weapp/StorageController.js +14 -1
  229. package/lib/weapp/StorageController.react-native.js +31 -30
  230. package/lib/weapp/StorageController.weapp.js +19 -13
  231. package/lib/weapp/TaskQueue.js +31 -43
  232. package/lib/weapp/UniqueInstanceStateController.js +65 -86
  233. package/lib/weapp/WebSocketController.js +11 -4
  234. package/lib/weapp/Xhr.weapp.js +90 -78
  235. package/lib/weapp/arrayContainsObject.js +3 -3
  236. package/lib/weapp/canBeSerialized.js +10 -11
  237. package/lib/weapp/decode.js +11 -11
  238. package/lib/weapp/encode.js +11 -11
  239. package/lib/weapp/equals.js +9 -10
  240. package/lib/weapp/escape.js +2 -2
  241. package/lib/weapp/isRevocableSession.js +1 -1
  242. package/lib/weapp/parseDate.js +10 -10
  243. package/lib/weapp/promiseUtils.js +19 -19
  244. package/lib/weapp/unique.js +4 -4
  245. package/lib/weapp/unsavedChildren.js +20 -21
  246. package/lib/weapp/uuid.js +6 -8
  247. package/package.json +24 -30
@@ -7,19 +7,9 @@ _Object$defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.default = void 0;
9
9
  var _keys = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/keys"));
10
- var _typeof2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/typeof"));
11
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/classCallCheck"));
12
- var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/createClass"));
13
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
14
11
  var _CoreManager = _interopRequireDefault(require("./CoreManager"));
15
- /**
16
- * @flow
17
- */
18
- /*:: import type ParseRole from './ParseRole';*/
19
- /*:: import type ParseUser from './ParseUser';*/
20
- /*:: type PermissionsMap = { [permission: string]: boolean };*/
21
- /*:: type ByIdMap = { [userId: string]: PermissionsMap };*/
22
- var PUBLIC_KEY = '*';
12
+ const PUBLIC_KEY = '*';
23
13
 
24
14
  /**
25
15
  * Creates a new ACL.
@@ -35,32 +25,31 @@ var PUBLIC_KEY = '*';
35
25
  *
36
26
  * @alias Parse.ACL
37
27
  */
38
- var ParseACL = /*#__PURE__*/function () {
28
+ class ParseACL {
39
29
  /**
40
30
  * @param {(Parse.User | object)} arg1 The user to initialize the ACL for
41
31
  */
42
- function ParseACL(arg1 /*: ParseUser | ByIdMap*/) {
43
- (0, _classCallCheck2.default)(this, ParseACL);
32
+ constructor(arg1) {
44
33
  (0, _defineProperty2.default)(this, "permissionsById", void 0);
45
34
  this.permissionsById = {};
46
- if (arg1 && (0, _typeof2.default)(arg1) === 'object') {
47
- var _ParseUser = _CoreManager.default.getParseUser();
48
- if (arg1 instanceof _ParseUser) {
35
+ if (arg1 && typeof arg1 === 'object') {
36
+ const ParseUser = _CoreManager.default.getParseUser();
37
+ if (arg1 instanceof ParseUser) {
49
38
  this.setReadAccess(arg1, true);
50
39
  this.setWriteAccess(arg1, true);
51
40
  } else {
52
- for (var _userId in arg1) {
53
- var accessList = arg1[_userId];
54
- this.permissionsById[_userId] = {};
55
- for (var _permission in accessList) {
56
- var allowed = accessList[_permission];
57
- if (_permission !== 'read' && _permission !== 'write') {
41
+ for (const userId in arg1) {
42
+ const accessList = arg1[userId];
43
+ this.permissionsById[userId] = {};
44
+ for (const permission in accessList) {
45
+ const allowed = accessList[permission];
46
+ if (permission !== 'read' && permission !== 'write') {
58
47
  throw new TypeError('Tried to create an ACL with an invalid permission type.');
59
48
  }
60
49
  if (typeof allowed !== 'boolean') {
61
50
  throw new TypeError('Tried to create an ACL with an invalid permission value.');
62
51
  }
63
- this.permissionsById[_userId][_permission] = allowed;
52
+ this.permissionsById[userId][permission] = allowed;
64
53
  }
65
54
  }
66
55
  }
@@ -74,298 +63,263 @@ var ParseACL = /*#__PURE__*/function () {
74
63
  *
75
64
  * @returns {object}
76
65
  */
77
- (0, _createClass2.default)(ParseACL, [{
78
- key: "toJSON",
79
- value: function () /*: ByIdMap*/{
80
- var permissions = {};
81
- for (var p in this.permissionsById) {
82
- permissions[p] = this.permissionsById[p];
83
- }
84
- return permissions;
66
+ toJSON() {
67
+ const permissions = {};
68
+ for (const p in this.permissionsById) {
69
+ permissions[p] = this.permissionsById[p];
85
70
  }
71
+ return permissions;
72
+ }
86
73
 
87
- /**
88
- * Returns whether this ACL is equal to another object
89
- *
90
- * @param {ParseACL} other The other object's ACL to compare to
91
- * @returns {boolean}
92
- */
93
- }, {
94
- key: "equals",
95
- value: function (other /*: ParseACL*/) /*: boolean*/{
96
- if (!(other instanceof ParseACL)) {
74
+ /**
75
+ * Returns whether this ACL is equal to another object
76
+ *
77
+ * @param {ParseACL} other The other object's ACL to compare to
78
+ * @returns {boolean}
79
+ */
80
+ equals(other) {
81
+ if (!(other instanceof ParseACL)) {
82
+ return false;
83
+ }
84
+ const users = (0, _keys.default)(this.permissionsById);
85
+ const otherUsers = (0, _keys.default)(other.permissionsById);
86
+ if (users.length !== otherUsers.length) {
87
+ return false;
88
+ }
89
+ for (const u in this.permissionsById) {
90
+ if (!other.permissionsById[u]) {
97
91
  return false;
98
92
  }
99
- var users = (0, _keys.default)(this.permissionsById);
100
- var otherUsers = (0, _keys.default)(other.permissionsById);
101
- if (users.length !== otherUsers.length) {
93
+ if (this.permissionsById[u].read !== other.permissionsById[u].read) {
102
94
  return false;
103
95
  }
104
- for (var u in this.permissionsById) {
105
- if (!other.permissionsById[u]) {
106
- return false;
107
- }
108
- if (this.permissionsById[u].read !== other.permissionsById[u].read) {
109
- return false;
110
- }
111
- if (this.permissionsById[u].write !== other.permissionsById[u].write) {
112
- return false;
113
- }
96
+ if (this.permissionsById[u].write !== other.permissionsById[u].write) {
97
+ return false;
114
98
  }
115
- return true;
116
99
  }
117
- }, {
118
- key: "_setAccess",
119
- value: function (accessType /*: string*/, userId /*: ParseUser | ParseRole | string*/, allowed /*: boolean*/) {
120
- var ParseRole = _CoreManager.default.getParseRole();
121
- var ParseUser = _CoreManager.default.getParseUser();
122
- if (userId instanceof ParseUser) {
123
- userId = userId.id;
124
- } else if (userId instanceof ParseRole) {
125
- var name = userId.getName();
126
- if (!name) {
127
- throw new TypeError('Role must have a name');
128
- }
129
- userId = 'role:' + name;
130
- }
131
- if (typeof userId !== 'string') {
132
- throw new TypeError('userId must be a string.');
133
- }
134
- if (typeof allowed !== 'boolean') {
135
- throw new TypeError('allowed must be either true or false.');
136
- }
137
- var permissions = this.permissionsById[userId];
138
- if (!permissions) {
139
- if (!allowed) {
140
- // The user already doesn't have this permission, so no action is needed
141
- return;
142
- } else {
143
- permissions = {};
144
- this.permissionsById[userId] = permissions;
145
- }
100
+ return true;
101
+ }
102
+ _setAccess(accessType, userId, allowed) {
103
+ const ParseRole = _CoreManager.default.getParseRole();
104
+ const ParseUser = _CoreManager.default.getParseUser();
105
+ if (userId instanceof ParseUser) {
106
+ userId = userId.id;
107
+ } else if (userId instanceof ParseRole) {
108
+ const name = userId.getName();
109
+ if (!name) {
110
+ throw new TypeError('Role must have a name');
146
111
  }
147
- if (allowed) {
148
- this.permissionsById[userId][accessType] = true;
112
+ userId = 'role:' + name;
113
+ }
114
+ if (typeof userId !== 'string') {
115
+ throw new TypeError('userId must be a string.');
116
+ }
117
+ if (typeof allowed !== 'boolean') {
118
+ throw new TypeError('allowed must be either true or false.');
119
+ }
120
+ let permissions = this.permissionsById[userId];
121
+ if (!permissions) {
122
+ if (!allowed) {
123
+ // The user already doesn't have this permission, so no action is needed
124
+ return;
149
125
  } else {
150
- delete permissions[accessType];
151
- if ((0, _keys.default)(permissions).length === 0) {
152
- delete this.permissionsById[userId];
153
- }
126
+ permissions = {};
127
+ this.permissionsById[userId] = permissions;
154
128
  }
155
129
  }
156
- }, {
157
- key: "_getAccess",
158
- value: function (accessType /*: string*/, userId /*: ParseUser | ParseRole | string*/) /*: boolean*/{
159
- var ParseRole = _CoreManager.default.getParseRole();
160
- var ParseUser = _CoreManager.default.getParseUser();
161
- if (userId instanceof ParseUser) {
162
- userId = userId.id;
163
- if (!userId) {
164
- throw new Error('Cannot get access for a ParseUser without an ID');
165
- }
166
- } else if (userId instanceof ParseRole) {
167
- var name = userId.getName();
168
- if (!name) {
169
- throw new TypeError('Role must have a name');
170
- }
171
- userId = 'role:' + name;
130
+ if (allowed) {
131
+ this.permissionsById[userId][accessType] = true;
132
+ } else {
133
+ delete permissions[accessType];
134
+ if ((0, _keys.default)(permissions).length === 0) {
135
+ delete this.permissionsById[userId];
172
136
  }
173
- var permissions = this.permissionsById[userId];
174
- if (!permissions) {
175
- return false;
137
+ }
138
+ }
139
+ _getAccess(accessType, userId) {
140
+ const ParseRole = _CoreManager.default.getParseRole();
141
+ const ParseUser = _CoreManager.default.getParseUser();
142
+ if (userId instanceof ParseUser) {
143
+ userId = userId.id;
144
+ if (!userId) {
145
+ throw new Error('Cannot get access for a ParseUser without an ID');
146
+ }
147
+ } else if (userId instanceof ParseRole) {
148
+ const name = userId.getName();
149
+ if (!name) {
150
+ throw new TypeError('Role must have a name');
176
151
  }
177
- return !!permissions[accessType];
152
+ userId = 'role:' + name;
178
153
  }
179
-
180
- /**
181
- * Sets whether the given user is allowed to read this object.
182
- *
183
- * @param userId An instance of Parse.User or its objectId.
184
- * @param {boolean} allowed Whether that user should have read access.
185
- */
186
- }, {
187
- key: "setReadAccess",
188
- value: function (userId /*: ParseUser | ParseRole | string*/, allowed /*: boolean*/) {
189
- this._setAccess('read', userId, allowed);
154
+ const permissions = this.permissionsById[userId];
155
+ if (!permissions) {
156
+ return false;
190
157
  }
158
+ return !!permissions[accessType];
159
+ }
191
160
 
192
- /**
193
- * Get whether the given user id is *explicitly* allowed to read this object.
194
- * Even if this returns false, the user may still be able to access it if
195
- * getPublicReadAccess returns true or a role that the user belongs to has
196
- * write access.
197
- *
198
- * @param userId An instance of Parse.User or its objectId, or a Parse.Role.
199
- * @returns {boolean}
200
- */
201
- }, {
202
- key: "getReadAccess",
203
- value: function (userId /*: ParseUser | ParseRole | string*/) /*: boolean*/{
204
- return this._getAccess('read', userId);
205
- }
161
+ /**
162
+ * Sets whether the given user is allowed to read this object.
163
+ *
164
+ * @param userId An instance of Parse.User or its objectId.
165
+ * @param {boolean} allowed Whether that user should have read access.
166
+ */
167
+ setReadAccess(userId, allowed) {
168
+ this._setAccess('read', userId, allowed);
169
+ }
206
170
 
207
- /**
208
- * Sets whether the given user id is allowed to write this object.
209
- *
210
- * @param userId An instance of Parse.User or its objectId, or a Parse.Role..
211
- * @param {boolean} allowed Whether that user should have write access.
212
- */
213
- }, {
214
- key: "setWriteAccess",
215
- value: function (userId /*: ParseUser | ParseRole | string*/, allowed /*: boolean*/) {
216
- this._setAccess('write', userId, allowed);
217
- }
171
+ /**
172
+ * Get whether the given user id is *explicitly* allowed to read this object.
173
+ * Even if this returns false, the user may still be able to access it if
174
+ * getPublicReadAccess returns true or a role that the user belongs to has
175
+ * write access.
176
+ *
177
+ * @param userId An instance of Parse.User or its objectId, or a Parse.Role.
178
+ * @returns {boolean}
179
+ */
180
+ getReadAccess(userId) {
181
+ return this._getAccess('read', userId);
182
+ }
218
183
 
219
- /**
220
- * Gets whether the given user id is *explicitly* allowed to write this object.
221
- * Even if this returns false, the user may still be able to write it if
222
- * getPublicWriteAccess returns true or a role that the user belongs to has
223
- * write access.
224
- *
225
- * @param userId An instance of Parse.User or its objectId, or a Parse.Role.
226
- * @returns {boolean}
227
- */
228
- }, {
229
- key: "getWriteAccess",
230
- value: function (userId /*: ParseUser | ParseRole | string*/) /*: boolean*/{
231
- return this._getAccess('write', userId);
232
- }
184
+ /**
185
+ * Sets whether the given user id is allowed to write this object.
186
+ *
187
+ * @param userId An instance of Parse.User or its objectId, or a Parse.Role..
188
+ * @param {boolean} allowed Whether that user should have write access.
189
+ */
190
+ setWriteAccess(userId, allowed) {
191
+ this._setAccess('write', userId, allowed);
192
+ }
233
193
 
234
- /**
235
- * Sets whether the public is allowed to read this object.
236
- *
237
- * @param {boolean} allowed
238
- */
239
- }, {
240
- key: "setPublicReadAccess",
241
- value: function (allowed /*: boolean*/) {
242
- this.setReadAccess(PUBLIC_KEY, allowed);
243
- }
194
+ /**
195
+ * Gets whether the given user id is *explicitly* allowed to write this object.
196
+ * Even if this returns false, the user may still be able to write it if
197
+ * getPublicWriteAccess returns true or a role that the user belongs to has
198
+ * write access.
199
+ *
200
+ * @param userId An instance of Parse.User or its objectId, or a Parse.Role.
201
+ * @returns {boolean}
202
+ */
203
+ getWriteAccess(userId) {
204
+ return this._getAccess('write', userId);
205
+ }
244
206
 
245
- /**
246
- * Gets whether the public is allowed to read this object.
247
- *
248
- * @returns {boolean}
249
- */
250
- }, {
251
- key: "getPublicReadAccess",
252
- value: function () /*: boolean*/{
253
- return this.getReadAccess(PUBLIC_KEY);
254
- }
207
+ /**
208
+ * Sets whether the public is allowed to read this object.
209
+ *
210
+ * @param {boolean} allowed
211
+ */
212
+ setPublicReadAccess(allowed) {
213
+ this.setReadAccess(PUBLIC_KEY, allowed);
214
+ }
255
215
 
256
- /**
257
- * Sets whether the public is allowed to write this object.
258
- *
259
- * @param {boolean} allowed
260
- */
261
- }, {
262
- key: "setPublicWriteAccess",
263
- value: function (allowed /*: boolean*/) {
264
- this.setWriteAccess(PUBLIC_KEY, allowed);
265
- }
216
+ /**
217
+ * Gets whether the public is allowed to read this object.
218
+ *
219
+ * @returns {boolean}
220
+ */
221
+ getPublicReadAccess() {
222
+ return this.getReadAccess(PUBLIC_KEY);
223
+ }
266
224
 
267
- /**
268
- * Gets whether the public is allowed to write this object.
269
- *
270
- * @returns {boolean}
271
- */
272
- }, {
273
- key: "getPublicWriteAccess",
274
- value: function () /*: boolean*/{
275
- return this.getWriteAccess(PUBLIC_KEY);
276
- }
225
+ /**
226
+ * Sets whether the public is allowed to write this object.
227
+ *
228
+ * @param {boolean} allowed
229
+ */
230
+ setPublicWriteAccess(allowed) {
231
+ this.setWriteAccess(PUBLIC_KEY, allowed);
232
+ }
277
233
 
278
- /**
279
- * Gets whether users belonging to the given role are allowed
280
- * to read this object. Even if this returns false, the role may
281
- * still be able to write it if a parent role has read access.
282
- *
283
- * @param role The name of the role, or a Parse.Role object.
284
- * @returns {boolean} true if the role has read access. false otherwise.
285
- * @throws {TypeError} If role is neither a Parse.Role nor a String.
286
- */
287
- }, {
288
- key: "getRoleReadAccess",
289
- value: function (role /*: ParseRole | string*/) /*: boolean*/{
290
- var ParseRole = _CoreManager.default.getParseRole();
291
- if (role instanceof ParseRole) {
292
- // Normalize to the String name
293
- role = role.getName();
294
- }
295
- if (typeof role !== 'string') {
296
- throw new TypeError('role must be a ParseRole or a String');
297
- }
298
- return this.getReadAccess('role:' + role);
234
+ /**
235
+ * Gets whether the public is allowed to write this object.
236
+ *
237
+ * @returns {boolean}
238
+ */
239
+ getPublicWriteAccess() {
240
+ return this.getWriteAccess(PUBLIC_KEY);
241
+ }
242
+
243
+ /**
244
+ * Gets whether users belonging to the given role are allowed
245
+ * to read this object. Even if this returns false, the role may
246
+ * still be able to write it if a parent role has read access.
247
+ *
248
+ * @param role The name of the role, or a Parse.Role object.
249
+ * @returns {boolean} true if the role has read access. false otherwise.
250
+ * @throws {TypeError} If role is neither a Parse.Role nor a String.
251
+ */
252
+ getRoleReadAccess(role) {
253
+ const ParseRole = _CoreManager.default.getParseRole();
254
+ if (role instanceof ParseRole) {
255
+ // Normalize to the String name
256
+ role = role.getName();
257
+ }
258
+ if (typeof role !== 'string') {
259
+ throw new TypeError('role must be a ParseRole or a String');
299
260
  }
261
+ return this.getReadAccess('role:' + role);
262
+ }
300
263
 
301
- /**
302
- * Gets whether users belonging to the given role are allowed
303
- * to write this object. Even if this returns false, the role may
304
- * still be able to write it if a parent role has write access.
305
- *
306
- * @param role The name of the role, or a Parse.Role object.
307
- * @returns {boolean} true if the role has write access. false otherwise.
308
- * @throws {TypeError} If role is neither a Parse.Role nor a String.
309
- */
310
- }, {
311
- key: "getRoleWriteAccess",
312
- value: function (role /*: ParseRole | string*/) /*: boolean*/{
313
- var ParseRole = _CoreManager.default.getParseRole();
314
- if (role instanceof ParseRole) {
315
- // Normalize to the String name
316
- role = role.getName();
317
- }
318
- if (typeof role !== 'string') {
319
- throw new TypeError('role must be a ParseRole or a String');
320
- }
321
- return this.getWriteAccess('role:' + role);
264
+ /**
265
+ * Gets whether users belonging to the given role are allowed
266
+ * to write this object. Even if this returns false, the role may
267
+ * still be able to write it if a parent role has write access.
268
+ *
269
+ * @param role The name of the role, or a Parse.Role object.
270
+ * @returns {boolean} true if the role has write access. false otherwise.
271
+ * @throws {TypeError} If role is neither a Parse.Role nor a String.
272
+ */
273
+ getRoleWriteAccess(role) {
274
+ const ParseRole = _CoreManager.default.getParseRole();
275
+ if (role instanceof ParseRole) {
276
+ // Normalize to the String name
277
+ role = role.getName();
278
+ }
279
+ if (typeof role !== 'string') {
280
+ throw new TypeError('role must be a ParseRole or a String');
322
281
  }
282
+ return this.getWriteAccess('role:' + role);
283
+ }
323
284
 
324
- /**
325
- * Sets whether users belonging to the given role are allowed
326
- * to read this object.
327
- *
328
- * @param role The name of the role, or a Parse.Role object.
329
- * @param {boolean} allowed Whether the given role can read this object.
330
- * @throws {TypeError} If role is neither a Parse.Role nor a String.
331
- */
332
- }, {
333
- key: "setRoleReadAccess",
334
- value: function (role /*: ParseRole | string*/, allowed /*: boolean*/) {
335
- var ParseRole = _CoreManager.default.getParseRole();
336
- if (role instanceof ParseRole) {
337
- // Normalize to the String name
338
- role = role.getName();
339
- }
340
- if (typeof role !== 'string') {
341
- throw new TypeError('role must be a ParseRole or a String');
342
- }
343
- this.setReadAccess('role:' + role, allowed);
285
+ /**
286
+ * Sets whether users belonging to the given role are allowed
287
+ * to read this object.
288
+ *
289
+ * @param role The name of the role, or a Parse.Role object.
290
+ * @param {boolean} allowed Whether the given role can read this object.
291
+ * @throws {TypeError} If role is neither a Parse.Role nor a String.
292
+ */
293
+ setRoleReadAccess(role, allowed) {
294
+ const ParseRole = _CoreManager.default.getParseRole();
295
+ if (role instanceof ParseRole) {
296
+ // Normalize to the String name
297
+ role = role.getName();
344
298
  }
299
+ if (typeof role !== 'string') {
300
+ throw new TypeError('role must be a ParseRole or a String');
301
+ }
302
+ this.setReadAccess('role:' + role, allowed);
303
+ }
345
304
 
346
- /**
347
- * Sets whether users belonging to the given role are allowed
348
- * to write this object.
349
- *
350
- * @param role The name of the role, or a Parse.Role object.
351
- * @param {boolean} allowed Whether the given role can write this object.
352
- * @throws {TypeError} If role is neither a Parse.Role nor a String.
353
- */
354
- }, {
355
- key: "setRoleWriteAccess",
356
- value: function (role /*: ParseRole | string*/, allowed /*: boolean*/) {
357
- var ParseRole = _CoreManager.default.getParseRole();
358
- if (role instanceof ParseRole) {
359
- // Normalize to the String name
360
- role = role.getName();
361
- }
362
- if (typeof role !== 'string') {
363
- throw new TypeError('role must be a ParseRole or a String');
364
- }
365
- this.setWriteAccess('role:' + role, allowed);
305
+ /**
306
+ * Sets whether users belonging to the given role are allowed
307
+ * to write this object.
308
+ *
309
+ * @param role The name of the role, or a Parse.Role object.
310
+ * @param {boolean} allowed Whether the given role can write this object.
311
+ * @throws {TypeError} If role is neither a Parse.Role nor a String.
312
+ */
313
+ setRoleWriteAccess(role, allowed) {
314
+ const ParseRole = _CoreManager.default.getParseRole();
315
+ if (role instanceof ParseRole) {
316
+ // Normalize to the String name
317
+ role = role.getName();
318
+ }
319
+ if (typeof role !== 'string') {
320
+ throw new TypeError('role must be a ParseRole or a String');
366
321
  }
367
- }]);
368
- return ParseACL;
369
- }();
370
- var _default = ParseACL;
371
- exports.default = _default;
322
+ this.setWriteAccess('role:' + role, allowed);
323
+ }
324
+ }
325
+ var _default = exports.default = ParseACL;