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,21 +7,11 @@ _Object$defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.default = void 0;
9
9
  var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
10
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/classCallCheck"));
11
- var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/createClass"));
12
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
13
11
  var _CoreManager = _interopRequireDefault(require("./CoreManager"));
14
12
  var _ParseObject = _interopRequireDefault(require("./ParseObject"));
15
13
  var _ParseCLP = _interopRequireDefault(require("./ParseCLP"));
16
- /**
17
- * @flow
18
- */
19
- /*:: import type { PermissionsMap } from './ParseCLP';*/
20
- var FIELD_TYPES = ['String', 'Number', 'Boolean', 'Bytes', 'Date', 'File', 'GeoPoint', 'Polygon', 'Array', 'Object', 'Pointer', 'Relation'];
21
- /*:: type FieldOptions = {
22
- required: boolean,
23
- defaultValue: any,
24
- };*/
14
+ const FIELD_TYPES = ['String', 'Number', 'Boolean', 'Bytes', 'Date', 'File', 'GeoPoint', 'Polygon', 'Array', 'Object', 'Pointer', 'Relation'];
25
15
  /**
26
16
  * A Parse.Schema object is for handling schema data from Parse.
27
17
  * <p>All the schemas methods require MasterKey.
@@ -39,12 +29,11 @@ var FIELD_TYPES = ['String', 'Number', 'Boolean', 'Bytes', 'Date', 'File', 'GeoP
39
29
  *
40
30
  * @alias Parse.Schema
41
31
  */
