cozy-client 59.0.0 → 59.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CozyClient.js +434 -313
- package/dist/links/StackLink.js +14 -11
- package/dist/queries/dsl.js +31 -1
- package/dist/store/queries.js +5 -1
- package/dist/store/queries.spec.js +27 -1
- package/dist/types.js +3 -3
- package/package.json +2 -2
- package/types/CozyClient.d.ts +56 -22
- package/types/queries/dsl.d.ts +14 -0
- package/types/store/queries.d.ts +1 -0
- package/types/types.d.ts +12 -3
package/dist/CozyClient.js
CHANGED
|
@@ -766,6 +766,11 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
766
766
|
id: id
|
|
767
767
|
});
|
|
768
768
|
}
|
|
769
|
+
}, {
|
|
770
|
+
key: "validate",
|
|
771
|
+
value: function validate(document) {
|
|
772
|
+
return this.schema.validate(document);
|
|
773
|
+
}
|
|
769
774
|
/**
|
|
770
775
|
* Creates a document and saves it on the server
|
|
771
776
|
*
|
|
@@ -841,39 +846,71 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
841
846
|
|
|
842
847
|
return create;
|
|
843
848
|
}()
|
|
849
|
+
/**
|
|
850
|
+
* Create multiple documents in one batch.
|
|
851
|
+
* WARNING: this method is currently not supported by the stack, but
|
|
852
|
+
* works with PouchDB
|
|
853
|
+
*
|
|
854
|
+
* @param {import("./types").CozyClientDocument[]} docs - Documents to create. Should not have _id nor _rev
|
|
855
|
+
* @param {object} [options] - options
|
|
856
|
+
* @returns {Promise}
|
|
857
|
+
*/
|
|
858
|
+
|
|
844
859
|
}, {
|
|
845
|
-
key: "
|
|
846
|
-
value: function
|
|
847
|
-
|
|
848
|
-
|
|
860
|
+
key: "createAll",
|
|
861
|
+
value: function () {
|
|
862
|
+
var _createAll = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(docs) {
|
|
863
|
+
var options,
|
|
864
|
+
_args5 = arguments;
|
|
865
|
+
return _regenerator.default.wrap(function _callee5$(_context5) {
|
|
866
|
+
while (1) {
|
|
867
|
+
switch (_context5.prev = _context5.next) {
|
|
868
|
+
case 0:
|
|
869
|
+
options = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : {};
|
|
870
|
+
return _context5.abrupt("return", this.saveAll(docs, options));
|
|
871
|
+
|
|
872
|
+
case 2:
|
|
873
|
+
case "end":
|
|
874
|
+
return _context5.stop();
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
}, _callee5, this);
|
|
878
|
+
}));
|
|
879
|
+
|
|
880
|
+
function createAll(_x6) {
|
|
881
|
+
return _createAll.apply(this, arguments);
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
return createAll;
|
|
885
|
+
}()
|
|
849
886
|
/**
|
|
850
|
-
* Create or update a document
|
|
887
|
+
* Create or update a document
|
|
851
888
|
*
|
|
852
889
|
* @param {object} doc - Document to save
|
|
853
|
-
* @param
|
|
890
|
+
* @param {object} [options] - options
|
|
854
891
|
* @returns {Promise}
|
|
855
892
|
*/
|
|
856
893
|
|
|
857
894
|
}, {
|
|
858
895
|
key: "save",
|
|
859
896
|
value: function () {
|
|
860
|
-
var _save = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
861
|
-
var
|
|
897
|
+
var _save = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(doc) {
|
|
898
|
+
var options,
|
|
862
899
|
_type,
|
|
863
900
|
attributes,
|
|
864
901
|
normalizedDoc,
|
|
865
902
|
ret,
|
|
866
|
-
|
|
903
|
+
_args6 = arguments;
|
|
867
904
|
|
|
868
|
-
return _regenerator.default.wrap(function
|
|
905
|
+
return _regenerator.default.wrap(function _callee6$(_context6) {
|
|
869
906
|
while (1) {
|
|
870
|
-
switch (
|
|
907
|
+
switch (_context6.prev = _context6.next) {
|
|
871
908
|
case 0:
|
|
872
|
-
|
|
909
|
+
options = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : {};
|
|
873
910
|
_type = doc._type, attributes = (0, _objectWithoutProperties2.default)(doc, ["_type"]);
|
|
874
911
|
|
|
875
912
|
if (_type) {
|
|
876
|
-
|
|
913
|
+
_context6.next = 4;
|
|
877
914
|
break;
|
|
878
915
|
}
|
|
879
916
|
|
|
@@ -883,92 +920,129 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
883
920
|
normalizedDoc = _objectSpread({
|
|
884
921
|
_type: _type
|
|
885
922
|
}, attributes);
|
|
886
|
-
|
|
923
|
+
_context6.next = 7;
|
|
887
924
|
return this.schema.validate(normalizedDoc);
|
|
888
925
|
|
|
889
926
|
case 7:
|
|
890
|
-
ret =
|
|
927
|
+
ret = _context6.sent;
|
|
891
928
|
|
|
892
929
|
if (!(ret !== true)) {
|
|
893
|
-
|
|
930
|
+
_context6.next = 10;
|
|
894
931
|
break;
|
|
895
932
|
}
|
|
896
933
|
|
|
897
934
|
throw new Error('Validation failed');
|
|
898
935
|
|
|
899
936
|
case 10:
|
|
900
|
-
return
|
|
937
|
+
return _context6.abrupt("return", this.mutate(this.getDocumentSavePlan(normalizedDoc), options));
|
|
901
938
|
|
|
902
939
|
case 11:
|
|
903
940
|
case "end":
|
|
904
|
-
return
|
|
941
|
+
return _context6.stop();
|
|
905
942
|
}
|
|
906
943
|
}
|
|
907
|
-
},
|
|
944
|
+
}, _callee6, this);
|
|
908
945
|
}));
|
|
909
946
|
|
|
910
|
-
function save(
|
|
947
|
+
function save(_x7) {
|
|
911
948
|
return _save.apply(this, arguments);
|
|
912
949
|
}
|
|
913
950
|
|
|
914
951
|
return save;
|
|
915
952
|
}()
|
|
916
953
|
/**
|
|
917
|
-
*
|
|
954
|
+
* Updates multiple documents in one batch. Should have _id and _rev
|
|
955
|
+
*
|
|
956
|
+
* @param {import("./types").CozyClientDocument[]} docs - Documents from the same doctype
|
|
957
|
+
* @param {object} [options] - options
|
|
958
|
+
* @returns {Promise<void>}
|
|
959
|
+
*/
|
|
960
|
+
|
|
961
|
+
}, {
|
|
962
|
+
key: "updateAll",
|
|
963
|
+
value: function () {
|
|
964
|
+
var _updateAll = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee7(docs) {
|
|
965
|
+
var options,
|
|
966
|
+
_args7 = arguments;
|
|
967
|
+
return _regenerator.default.wrap(function _callee7$(_context7) {
|
|
968
|
+
while (1) {
|
|
969
|
+
switch (_context7.prev = _context7.next) {
|
|
970
|
+
case 0:
|
|
971
|
+
options = _args7.length > 1 && _args7[1] !== undefined ? _args7[1] : {};
|
|
972
|
+
return _context7.abrupt("return", this.saveAll(docs, options));
|
|
973
|
+
|
|
974
|
+
case 2:
|
|
975
|
+
case "end":
|
|
976
|
+
return _context7.stop();
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
}, _callee7, this);
|
|
980
|
+
}));
|
|
981
|
+
|
|
982
|
+
function updateAll(_x8) {
|
|
983
|
+
return _updateAll.apply(this, arguments);
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
return updateAll;
|
|
987
|
+
}()
|
|
988
|
+
/**
|
|
989
|
+
* Create or update multiple documents in one batch
|
|
918
990
|
* - Can only be called with documents from the same doctype
|
|
991
|
+
* - Can either be creation (no _id nor _rev) or update, not both
|
|
919
992
|
* - Does not support automatic creation of references
|
|
920
993
|
*
|
|
994
|
+
* WARNING: multiple creations is currently not supported by the stack, but
|
|
995
|
+
* works with PouchDB
|
|
996
|
+
*
|
|
921
997
|
* @param {import("./types").CozyClientDocument[]} docs - Documents from the same doctype
|
|
922
|
-
* @param
|
|
923
|
-
* @param {string} [mutationOptions.as] - Mutation id
|
|
924
|
-
* @param {Function} [mutationOptions.update] - Function to update the document
|
|
925
|
-
* @param {Function} [mutationOptions.updateQueries] - Function to update queries
|
|
998
|
+
* @param {object} [options] - options
|
|
926
999
|
* @returns {Promise<void>}
|
|
927
1000
|
*/
|
|
928
1001
|
|
|
929
1002
|
}, {
|
|
930
1003
|
key: "saveAll",
|
|
931
1004
|
value: function () {
|
|
932
|
-
var _saveAll = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
1005
|
+
var _saveAll = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee8(docs) {
|
|
933
1006
|
var _this2 = this;
|
|
934
1007
|
|
|
935
|
-
var
|
|
1008
|
+
var options,
|
|
936
1009
|
doctypes,
|
|
937
1010
|
validations,
|
|
938
1011
|
errors,
|
|
939
1012
|
toSaveDocs,
|
|
1013
|
+
isCreation,
|
|
940
1014
|
mutation,
|
|
941
|
-
|
|
942
|
-
return _regenerator.default.wrap(function
|
|
1015
|
+
_args8 = arguments;
|
|
1016
|
+
return _regenerator.default.wrap(function _callee8$(_context8) {
|
|
943
1017
|
while (1) {
|
|
944
|
-
switch (
|
|
1018
|
+
switch (_context8.prev = _context8.next) {
|
|
945
1019
|
case 0:
|
|
946
|
-
|
|
1020
|
+
options = _args8.length > 1 && _args8[1] !== undefined ? _args8[1] : {};
|
|
947
1021
|
doctypes = Array.from(new Set(docs.map(function (x) {
|
|
948
1022
|
return x._type;
|
|
949
1023
|
})));
|
|
950
1024
|
|
|
951
1025
|
if (!(doctypes.length !== 1)) {
|
|
952
|
-
|
|
1026
|
+
_context8.next = 4;
|
|
953
1027
|
break;
|
|
954
1028
|
}
|
|
955
1029
|
|
|
956
1030
|
throw new Error('saveAll can only save documents with the same doctype');
|
|
957
1031
|
|
|
958
1032
|
case 4:
|
|
959
|
-
|
|
1033
|
+
_context8.next = 6;
|
|
960
1034
|
return Promise.all(docs.map(function (d) {
|
|
961
1035
|
return _this2.schema.validate(d);
|
|
962
1036
|
}));
|
|
963
1037
|
|
|
964
1038
|
case 6:
|
|
965
|
-
validations =
|
|
1039
|
+
validations = _context8.sent;
|
|
966
1040
|
errors = validations.filter(function (validation) {
|
|
967
1041
|
return validation !== true;
|
|
968
1042
|
});
|
|
969
1043
|
|
|
970
1044
|
if (!(errors.length > 0)) {
|
|
971
|
-
|
|
1045
|
+
_context8.next = 11;
|
|
972
1046
|
break;
|
|
973
1047
|
}
|
|
974
1048
|
|
|
@@ -980,18 +1054,19 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
980
1054
|
toSaveDocs = docs.map(function (d) {
|
|
981
1055
|
return _this2.prepareDocumentForSave(d);
|
|
982
1056
|
});
|
|
983
|
-
|
|
984
|
-
|
|
1057
|
+
isCreation = docs[0]._id === undefined;
|
|
1058
|
+
mutation = isCreation ? _dsl.Mutations.createDocuments(toSaveDocs) : _dsl.Mutations.updateDocuments(toSaveDocs);
|
|
1059
|
+
return _context8.abrupt("return", this.mutate(mutation, options));
|
|
985
1060
|
|
|
986
|
-
case
|
|
1061
|
+
case 15:
|
|
987
1062
|
case "end":
|
|
988
|
-
return
|
|
1063
|
+
return _context8.stop();
|
|
989
1064
|
}
|
|
990
1065
|
}
|
|
991
|
-
},
|
|
1066
|
+
}, _callee8, this);
|
|
992
1067
|
}));
|
|
993
1068
|
|
|
994
|
-
function saveAll(
|
|
1069
|
+
function saveAll(_x9) {
|
|
995
1070
|
return _saveAll.apply(this, arguments);
|
|
996
1071
|
}
|
|
997
1072
|
|
|
@@ -1186,55 +1261,100 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
1186
1261
|
* Destroys a document. {before,after}:destroy hooks will be fired.
|
|
1187
1262
|
*
|
|
1188
1263
|
* @param {import("./types").CozyClientDocument} document - Document to be deleted
|
|
1264
|
+
* @param {object} [options] - options
|
|
1189
1265
|
* @returns {Promise<import("./types").CozyClientDocument>} The document that has been deleted
|
|
1190
1266
|
*/
|
|
1191
1267
|
|
|
1192
1268
|
}, {
|
|
1193
1269
|
key: "destroy",
|
|
1194
1270
|
value: function () {
|
|
1195
|
-
var _destroy = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
1196
|
-
var
|
|
1271
|
+
var _destroy = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee9(document) {
|
|
1272
|
+
var options,
|
|
1197
1273
|
res,
|
|
1198
|
-
|
|
1199
|
-
return _regenerator.default.wrap(function
|
|
1274
|
+
_args9 = arguments;
|
|
1275
|
+
return _regenerator.default.wrap(function _callee9$(_context9) {
|
|
1200
1276
|
while (1) {
|
|
1201
|
-
switch (
|
|
1277
|
+
switch (_context9.prev = _context9.next) {
|
|
1202
1278
|
case 0:
|
|
1203
|
-
|
|
1204
|
-
|
|
1279
|
+
options = _args9.length > 1 && _args9[1] !== undefined ? _args9[1] : {};
|
|
1280
|
+
_context9.next = 3;
|
|
1205
1281
|
return this.triggerHook('before:destroy', document);
|
|
1206
1282
|
|
|
1207
1283
|
case 3:
|
|
1208
|
-
|
|
1209
|
-
return this.mutate(_dsl.Mutations.deleteDocument(document),
|
|
1284
|
+
_context9.next = 5;
|
|
1285
|
+
return this.mutate(_dsl.Mutations.deleteDocument(document), options);
|
|
1210
1286
|
|
|
1211
1287
|
case 5:
|
|
1212
|
-
res =
|
|
1213
|
-
|
|
1288
|
+
res = _context9.sent;
|
|
1289
|
+
_context9.next = 8;
|
|
1214
1290
|
return this.triggerHook('after:destroy', document);
|
|
1215
1291
|
|
|
1216
1292
|
case 8:
|
|
1217
|
-
return
|
|
1293
|
+
return _context9.abrupt("return", res);
|
|
1218
1294
|
|
|
1219
1295
|
case 9:
|
|
1220
1296
|
case "end":
|
|
1221
|
-
return
|
|
1297
|
+
return _context9.stop();
|
|
1222
1298
|
}
|
|
1223
1299
|
}
|
|
1224
|
-
},
|
|
1300
|
+
}, _callee9, this);
|
|
1225
1301
|
}));
|
|
1226
1302
|
|
|
1227
|
-
function destroy(
|
|
1303
|
+
function destroy(_x10) {
|
|
1228
1304
|
return _destroy.apply(this, arguments);
|
|
1229
1305
|
}
|
|
1230
1306
|
|
|
1231
1307
|
return destroy;
|
|
1232
1308
|
}()
|
|
1309
|
+
/**
|
|
1310
|
+
* Destroy multiple documents
|
|
1311
|
+
*
|
|
1312
|
+
* @param {Array<import("./types").CozyClientDocument>} documents - Documents to be deleted
|
|
1313
|
+
* @param {object} [options] - options
|
|
1314
|
+
* @returns {Promise<Array<import("./types").CozyClientDocument>>} The deleted documents
|
|
1315
|
+
*/
|
|
1316
|
+
|
|
1317
|
+
}, {
|
|
1318
|
+
key: "destroyAll",
|
|
1319
|
+
value: function () {
|
|
1320
|
+
var _destroyAll = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee10(documents) {
|
|
1321
|
+
var options,
|
|
1322
|
+
_args10 = arguments;
|
|
1323
|
+
return _regenerator.default.wrap(function _callee10$(_context10) {
|
|
1324
|
+
while (1) {
|
|
1325
|
+
switch (_context10.prev = _context10.next) {
|
|
1326
|
+
case 0:
|
|
1327
|
+
options = _args10.length > 1 && _args10[1] !== undefined ? _args10[1] : {};
|
|
1328
|
+
return _context10.abrupt("return", this.mutate(_dsl.Mutations.deleteDocuments(documents), options));
|
|
1329
|
+
|
|
1330
|
+
case 2:
|
|
1331
|
+
case "end":
|
|
1332
|
+
return _context10.stop();
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
}, _callee10, this);
|
|
1336
|
+
}));
|
|
1337
|
+
|
|
1338
|
+
function destroyAll(_x11) {
|
|
1339
|
+
return _destroyAll.apply(this, arguments);
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
return destroyAll;
|
|
1343
|
+
}()
|
|
1344
|
+
/**
|
|
1345
|
+
* Upload a file
|
|
1346
|
+
*
|
|
1347
|
+
* @param {File|Blob|import('cozy-stack-client/dist/FileCollection').Stream|string|ArrayBuffer} file - File to be uploaded
|
|
1348
|
+
* @param {string} dirPath - Path to upload the file to. ie : /Administative/XXX/
|
|
1349
|
+
* @param {object} [options] - Optionnal request options
|
|
1350
|
+
* @returns {Promise<object>} Created io.cozy.files
|
|
1351
|
+
*/
|
|
1352
|
+
|
|
1233
1353
|
}, {
|
|
1234
1354
|
key: "upload",
|
|
1235
1355
|
value: function upload(file, dirPath) {
|
|
1236
|
-
var
|
|
1237
|
-
return this.mutate(_dsl.Mutations.uploadFile(file, dirPath),
|
|
1356
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1357
|
+
return this.mutate(_dsl.Mutations.uploadFile(file, dirPath), options);
|
|
1238
1358
|
}
|
|
1239
1359
|
/**
|
|
1240
1360
|
* Makes sure that the query exists in the store
|
|
@@ -1273,7 +1393,7 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
1273
1393
|
}, {
|
|
1274
1394
|
key: "query",
|
|
1275
1395
|
value: function () {
|
|
1276
|
-
var _query = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
1396
|
+
var _query = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee11(queryDefinition) {
|
|
1277
1397
|
var _this4 = this;
|
|
1278
1398
|
|
|
1279
1399
|
var _ref5,
|
|
@@ -1287,13 +1407,13 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
1287
1407
|
backgroundFetching,
|
|
1288
1408
|
requestFn,
|
|
1289
1409
|
response,
|
|
1290
|
-
|
|
1410
|
+
_args11 = arguments;
|
|
1291
1411
|
|
|
1292
|
-
return _regenerator.default.wrap(function
|
|
1412
|
+
return _regenerator.default.wrap(function _callee11$(_context11) {
|
|
1293
1413
|
while (1) {
|
|
1294
|
-
switch (
|
|
1414
|
+
switch (_context11.prev = _context11.next) {
|
|
1295
1415
|
case 0:
|
|
1296
|
-
_ref5 =
|
|
1416
|
+
_ref5 = _args11.length > 1 && _args11[1] !== undefined ? _args11[1] : {};
|
|
1297
1417
|
update = _ref5.update, executeFromStore = _ref5.executeFromStore, options = (0, _objectWithoutProperties2.default)(_ref5, ["update", "executeFromStore"]);
|
|
1298
1418
|
markQuery = this.performanceApi.mark("client.query(".concat(queryDefinition.doctype, ")"));
|
|
1299
1419
|
this.ensureStore();
|
|
@@ -1301,12 +1421,12 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
1301
1421
|
existingQuery = this.disableStoreForQueries ? null : this.getQueryFromState(queryId, options);
|
|
1302
1422
|
|
|
1303
1423
|
if (!(options.enabled !== undefined)) {
|
|
1304
|
-
|
|
1424
|
+
_context11.next = 9;
|
|
1305
1425
|
break;
|
|
1306
1426
|
}
|
|
1307
1427
|
|
|
1308
1428
|
if (!('boolean' !== typeof options.enabled)) {
|
|
1309
|
-
|
|
1429
|
+
_context11.next = 9;
|
|
1310
1430
|
break;
|
|
1311
1431
|
}
|
|
1312
1432
|
|
|
@@ -1314,12 +1434,12 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
1314
1434
|
|
|
1315
1435
|
case 9:
|
|
1316
1436
|
if (!options.fetchPolicy) {
|
|
1317
|
-
|
|
1437
|
+
_context11.next = 15;
|
|
1318
1438
|
break;
|
|
1319
1439
|
}
|
|
1320
1440
|
|
|
1321
1441
|
if (options.as) {
|
|
1322
|
-
|
|
1442
|
+
_context11.next = 12;
|
|
1323
1443
|
break;
|
|
1324
1444
|
}
|
|
1325
1445
|
|
|
@@ -1329,24 +1449,24 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
1329
1449
|
shouldFetch = options.fetchPolicy(existingQuery);
|
|
1330
1450
|
|
|
1331
1451
|
if (shouldFetch) {
|
|
1332
|
-
|
|
1452
|
+
_context11.next = 15;
|
|
1333
1453
|
break;
|
|
1334
1454
|
}
|
|
1335
1455
|
|
|
1336
|
-
return
|
|
1456
|
+
return _context11.abrupt("return");
|
|
1337
1457
|
|
|
1338
1458
|
case 15:
|
|
1339
1459
|
if (!(existingQuery && Object.keys(existingQuery).length > 0)) {
|
|
1340
|
-
|
|
1460
|
+
_context11.next = 18;
|
|
1341
1461
|
break;
|
|
1342
1462
|
}
|
|
1343
1463
|
|
|
1344
1464
|
if (!(existingQuery.fetchStatus === 'loading')) {
|
|
1345
|
-
|
|
1465
|
+
_context11.next = 18;
|
|
1346
1466
|
break;
|
|
1347
1467
|
}
|
|
1348
1468
|
|
|
1349
|
-
return
|
|
1469
|
+
return _context11.abrupt("return", this._promiseCache.get(function () {
|
|
1350
1470
|
return (0, _jsonStableStringify.default)(queryDefinition);
|
|
1351
1471
|
}));
|
|
1352
1472
|
|
|
@@ -1355,7 +1475,7 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
1355
1475
|
this.ensureQueryExists(queryId, queryDefinition, options);
|
|
1356
1476
|
}
|
|
1357
1477
|
|
|
1358
|
-
|
|
1478
|
+
_context11.prev = 19;
|
|
1359
1479
|
backgroundFetching = options.backgroundFetching !== undefined ? options.backgroundFetching : this.options.backgroundFetching;
|
|
1360
1480
|
|
|
1361
1481
|
if (!this.disableStoreForQueries) {
|
|
@@ -1369,20 +1489,20 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
1369
1489
|
} : function () {
|
|
1370
1490
|
return _this4.requestQuery(queryDefinition, options);
|
|
1371
1491
|
};
|
|
1372
|
-
|
|
1492
|
+
_context11.next = 25;
|
|
1373
1493
|
return this._promiseCache.exec(requestFn, function () {
|
|
1374
1494
|
return (0, _jsonStableStringify.default)(queryDefinition);
|
|
1375
1495
|
});
|
|
1376
1496
|
|
|
1377
1497
|
case 25:
|
|
1378
|
-
response =
|
|
1498
|
+
response = _context11.sent;
|
|
1379
1499
|
|
|
1380
1500
|
if (!this.disableStoreForQueries) {
|
|
1381
|
-
|
|
1501
|
+
_context11.next = 28;
|
|
1382
1502
|
break;
|
|
1383
1503
|
}
|
|
1384
1504
|
|
|
1385
|
-
return
|
|
1505
|
+
return _context11.abrupt("return", response);
|
|
1386
1506
|
|
|
1387
1507
|
case 28:
|
|
1388
1508
|
this.dispatch((0, _store.receiveQueryResult)(queryId, response, {
|
|
@@ -1394,50 +1514,50 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
1394
1514
|
measureName: "".concat(markQuery, " success"),
|
|
1395
1515
|
color: 'primary'
|
|
1396
1516
|
});
|
|
1397
|
-
return
|
|
1517
|
+
return _context11.abrupt("return", response);
|
|
1398
1518
|
|
|
1399
1519
|
case 33:
|
|
1400
|
-
|
|
1401
|
-
|
|
1520
|
+
_context11.prev = 33;
|
|
1521
|
+
_context11.t0 = _context11["catch"](19);
|
|
1402
1522
|
this.performanceApi.measure({
|
|
1403
1523
|
markName: markQuery,
|
|
1404
1524
|
measureName: "".concat(markQuery, " error"),
|
|
1405
1525
|
color: 'error'
|
|
1406
1526
|
});
|
|
1407
|
-
this.dispatch((0, _store.receiveQueryError)(queryId,
|
|
1527
|
+
this.dispatch((0, _store.receiveQueryError)(queryId, _context11.t0)); // specific onError
|
|
1408
1528
|
|
|
1409
1529
|
if (!options.onError) {
|
|
1410
|
-
|
|
1530
|
+
_context11.next = 41;
|
|
1411
1531
|
break;
|
|
1412
1532
|
}
|
|
1413
1533
|
|
|
1414
|
-
options.onError(
|
|
1534
|
+
options.onError(_context11.t0); // defaulted onError
|
|
1415
1535
|
|
|
1416
|
-
|
|
1536
|
+
_context11.next = 46;
|
|
1417
1537
|
break;
|
|
1418
1538
|
|
|
1419
1539
|
case 41:
|
|
1420
1540
|
if (!this.options.onError) {
|
|
1421
|
-
|
|
1541
|
+
_context11.next = 45;
|
|
1422
1542
|
break;
|
|
1423
1543
|
}
|
|
1424
1544
|
|
|
1425
|
-
this.options.onError(
|
|
1426
|
-
|
|
1545
|
+
this.options.onError(_context11.t0);
|
|
1546
|
+
_context11.next = 46;
|
|
1427
1547
|
break;
|
|
1428
1548
|
|
|
1429
1549
|
case 45:
|
|
1430
|
-
throw
|
|
1550
|
+
throw _context11.t0;
|
|
1431
1551
|
|
|
1432
1552
|
case 46:
|
|
1433
1553
|
case "end":
|
|
1434
|
-
return
|
|
1554
|
+
return _context11.stop();
|
|
1435
1555
|
}
|
|
1436
1556
|
}
|
|
1437
|
-
},
|
|
1557
|
+
}, _callee11, this, [[19, 33]]);
|
|
1438
1558
|
}));
|
|
1439
1559
|
|
|
1440
|
-
function query(
|
|
1560
|
+
function query(_x12) {
|
|
1441
1561
|
return _query.apply(this, arguments);
|
|
1442
1562
|
}
|
|
1443
1563
|
|
|
@@ -1456,83 +1576,83 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
1456
1576
|
}, {
|
|
1457
1577
|
key: "queryAll",
|
|
1458
1578
|
value: function () {
|
|
1459
|
-
var _queryAll = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
1579
|
+
var _queryAll = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee12(queryDefinition) {
|
|
1460
1580
|
var options,
|
|
1461
1581
|
queryId,
|
|
1462
1582
|
mergedOptions,
|
|
1463
1583
|
resp,
|
|
1464
1584
|
documents,
|
|
1465
1585
|
currentResult,
|
|
1466
|
-
|
|
1467
|
-
return _regenerator.default.wrap(function
|
|
1586
|
+
_args12 = arguments;
|
|
1587
|
+
return _regenerator.default.wrap(function _callee12$(_context12) {
|
|
1468
1588
|
while (1) {
|
|
1469
|
-
switch (
|
|
1589
|
+
switch (_context12.prev = _context12.next) {
|
|
1470
1590
|
case 0:
|
|
1471
|
-
options =
|
|
1591
|
+
options = _args12.length > 1 && _args12[1] !== undefined ? _args12[1] : {};
|
|
1472
1592
|
queryId = options.as || this.queryIdGenerator.generateId(queryDefinition);
|
|
1473
1593
|
mergedOptions = _objectSpread(_objectSpread({}, options), {}, {
|
|
1474
1594
|
as: queryId
|
|
1475
1595
|
});
|
|
1476
|
-
|
|
1477
|
-
|
|
1596
|
+
_context12.prev = 3;
|
|
1597
|
+
_context12.next = 6;
|
|
1478
1598
|
return this.query(queryDefinition, mergedOptions);
|
|
1479
1599
|
|
|
1480
1600
|
case 6:
|
|
1481
|
-
resp =
|
|
1601
|
+
resp = _context12.sent;
|
|
1482
1602
|
documents = resp.data;
|
|
1483
1603
|
|
|
1484
1604
|
case 8:
|
|
1485
1605
|
if (!(resp && resp.next)) {
|
|
1486
|
-
|
|
1606
|
+
_context12.next = 22;
|
|
1487
1607
|
break;
|
|
1488
1608
|
}
|
|
1489
1609
|
|
|
1490
1610
|
if (!resp.bookmark) {
|
|
1491
|
-
|
|
1611
|
+
_context12.next = 15;
|
|
1492
1612
|
break;
|
|
1493
1613
|
}
|
|
1494
1614
|
|
|
1495
|
-
|
|
1615
|
+
_context12.next = 12;
|
|
1496
1616
|
return this.query(queryDefinition.offsetBookmark(resp.bookmark), mergedOptions);
|
|
1497
1617
|
|
|
1498
1618
|
case 12:
|
|
1499
|
-
resp =
|
|
1500
|
-
|
|
1619
|
+
resp = _context12.sent;
|
|
1620
|
+
_context12.next = 19;
|
|
1501
1621
|
break;
|
|
1502
1622
|
|
|
1503
1623
|
case 15:
|
|
1504
1624
|
currentResult = (0, _store.getRawQueryFromState)(this.store.getState(), queryId);
|
|
1505
|
-
|
|
1625
|
+
_context12.next = 18;
|
|
1506
1626
|
return this.query(queryDefinition.offset(currentResult.data.length), mergedOptions);
|
|
1507
1627
|
|
|
1508
1628
|
case 18:
|
|
1509
|
-
resp =
|
|
1629
|
+
resp = _context12.sent;
|
|
1510
1630
|
|
|
1511
1631
|
case 19:
|
|
1512
1632
|
documents.push.apply(documents, (0, _toConsumableArray2.default)(resp.data));
|
|
1513
|
-
|
|
1633
|
+
_context12.next = 8;
|
|
1514
1634
|
break;
|
|
1515
1635
|
|
|
1516
1636
|
case 22:
|
|
1517
|
-
return
|
|
1637
|
+
return _context12.abrupt("return", documents);
|
|
1518
1638
|
|
|
1519
1639
|
case 25:
|
|
1520
|
-
|
|
1521
|
-
|
|
1640
|
+
_context12.prev = 25;
|
|
1641
|
+
_context12.t0 = _context12["catch"](3);
|
|
1522
1642
|
|
|
1523
|
-
_logger.default.log("queryAll error for ".concat(
|
|
1643
|
+
_logger.default.log("queryAll error for ".concat(_context12.t0.toString()));
|
|
1524
1644
|
|
|
1525
|
-
return
|
|
1645
|
+
return _context12.abrupt("return", []);
|
|
1526
1646
|
|
|
1527
1647
|
case 29:
|
|
1528
1648
|
case "end":
|
|
1529
|
-
return
|
|
1649
|
+
return _context12.stop();
|
|
1530
1650
|
}
|
|
1531
1651
|
}
|
|
1532
|
-
},
|
|
1652
|
+
}, _callee12, this, [[3, 25]]);
|
|
1533
1653
|
}));
|
|
1534
1654
|
|
|
1535
|
-
function queryAll(
|
|
1655
|
+
function queryAll(_x13) {
|
|
1536
1656
|
return _queryAll.apply(this, arguments);
|
|
1537
1657
|
}
|
|
1538
1658
|
|
|
@@ -1557,62 +1677,63 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
1557
1677
|
/**
|
|
1558
1678
|
* Mutate a document
|
|
1559
1679
|
*
|
|
1560
|
-
* @param {object}
|
|
1561
|
-
* @param {object} [
|
|
1562
|
-
* @param
|
|
1563
|
-
* @param
|
|
1564
|
-
* @param
|
|
1680
|
+
* @param {object} mutationDefinition - Describe the mutation
|
|
1681
|
+
* @param {object} [params] The mutation params
|
|
1682
|
+
* @param {function} [params.update] - update function from MutationOptions
|
|
1683
|
+
* @param {function} [params.updateQueries] - updateQueries function from MutationOptions
|
|
1684
|
+
* @param {string} [params.as] - Mutation id
|
|
1685
|
+
* @param {Object} [params.options={}] - Additional options
|
|
1565
1686
|
* @returns {Promise}
|
|
1566
1687
|
*/
|
|
1567
1688
|
|
|
1568
1689
|
}, {
|
|
1569
1690
|
key: "mutate",
|
|
1570
1691
|
value: function () {
|
|
1571
|
-
var _mutate = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
1692
|
+
var _mutate = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee13(mutationDefinition) {
|
|
1572
1693
|
var _ref6,
|
|
1573
1694
|
update,
|
|
1574
1695
|
updateQueries,
|
|
1575
1696
|
options,
|
|
1576
1697
|
mutationId,
|
|
1577
1698
|
response,
|
|
1578
|
-
|
|
1699
|
+
_args13 = arguments;
|
|
1579
1700
|
|
|
1580
|
-
return _regenerator.default.wrap(function
|
|
1701
|
+
return _regenerator.default.wrap(function _callee13$(_context13) {
|
|
1581
1702
|
while (1) {
|
|
1582
|
-
switch (
|
|
1703
|
+
switch (_context13.prev = _context13.next) {
|
|
1583
1704
|
case 0:
|
|
1584
|
-
_ref6 =
|
|
1705
|
+
_ref6 = _args13.length > 1 && _args13[1] !== undefined ? _args13[1] : {};
|
|
1585
1706
|
update = _ref6.update, updateQueries = _ref6.updateQueries, options = (0, _objectWithoutProperties2.default)(_ref6, ["update", "updateQueries"]);
|
|
1586
1707
|
this.ensureStore();
|
|
1587
1708
|
mutationId = options.as || this.queryIdGenerator.generateId(mutationDefinition);
|
|
1588
1709
|
this.dispatch((0, _store.initMutation)(mutationId, mutationDefinition));
|
|
1589
|
-
|
|
1590
|
-
|
|
1710
|
+
_context13.prev = 5;
|
|
1711
|
+
_context13.next = 8;
|
|
1591
1712
|
return this.requestMutation(mutationDefinition, options);
|
|
1592
1713
|
|
|
1593
1714
|
case 8:
|
|
1594
|
-
response =
|
|
1715
|
+
response = _context13.sent;
|
|
1595
1716
|
this.dispatch((0, _store.receiveMutationResult)(mutationId, response, {
|
|
1596
1717
|
update: update,
|
|
1597
1718
|
updateQueries: updateQueries
|
|
1598
1719
|
}, mutationDefinition));
|
|
1599
|
-
return
|
|
1720
|
+
return _context13.abrupt("return", response);
|
|
1600
1721
|
|
|
1601
1722
|
case 13:
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
this.dispatch((0, _store.receiveMutationError)(mutationId,
|
|
1605
|
-
throw
|
|
1723
|
+
_context13.prev = 13;
|
|
1724
|
+
_context13.t0 = _context13["catch"](5);
|
|
1725
|
+
this.dispatch((0, _store.receiveMutationError)(mutationId, _context13.t0, mutationDefinition));
|
|
1726
|
+
throw _context13.t0;
|
|
1606
1727
|
|
|
1607
1728
|
case 17:
|
|
1608
1729
|
case "end":
|
|
1609
|
-
return
|
|
1730
|
+
return _context13.stop();
|
|
1610
1731
|
}
|
|
1611
1732
|
}
|
|
1612
|
-
},
|
|
1733
|
+
}, _callee13, this, [[5, 13]]);
|
|
1613
1734
|
}));
|
|
1614
1735
|
|
|
1615
|
-
function mutate(
|
|
1736
|
+
function mutate(_x14) {
|
|
1616
1737
|
return _mutate.apply(this, arguments);
|
|
1617
1738
|
}
|
|
1618
1739
|
|
|
@@ -1629,55 +1750,55 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
1629
1750
|
}, {
|
|
1630
1751
|
key: "requestQuery",
|
|
1631
1752
|
value: function () {
|
|
1632
|
-
var _requestQuery = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
1753
|
+
var _requestQuery = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee14(definition, options) {
|
|
1633
1754
|
var mainResponse, schema, withIncluded;
|
|
1634
|
-
return _regenerator.default.wrap(function
|
|
1755
|
+
return _regenerator.default.wrap(function _callee14$(_context14) {
|
|
1635
1756
|
while (1) {
|
|
1636
|
-
switch (
|
|
1757
|
+
switch (_context14.prev = _context14.next) {
|
|
1637
1758
|
case 0:
|
|
1638
|
-
|
|
1759
|
+
_context14.next = 2;
|
|
1639
1760
|
return this.chain.request(definition, options);
|
|
1640
1761
|
|
|
1641
1762
|
case 2:
|
|
1642
|
-
mainResponse =
|
|
1643
|
-
|
|
1763
|
+
mainResponse = _context14.sent;
|
|
1764
|
+
_context14.next = 5;
|
|
1644
1765
|
return (0, _storage.persistVirtualDocuments)(this, definition, mainResponse.data);
|
|
1645
1766
|
|
|
1646
1767
|
case 5:
|
|
1647
1768
|
if (definition.includes) {
|
|
1648
|
-
|
|
1769
|
+
_context14.next = 7;
|
|
1649
1770
|
break;
|
|
1650
1771
|
}
|
|
1651
1772
|
|
|
1652
|
-
return
|
|
1773
|
+
return _context14.abrupt("return", mainResponse);
|
|
1653
1774
|
|
|
1654
1775
|
case 7:
|
|
1655
1776
|
schema = this.schema.getDoctypeSchema(definition.doctype);
|
|
1656
1777
|
|
|
1657
1778
|
if (!schema.relationships) {
|
|
1658
|
-
|
|
1779
|
+
_context14.next = 13;
|
|
1659
1780
|
break;
|
|
1660
1781
|
}
|
|
1661
1782
|
|
|
1662
|
-
|
|
1783
|
+
_context14.next = 11;
|
|
1663
1784
|
return this.fetchRelationships(mainResponse, this.getIncludesRelationships(definition));
|
|
1664
1785
|
|
|
1665
1786
|
case 11:
|
|
1666
|
-
withIncluded =
|
|
1667
|
-
return
|
|
1787
|
+
withIncluded = _context14.sent;
|
|
1788
|
+
return _context14.abrupt("return", withIncluded);
|
|
1668
1789
|
|
|
1669
1790
|
case 13:
|
|
1670
|
-
return
|
|
1791
|
+
return _context14.abrupt("return", mainResponse);
|
|
1671
1792
|
|
|
1672
1793
|
case 14:
|
|
1673
1794
|
case "end":
|
|
1674
|
-
return
|
|
1795
|
+
return _context14.stop();
|
|
1675
1796
|
}
|
|
1676
1797
|
}
|
|
1677
|
-
},
|
|
1798
|
+
}, _callee14, this);
|
|
1678
1799
|
}));
|
|
1679
1800
|
|
|
1680
|
-
function requestQuery(
|
|
1801
|
+
function requestQuery(_x15, _x16) {
|
|
1681
1802
|
return _requestQuery.apply(this, arguments);
|
|
1682
1803
|
}
|
|
1683
1804
|
|
|
@@ -1694,22 +1815,22 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
1694
1815
|
}, {
|
|
1695
1816
|
key: "persistVirtualDocuments",
|
|
1696
1817
|
value: function () {
|
|
1697
|
-
var _persistVirtualDocuments = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
1818
|
+
var _persistVirtualDocuments = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee15(definition, data) {
|
|
1698
1819
|
var enforceList, enforce, documentsToPersist, _iterator5, _step5, _document;
|
|
1699
1820
|
|
|
1700
|
-
return _regenerator.default.wrap(function
|
|
1821
|
+
return _regenerator.default.wrap(function _callee15$(_context15) {
|
|
1701
1822
|
while (1) {
|
|
1702
|
-
switch (
|
|
1823
|
+
switch (_context15.prev = _context15.next) {
|
|
1703
1824
|
case 0:
|
|
1704
1825
|
enforceList = ['io.cozy.files.shortcuts'];
|
|
1705
1826
|
enforce = enforceList.includes(definition.doctype);
|
|
1706
1827
|
|
|
1707
1828
|
if (!(definition.doctype === 'io.cozy.apps_registry')) {
|
|
1708
|
-
|
|
1829
|
+
_context15.next = 6;
|
|
1709
1830
|
break;
|
|
1710
1831
|
}
|
|
1711
1832
|
|
|
1712
|
-
|
|
1833
|
+
_context15.next = 5;
|
|
1713
1834
|
return this.persistVirtualDocument({
|
|
1714
1835
|
_type: 'io.cozy.apps_registry',
|
|
1715
1836
|
_id: definition.id,
|
|
@@ -1718,19 +1839,19 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
1718
1839
|
}, enforce);
|
|
1719
1840
|
|
|
1720
1841
|
case 5:
|
|
1721
|
-
return
|
|
1842
|
+
return _context15.abrupt("return", _context15.sent);
|
|
1722
1843
|
|
|
1723
1844
|
case 6:
|
|
1724
1845
|
if (Array.isArray(data)) {
|
|
1725
|
-
|
|
1846
|
+
_context15.next = 11;
|
|
1726
1847
|
break;
|
|
1727
1848
|
}
|
|
1728
1849
|
|
|
1729
|
-
|
|
1850
|
+
_context15.next = 9;
|
|
1730
1851
|
return this.persistVirtualDocument(data, enforce);
|
|
1731
1852
|
|
|
1732
1853
|
case 9:
|
|
1733
|
-
|
|
1854
|
+
_context15.next = 29;
|
|
1734
1855
|
break;
|
|
1735
1856
|
|
|
1736
1857
|
case 11:
|
|
@@ -1748,50 +1869,50 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
1748
1869
|
return false;
|
|
1749
1870
|
});
|
|
1750
1871
|
_iterator5 = _createForOfIteratorHelper(documentsToPersist);
|
|
1751
|
-
|
|
1872
|
+
_context15.prev = 13;
|
|
1752
1873
|
|
|
1753
1874
|
_iterator5.s();
|
|
1754
1875
|
|
|
1755
1876
|
case 15:
|
|
1756
1877
|
if ((_step5 = _iterator5.n()).done) {
|
|
1757
|
-
|
|
1878
|
+
_context15.next = 21;
|
|
1758
1879
|
break;
|
|
1759
1880
|
}
|
|
1760
1881
|
|
|
1761
1882
|
_document = _step5.value;
|
|
1762
|
-
|
|
1883
|
+
_context15.next = 19;
|
|
1763
1884
|
return this.persistVirtualDocument(_document, enforce);
|
|
1764
1885
|
|
|
1765
1886
|
case 19:
|
|
1766
|
-
|
|
1887
|
+
_context15.next = 15;
|
|
1767
1888
|
break;
|
|
1768
1889
|
|
|
1769
1890
|
case 21:
|
|
1770
|
-
|
|
1891
|
+
_context15.next = 26;
|
|
1771
1892
|
break;
|
|
1772
1893
|
|
|
1773
1894
|
case 23:
|
|
1774
|
-
|
|
1775
|
-
|
|
1895
|
+
_context15.prev = 23;
|
|
1896
|
+
_context15.t0 = _context15["catch"](13);
|
|
1776
1897
|
|
|
1777
|
-
_iterator5.e(
|
|
1898
|
+
_iterator5.e(_context15.t0);
|
|
1778
1899
|
|
|
1779
1900
|
case 26:
|
|
1780
|
-
|
|
1901
|
+
_context15.prev = 26;
|
|
1781
1902
|
|
|
1782
1903
|
_iterator5.f();
|
|
1783
1904
|
|
|
1784
|
-
return
|
|
1905
|
+
return _context15.finish(26);
|
|
1785
1906
|
|
|
1786
1907
|
case 29:
|
|
1787
1908
|
case "end":
|
|
1788
|
-
return
|
|
1909
|
+
return _context15.stop();
|
|
1789
1910
|
}
|
|
1790
1911
|
}
|
|
1791
|
-
},
|
|
1912
|
+
}, _callee15, this, [[13, 23, 26, 29]]);
|
|
1792
1913
|
}));
|
|
1793
1914
|
|
|
1794
|
-
function persistVirtualDocuments(
|
|
1915
|
+
function persistVirtualDocuments(_x17, _x18) {
|
|
1795
1916
|
return _persistVirtualDocuments.apply(this, arguments);
|
|
1796
1917
|
}
|
|
1797
1918
|
|
|
@@ -1809,38 +1930,38 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
1809
1930
|
}, {
|
|
1810
1931
|
key: "persistVirtualDocument",
|
|
1811
1932
|
value: function () {
|
|
1812
|
-
var _persistVirtualDocument = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
1933
|
+
var _persistVirtualDocument = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee16(document, enforce) {
|
|
1813
1934
|
var _document$meta2;
|
|
1814
1935
|
|
|
1815
|
-
return _regenerator.default.wrap(function
|
|
1936
|
+
return _regenerator.default.wrap(function _callee16$(_context16) {
|
|
1816
1937
|
while (1) {
|
|
1817
|
-
switch (
|
|
1938
|
+
switch (_context16.prev = _context16.next) {
|
|
1818
1939
|
case 0:
|
|
1819
1940
|
if (!(!document || document.cozyLocalOnly)) {
|
|
1820
|
-
|
|
1941
|
+
_context16.next = 2;
|
|
1821
1942
|
break;
|
|
1822
1943
|
}
|
|
1823
1944
|
|
|
1824
|
-
return
|
|
1945
|
+
return _context16.abrupt("return");
|
|
1825
1946
|
|
|
1826
1947
|
case 2:
|
|
1827
1948
|
if (!(!((_document$meta2 = document.meta) !== null && _document$meta2 !== void 0 && _document$meta2.rev) && !document._rev || enforce)) {
|
|
1828
|
-
|
|
1949
|
+
_context16.next = 5;
|
|
1829
1950
|
break;
|
|
1830
1951
|
}
|
|
1831
1952
|
|
|
1832
|
-
|
|
1953
|
+
_context16.next = 5;
|
|
1833
1954
|
return this.chain.persistCozyData(document);
|
|
1834
1955
|
|
|
1835
1956
|
case 5:
|
|
1836
1957
|
case "end":
|
|
1837
|
-
return
|
|
1958
|
+
return _context16.stop();
|
|
1838
1959
|
}
|
|
1839
1960
|
}
|
|
1840
|
-
},
|
|
1961
|
+
}, _callee16, this);
|
|
1841
1962
|
}));
|
|
1842
1963
|
|
|
1843
|
-
function persistVirtualDocument(
|
|
1964
|
+
function persistVirtualDocument(_x19, _x20) {
|
|
1844
1965
|
return _persistVirtualDocument.apply(this, arguments);
|
|
1845
1966
|
}
|
|
1846
1967
|
|
|
@@ -1860,23 +1981,23 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
1860
1981
|
}, {
|
|
1861
1982
|
key: "fetchRelationships",
|
|
1862
1983
|
value: function () {
|
|
1863
|
-
var _fetchRelationships = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
1984
|
+
var _fetchRelationships = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee17(response, relationshipsByName) {
|
|
1864
1985
|
var _this5 = this;
|
|
1865
1986
|
|
|
1866
1987
|
var isSingleDoc, responseDocs, queryDefToDocIdAndRel, documents, definitions, optimizedDefinitions, responses, uniqueDocuments, included, relationshipsByDocId, _iterator6, _step6, _step6$value, def, resp, docIdAndRel, _docIdAndRel, docId, relName;
|
|
1867
1988
|
|
|
1868
|
-
return _regenerator.default.wrap(function
|
|
1989
|
+
return _regenerator.default.wrap(function _callee17$(_context17) {
|
|
1869
1990
|
while (1) {
|
|
1870
|
-
switch (
|
|
1991
|
+
switch (_context17.prev = _context17.next) {
|
|
1871
1992
|
case 0:
|
|
1872
1993
|
isSingleDoc = !Array.isArray(response.data);
|
|
1873
1994
|
|
|
1874
1995
|
if (!(!isSingleDoc && response.data.length === 0)) {
|
|
1875
|
-
|
|
1996
|
+
_context17.next = 3;
|
|
1876
1997
|
break;
|
|
1877
1998
|
}
|
|
1878
1999
|
|
|
1879
|
-
return
|
|
2000
|
+
return _context17.abrupt("return", response);
|
|
1880
2001
|
|
|
1881
2002
|
case 3:
|
|
1882
2003
|
responseDocs = isSingleDoc ? [response.data] : response.data;
|
|
@@ -1906,13 +2027,13 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
1906
2027
|
}); // Definitions can be in optimized/regrouped in case of HasMany relationships.
|
|
1907
2028
|
|
|
1908
2029
|
optimizedDefinitions = (0, _optimize.default)(definitions);
|
|
1909
|
-
|
|
2030
|
+
_context17.next = 11;
|
|
1910
2031
|
return Promise.all(optimizedDefinitions.map(function (req) {
|
|
1911
2032
|
return _this5.chain.request(req);
|
|
1912
2033
|
}));
|
|
1913
2034
|
|
|
1914
2035
|
case 11:
|
|
1915
|
-
responses =
|
|
2036
|
+
responses = _context17.sent;
|
|
1916
2037
|
// "Included" documents will be stored in the `documents` store
|
|
1917
2038
|
uniqueDocuments = (0, _uniqBy.default)((0, _flatten.default)(documents), '_id');
|
|
1918
2039
|
included = (0, _flatten.default)(responses.map(function (r) {
|
|
@@ -1944,19 +2065,19 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
1944
2065
|
_iterator6.f();
|
|
1945
2066
|
}
|
|
1946
2067
|
|
|
1947
|
-
return
|
|
2068
|
+
return _context17.abrupt("return", _objectSpread(_objectSpread({}, (0, _helpers.attachRelationships)(response, relationshipsByDocId)), {}, {
|
|
1948
2069
|
included: included
|
|
1949
2070
|
}));
|
|
1950
2071
|
|
|
1951
2072
|
case 18:
|
|
1952
2073
|
case "end":
|
|
1953
|
-
return
|
|
2074
|
+
return _context17.stop();
|
|
1954
2075
|
}
|
|
1955
2076
|
}
|
|
1956
|
-
},
|
|
2077
|
+
}, _callee17);
|
|
1957
2078
|
}));
|
|
1958
2079
|
|
|
1959
|
-
function fetchRelationships(
|
|
2080
|
+
function fetchRelationships(_x21, _x22) {
|
|
1960
2081
|
return _fetchRelationships.apply(this, arguments);
|
|
1961
2082
|
}
|
|
1962
2083
|
|
|
@@ -1965,47 +2086,47 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
1965
2086
|
}, {
|
|
1966
2087
|
key: "requestMutation",
|
|
1967
2088
|
value: function () {
|
|
1968
|
-
var _requestMutation = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
2089
|
+
var _requestMutation = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee18(definition, options) {
|
|
1969
2090
|
var _this6 = this;
|
|
1970
2091
|
|
|
1971
2092
|
var _definition, first, rest, firstResponse;
|
|
1972
2093
|
|
|
1973
|
-
return _regenerator.default.wrap(function
|
|
2094
|
+
return _regenerator.default.wrap(function _callee18$(_context18) {
|
|
1974
2095
|
while (1) {
|
|
1975
|
-
switch (
|
|
2096
|
+
switch (_context18.prev = _context18.next) {
|
|
1976
2097
|
case 0:
|
|
1977
2098
|
if (!Array.isArray(definition)) {
|
|
1978
|
-
|
|
2099
|
+
_context18.next = 8;
|
|
1979
2100
|
break;
|
|
1980
2101
|
}
|
|
1981
2102
|
|
|
1982
2103
|
_definition = (0, _toArray2.default)(definition), first = _definition[0], rest = _definition.slice(1);
|
|
1983
|
-
|
|
2104
|
+
_context18.next = 4;
|
|
1984
2105
|
return this.requestMutation(first);
|
|
1985
2106
|
|
|
1986
2107
|
case 4:
|
|
1987
|
-
firstResponse =
|
|
1988
|
-
|
|
2108
|
+
firstResponse = _context18.sent;
|
|
2109
|
+
_context18.next = 7;
|
|
1989
2110
|
return Promise.all(rest.map(function (def) {
|
|
1990
2111
|
var mutationDef = typeof def === 'function' ? def(firstResponse) : def;
|
|
1991
2112
|
return _this6.requestMutation(mutationDef);
|
|
1992
2113
|
}));
|
|
1993
2114
|
|
|
1994
2115
|
case 7:
|
|
1995
|
-
return
|
|
2116
|
+
return _context18.abrupt("return", firstResponse);
|
|
1996
2117
|
|
|
1997
2118
|
case 8:
|
|
1998
|
-
return
|
|
2119
|
+
return _context18.abrupt("return", this.chain.request(definition, options));
|
|
1999
2120
|
|
|
2000
2121
|
case 9:
|
|
2001
2122
|
case "end":
|
|
2002
|
-
return
|
|
2123
|
+
return _context18.stop();
|
|
2003
2124
|
}
|
|
2004
2125
|
}
|
|
2005
|
-
},
|
|
2126
|
+
}, _callee18, this);
|
|
2006
2127
|
}));
|
|
2007
2128
|
|
|
2008
|
-
function requestMutation(
|
|
2129
|
+
function requestMutation(_x23, _x24) {
|
|
2009
2130
|
return _requestMutation.apply(this, arguments);
|
|
2010
2131
|
}
|
|
2011
2132
|
|
|
@@ -2263,34 +2384,34 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2263
2384
|
}, {
|
|
2264
2385
|
key: "startOAuthFlow",
|
|
2265
2386
|
value: function () {
|
|
2266
|
-
var _startOAuthFlow = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
2387
|
+
var _startOAuthFlow = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee19(openURLCallback) {
|
|
2267
2388
|
var stackClient;
|
|
2268
|
-
return _regenerator.default.wrap(function
|
|
2389
|
+
return _regenerator.default.wrap(function _callee19$(_context19) {
|
|
2269
2390
|
while (1) {
|
|
2270
|
-
switch (
|
|
2391
|
+
switch (_context19.prev = _context19.next) {
|
|
2271
2392
|
case 0:
|
|
2272
2393
|
stackClient = this.getStackClient();
|
|
2273
|
-
|
|
2394
|
+
_context19.next = 3;
|
|
2274
2395
|
return stackClient.register();
|
|
2275
2396
|
|
|
2276
2397
|
case 3:
|
|
2277
|
-
|
|
2398
|
+
_context19.next = 5;
|
|
2278
2399
|
return this.certifyFlagship();
|
|
2279
2400
|
|
|
2280
2401
|
case 5:
|
|
2281
|
-
return
|
|
2402
|
+
return _context19.abrupt("return", this.authorize({
|
|
2282
2403
|
openURLCallback: openURLCallback
|
|
2283
2404
|
}));
|
|
2284
2405
|
|
|
2285
2406
|
case 6:
|
|
2286
2407
|
case "end":
|
|
2287
|
-
return
|
|
2408
|
+
return _context19.stop();
|
|
2288
2409
|
}
|
|
2289
2410
|
}
|
|
2290
|
-
},
|
|
2411
|
+
}, _callee19, this);
|
|
2291
2412
|
}));
|
|
2292
2413
|
|
|
2293
|
-
function startOAuthFlow(
|
|
2414
|
+
function startOAuthFlow(_x25) {
|
|
2294
2415
|
return _startOAuthFlow.apply(this, arguments);
|
|
2295
2416
|
}
|
|
2296
2417
|
|
|
@@ -2305,28 +2426,28 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2305
2426
|
}, {
|
|
2306
2427
|
key: "certifyFlagship",
|
|
2307
2428
|
value: function () {
|
|
2308
|
-
var _certifyFlagship2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
2429
|
+
var _certifyFlagship2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee20() {
|
|
2309
2430
|
var stackClient;
|
|
2310
|
-
return _regenerator.default.wrap(function
|
|
2431
|
+
return _regenerator.default.wrap(function _callee20$(_context20) {
|
|
2311
2432
|
while (1) {
|
|
2312
|
-
switch (
|
|
2433
|
+
switch (_context20.prev = _context20.next) {
|
|
2313
2434
|
case 0:
|
|
2314
2435
|
stackClient = this.getStackClient();
|
|
2315
2436
|
|
|
2316
2437
|
if (!stackClient.oauthOptions.shouldRequireFlagshipPermissions) {
|
|
2317
|
-
|
|
2438
|
+
_context20.next = 4;
|
|
2318
2439
|
break;
|
|
2319
2440
|
}
|
|
2320
2441
|
|
|
2321
|
-
|
|
2442
|
+
_context20.next = 4;
|
|
2322
2443
|
return (0, _flagshipCertification.certifyFlagship)(stackClient.oauthOptions.certificationConfig, this);
|
|
2323
2444
|
|
|
2324
2445
|
case 4:
|
|
2325
2446
|
case "end":
|
|
2326
|
-
return
|
|
2447
|
+
return _context20.stop();
|
|
2327
2448
|
}
|
|
2328
2449
|
}
|
|
2329
|
-
},
|
|
2450
|
+
}, _callee20, this);
|
|
2330
2451
|
}));
|
|
2331
2452
|
|
|
2332
2453
|
function certifyFlagship() {
|
|
@@ -2350,7 +2471,7 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2350
2471
|
}, {
|
|
2351
2472
|
key: "authorize",
|
|
2352
2473
|
value: function () {
|
|
2353
|
-
var _authorize = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
2474
|
+
var _authorize = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee21() {
|
|
2354
2475
|
var _ref7,
|
|
2355
2476
|
_ref7$openURLCallback,
|
|
2356
2477
|
openURLCallback,
|
|
@@ -2367,14 +2488,14 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2367
2488
|
code,
|
|
2368
2489
|
token,
|
|
2369
2490
|
_stackClient,
|
|
2370
|
-
|
|
2491
|
+
_args21 = arguments;
|
|
2371
2492
|
|
|
2372
|
-
return _regenerator.default.wrap(function
|
|
2493
|
+
return _regenerator.default.wrap(function _callee21$(_context21) {
|
|
2373
2494
|
while (1) {
|
|
2374
|
-
switch (
|
|
2495
|
+
switch (_context21.prev = _context21.next) {
|
|
2375
2496
|
case 0:
|
|
2376
|
-
_ref7 =
|
|
2377
|
-
|
|
2497
|
+
_ref7 = _args21.length > 0 && _args21[0] !== undefined ? _args21[0] : {}, _ref7$openURLCallback = _ref7.openURLCallback, openURLCallback = _ref7$openURLCallback === void 0 ? _mobile.authFunction : _ref7$openURLCallback, _ref7$sessionCode = _ref7.sessionCode, sessionCode = _ref7$sessionCode === void 0 ? undefined : _ref7$sessionCode, _ref7$pkceCodes = _ref7.pkceCodes, pkceCodes = _ref7$pkceCodes === void 0 ? {} : _ref7$pkceCodes;
|
|
2498
|
+
_context21.prev = 1;
|
|
2378
2499
|
codeVerifier = pkceCodes.codeVerifier, codeChallenge = pkceCodes.codeChallenge;
|
|
2379
2500
|
stackClient = this.getStackClient();
|
|
2380
2501
|
stateCode = stackClient.generateStateCode();
|
|
@@ -2384,19 +2505,19 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2384
2505
|
sessionCode: sessionCode,
|
|
2385
2506
|
codeChallenge: codeChallenge
|
|
2386
2507
|
});
|
|
2387
|
-
|
|
2508
|
+
_context21.next = 8;
|
|
2388
2509
|
return openURLCallback(url);
|
|
2389
2510
|
|
|
2390
2511
|
case 8:
|
|
2391
|
-
redirectedURL =
|
|
2512
|
+
redirectedURL = _context21.sent;
|
|
2392
2513
|
code = stackClient.getAccessCodeFromURL(redirectedURL, stateCode);
|
|
2393
|
-
|
|
2514
|
+
_context21.next = 12;
|
|
2394
2515
|
return stackClient.fetchAccessToken(code, undefined, undefined, codeVerifier);
|
|
2395
2516
|
|
|
2396
2517
|
case 12:
|
|
2397
|
-
token =
|
|
2518
|
+
token = _context21.sent;
|
|
2398
2519
|
stackClient.setToken(token);
|
|
2399
|
-
return
|
|
2520
|
+
return _context21.abrupt("return", {
|
|
2400
2521
|
token: token,
|
|
2401
2522
|
infos: stackClient.oauthOptions,
|
|
2402
2523
|
client: stackClient.oauthOptions // for compat with Authentication comp reasons
|
|
@@ -2404,24 +2525,24 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2404
2525
|
});
|
|
2405
2526
|
|
|
2406
2527
|
case 17:
|
|
2407
|
-
|
|
2408
|
-
|
|
2528
|
+
_context21.prev = 17;
|
|
2529
|
+
_context21.t0 = _context21["catch"](1);
|
|
2409
2530
|
|
|
2410
2531
|
/* if REGISTRATION_ABORT is emited, we have to unregister the client. */
|
|
2411
|
-
if (
|
|
2532
|
+
if (_context21.t0.message === _const.REGISTRATION_ABORT) {
|
|
2412
2533
|
_stackClient = this.getStackClient();
|
|
2413
2534
|
|
|
2414
2535
|
_stackClient.unregister();
|
|
2415
2536
|
}
|
|
2416
2537
|
|
|
2417
|
-
throw
|
|
2538
|
+
throw _context21.t0;
|
|
2418
2539
|
|
|
2419
2540
|
case 21:
|
|
2420
2541
|
case "end":
|
|
2421
|
-
return
|
|
2542
|
+
return _context21.stop();
|
|
2422
2543
|
}
|
|
2423
2544
|
}
|
|
2424
|
-
},
|
|
2545
|
+
}, _callee21, this, [[1, 17]]);
|
|
2425
2546
|
}));
|
|
2426
2547
|
|
|
2427
2548
|
function authorize() {
|
|
@@ -2496,27 +2617,27 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2496
2617
|
}, {
|
|
2497
2618
|
key: "checkForRevocation",
|
|
2498
2619
|
value: function () {
|
|
2499
|
-
var _checkForRevocation = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
2500
|
-
return _regenerator.default.wrap(function
|
|
2620
|
+
var _checkForRevocation = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee22() {
|
|
2621
|
+
return _regenerator.default.wrap(function _callee22$(_context22) {
|
|
2501
2622
|
while (1) {
|
|
2502
|
-
switch (
|
|
2623
|
+
switch (_context22.prev = _context22.next) {
|
|
2503
2624
|
case 0:
|
|
2504
2625
|
if (!(this.stackClient instanceof _cozyStackClient.OAuthClient)) {
|
|
2505
|
-
|
|
2626
|
+
_context22.next = 4;
|
|
2506
2627
|
break;
|
|
2507
2628
|
}
|
|
2508
2629
|
|
|
2509
|
-
return
|
|
2630
|
+
return _context22.abrupt("return", this.stackClient.checkForRevocation());
|
|
2510
2631
|
|
|
2511
2632
|
case 4:
|
|
2512
2633
|
throw 'checkForRevocation is only implemented for OAutClient';
|
|
2513
2634
|
|
|
2514
2635
|
case 5:
|
|
2515
2636
|
case "end":
|
|
2516
|
-
return
|
|
2637
|
+
return _context22.stop();
|
|
2517
2638
|
}
|
|
2518
2639
|
}
|
|
2519
|
-
},
|
|
2640
|
+
}, _callee22, this);
|
|
2520
2641
|
}));
|
|
2521
2642
|
|
|
2522
2643
|
function checkForRevocation() {
|
|
@@ -2672,17 +2793,17 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2672
2793
|
}, {
|
|
2673
2794
|
key: "loadInstanceOptionsFromStack",
|
|
2674
2795
|
value: function () {
|
|
2675
|
-
var _loadInstanceOptionsFromStack = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
2796
|
+
var _loadInstanceOptionsFromStack = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee23() {
|
|
2676
2797
|
var results, capabilitiesData, instanceData;
|
|
2677
|
-
return _regenerator.default.wrap(function
|
|
2798
|
+
return _regenerator.default.wrap(function _callee23$(_context23) {
|
|
2678
2799
|
while (1) {
|
|
2679
|
-
switch (
|
|
2800
|
+
switch (_context23.prev = _context23.next) {
|
|
2680
2801
|
case 0:
|
|
2681
|
-
|
|
2802
|
+
_context23.next = 2;
|
|
2682
2803
|
return Promise.all([this.query((0, _dsl.Q)('io.cozy.settings').getById('io.cozy.settings.capabilities')), this.query((0, _dsl.Q)('io.cozy.settings').getById('io.cozy.settings.instance'))]);
|
|
2683
2804
|
|
|
2684
2805
|
case 2:
|
|
2685
|
-
results =
|
|
2806
|
+
results = _context23.sent;
|
|
2686
2807
|
capabilitiesData = results[0].data;
|
|
2687
2808
|
instanceData = results[1].data;
|
|
2688
2809
|
this.instanceOptions = {
|
|
@@ -2694,10 +2815,10 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2694
2815
|
|
|
2695
2816
|
case 7:
|
|
2696
2817
|
case "end":
|
|
2697
|
-
return
|
|
2818
|
+
return _context23.stop();
|
|
2698
2819
|
}
|
|
2699
2820
|
}
|
|
2700
|
-
},
|
|
2821
|
+
}, _callee23, this);
|
|
2701
2822
|
}));
|
|
2702
2823
|
|
|
2703
2824
|
function loadInstanceOptionsFromStack() {
|
|
@@ -2774,12 +2895,12 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2774
2895
|
}, {
|
|
2775
2896
|
key: "setLinks",
|
|
2776
2897
|
value: function () {
|
|
2777
|
-
var _setLinks = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
2898
|
+
var _setLinks = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee24(links) {
|
|
2778
2899
|
var _iterator7, _step7, link;
|
|
2779
2900
|
|
|
2780
|
-
return _regenerator.default.wrap(function
|
|
2901
|
+
return _regenerator.default.wrap(function _callee24$(_context24) {
|
|
2781
2902
|
while (1) {
|
|
2782
|
-
switch (
|
|
2903
|
+
switch (_context24.prev = _context24.next) {
|
|
2783
2904
|
case 0:
|
|
2784
2905
|
this.links = links ? links : [new _StackLink.default({
|
|
2785
2906
|
performanceApi: this.performanceApi
|
|
@@ -2788,7 +2909,7 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2788
2909
|
this.chain = (0, _CozyLink.chain)(this.links);
|
|
2789
2910
|
|
|
2790
2911
|
if (!this.isLogged) {
|
|
2791
|
-
|
|
2912
|
+
_context24.next = 22;
|
|
2792
2913
|
break;
|
|
2793
2914
|
}
|
|
2794
2915
|
|
|
@@ -2796,56 +2917,56 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2796
2917
|
// a client instanciation.
|
|
2797
2918
|
// Thus, we call the link's onLogin methods
|
|
2798
2919
|
_iterator7 = _createForOfIteratorHelper(this.links);
|
|
2799
|
-
|
|
2920
|
+
_context24.prev = 5;
|
|
2800
2921
|
|
|
2801
2922
|
_iterator7.s();
|
|
2802
2923
|
|
|
2803
2924
|
case 7:
|
|
2804
2925
|
if ((_step7 = _iterator7.n()).done) {
|
|
2805
|
-
|
|
2926
|
+
_context24.next = 14;
|
|
2806
2927
|
break;
|
|
2807
2928
|
}
|
|
2808
2929
|
|
|
2809
2930
|
link = _step7.value;
|
|
2810
2931
|
|
|
2811
2932
|
if (!link.onLogin) {
|
|
2812
|
-
|
|
2933
|
+
_context24.next = 12;
|
|
2813
2934
|
break;
|
|
2814
2935
|
}
|
|
2815
2936
|
|
|
2816
|
-
|
|
2937
|
+
_context24.next = 12;
|
|
2817
2938
|
return link.onLogin();
|
|
2818
2939
|
|
|
2819
2940
|
case 12:
|
|
2820
|
-
|
|
2941
|
+
_context24.next = 7;
|
|
2821
2942
|
break;
|
|
2822
2943
|
|
|
2823
2944
|
case 14:
|
|
2824
|
-
|
|
2945
|
+
_context24.next = 19;
|
|
2825
2946
|
break;
|
|
2826
2947
|
|
|
2827
2948
|
case 16:
|
|
2828
|
-
|
|
2829
|
-
|
|
2949
|
+
_context24.prev = 16;
|
|
2950
|
+
_context24.t0 = _context24["catch"](5);
|
|
2830
2951
|
|
|
2831
|
-
_iterator7.e(
|
|
2952
|
+
_iterator7.e(_context24.t0);
|
|
2832
2953
|
|
|
2833
2954
|
case 19:
|
|
2834
|
-
|
|
2955
|
+
_context24.prev = 19;
|
|
2835
2956
|
|
|
2836
2957
|
_iterator7.f();
|
|
2837
2958
|
|
|
2838
|
-
return
|
|
2959
|
+
return _context24.finish(19);
|
|
2839
2960
|
|
|
2840
2961
|
case 22:
|
|
2841
2962
|
case "end":
|
|
2842
|
-
return
|
|
2963
|
+
return _context24.stop();
|
|
2843
2964
|
}
|
|
2844
2965
|
}
|
|
2845
|
-
},
|
|
2966
|
+
}, _callee24, this, [[5, 16, 19, 22]]);
|
|
2846
2967
|
}));
|
|
2847
2968
|
|
|
2848
|
-
function setLinks(
|
|
2969
|
+
function setLinks(_x26) {
|
|
2849
2970
|
return _setLinks.apply(this, arguments);
|
|
2850
2971
|
}
|
|
2851
2972
|
|
|
@@ -2865,22 +2986,22 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2865
2986
|
}, {
|
|
2866
2987
|
key: "getSettings",
|
|
2867
2988
|
value: function () {
|
|
2868
|
-
var _getSettings2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
2869
|
-
return _regenerator.default.wrap(function
|
|
2989
|
+
var _getSettings2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee25(slug, keys) {
|
|
2990
|
+
return _regenerator.default.wrap(function _callee25$(_context25) {
|
|
2870
2991
|
while (1) {
|
|
2871
|
-
switch (
|
|
2992
|
+
switch (_context25.prev = _context25.next) {
|
|
2872
2993
|
case 0:
|
|
2873
|
-
return
|
|
2994
|
+
return _context25.abrupt("return", (0, _helpers2.getSettings)(this, slug, keys));
|
|
2874
2995
|
|
|
2875
2996
|
case 1:
|
|
2876
2997
|
case "end":
|
|
2877
|
-
return
|
|
2998
|
+
return _context25.stop();
|
|
2878
2999
|
}
|
|
2879
3000
|
}
|
|
2880
|
-
},
|
|
3001
|
+
}, _callee25, this);
|
|
2881
3002
|
}));
|
|
2882
3003
|
|
|
2883
|
-
function getSettings(
|
|
3004
|
+
function getSettings(_x27, _x28) {
|
|
2884
3005
|
return _getSettings2.apply(this, arguments);
|
|
2885
3006
|
}
|
|
2886
3007
|
|
|
@@ -2903,22 +3024,22 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2903
3024
|
}, {
|
|
2904
3025
|
key: "saveAfterFetchSettings",
|
|
2905
3026
|
value: function () {
|
|
2906
|
-
var _saveAfterFetchSettings2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
2907
|
-
return _regenerator.default.wrap(function
|
|
3027
|
+
var _saveAfterFetchSettings2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee26(slug, itemsOrSetter, setterKeys) {
|
|
3028
|
+
return _regenerator.default.wrap(function _callee26$(_context26) {
|
|
2908
3029
|
while (1) {
|
|
2909
|
-
switch (
|
|
3030
|
+
switch (_context26.prev = _context26.next) {
|
|
2910
3031
|
case 0:
|
|
2911
|
-
return
|
|
3032
|
+
return _context26.abrupt("return", (0, _helpers2.saveAfterFetchSettings)(this, slug, itemsOrSetter, setterKeys));
|
|
2912
3033
|
|
|
2913
3034
|
case 1:
|
|
2914
3035
|
case "end":
|
|
2915
|
-
return
|
|
3036
|
+
return _context26.stop();
|
|
2916
3037
|
}
|
|
2917
3038
|
}
|
|
2918
|
-
},
|
|
3039
|
+
}, _callee26, this);
|
|
2919
3040
|
}));
|
|
2920
3041
|
|
|
2921
|
-
function saveAfterFetchSettings(
|
|
3042
|
+
function saveAfterFetchSettings(_x29, _x30, _x31) {
|
|
2922
3043
|
return _saveAfterFetchSettings2.apply(this, arguments);
|
|
2923
3044
|
}
|
|
2924
3045
|
|
|
@@ -2936,46 +3057,46 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2936
3057
|
}, {
|
|
2937
3058
|
key: "resetQuery",
|
|
2938
3059
|
value: function () {
|
|
2939
|
-
var _resetQuery2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
3060
|
+
var _resetQuery2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee27(queryId) {
|
|
2940
3061
|
var query;
|
|
2941
|
-
return _regenerator.default.wrap(function
|
|
3062
|
+
return _regenerator.default.wrap(function _callee27$(_context27) {
|
|
2942
3063
|
while (1) {
|
|
2943
|
-
switch (
|
|
3064
|
+
switch (_context27.prev = _context27.next) {
|
|
2944
3065
|
case 0:
|
|
2945
|
-
|
|
3066
|
+
_context27.prev = 0;
|
|
2946
3067
|
|
|
2947
3068
|
if ((0, _store.isQueryExisting)(this.store.getState(), queryId)) {
|
|
2948
|
-
|
|
3069
|
+
_context27.next = 3;
|
|
2949
3070
|
break;
|
|
2950
3071
|
}
|
|
2951
3072
|
|
|
2952
|
-
return
|
|
3073
|
+
return _context27.abrupt("return", Promise.resolve(null));
|
|
2953
3074
|
|
|
2954
3075
|
case 3:
|
|
2955
3076
|
this.dispatch((0, _store.resetQuery)(queryId));
|
|
2956
3077
|
query = this.getQueryFromState(queryId);
|
|
2957
|
-
|
|
3078
|
+
_context27.next = 7;
|
|
2958
3079
|
return this.query(query.definition, {
|
|
2959
3080
|
as: queryId
|
|
2960
3081
|
});
|
|
2961
3082
|
|
|
2962
3083
|
case 7:
|
|
2963
|
-
return
|
|
3084
|
+
return _context27.abrupt("return", _context27.sent);
|
|
2964
3085
|
|
|
2965
3086
|
case 10:
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
throw
|
|
3087
|
+
_context27.prev = 10;
|
|
3088
|
+
_context27.t0 = _context27["catch"](0);
|
|
3089
|
+
throw _context27.t0;
|
|
2969
3090
|
|
|
2970
3091
|
case 13:
|
|
2971
3092
|
case "end":
|
|
2972
|
-
return
|
|
3093
|
+
return _context27.stop();
|
|
2973
3094
|
}
|
|
2974
3095
|
}
|
|
2975
|
-
},
|
|
3096
|
+
}, _callee27, this, [[0, 10]]);
|
|
2976
3097
|
}));
|
|
2977
3098
|
|
|
2978
|
-
function resetQuery(
|
|
3099
|
+
function resetQuery(_x32) {
|
|
2979
3100
|
return _resetQuery2.apply(this, arguments);
|
|
2980
3101
|
}
|
|
2981
3102
|
|
|
@@ -3003,22 +3124,22 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
3003
3124
|
}, {
|
|
3004
3125
|
key: "fromOldOAuthClient",
|
|
3005
3126
|
value: function () {
|
|
3006
|
-
var _fromOldOAuthClient = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
3127
|
+
var _fromOldOAuthClient = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee28(oldClient, options) {
|
|
3007
3128
|
var credentials, oauthOptions, client;
|
|
3008
|
-
return _regenerator.default.wrap(function
|
|
3129
|
+
return _regenerator.default.wrap(function _callee28$(_context28) {
|
|
3009
3130
|
while (1) {
|
|
3010
|
-
switch (
|
|
3131
|
+
switch (_context28.prev = _context28.next) {
|
|
3011
3132
|
case 0:
|
|
3012
3133
|
if (!oldClient._oauth) {
|
|
3013
|
-
|
|
3134
|
+
_context28.next = 12;
|
|
3014
3135
|
break;
|
|
3015
3136
|
}
|
|
3016
3137
|
|
|
3017
|
-
|
|
3138
|
+
_context28.next = 3;
|
|
3018
3139
|
return oldClient.authorize();
|
|
3019
3140
|
|
|
3020
3141
|
case 3:
|
|
3021
|
-
credentials =
|
|
3142
|
+
credentials = _context28.sent;
|
|
3022
3143
|
oauthOptions = {
|
|
3023
3144
|
oauth: credentials.client,
|
|
3024
3145
|
token: credentials.token,
|
|
@@ -3029,28 +3150,28 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
3029
3150
|
}, oauthOptions), options));
|
|
3030
3151
|
|
|
3031
3152
|
if (!client.loginPromise) {
|
|
3032
|
-
|
|
3153
|
+
_context28.next = 9;
|
|
3033
3154
|
break;
|
|
3034
3155
|
}
|
|
3035
3156
|
|
|
3036
|
-
|
|
3157
|
+
_context28.next = 9;
|
|
3037
3158
|
return client.loginPromise;
|
|
3038
3159
|
|
|
3039
3160
|
case 9:
|
|
3040
|
-
return
|
|
3161
|
+
return _context28.abrupt("return", client);
|
|
3041
3162
|
|
|
3042
3163
|
case 12:
|
|
3043
3164
|
throw new Error('Cannot instantiate a new client: old client is not an OAuth client. CozyClient.fromOldClient might be more suitable.');
|
|
3044
3165
|
|
|
3045
3166
|
case 13:
|
|
3046
3167
|
case "end":
|
|
3047
|
-
return
|
|
3168
|
+
return _context28.stop();
|
|
3048
3169
|
}
|
|
3049
3170
|
}
|
|
3050
|
-
},
|
|
3171
|
+
}, _callee28);
|
|
3051
3172
|
}));
|
|
3052
3173
|
|
|
3053
|
-
function fromOldOAuthClient(
|
|
3174
|
+
function fromOldOAuthClient(_x33, _x34) {
|
|
3054
3175
|
return _fromOldOAuthClient.apply(this, arguments);
|
|
3055
3176
|
}
|
|
3056
3177
|
|
|
@@ -3143,7 +3264,7 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
3143
3264
|
CozyClient.hooks = CozyClient.hooks || {};
|
|
3144
3265
|
CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
|
|
3145
3266
|
|
|
3146
|
-
CozyClient.version = "59.
|
|
3267
|
+
CozyClient.version = "59.1.1";
|
|
3147
3268
|
|
|
3148
3269
|
_microee.default.mixin(CozyClient);
|
|
3149
3270
|
|