backendless 6.3.8 → 6.3.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/backendless.d.ts CHANGED
@@ -4,6 +4,7 @@
4
4
  */
5
5
  declare module Backendless {
6
6
  let debugMode: boolean;
7
+ let useTableClassesFromGlobalScope: boolean;
7
8
  let serverURL: string;
8
9
  let appId: string;
9
10
  let apiKey: string;
@@ -35,7 +36,8 @@ declare module Backendless {
35
36
  serverURL?: string;
36
37
  domain?: string;
37
38
  debugMode?: boolean;
38
- XMLHttpRequest?: XMLHttpRequest,
39
+ XMLHttpRequest?: XMLHttpRequest;
40
+ useTableClassesFromGlobalScope?: boolean;
39
41
  }
40
42
 
41
43
  /**
@@ -297,7 +299,7 @@ declare module Backendless {
297
299
 
298
300
  function findByRole<T = Backendless.User>(roleName: string, loadRoles?: boolean, query?: Backendless.DataQueryBuilder | DataQueryI): Promise<T[]>;
299
301
 
300
- function getUserRoles(): Promise<string[]>;
302
+ function getUserRoles(userId?: string): Promise<string[]>;
301
303
 
302
304
  function describeUserClass(): Promise<Object[]>;
303
305
 
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * ********************************************************************************************************************
3
- * Backendless SDK for JavaScript. Version: 6.3.8
3
+ * Backendless SDK for JavaScript. Version: 6.3.11
4
4
  *
5
5
  * Copyright 2012-2022 BACKENDLESS.COM. All Rights Reserved.
6
6
  *
@@ -1193,23 +1193,34 @@ function parseHeaders(headersString) {
1193
1193
  return parsed;
1194
1194
  }
1195
1195
 
1196
- var sendXmlHttpRequest = function sendXmlHttpRequest(path, method, headers, body) {
1196
+ var sendXmlHttpRequest = function sendXmlHttpRequest(path, method, headers, body, encoding, timeout) {
1197
1197
  return new Promise(function sendRequest(resolve, reject) {
1198
1198
  var request = new Request.XMLHttpRequest();
1199
1199
 
1200
+ request.timeout = timeout;
1201
+
1202
+ if (!encoding) {
1203
+ request.responseType = 'arraybuffer';
1204
+ }
1205
+
1200
1206
  request.open(method.toUpperCase(), path, true);
1201
1207
 
1202
1208
  request.onload = function handleLoadEvent() {
1203
1209
  var headers = parseHeaders(request.getAllResponseHeaders());
1204
1210
  var _request = request,
1205
1211
  status = _request.status,
1206
- statusText = _request.statusText,
1207
- response = _request.response,
1208
- responseText = _request.responseText;
1212
+ statusText = _request.statusText;
1209
1213
 
1210
- var body = response || responseText;
1211
1214
 
1212
- resolve({ status: status, statusText: statusText, headers: headers, body: body });
1215
+ var result = { status: status, statusText: statusText, headers: headers };
1216
+
1217
+ if (encoding === 'utf8') {
1218
+ result.body = request.response || request.responseText;
1219
+ } else if (request.response) {
1220
+ result.body = new Uint8Array(request.response);
1221
+ }
1222
+
1223
+ resolve(result);
1213
1224
 
1214
1225
  request = null;
1215
1226
  };
@@ -1234,7 +1245,7 @@ var sendXmlHttpRequest = function sendXmlHttpRequest(path, method, headers, body
1234
1245
  });
1235
1246
  };
1236
1247
 
1237
- var sendNodeAPIRequest = function sendNodeAPIRequest(path, method, headers, body, encoding) {
1248
+ var sendNodeAPIRequest = function sendNodeAPIRequest(path, method, headers, body, encoding, timeout) {
1238
1249
  return new Promise(function (resolve, reject) {
1239
1250
  var u = __webpack_require__(7).parse(path);
1240
1251
  var form = (0, _utils.isFormData)(body) && body;
@@ -1243,9 +1254,10 @@ var sendNodeAPIRequest = function sendNodeAPIRequest(path, method, headers, body
1243
1254
  var options = {
1244
1255
  host: u.hostname,
1245
1256
  port: u.port || (https ? 443 : 80),
1246
- method: method,
1247
1257
  path: u.path,
1248
- headers: headers
1258
+ method: method,
1259
+ headers: headers,
1260
+ timeout: timeout
1249
1261
  };
1250
1262
 
1251
1263
  var _send = function _send() {
@@ -1291,6 +1303,10 @@ var sendNodeAPIRequest = function sendNodeAPIRequest(path, method, headers, body
1291
1303
 
1292
1304
  req.on('error', reject);
1293
1305
 
1306
+ req.on('timeout', function () {
1307
+ req.destroy(new Error('Connection aborted due to timeout'));
1308
+ });
1309
+
1294
1310
  if (body) {
1295
1311
  if ((0, _utils.isStream)(body)) {
1296
1312
  body.pipe(req);
@@ -1361,6 +1377,7 @@ var Request = function (_EventEmitter) {
1361
1377
  _this2.headers = {};
1362
1378
  _this2.queryParams = {};
1363
1379
  _this2.encoding = 'utf8';
1380
+ _this2.timeout = 0;
1364
1381
  return _this2;
1365
1382
  }
1366
1383
 
@@ -1537,6 +1554,20 @@ var Request = function (_EventEmitter) {
1537
1554
  return this;
1538
1555
  }
1539
1556
 
1557
+ /**
1558
+ * A number specifying request timeout in milliseconds.
1559
+ * @param {Number} ms
1560
+ * @returns {Request}
1561
+ */
1562
+
1563
+ }, {
1564
+ key: 'setTimeout',
1565
+ value: function setTimeout(ms) {
1566
+ this.timeout = ms;
1567
+
1568
+ return this;
1569
+ }
1570
+
1540
1571
  /**
1541
1572
  * Sends the requst
1542
1573
  *
@@ -1608,7 +1639,7 @@ var Request = function (_EventEmitter) {
1608
1639
  console.log(this.method.toUpperCase(), decodeURIComponent(path), body, this.headers);
1609
1640
  }
1610
1641
 
1611
- var request = Request.send(path, this.method.toUpperCase(), this.headers, body, this.encoding).then(parseBody).then(checkStatus).then(unwrapBody).then(cacheResponse).then(flushCache);
1642
+ var request = Request.send(path, this.method.toUpperCase(), this.headers, body, this.encoding, this.timeout).then(parseBody).then(checkStatus).then(unwrapBody).then(cacheResponse).then(flushCache);
1612
1643
 
1613
1644
  request.then(function (result) {
1614
1645
  _this4.emit(RESPONSE_EVENT, result);
@@ -1662,10 +1693,10 @@ Object.defineProperty(Request, 'FormData', {
1662
1693
 
1663
1694
  Request.XMLHttpRequest = typeof XMLHttpRequest !== 'undefined' ? XMLHttpRequest : undefined;
1664
1695
 
1665
- Request.send = function (path, method, headers, body, encoding) {
1696
+ Request.send = function (path, method, headers, body, encoding, timeout) {
1666
1697
  var sender = typeof Request.XMLHttpRequest !== 'undefined' ? sendXmlHttpRequest : sendNodeAPIRequest;
1667
1698
 
1668
- return sender(path, method, headers, body, encoding);
1699
+ return sender(path, method, headers, body, encoding, timeout);
1669
1700
  };
1670
1701
 
1671
1702
  Request.verbose = false;
@@ -16673,7 +16704,7 @@ var DataStore = /*#__PURE__*/function () {
16673
16704
  }, {
16674
16705
  key: "parseRelationsResponse",
16675
16706
  value: function parseRelationsResponse(result, RelationModel) {
16676
- return convertToClientRecords(result, RelationModel, this.classToTableMap);
16707
+ return convertToClientRecords(result, RelationModel, this);
16677
16708
  }
16678
16709
  /**
16679
16710
  * @private
@@ -16682,7 +16713,7 @@ var DataStore = /*#__PURE__*/function () {
16682
16713
  }, {
16683
16714
  key: "parseResponse",
16684
16715
  value: function parseResponse(result) {
16685
- return convertToClientRecords(result, this.model, this.classToTableMap);
16716
+ return convertToClientRecords(result, this.model, this);
16686
16717
  }
16687
16718
  /**
16688
16719
  * @private
@@ -16781,14 +16812,15 @@ var convertToServerRecord = function () {
16781
16812
  }();
16782
16813
 
16783
16814
  var convertToClientRecords = function () {
16784
- return function (records, RootModel, classToTableMap) {
16815
+ return function (records, RootModel, dataStore) {
16785
16816
  if (!records) {
16786
16817
  return records;
16787
16818
  }
16788
16819
 
16789
16820
  var context = {
16790
16821
  RootModel: RootModel,
16791
- classToTableMap: classToTableMap,
16822
+ app: dataStore.app,
16823
+ classToTableMap: dataStore.classToTableMap,
16792
16824
  subIds: {},
16793
16825
  postAssign: []
16794
16826
  };
@@ -16806,7 +16838,14 @@ var convertToClientRecords = function () {
16806
16838
  target[prop] = context.subIds[__subID];
16807
16839
  delete source[prop].__subID;
16808
16840
  } else {
16809
- var Model = context.classToTableMap[source[prop].___class] || _utils["default"].globalScope[source[prop].___class];
16841
+ var Model = context.classToTableMap[source[prop].___class];
16842
+
16843
+ if (!Model && context.app.useTableClassesFromGlobalScope && _utils["default"].globalScope[source[prop].___class]) {
16844
+ // eslint-disable-next-line no-console
16845
+ console.warn('Resolving DataTable classes from the global scope is deprecated ' + 'and it won\'t be supported in the nearest future. ' + 'Instead, you should register your DataTable classes ' + 'using the following method Backendless.Data.mapTableToClass');
16846
+ Model = _utils["default"].globalScope[source[prop].___class];
16847
+ }
16848
+
16810
16849
  target[prop] = Model ? new Model() : {};
16811
16850
 
16812
16851
  if (__subID && !context.subIds[__subID]) {
@@ -17817,7 +17856,10 @@ var DEFAULT_PROPS = {
17817
17856
  apiURI: '/api',
17818
17857
  debugMode: false,
17819
17858
  standalone: false,
17820
- XMLHttpRequest: typeof XMLHttpRequest !== 'undefined' ? XMLHttpRequest : undefined
17859
+ XMLHttpRequest: typeof XMLHttpRequest !== 'undefined' ? XMLHttpRequest : undefined,
17860
+ //TODO: this is a temporary to disable getting DataTable classes from the global scope
17861
+ //TODO: it will be removed in the nearest future
17862
+ useTableClassesFromGlobalScope: true
17821
17863
  };
17822
17864
  var STATELESS_PROPS = ['appId', 'apiKey', 'domain'];
17823
17865
  var root = (typeof self === "undefined" ? "undefined" : (0, _typeof2["default"])(self)) === 'object' && self.self === self && self || (typeof global === "undefined" ? "undefined" : (0, _typeof2["default"])(global)) === 'object' && global.global === global && global;
@@ -18060,6 +18102,15 @@ var Backendless = /*#__PURE__*/function () {
18060
18102
  },
18061
18103
  set: function set(appPath) {
18062
18104
  throw new Error("Setting '".concat(appPath, "' value to Backendless.appPath directly is not possible, ") + 'instead you must use Backendless.initApp(APP_ID, API_KEY) for setup the value');
18105
+ } ///--------useTableClassesFromGlobalScope-------///
18106
+
18107
+ }, {
18108
+ key: "useTableClassesFromGlobalScope",
18109
+ get: function get() {
18110
+ return this.__useTableClassesFromGlobalScope;
18111
+ },
18112
+ set: function set(useTableClassesFromGlobalScope) {
18113
+ this.__useTableClassesFromGlobalScope = !!useTableClassesFromGlobalScope;
18063
18114
  } ///--------debugMode-------///
18064
18115
 
18065
18116
  }, {
@@ -22228,8 +22279,8 @@ var Urls = /*#__PURE__*/function () {
22228
22279
  }
22229
22280
  }, {
22230
22281
  key: "userRoles",
22231
- value: function userRoles() {
22232
- return "".concat(this.users(), "/userroles");
22282
+ value: function userRoles(userId) {
22283
+ return "".concat(this.users(), "/userroles").concat(userId ? "/".concat(userId) : '');
22233
22284
  }
22234
22285
  }, {
22235
22286
  key: "usersRole",
@@ -23128,12 +23179,12 @@ var Users = /*#__PURE__*/function () {
23128
23179
  }, {
23129
23180
  key: "getUserRoles",
23130
23181
  value: function () {
23131
- var _getUserRoles = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee20() {
23182
+ var _getUserRoles = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee20(userId) {
23132
23183
  return _regenerator["default"].wrap(function _callee20$(_context20) {
23133
23184
  while (1) {
23134
23185
  switch (_context20.prev = _context20.next) {
23135
23186
  case 0:
23136
- return _context20.abrupt("return", this.roles.getUserRoles());
23187
+ return _context20.abrupt("return", this.roles.getUserRoles(userId));
23137
23188
 
23138
23189
  case 1:
23139
23190
  case "end":
@@ -23143,7 +23194,7 @@ var Users = /*#__PURE__*/function () {
23143
23194
  }, _callee20, this);
23144
23195
  }));
23145
23196
 
23146
- function getUserRoles() {
23197
+ function getUserRoles(_x42) {
23147
23198
  return _getUserRoles.apply(this, arguments);
23148
23199
  }
23149
23200
 
@@ -23167,7 +23218,7 @@ var Users = /*#__PURE__*/function () {
23167
23218
  }, _callee21, this);
23168
23219
  }));
23169
23220
 
23170
- function assignRole(_x42, _x43) {
23221
+ function assignRole(_x43, _x44) {
23171
23222
  return _assignRole.apply(this, arguments);
23172
23223
  }
23173
23224
 
@@ -23191,7 +23242,7 @@ var Users = /*#__PURE__*/function () {
23191
23242
  }, _callee22, this);
23192
23243
  }));
23193
23244
 
23194
- function unassignRole(_x44, _x45) {
23245
+ function unassignRole(_x45, _x46) {
23195
23246
  return _unassignRole.apply(this, arguments);
23196
23247
  }
23197
23248
 
@@ -23241,7 +23292,7 @@ var Users = /*#__PURE__*/function () {
23241
23292
  }, _callee24, this);
23242
23293
  }));
