cozy-client 60.1.0 → 60.2.0

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.
@@ -1207,7 +1207,11 @@ var CozyClient = /*#__PURE__*/function () {
1207
1207
  }
1208
1208
 
1209
1209
  return [saveMutation, function (response) {
1210
- var doc = _this3.hydrateDocument(response.data);
1210
+ var schema = _this3.schema.getDoctypeSchema(response.data._type);
1211
+
1212
+ var doc = _this3.hydrateDocument(response.data, schema, {
1213
+ forceHydratation: true
1214
+ });
1211
1215
 
1212
1216
  return Object.entries(referencesByName).map(function (_ref3) {
1213
1217
  var _ref4 = (0, _slicedToArray2.default)(_ref3, 2),
@@ -1990,6 +1994,8 @@ var CozyClient = /*#__PURE__*/function () {
1990
1994
  *
1991
1995
  * @param {string} doctype - Doctype of the documents being hydrated
1992
1996
  * @param {Array<import("./types").CozyClientDocument>} documents - Documents to be hydrated
1997
+ * @param {object} [options] - Options
1998
+ * @param {boolean} [options.forceHydratation=false] - If set to true, all documents will be hydrated w.r.t. the provided schema's relationships, even if the relationship does not exist on the doc.
1993
1999
  * @returns {Array<import("./types").HydratedDocument>}
1994
2000
  */
1995
2001
 
@@ -1998,12 +2004,18 @@ var CozyClient = /*#__PURE__*/function () {
1998
2004
  value: function hydrateDocuments(doctype, documents) {
1999
2005
  var _this8 = this;
2000
2006
 
2007
+ var _ref7 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
2008
+ _ref7$forceHydratatio = _ref7.forceHydratation,
2009
+ forceHydratation = _ref7$forceHydratatio === void 0 ? false : _ref7$forceHydratatio;
2010
+
2001
2011
  var schema = this.schema.getDoctypeSchema(doctype);
2002
2012
  var relationships = schema.relationships;
2003
2013
 
2004
2014
  if (relationships) {
2005
2015
  return documents.map(function (doc) {
2006
- return _this8.hydrateDocument(doc, schema);
2016
+ return _this8.hydrateDocument(doc, schema, {
2017
+ forceHydratation: forceHydratation
2018
+ });
2007
2019
  });
2008
2020
  } else {
2009
2021
  return documents;
@@ -2016,31 +2028,42 @@ var CozyClient = /*#__PURE__*/function () {
2016
2028
  * the relationship
2017
2029
  *
2018
2030
  * @param {import("./types").CozyClientDocument} document - for which relationships must be resolved
2019
- * @param {Schema} [schemaArg] - Optional
2031
+ * @param {Schema} [schemaArg] - The schema describing the relationships
2032
+ * @param {object} [options] - Options
2033
+ * @param {boolean} [options.forceHydratation=false] - If set to true, the doc will be hydrated w.r.t. the provided schema's relationships, even if the relationship does not exist on the doc.
2020
2034
  * @returns {import("./types").HydratedDocument}
2021
2035
  */
2022
2036
 
2023
2037
  }, {
2024
2038
  key: "hydrateDocument",
2025
2039
  value: function hydrateDocument(document, schemaArg) {
2040
+ var _ref8 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
2041
+ _ref8$forceHydratatio = _ref8.forceHydratation,
2042
+ forceHydratation = _ref8$forceHydratatio === void 0 ? false : _ref8$forceHydratatio;
2043
+
2026
2044
  if (!document) {
2027
2045
  return document;
2028
2046
  }
2029
2047
 
2030
2048
  var schema = schemaArg || this.schema.getDoctypeSchema(document._type);
2031
- var hydratedRelationships = this.hydrateRelationships(document, schema.relationships);
2049
+ var shouldForceHydrate = this.options.autoHydrate || forceHydratation;
2050
+ var hydratedRelationships = this.hydrateRelationships(document, schema.relationships, {
2051
+ forceHydratation: shouldForceHydrate
2052
+ });
2032
2053
  return _objectSpread(_objectSpread({}, document), hydratedRelationships);
2033
2054
  }
2034
2055
  }, {
2035
2056
  key: "hydrateRelationships",
2036
2057
  value: function hydrateRelationships(document, schemaRelationships) {
2037
- var _this9 = this;
2058
+ var _ref9 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
2059
+ _ref9$forceHydratatio = _ref9.forceHydratation,
2060
+ forceHydratation = _ref9$forceHydratatio === void 0 ? false : _ref9$forceHydratatio;
2038
2061
 
2039
2062
  var methods = this.getRelationshipStoreAccessors();
2040
2063
  return (0, _mapValues.default)(schemaRelationships, function (assoc, name) {
2041
- var _this9$options, _document$relationshi;
2064
+ var _document$relationshi;
2042
2065
 
2043
- if ((_this9$options = _this9.options) !== null && _this9$options !== void 0 && _this9$options.autoHydrate || (_document$relationshi = document.relationships) !== null && _document$relationshi !== void 0 && _document$relationshi[name]) {
2066
+ if (forceHydratation || (_document$relationshi = document.relationships) !== null && _document$relationshi !== void 0 && _document$relationshi[name]) {
2044
2067
  return (0, _associations.create)(document, assoc, methods);
2045
2068
  }
2046
2069
  });
@@ -2071,20 +2094,20 @@ var CozyClient = /*#__PURE__*/function () {
2071
2094
  }, {
2072
2095
  key: "getRelationshipStoreAccessors",
2073
2096
  value: function getRelationshipStoreAccessors() {
2074
- var _this10 = this;
2097
+ var _this9 = this;
2075
2098
 
2076
2099
  if (!this.storeAccesors) {
2077
2100
  this.storeAccessors = {
2078
2101
  get: this.getDocumentFromState.bind(this),
2079
2102
  save: function save(document, opts) {
2080
- return _this10.save.call(_this10, document, opts);
2103
+ return _this9.save.call(_this9, document, opts);
2081
2104
  },
2082
2105
  dispatch: this.dispatch.bind(this),
2083
2106
  query: function query(def, opts) {
2084
- return _this10.query.call(_this10, def, opts);
2107
+ return _this9.query.call(_this9, def, opts);
2085
2108
  },
2086
2109
  mutate: function mutate(def, opts) {
2087
- return _this10.mutate.call(_this10, def, opts);
2110
+ return _this9.mutate.call(_this9, def, opts);
2088
2111
  }
2089
2112
  };
2090
2113
  }
@@ -2311,12 +2334,12 @@ var CozyClient = /*#__PURE__*/function () {
2311
2334
  key: "authorize",
2312
2335
  value: function () {
2313
2336
  var _authorize = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee19() {
2314
- var _ref7,
2315
- _ref7$openURLCallback,
2337
+ var _ref10,
2338
+ _ref10$openURLCallbac,
2316
2339
  openURLCallback,
2317
- _ref7$sessionCode,
2340
+ _ref10$sessionCode,
2318
2341
  sessionCode,
2319
- _ref7$pkceCodes,
2342
+ _ref10$pkceCodes,
2320
2343
  pkceCodes,
2321
2344
  codeVerifier,
2322
2345
  codeChallenge,
@@ -2333,7 +2356,7 @@ var CozyClient = /*#__PURE__*/function () {
2333
2356
  while (1) {
2334
2357
  switch (_context19.prev = _context19.next) {
2335
2358
  case 0:
2336
- _ref7 = _args19.length > 0 && _args19[0] !== undefined ? _args19[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;
2359
+ _ref10 = _args19.length > 0 && _args19[0] !== undefined ? _args19[0] : {}, _ref10$openURLCallbac = _ref10.openURLCallback, openURLCallback = _ref10$openURLCallbac === void 0 ? _mobile.authFunction : _ref10$openURLCallbac, _ref10$sessionCode = _ref10.sessionCode, sessionCode = _ref10$sessionCode === void 0 ? undefined : _ref10$sessionCode, _ref10$pkceCodes = _ref10.pkceCodes, pkceCodes = _ref10$pkceCodes === void 0 ? {} : _ref10$pkceCodes;
2337
2360
  _context19.prev = 1;
2338
2361
  codeVerifier = pkceCodes.codeVerifier, codeChallenge = pkceCodes.codeChallenge;
2339
2362
  stackClient = this.getStackClient();
@@ -2430,9 +2453,9 @@ var CozyClient = /*#__PURE__*/function () {
2430
2453
  }, {
2431
2454
  key: "setStore",
2432
2455
  value: function setStore(store) {
2433
- var _ref8 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
2434
- _ref8$force = _ref8.force,
2435
- force = _ref8$force === void 0 ? false : _ref8$force;
2456
+ var _ref11 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
2457
+ _ref11$force = _ref11.force,
2458
+ force = _ref11$force === void 0 ? false : _ref11$force;
2436
2459
 
2437
2460
  if (store === undefined) {
2438
2461
  throw new Error('Store is undefined');
@@ -2677,15 +2700,15 @@ var CozyClient = /*#__PURE__*/function () {
2677
2700
  }, {
2678
2701
  key: "setData",
2679
2702
  value: function setData(data) {
2680
- var _this11 = this;
2703
+ var _this10 = this;
2681
2704
 
2682
2705
  this.ensureStore();
2683
- Object.entries(data).forEach(function (_ref9) {
2684
- var _ref10 = (0, _slicedToArray2.default)(_ref9, 2),
2685
- doctype = _ref10[0],
2686
- data = _ref10[1];
2706
+ Object.entries(data).forEach(function (_ref12) {
2707
+ var _ref13 = (0, _slicedToArray2.default)(_ref12, 2),
2708
+ doctype = _ref13[0],
2709
+ data = _ref13[1];
2687
2710
 
2688
- _this11.dispatch((0, _store.receiveQueryResult)(null, {
2711
+ _this10.dispatch((0, _store.receiveQueryResult)(null, {
2689
2712
  data: data
2690
2713
  }));
2691
2714
  });
@@ -3103,7 +3126,7 @@ var CozyClient = /*#__PURE__*/function () {
3103
3126
  CozyClient.hooks = CozyClient.hooks || {};
3104
3127
  CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
3105
3128
 
3106
- CozyClient.version = "60.1.0";
3129
+ CozyClient.version = "60.2.0";
3107
3130
 
3108
3131
  _microee.default.mixin(CozyClient);
3109
3132
 
@@ -15,14 +15,20 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl
15
15
 
16
16
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
17
17
 
18
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
19
+
18
20
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
19
21
 
20
22
  var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
21
23
 
22
24
  var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
23
25
 
26
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
27
+
24
28
  var _CozyLink2 = _interopRequireDefault(require("./CozyLink"));
25
29
 
30
+ var _cozyLogger = _interopRequireDefault(require("cozy-logger"));
31
+
26
32
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
27
33
 
28
34
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
@@ -44,7 +50,30 @@ var DataProxyLink = /*#__PURE__*/function (_CozyLink) {
44
50
 
45
51
  (0, _classCallCheck2.default)(this, DataProxyLink);
46
52
  _this = _super.call(this);
53
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_onReceiveMessage", function (event) {
54
+ // See https://github.com/cozy/cozy-web-data-proxy/blob/1fc3deef767536aa264074c8a377f422b588409d/src/dataproxy/parent/ParentWindowProvider.tsx#L27
55
+ if (!event.origin.includes('dataproxy')) {
56
+ return;
57
+ }
58
+
59
+ var eventData = event === null || event === void 0 ? void 0 : event.data;
60
+
61
+ if (eventData && typeof eventData === 'object') {
62
+ if (eventData.type === 'DATAPROXYMESSAGE' && eventData.payload === 'READY') {
63
+ _cozyLogger.default.info("Received message: DataProxy is ready");
64
+
65
+ _this._flushQueue();
66
+ }
67
+ }
68
+ });
47
69
  _this.dataproxy = dataproxy || null;
70
+ _this._queue = [];
71
+ _this._drainingRequests = false;
72
+
73
+ if (window) {
74
+ window.addEventListener('message', _this._onReceiveMessage);
75
+ }
76
+
48
77
  return _this;
49
78
  }
50
79
 
@@ -64,6 +93,8 @@ var DataProxyLink = /*#__PURE__*/function (_CozyLink) {
64
93
  key: "registerDataProxy",
65
94
  value: function registerDataProxy(dataproxy) {
66
95
  this.dataproxy = dataproxy;
96
+
97
+ this._flushQueue();
67
98
  }
68
99
  }, {
69
100
  key: "reset",
@@ -90,24 +121,31 @@ var DataProxyLink = /*#__PURE__*/function (_CozyLink) {
90
121
  key: "request",
91
122
  value: function () {
92
123
  var _request = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(operation, options, result, forward) {
93
- var opts;
124
+ var _this$dataproxy,
125
+ _this2 = this;
126
+
94
127
  return _regenerator.default.wrap(function _callee2$(_context2) {
95
128
  while (1) {
96
129
  switch (_context2.prev = _context2.next) {
97
130
  case 0:
98
- if (!this.dataproxy) {
99
- _context2.next = 5;
131
+ if (!((_this$dataproxy = this.dataproxy) !== null && _this$dataproxy !== void 0 && _this$dataproxy.requestLink)) {
132
+ _context2.next = 2;
100
133
  break;
101
134
  }
102
135
 
103
- // Send the request to the DataProxy, that will handle both web and mobile environments
104
- opts = options || {};
105
- return _context2.abrupt("return", this.dataproxy.requestLink(operation, opts));
136
+ return _context2.abrupt("return", this.doRequest(operation, options));
106
137
 
107
- case 5:
108
- return _context2.abrupt("return", forward(operation, options));
138
+ case 2:
139
+ return _context2.abrupt("return", new Promise(function (resolve, reject) {
140
+ _this2._queue.push({
141
+ operation: operation,
142
+ options: options,
143
+ resolve: resolve,
144
+ reject: reject
145
+ });
146
+ }));
109
147
 
110
- case 6:
148
+ case 3:
111
149
  case "end":
112
150
  return _context2.stop();
113
151
  }
@@ -122,29 +160,141 @@ var DataProxyLink = /*#__PURE__*/function (_CozyLink) {
122
160
  return request;
123
161
  }()
124
162
  }, {
125
- key: "persistCozyData",
163
+ key: "doRequest",
126
164
  value: function () {
127
- var _persistCozyData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(data, forward) {
165
+ var _doRequest = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(operation, options) {
166
+ var opts, startQuery, resp, endQuery;
128
167
  return _regenerator.default.wrap(function _callee3$(_context3) {
129
168
  while (1) {
130
169
  switch (_context3.prev = _context3.next) {
131
170
  case 0:
132
- return _context3.abrupt("return");
171
+ opts = options || {};
172
+ startQuery = performance.now(); // Send the request to the DataProxy, that will handle both web and mobile environments
133
173
 
134
- case 1:
174
+ _context3.next = 4;
175
+ return this.dataproxy.requestLink(operation, opts);
176
+
177
+ case 4:
178
+ resp = _context3.sent;
179
+ endQuery = performance.now();
180
+
181
+ _cozyLogger.default.info("Request query took ".concat(endQuery - startQuery, " ms"));
182
+
183
+ return _context3.abrupt("return", resp);
184
+
185
+ case 8:
135
186
  case "end":
136
187
  return _context3.stop();
137
188
  }
138
189
  }
139
- }, _callee3);
190
+ }, _callee3, this);
140
191
  }));
141
192
 
142
- function persistCozyData(_x5, _x6) {
193
+ function doRequest(_x5, _x6) {
194
+ return _doRequest.apply(this, arguments);
195
+ }
196
+
197
+ return doRequest;
198
+ }()
199
+ }, {
200
+ key: "persistCozyData",
201
+ value: function () {
202
+ var _persistCozyData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(data, forward) {
203
+ return _regenerator.default.wrap(function _callee4$(_context4) {
204
+ while (1) {
205
+ switch (_context4.prev = _context4.next) {
206
+ case 0:
207
+ return _context4.abrupt("return");
208
+
209
+ case 1:
210
+ case "end":
211
+ return _context4.stop();
212
+ }
213
+ }
214
+ }, _callee4);
215
+ }));
216
+
217
+ function persistCozyData(_x7, _x8) {
143
218
  return _persistCozyData.apply(this, arguments);
144
219
  }
145
220
 
146
221
  return persistCozyData;
147
222
  }()
223
+ }, {
224
+ key: "_flushQueue",
225
+ value: function () {
226
+ var _flushQueue2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5() {
227
+ var _this$dataproxy2;
228
+
229
+ var _this$_queue$shift, operation, options, resolve, reject, resp;
230
+
231
+ return _regenerator.default.wrap(function _callee5$(_context5) {
232
+ while (1) {
233
+ switch (_context5.prev = _context5.next) {
234
+ case 0:
235
+ if (!(!((_this$dataproxy2 = this.dataproxy) !== null && _this$dataproxy2 !== void 0 && _this$dataproxy2.requestLink) || this._queue.length < 1)) {
236
+ _context5.next = 2;
237
+ break;
238
+ }
239
+
240
+ return _context5.abrupt("return");
241
+
242
+ case 2:
243
+ _cozyLogger.default.info("Execute ".concat(this._queue.length, " delayed requests"));
244
+
245
+ this._drainingRequests = true;
246
+ _context5.prev = 4;
247
+
248
+ case 5:
249
+ if (!(this._queue.length > 0)) {
250
+ _context5.next = 19;
251
+ break;
252
+ }
253
+
254
+ _this$_queue$shift = this._queue.shift(), operation = _this$_queue$shift.operation, options = _this$_queue$shift.options, resolve = _this$_queue$shift.resolve, reject = _this$_queue$shift.reject;
255
+ _context5.prev = 7;
256
+ _context5.next = 10;
257
+ return this.doRequest(operation, options);
258
+
259
+ case 10:
260
+ resp = _context5.sent;
261
+ resolve(resp);
262
+ _context5.next = 17;
263
+ break;
264
+
265
+ case 14:
266
+ _context5.prev = 14;
267
+ _context5.t0 = _context5["catch"](7);
268
+ reject(_context5.t0);
269
+
270
+ case 17:
271
+ _context5.next = 5;
272
+ break;
273
+
274
+ case 19:
275
+ _context5.prev = 19;
276
+ this._drainingRequests = false; // Run it again in case queue has filled again during the flush
277
+
278
+ if (this._queue.length > 0) {
279
+ this._flushQueue();
280
+ }
281
+
282
+ return _context5.finish(19);
283
+
284
+ case 23:
285
+ case "end":
286
+ return _context5.stop();
287
+ }
288
+ }
289
+ }, _callee5, this, [[4,, 19, 23], [7, 14]]);
290
+ }));
291
+
292
+ function _flushQueue() {
293
+ return _flushQueue2.apply(this, arguments);
294
+ }
295
+
296
+ return _flushQueue;
297
+ }()
148
298
  }]);
149
299
  return DataProxyLink;
150
300
  }(_CozyLink2.default);
@@ -0,0 +1,86 @@
1
+ /** @jest-environment jsdom */
2
+ import DataProxyLink from './DataProxyLink'
3
+
4
+ describe('DataProxyLink queueing', () => {
5
+ it('should directly call dataproxy requestLink if available', async () => {
6
+ const requestLink = jest.fn().mockResolvedValue('OK')
7
+ const dataproxy = { requestLink }
8
+ const link = new DataProxyLink({ dataproxy })
9
+
10
+ const res = await link.request({ op: 'op1' }, {}, undefined, undefined)
11
+
12
+ expect(res).toBe('OK')
13
+ expect(requestLink).toHaveBeenCalledTimes(1)
14
+ expect(requestLink).toHaveBeenCalledWith({ op: 'op1' }, {})
15
+ })
16
+
17
+ it('should fill the event queue as long as dataproxy is not ready and run all of them once it registers', async () => {
18
+ const link = new DataProxyLink() // no dataproxy
19
+
20
+ const p1 = link.request({ op: 'op1' }, {}, undefined, undefined)
21
+ const p2 = link.request({ op: 'op2' }, {}, undefined, undefined)
22
+
23
+ expect(link._queue.length).toEqual(2)
24
+
25
+ const requestLink = jest
26
+ .fn()
27
+ .mockResolvedValueOnce('Res1')
28
+ .mockResolvedValueOnce('Res2')
29
+
30
+ link.registerDataProxy({ requestLink })
31
+
32
+ await expect(p1).resolves.toBe('Res1')
33
+ await expect(p2).resolves.toBe('Res2')
34
+
35
+ expect(requestLink.mock.calls.map(c => c[0].op)).toEqual(['op1', 'op2'])
36
+ expect(link._queue.length).toEqual(0)
37
+ })
38
+
39
+ it('should correctly deal with rejected promises ', async () => {
40
+ const link = new DataProxyLink()
41
+
42
+ const pOk1 = link.request({ op: 'op1' }, {})
43
+ const pFail = link.request({ op: 'op2' }, {})
44
+ const pOk2 = link.request({ op: 'op3' }, {})
45
+
46
+ const requestLink = jest
47
+ .fn()
48
+ .mockResolvedValueOnce('Res1')
49
+ .mockRejectedValueOnce(new Error('boom'))
50
+ .mockResolvedValueOnce('Res3')
51
+
52
+ link.registerDataProxy({ requestLink })
53
+
54
+ await expect(pOk1).resolves.toBe('Res1')
55
+ await expect(pFail).rejects.toThrow('boom')
56
+ await expect(pOk2).resolves.toBe('Res3')
57
+
58
+ expect(requestLink.mock.calls.map(c => c[0].op)).toEqual([
59
+ 'op1',
60
+ 'op2',
61
+ 'op3'
62
+ ])
63
+ })
64
+
65
+ it('should flush events when ready message is received', async () => {
66
+ const link = new DataProxyLink()
67
+
68
+ const p1 = link.request({ op: 'op1' }, {})
69
+ const p2 = link.request({ op: 'op2' }, {})
70
+
71
+ const requestLink = jest
72
+ .fn()
73
+ .mockResolvedValueOnce('Res1')
74
+ .mockResolvedValueOnce('Res2')
75
+ link.dataproxy = { requestLink }
76
+
77
+ const ev = new MessageEvent('message', {
78
+ data: { type: 'DATAPROXYMESSAGE', payload: 'READY' },
79
+ origin: 'http://dataproxy.cozy.localhost:8080'
80
+ })
81
+ window.dispatchEvent(ev)
82
+
83
+ await expect(p1).resolves.toBe('Res1')
84
+ await expect(p2).resolves.toBe('Res2')
85
+ })
86
+ })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "60.1.0",
3
+ "version": "60.2.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.node.js",
6
6
  "browser": "dist/index.js",
@@ -74,5 +74,5 @@
74
74
  "react-native-ios11-devicecheck": "^0.0.3"
75
75
  },
76
76
  "sideEffects": false,
77
- "gitHead": "78342f53c89c0c28a1559e6f0224249f4713c47b"
77
+ "gitHead": "48687a04cfb284dadd0d208451ca4f6a514519f2"
78
78
  }
@@ -584,9 +584,13 @@ declare class CozyClient {
584
584
  *
585
585
  * @param {string} doctype - Doctype of the documents being hydrated
586
586
  * @param {Array<import("./types").CozyClientDocument>} documents - Documents to be hydrated
587
+ * @param {object} [options] - Options
588
+ * @param {boolean} [options.forceHydratation=false] - If set to true, all documents will be hydrated w.r.t. the provided schema's relationships, even if the relationship does not exist on the doc.
587
589
  * @returns {Array<import("./types").HydratedDocument>}
588
590
  */
589
- hydrateDocuments(doctype: string, documents: Array<import("./types").CozyClientDocument>): Array<import("./types").HydratedDocument>;
591
+ hydrateDocuments(doctype: string, documents: Array<import("./types").CozyClientDocument>, { forceHydratation }?: {
592
+ forceHydratation?: boolean;
593
+ }): Array<import("./types").HydratedDocument>;
590
594
  /**
591
595
  * Resolves relationships on a document.
592
596
  *
@@ -594,11 +598,17 @@ declare class CozyClient {
594
598
  * the relationship
595
599
  *
596
600
  * @param {import("./types").CozyClientDocument} document - for which relationships must be resolved
597
- * @param {Schema} [schemaArg] - Optional
601
+ * @param {Schema} [schemaArg] - The schema describing the relationships
602
+ * @param {object} [options] - Options
603
+ * @param {boolean} [options.forceHydratation=false] - If set to true, the doc will be hydrated w.r.t. the provided schema's relationships, even if the relationship does not exist on the doc.
598
604
  * @returns {import("./types").HydratedDocument}
599
605
  */
600
- hydrateDocument(document: import("./types").CozyClientDocument, schemaArg?: Schema): import("./types").HydratedDocument;
601
- hydrateRelationships(document: any, schemaRelationships: any): {
606
+ hydrateDocument(document: import("./types").CozyClientDocument, schemaArg?: Schema, { forceHydratation }?: {
607
+ forceHydratation?: boolean;
608
+ }): import("./types").HydratedDocument;
609
+ hydrateRelationships(document: any, schemaRelationships: any, { forceHydratation }?: {
610
+ forceHydratation?: boolean;
611
+ }): {
602
612
  [x: string]: any;
603
613
  };
604
614
  generateRandomId(): string;
@@ -7,6 +7,8 @@ export default class DataProxyLink extends CozyLink {
7
7
  dataproxy: object;
8
8
  });
9
9
  dataproxy: any;
10
+ _queue: any[];
11
+ _drainingRequests: boolean;
10
12
  registerClient(client: any): void;
11
13
  /**
12
14
  * When the link is given to a cozy-client instance, the dataproxy might not be ready yet.
@@ -16,5 +18,8 @@ export default class DataProxyLink extends CozyLink {
16
18
  * @param {object} dataproxy - The dataproxy instance
17
19
  */
18
20
  registerDataProxy(dataproxy: object): void;
21
+ doRequest(operation: any, options: any): Promise<any>;
22
+ _flushQueue(): Promise<void>;
23
+ _onReceiveMessage: (event: any) => void;
19
24
  }
20
25
  import CozyLink from "./CozyLink";