42
- var ParseSchema = /*#__PURE__*/function () {
32
+ class ParseSchema {
43
33
  /**
44
34
  * @param {string} className Parse Class string.
45
35
  */
46
- function ParseSchema(className /*: string*/) {
47
- (0, _classCallCheck2.default)(this, ParseSchema);
36
+ constructor(className) {
48
37
  (0, _defineProperty2.default)(this, "className", void 0);
49
38
  (0, _defineProperty2.default)(this, "_fields", void 0);
50
39
  (0, _defineProperty2.default)(this, "_indexes", void 0);
@@ -66,470 +55,419 @@ var ParseSchema = /*#__PURE__*/function () {
66
55
  * @returns {Promise} A promise that is resolved with the result when
67
56
  * the query completes.
68
57
  */
69
- (0, _createClass2.default)(ParseSchema, [{
70
- key: "get",
71
- value:
72
- /**
73
- * Get the Schema from Parse
74
- *
75
- * @returns {Promise} A promise that is resolved with the result when
76
- * the query completes.
77
- */
78
- function () {
79
- this.assertClassName();
80
- var controller = _CoreManager.default.getSchemaController();
81
- return controller.get(this.className).then(function (response) {
82
- if (!response) {
83
- throw new Error('Schema not found.');
84
- }
85
- return response;
86
- });
87
- }
58
+ static all() {
59
+ const controller = _CoreManager.default.getSchemaController();
60
+ return controller.get('').then(response => {
61
+ if (response.results.length === 0) {
62
+ throw new Error('Schema not found.');
63
+ }
64
+ return response.results;
65
+ });
66
+ }
88
67
 
89
- /**
90
- * Create a new Schema on Parse
91
- *
92
- * @returns {Promise} A promise that is resolved with the result when
93
- * the query completes.
94
- */
95
- }, {
96
- key: "save",
97
- value: function () {
98
- this.assertClassName();
99
- var controller = _CoreManager.default.getSchemaController();
100
- var params = {
101
- className: this.className,
102
- fields: this._fields,
103
- indexes: this._indexes,
104
- classLevelPermissions: this._clp
105
- };
106
- return controller.create(this.className, params);
107
- }
68
+ /**
69
+ * Get the Schema from Parse
70
+ *
71
+ * @returns {Promise} A promise that is resolved with the result when
72
+ * the query completes.
73
+ */
74
+ get() {
75
+ this.assertClassName();
76
+ const controller = _CoreManager.default.getSchemaController();
77
+ return controller.get(this.className).then(response => {
78
+ if (!response) {
79
+ throw new Error('Schema not found.');
80
+ }
81
+ return response;
82
+ });
83
+ }
108
84
 
109
- /**
110
- * Update a Schema on Parse
111
- *
112
- * @returns {Promise} A promise that is resolved with the result when
113
- * the query completes.
114
- */
115
- }, {
116
- key: "update",
117
- value: function () {
118
- this.assertClassName();
119
- var controller = _CoreManager.default.getSchemaController();
120
- var params = {
121
- className: this.className,
122
- fields: this._fields,
123
- indexes: this._indexes,
124
- classLevelPermissions: this._clp
125
- };
126
- this._fields = {};
127
- this._indexes = {};
128
- return controller.update(this.className, params);
129
- }
85
+ /**
86
+ * Create a new Schema on Parse
87
+ *
88
+ * @returns {Promise} A promise that is resolved with the result when
89
+ * the query completes.
90
+ */
91
+ save() {
92
+ this.assertClassName();
93
+ const controller = _CoreManager.default.getSchemaController();
94
+ const params = {
95
+ className: this.className,
96
+ fields: this._fields,
97
+ indexes: this._indexes,
98
+ classLevelPermissions: this._clp
99
+ };
100
+ return controller.create(this.className, params);
101
+ }
130
102
 
131
- /**
132
- * Removing a Schema from Parse
133
- * Can only be used on Schema without objects
134
- *
135
- * @returns {Promise} A promise that is resolved with the result when
136
- * the query completes.
137
- */
138
- }, {
139
- key: "delete",
140
- value: function () {
141
- this.assertClassName();
142
- var controller = _CoreManager.default.getSchemaController();
143
- return controller.delete(this.className);
144
- }
103
+ /**
104
+ * Update a Schema on Parse
105
+ *
106
+ * @returns {Promise} A promise that is resolved with the result when
107
+ * the query completes.
108
+ */
109
+ update() {
110
+ this.assertClassName();
111
+ const controller = _CoreManager.default.getSchemaController();
112
+ const params = {
113
+ className: this.className,
114
+ fields: this._fields,
115
+ indexes: this._indexes,
116
+ classLevelPermissions: this._clp
117
+ };
118
+ this._fields = {};
119
+ this._indexes = {};
120
+ return controller.update(this.className, params);
121
+ }
145
122
 
146
- /**
147
- * Removes all objects from a Schema (class) in Parse.
148
- * EXERCISE CAUTION, running this will delete all objects for this schema and cannot be reversed
149
- *
150
- * @returns {Promise} A promise that is resolved with the result when
151
- * the query completes.
152
- */
153
- }, {
154
- key: "purge",
155
- value: function () {
156
- this.assertClassName();
157
- var controller = _CoreManager.default.getSchemaController();
158
- return controller.purge(this.className);
159
- }
123
+ /**
124
+ * Removing a Schema from Parse
125
+ * Can only be used on Schema without objects
126
+ *
127
+ * @returns {Promise} A promise that is resolved with the result when
128
+ * the query completes.
129
+ */
130
+ delete() {
131
+ this.assertClassName();
132
+ const controller = _CoreManager.default.getSchemaController();
133
+ return controller.delete(this.className);
134
+ }
160
135
 
161
- /**
162
- * Assert if ClassName has been filled
163
- *
164
- * @private
165
- */
166
- }, {
167
- key: "assertClassName",
168
- value: function () {
169
- if (!this.className) {
170
- throw new Error('You must set a Class Name before making any request.');
171
- }
172
- }
136
+ /**
137
+ * Removes all objects from a Schema (class) in Parse.
138
+ * EXERCISE CAUTION, running this will delete all objects for this schema and cannot be reversed
139
+ *
140
+ * @returns {Promise} A promise that is resolved with the result when
141
+ * the query completes.
142
+ */
143
+ purge() {
144
+ this.assertClassName();
145
+ const controller = _CoreManager.default.getSchemaController();
146
+ return controller.purge(this.className);
147
+ }
173
148
 
174
- /**
175
- * Sets Class Level Permissions when creating / updating a Schema.
176
- * EXERCISE CAUTION, running this may override CLP for this schema and cannot be reversed
177
- *
178
- * @param {object | Parse.CLP} clp Class Level Permissions
179
- * @returns {Parse.Schema} Returns the schema, so you can chain this call.
180
- */
181
- }, {
182
- key: "setCLP",
183
- value: function (clp /*: PermissionsMap | ParseCLP*/) {
184
- if (clp instanceof _ParseCLP.default) {
185
- this._clp = clp.toJSON();
186
- } else {
187
- this._clp = clp;
188
- }
189
- return this;
149
+ /**
150
+ * Assert if ClassName has been filled
151
+ *
152
+ * @private
153
+ */
154
+ assertClassName() {
155
+ if (!this.className) {
156
+ throw new Error('You must set a Class Name before making any request.');
190
157
  }
158
+ }
191
159
 
192
- /**
193
- * Adding a Field to Create / Update a Schema
194
- *
195
- * @param {string} name Name of the field that will be created on Parse
196
- * @param {string} type Can be a (String|Number|Boolean|Date|Parse.File|Parse.GeoPoint|Array|Object|Pointer|Parse.Relation)
197
- * @param {object} options
198
- * Valid options are:<ul>
199
- * <li>required: If field is not set, save operation fails (Requires Parse Server 3.7.0+)
200
- * <li>defaultValue: If field is not set, a default value is selected (Requires Parse Server 3.7.0+)
201
- * <li>targetClass: Required if type is Pointer or Parse.Relation
202
- * </ul>
203
- * @returns {Parse.Schema} Returns the schema, so you can chain this call.
204
- */
205
- }, {
206
- key: "addField",
207
- value: function (name /*: string*/, type /*: string*/) {
208
- var options /*: FieldOptions*/ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
209
- type = type || 'String';
210
- if (!name) {
211
- throw new Error('field name may not be null.');
212
- }
213
- if ((0, _indexOf.default)(FIELD_TYPES).call(FIELD_TYPES, type) === -1) {
214
- throw new Error("".concat(type, " is not a valid type."));
215
- }
216
- if (type === 'Pointer') {
217
- return this.addPointer(name, options.targetClass, options);
218
- }
219
- if (type === 'Relation') {
220
- return this.addRelation(name, options.targetClass, options);
221
- }
222
- var fieldOptions = {
223
- type: type
224
- };
225
- if (typeof options.required === 'boolean') {
226
- fieldOptions.required = options.required;
227
- }
228
- if (options.defaultValue !== undefined) {
229
- fieldOptions.defaultValue = options.defaultValue;
230
- }
231
- if (type === 'Date') {
232
- if (options && options.defaultValue) {
233
- fieldOptions.defaultValue = {
234
- __type: 'Date',
235
- iso: new Date(options.defaultValue)
236
- };
237
- }
238
- }
239
- if (type === 'Bytes') {
240
- if (options && options.defaultValue) {
241
- fieldOptions.defaultValue = {
242
- __type: 'Bytes',
243
- base64: options.defaultValue
244
- };
245
- }
246
- }
247
- this._fields[name] = fieldOptions;
248
- return this;
160
+ /**
161
+ * Sets Class Level Permissions when creating / updating a Schema.
162
+ * EXERCISE CAUTION, running this may override CLP for this schema and cannot be reversed
163
+ *
164
+ * @param {object | Parse.CLP} clp Class Level Permissions
165
+ * @returns {Parse.Schema} Returns the schema, so you can chain this call.
166
+ */
167
+ setCLP(clp) {
168
+ if (clp instanceof _ParseCLP.default) {
169
+ this._clp = clp.toJSON();
170
+ } else {
171
+ this._clp = clp;
249
172
  }
173
+ return this;
174
+ }
250
175
 
251
- /**
252
- * Adding an Index to Create / Update a Schema
253
- *
254
- * @param {string} name Name of the index
255
- * @param {object} index { field: value }
256
- * @returns {Parse.Schema} Returns the schema, so you can chain this call.
257
- *
258
- * <pre>
259
- * schema.addIndex('index_name', { 'field': 1 });
260
- * </pre>
261
- */
262
- }, {
263
- key: "addIndex",
264
- value: function (name /*: string*/, index /*: any*/) {
265
- if (!name) {
266
- throw new Error('index name may not be null.');
176
+ /**
177
+ * Adding a Field to Create / Update a Schema
178
+ *
179
+ * @param {string} name Name of the field that will be created on Parse
180
+ * @param {string} type Can be a (String|Number|Boolean|Date|Parse.File|Parse.GeoPoint|Array|Object|Pointer|Parse.Relation)
181
+ * @param {object} options
182
+ * Valid options are:<ul>
183
+ * <li>required: If field is not set, save operation fails (Requires Parse Server 3.7.0+)
184
+ * <li>defaultValue: If field is not set, a default value is selected (Requires Parse Server 3.7.0+)
185
+ * <li>targetClass: Required if type is Pointer or Parse.Relation
186
+ * </ul>
187
+ * @returns {Parse.Schema} Returns the schema, so you can chain this call.
188
+ */
189
+ addField(name, type) {
190
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
191
+ type = type || 'String';
192
+ if (!name) {
193
+ throw new Error('field name may not be null.');
194
+ }
195
+ if ((0, _indexOf.default)(FIELD_TYPES).call(FIELD_TYPES, type) === -1) {
196
+ throw new Error(`${type} is not a valid type.`);
197
+ }
198
+ if (type === 'Pointer') {
199
+ return this.addPointer(name, options.targetClass, options);
200
+ }
201
+ if (type === 'Relation') {
202
+ return this.addRelation(name, options.targetClass);
203
+ }
204
+ const fieldOptions = {
205
+ type
206
+ };
207
+ if (typeof options.required === 'boolean') {
208
+ fieldOptions.required = options.required;
209
+ }
210
+ if (options.defaultValue !== undefined) {
211
+ fieldOptions.defaultValue = options.defaultValue;
212
+ }
213
+ if (type === 'Date') {
214
+ if (options && options.defaultValue) {
215
+ fieldOptions.defaultValue = {
216
+ __type: 'Date',
217
+ iso: new Date(options.defaultValue)
218
+ };
267
219
  }
268
- if (!index) {
269
- throw new Error('index may not be null.');
220
+ }
221
+ if (type === 'Bytes') {
222
+ if (options && options.defaultValue) {
223
+ fieldOptions.defaultValue = {
224
+ __type: 'Bytes',
225
+ base64: options.defaultValue
226
+ };
270
227
  }
271
- this._indexes[name] = index;
272
- return this;
273
228
  }
229
+ this._fields[name] = fieldOptions;
230
+ return this;
231
+ }
274
232
 
275
- /**
276
- * Adding String Field
277
- *
278
- * @param {string} name Name of the field that will be created on Parse
279
- * @param {object} options See {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.Schema.html#addField addField}
280
- * @returns {Parse.Schema} Returns the schema, so you can chain this call.
281
- */
282
- }, {
283
- key: "addString",
284
- value: function (name /*: string*/, options /*: FieldOptions*/) {
285
- return this.addField(name, 'String', options);
233
+ /**
234
+ * Adding an Index to Create / Update a Schema
235
+ *
236
+ * @param {string} name Name of the index
237
+ * @param {object} index { field: value }
238
+ * @returns {Parse.Schema} Returns the schema, so you can chain this call.
239
+ *
240
+ * <pre>
241
+ * schema.addIndex('index_name', { 'field': 1 });
242
+ * </pre>
243
+ */
244
+ addIndex(name, index) {
245
+ if (!name) {
246
+ throw new Error('index name may not be null.');
286
247
  }
287
-
288
- /**
289
- * Adding Number Field
290
- *
291
- * @param {string} name Name of the field that will be created on Parse
292
- * @param {object} options See {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.Schema.html#addField addField}
293
- * @returns {Parse.Schema} Returns the schema, so you can chain this call.
294
- */
295
- }, {
296
- key: "addNumber",
297
- value: function (name /*: string*/, options /*: FieldOptions*/) {
298
- return this.addField(name, 'Number', options);
248
+ if (!index) {
249
+ throw new Error('index may not be null.');
299
250
  }
251
+ this._indexes[name] = index;
252
+ return this;
253
+ }
300
254
 
301
- /**
302
- * Adding Boolean Field
303
- *
304
- * @param {string} name Name of the field that will be created on Parse
305
- * @param {object} options See {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.Schema.html#addField addField}
306
- * @returns {Parse.Schema} Returns the schema, so you can chain this call.
307
- */
308
- }, {
309
- key: "addBoolean",
310
- value: function (name /*: string*/, options /*: FieldOptions*/) {
311
- return this.addField(name, 'Boolean', options);
312
- }
255
+ /**
256
+ * Adding String Field
257
+ *
258
+ * @param {string} name Name of the field that will be created on Parse
259
+ * @param {object} options See {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.Schema.html#addField addField}
260
+ * @returns {Parse.Schema} Returns the schema, so you can chain this call.
261
+ */
262
+ addString(name, options) {
263
+ return this.addField(name, 'String', options);
264
+ }
313
265
 
314
- /**
315
- * Adding Bytes Field
316
- *
317
- * @param {string} name Name of the field that will be created on Parse
318
- * @param {object} options See {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.Schema.html#addField addField}
319
- * @returns {Parse.Schema} Returns the schema, so you can chain this call.
320
- */
321
- }, {
322
- key: "addBytes",
323
- value: function (name /*: string*/, options /*: FieldOptions*/) {
324
- return this.addField(name, 'Bytes', options);
325
- }
266
+ /**
267
+ * Adding Number Field
268
+ *
269
+ * @param {string} name Name of the field that will be created on Parse
270
+ * @param {object} options See {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.Schema.html#addField addField}
271
+ * @returns {Parse.Schema} Returns the schema, so you can chain this call.
272
+ */
273
+ addNumber(name, options) {
274
+ return this.addField(name, 'Number', options);
275
+ }
326
276
 
327
- /**
328
- * Adding Date Field
329
- *
330
- * @param {string} name Name of the field that will be created on Parse
331
- * @param {object} options See {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.Schema.html#addField addField}
332
- * @returns {Parse.Schema} Returns the schema, so you can chain this call.
333
- */
334
- }, {
335
- key: "addDate",
336
- value: function (name /*: string*/, options /*: FieldOptions*/) {
337
- return this.addField(name, 'Date', options);
338
- }
277
+ /**
278
+ * Adding Boolean Field
279
+ *
280
+ * @param {string} name Name of the field that will be created on Parse
281
+ * @param {object} options See {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.Schema.html#addField addField}
282
+ * @returns {Parse.Schema} Returns the schema, so you can chain this call.
283
+ */
284
+ addBoolean(name, options) {
285
+ return this.addField(name, 'Boolean', options);
286
+ }
339
287
 
340
- /**
341
- * Adding File Field
342
- *
343
- * @param {string} name Name of the field that will be created on Parse
344
- * @param {object} options See {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.Schema.html#addField addField}
345
- * @returns {Parse.Schema} Returns the schema, so you can chain this call.
346
- */
347
- }, {
348
- key: "addFile",
349
- value: function (name /*: string*/, options /*: FieldOptions*/) {
350
- return this.addField(name, 'File', options);
351
- }
288
+ /**
289
+ * Adding Bytes Field
290
+ *
291
+ * @param {string} name Name of the field that will be created on Parse
292
+ * @param {object} options See {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.Schema.html#addField addField}
293
+ * @returns {Parse.Schema} Returns the schema, so you can chain this call.
294
+ */
295
+ addBytes(name, options) {
296
+ return this.addField(name, 'Bytes', options);
297
+ }
352
298
 
353
- /**
354
- * Adding GeoPoint Field
355
- *
356
- * @param {string} name Name of the field that will be created on Parse
357
- * @param {object} options See {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.Schema.html#addField addField}
358
- * @returns {Parse.Schema} Returns the schema, so you can chain this call.
359
- */
360
- }, {
361
- key: "addGeoPoint",
362
- value: function (name /*: string*/, options /*: FieldOptions*/) {
363
- return this.addField(name, 'GeoPoint', options);
364
- }
299
+ /**
300
+ * Adding Date Field
301
+ *
302
+ * @param {string} name Name of the field that will be created on Parse
303
+ * @param {object} options See {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.Schema.html#addField addField}
304
+ * @returns {Parse.Schema} Returns the schema, so you can chain this call.
305
+ */
306
+ addDate(name, options) {
307
+ return this.addField(name, 'Date', options);
308
+ }
365
309
 
366
- /**
367
- * Adding Polygon Field
368
- *
369
- * @param {string} name Name of the field that will be created on Parse
370
- * @param {object} options See {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.Schema.html#addField addField}
371
- * @returns {Parse.Schema} Returns the schema, so you can chain this call.
372
- */
373
- }, {
374
- key: "addPolygon",
375
- value: function (name /*: string*/, options /*: FieldOptions*/) {
376
- return this.addField(name, 'Polygon', options);
377
- }
310
+ /**
311
+ * Adding File Field
312
+ *
313
+ * @param {string} name Name of the field that will be created on Parse
314
+ * @param {object} options See {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.Schema.html#addField addField}
315
+ * @returns {Parse.Schema} Returns the schema, so you can chain this call.
316
+ */
317
+ addFile(name, options) {
318
+ return this.addField(name, 'File', options);
319
+ }
378
320
 
379
- /**
380
- * Adding Array Field
381
- *
382
- * @param {string} name Name of the field that will be created on Parse
383
- * @param {object} options See {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.Schema.html#addField addField}
384
- * @returns {Parse.Schema} Returns the schema, so you can chain this call.
385
- */
386
- }, {
387
- key: "addArray",
388
- value: function (name /*: string*/, options /*: FieldOptions*/) {
389
- return this.addField(name, 'Array', options);
390
- }
321
+ /**
322
+ * Adding GeoPoint Field
323
+ *
324
+ * @param {string} name Name of the field that will be created on Parse
325
+ * @param {object} options See {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.Schema.html#addField addField}
326
+ * @returns {Parse.Schema} Returns the schema, so you can chain this call.
327
+ */
328
+ addGeoPoint(name, options) {
329
+ return this.addField(name, 'GeoPoint', options);
330
+ }
391
331
 
392
- /**
393
- * Adding Object Field
394
- *
395
- * @param {string} name Name of the field that will be created on Parse
396
- * @param {object} options See {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.Schema.html#addField addField}
397
- * @returns {Parse.Schema} Returns the schema, so you can chain this call.
398
- */
399
- }, {
400
- key: "addObject",
401
- value: function (name /*: string*/, options /*: FieldOptions*/) {
402
- return this.addField(name, 'Object', options);
403
- }
332
+ /**
333
+ * Adding Polygon Field
334
+ *
335
+ * @param {string} name Name of the field that will be created on Parse
336
+ * @param {object} options See {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.Schema.html#addField addField}
337
+ * @returns {Parse.Schema} Returns the schema, so you can chain this call.
338
+ */
339
+ addPolygon(name, options) {
340
+ return this.addField(name, 'Polygon', options);
341
+ }
404
342
 
405
- /**
406
- * Adding Pointer Field
407
- *
408
- * @param {string} name Name of the field that will be created on Parse
409
- * @param {string} targetClass Name of the target Pointer Class
410
- * @param {object} options See {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.Schema.html#addField addField}
411
- * @returns {Parse.Schema} Returns the schema, so you can chain this call.
412
- */
413
- }, {
414
- key: "addPointer",
415
- value: function (name /*: string*/, targetClass /*: string*/) {
416
- var options /*: FieldOptions*/ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
417
- if (!name) {
418
- throw new Error('field name may not be null.');
419
- }
420
- if (!targetClass) {
421
- throw new Error('You need to set the targetClass of the Pointer.');
422
- }
423
- var fieldOptions = {
424
- type: 'Pointer',
425
- targetClass: targetClass
426
- };
427
- if (typeof options.required === 'boolean') {
428
- fieldOptions.required = options.required;
429
- }
430
- if (options.defaultValue !== undefined) {
431
- fieldOptions.defaultValue = options.defaultValue;
432
- if (options.defaultValue instanceof _ParseObject.default) {
433
- fieldOptions.defaultValue = options.defaultValue.toPointer();
434
- }
435
- }
436
- this._fields[name] = fieldOptions;
437
- return this;
438
- }
343
+ /**
344
+ * Adding Array Field
345
+ *
346
+ * @param {string} name Name of the field that will be created on Parse
347
+ * @param {object} options See {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.Schema.html#addField addField}
348
+ * @returns {Parse.Schema} Returns the schema, so you can chain this call.
349
+ */
350
+ addArray(name, options) {
351
+ return this.addField(name, 'Array', options);
352
+ }
439
353
 
440
- /**
441
- * Adding Relation Field
442
- *
443
- * @param {string} name Name of the field that will be created on Parse
444
- * @param {string} targetClass Name of the target Pointer Class
445
- * @returns {Parse.Schema} Returns the schema, so you can chain this call.
446
- */
447
- }, {
448
- key: "addRelation",
449
- value: function (name /*: string*/, targetClass /*: string*/) {
450
- if (!name) {
451
- throw new Error('field name may not be null.');
452
- }
453
- if (!targetClass) {
454
- throw new Error('You need to set the targetClass of the Relation.');
455
- }
456
- this._fields[name] = {
457
- type: 'Relation',
458
- targetClass: targetClass
459
- };
460
- return this;
461
- }
354
+ /**
355
+ * Adding Object Field
356
+ *
357
+ * @param {string} name Name of the field that will be created on Parse
358
+ * @param {object} options See {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.Schema.html#addField addField}
359
+ * @returns {Parse.Schema} Returns the schema, so you can chain this call.
360
+ */
361
+ addObject(name, options) {
362
+ return this.addField(name, 'Object', options);
363
+ }
462
364
 
463
- /**
464
- * Deleting a Field to Update on a Schema
465
- *
466
- * @param {string} name Name of the field
467
- * @returns {Parse.Schema} Returns the schema, so you can chain this call.
468
- */
469
- }, {
470
- key: "deleteField",
471
- value: function (name /*: string*/) {
472
- this._fields[name] = {
473
- __op: 'Delete'
474
- };
475
- return this;
365
+ /**
366
+ * Adding Pointer Field
367
+ *
368
+ * @param {string} name Name of the field that will be created on Parse
369
+ * @param {string} targetClass Name of the target Pointer Class
370
+ * @param {object} options See {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.Schema.html#addField addField}
371
+ * @returns {Parse.Schema} Returns the schema, so you can chain this call.
372
+ */
373
+ addPointer(name, targetClass) {
374
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
375
+ if (!name) {
376
+ throw new Error('field name may not be null.');
476
377
  }
378
+ if (!targetClass) {
379
+ throw new Error('You need to set the targetClass of the Pointer.');
380
+ }
381
+ const fieldOptions = {
382
+ type: 'Pointer',
383
+ targetClass
384
+ };
385
+ if (typeof options.required === 'boolean') {
386
+ fieldOptions.required = options.required;
387
+ }
388
+ if (options.defaultValue !== undefined) {
389
+ fieldOptions.defaultValue = options.defaultValue;
390
+ if (options.defaultValue instanceof _ParseObject.default) {
391
+ fieldOptions.defaultValue = options.defaultValue.toPointer();
392
+ }
393
+ }
394
+ this._fields[name] = fieldOptions;
395
+ return this;
396
+ }
477
397
 
478
- /**
479
- * Deleting an Index to Update on a Schema
480
- *
481
- * @param {string} name Name of the field
482
- * @returns {Parse.Schema} Returns the schema, so you can chain this call.
483
- */
484
- }, {
485
- key: "deleteIndex",
486
- value: function (name /*: string*/) {
487
- this._indexes[name] = {
488
- __op: 'Delete'
489
- };
490
- return this;
398
+ /**
399
+ * Adding Relation Field
400
+ *
401
+ * @param {string} name Name of the field that will be created on Parse
402
+ * @param {string} targetClass Name of the target Pointer Class
403
+ * @returns {Parse.Schema} Returns the schema, so you can chain this call.
404
+ */
405
+ addRelation(name, targetClass) {
406
+ if (!name) {
407
+ throw new Error('field name may not be null.');
491
408
  }
492
- }], [{
493
- key: "all",
494
- value: function () {
495
- var controller = _CoreManager.default.getSchemaController();
496
- return controller.get('').then(function (response) {
497
- if (response.results.length === 0) {
498
- throw new Error('Schema not found.');
499
- }
500
- return response.results;
501
- });
409
+ if (!targetClass) {
410
+ throw new Error('You need to set the targetClass of the Relation.');
502
411
  }
503
- }]);
504
- return ParseSchema;
505
- }();
506
- var DefaultController = {
507
- send: function (className /*: string*/, method /*: string*/) /*: Promise*/{
508
- var params /*: any*/ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
509
- var RESTController = _CoreManager.default.getRESTController();
510
- return RESTController.request(method, "schemas/".concat(className), params, {
412
+ this._fields[name] = {
413
+ type: 'Relation',
414
+ targetClass
415
+ };
416
+ return this;
417
+ }
418
+
419
+ /**
420
+ * Deleting a Field to Update on a Schema
421
+ *
422
+ * @param {string} name Name of the field
423
+ * @returns {Parse.Schema} Returns the schema, so you can chain this call.
424
+ */
425
+ deleteField(name) {
426
+ this._fields[name] = {
427
+ __op: 'Delete'
428
+ };
429
+ return this;
430
+ }
431
+
432
+ /**
433
+ * Deleting an Index to Update on a Schema
434
+ *
435
+ * @param {string} name Name of the field
436
+ * @returns {Parse.Schema} Returns the schema, so you can chain this call.
437
+ */
438
+ deleteIndex(name) {
439
+ this._indexes[name] = {
440
+ __op: 'Delete'
441
+ };
442
+ return this;
443
+ }
444
+ }
445
+ const DefaultController = {
446
+ send(className, method) {
447
+ let params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
448
+ const RESTController = _CoreManager.default.getRESTController();
449
+ return RESTController.request(method, `schemas/${className}`, params, {
511
450
  useMasterKey: true
512
451
  });
513
452
  },
514
- get: function (className /*: string*/) /*: Promise*/{
453
+ get(className) {
515
454
  return this.send(className, 'GET');
516
455
  },
517
- create: function (className /*: string*/, params /*: any*/) /*: Promise*/{
456
+ create(className, params) {
518
457
  return this.send(className, 'POST', params);
519
458
  },
520
- update: function (className /*: string*/, params /*: any*/) /*: Promise*/{
459
+ update(className, params) {
521
460
  return this.send(className, 'PUT', params);
522
461
  },
523
- delete: function (className /*: string*/) /*: Promise*/{
462
+ delete(className) {
524
463
  return this.send(className, 'DELETE');
525
464
  },
526
- purge: function (className /*: string*/) /*: Promise*/{
527
- var RESTController = _CoreManager.default.getRESTController();
528
- return RESTController.request('DELETE', "purge/".concat(className), {}, {
465
+ purge(className) {
466
+ const RESTController = _CoreManager.default.getRESTController();
467
+ return RESTController.request('DELETE', `purge/${className}`, {}, {
529
468
  useMasterKey: true
530
469
  });
531
470
  }
532
471
  };
533
472
  _CoreManager.default.setSchemaController(DefaultController);
534
- var _default = ParseSchema;
535
- exports.default = _default;
473
+ var _default = exports.default = ParseSchema;