23243
23294
 
23244
- function enableUser(_x46) {
23295
+ function enableUser(_x47) {
23245
23296
  return _enableUser.apply(this, arguments);
23246
23297
  }
23247
23298
 
@@ -23265,7 +23316,7 @@ var Users = /*#__PURE__*/function () {
23265
23316
  }, _callee25, this);
23266
23317
  }));
23267
23318
 
23268
- function disableUser(_x47) {
23319
+ function disableUser(_x48) {
23269
23320
  return _disableUser.apply(this, arguments);
23270
23321
  }
23271
23322
 
@@ -23310,7 +23361,7 @@ var Users = /*#__PURE__*/function () {
23310
23361
  }, _callee26, this);
23311
23362
  }));
23312
23363
 
23313
- function updateUserStatus(_x48, _x49) {
23364
+ function updateUserStatus(_x49, _x50) {
23314
23365
  return _updateUserStatus.apply(this, arguments);
23315
23366
  }
23316
23367
 
@@ -23500,13 +23551,13 @@ var UsersRoles = /*#__PURE__*/function () {
23500
23551
  }, {
23501
23552
  key: "getUserRoles",
23502
23553
  value: function () {
23503
- var _getUserRoles = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
23554
+ var _getUserRoles = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(userId) {
23504
23555
  return _regenerator["default"].wrap(function _callee2$(_context2) {
23505
23556
  while (1) {
23506
23557
  switch (_context2.prev = _context2.next) {
23507
23558
  case 0:
23508
23559
  return _context2.abrupt("return", this.app.request.get({
23509
- url: this.app.urls.userRoles()
23560
+ url: this.app.urls.userRoles(userId)
23510
23561
  }));
23511
23562
 
23512
23563
  case 1:
@@ -23517,7 +23568,7 @@ var UsersRoles = /*#__PURE__*/function () {
23517
23568
  }, _callee2, this);
23518
23569
  }));
23519
23570
 
23520
- function getUserRoles() {
23571
+ function getUserRoles(_x4) {
23521
23572
  return _getUserRoles.apply(this, arguments);
23522
23573
  }
23523
23574
 
@@ -23541,7 +23592,7 @@ var UsersRoles = /*#__PURE__*/function () {
23541
23592
  }, _callee3, this);
23542
23593
  }));
23543
23594
 
23544
- function assignRole(_x4, _x5) {
23595
+ function assignRole(_x5, _x6) {
23545
23596
  return _assignRole.apply(this, arguments);
23546
23597
  }
23547
23598
 
@@ -23565,7 +23616,7 @@ var UsersRoles = /*#__PURE__*/function () {
23565
23616
  }, _callee4, this);
23566
23617
  }));
23567
23618
 
23568
- function unassignRole(_x6, _x7) {
23619
+ function unassignRole(_x7, _x8) {
23569
23620
  return _unassignRole.apply(this, arguments);
23570
23621
  }
23571
23622
 
@@ -23611,7 +23662,7 @@ var UsersRoles = /*#__PURE__*/function () {
23611
23662
  }, _callee5, this);
23612
23663
  }));
23613
23664
 
23614
- function changeRole(_x8, _x9, _x10) {
23665
+ function changeRole(_x9, _x10, _x11) {
23615
23666
  return _changeRole.apply(this, arguments);
23616
23667
  }
23617
23668