cozy-harvest-lib 18.1.2 → 18.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [18.1.3](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@18.1.2...cozy-harvest-lib@18.1.3) (2023-10-12)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * Optimize the request ([b948b48](https://github.com/cozy/cozy-libs/commit/b948b487c560db1e208612d7d5496e595bc94f21))
12
+
13
+
14
+
15
+
16
+
6
17
  ## [18.1.2](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@18.1.1...cozy-harvest-lib@18.1.2) (2023-10-11)
7
18
 
8
19
 
@@ -481,28 +481,34 @@ export var fetchAccountsWithoutTriggers = /*#__PURE__*/function () {
481
481
 
482
482
  export var fetchReusableAccount = /*#__PURE__*/function () {
483
483
  var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(client, konnector) {
484
- var _yield$client$collect, triggers, accountsWithoutTrigger;
485
-
484
+ var triggers, accountsWithoutTrigger;
486
485
  return _regeneratorRuntime.wrap(function _callee8$(_context8) {
487
486
  while (1) {
488
487
  switch (_context8.prev = _context8.next) {
489
488
  case 0:
490
489
  _context8.next = 2;
491
- return client.collection('io.cozy.triggers').all();
490
+ return client.queryAll(Q('io.cozy.triggers').where({
491
+ _id: {
492
+ $gt: null
493
+ }
494
+ }).partialIndex({
495
+ worker: {
496
+ $in: ['konnector', 'client']
497
+ }
498
+ }).indexFields(['_id']));
492
499
 
493
500
  case 2:
494
- _yield$client$collect = _context8.sent;
495
- triggers = _yield$client$collect.data;
496
- _context8.next = 6;
501
+ triggers = _context8.sent;
502
+ _context8.next = 5;
497
503
  return fetchAccountsWithoutTriggers(client, triggers);
498
504
 
499
- case 6:
505
+ case 5:
500
506
  accountsWithoutTrigger = _context8.sent;
501
507
  return _context8.abrupt("return", accountsWithoutTrigger.find(function (account) {
502
508
  return account.account_type === konnector.slug;
503
509
  }));
504
510
 
505
- case 8:
511
+ case 7:
506
512
  case "end":
507
513
  return _context8.stop();
508
514
  }
@@ -564,22 +564,14 @@ describe('fetchReusableAccount', function () {
564
564
  var accounts = _ref22.accounts,
565
565
  triggers = _ref22.triggers;
566
566
  var client = new CozyClient({});
567
- client.collection = jest.fn(function (doctype) {
568
- if (doctype === 'io.cozy.triggers') {
569
- return {
570
- all: jest.fn().mockResolvedValue({
571
- data: triggers
572
- })
573
- };
574
- } else {
575
- throw new Error("client.collection for ".concat(doctype, " is not mocked"));
576
- }
577
- });
578
567
  client.query = jest.fn().mockImplementation(function () {
579
568
  return {
580
569
  data: accounts
581
570
  };
582
571
  });
572
+ client.queryAll = jest.fn().mockImplementation(function () {
573
+ return triggers;
574
+ });
583
575
  return {
584
576
  client: client
585
577
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-harvest-lib",
3
- "version": "18.1.2",
3
+ "version": "18.1.3",
4
4
  "description": "Provides logic, modules and components for Cozy's harvest applications.",
5
5
  "main": "dist/index.js",
6
6
  "author": "Cozy",
@@ -112,5 +112,5 @@
112
112
  "react-router-dom": ">=4.3.1"
113
113
  },
114
114
  "sideEffects": false,
115
- "gitHead": "db4a954385db84b920e714ae87bda1fb96010c80"
115
+ "gitHead": "3b33cc4d8c10f44d2824a0cb0e017c4c8290dced"
116
116
  }
@@ -237,7 +237,22 @@ export const fetchAccountsWithoutTriggers = async (client, triggers) => {
237
237
  * @return {Account} An account without trigger for the given konnector
238
238
  */
239
239
  export const fetchReusableAccount = async (client, konnector) => {
240
- const { data: triggers } = await client.collection('io.cozy.triggers').all()
240
+ // the where is there because ATM TriggerCollection check if there is
241
+ // a selector to know if it should call /jobs/triggers or
242
+ // /data/io.cozy.triggers.
243
+ // In our case, we only want the triggers without the job, so we want
244
+ // to use /data/io.cozy.triggers
245
+ const triggers = await client.queryAll(
246
+ Q('io.cozy.triggers')
247
+ .where({
248
+ _id: { $gt: null }
249
+ })
250
+ .partialIndex({
251
+ worker: { $in: ['konnector', 'client'] }
252
+ })
253
+ .indexFields(['_id'])
254
+ )
255
+
241
256
  const accountsWithoutTrigger = await fetchAccountsWithoutTriggers(
242
257
  client,
243
258
  triggers
@@ -417,20 +417,15 @@ describe('Account mutations', () => {
417
417
  describe('fetchReusableAccount', () => {
418
418
  const setup = ({ accounts, triggers }) => {
419
419
  const client = new CozyClient({})
420
- client.collection = jest.fn(doctype => {
421
- if (doctype === 'io.cozy.triggers') {
422
- return {
423
- all: jest.fn().mockResolvedValue({ data: triggers })
424
- }
425
- } else {
426
- throw new Error(`client.collection for ${doctype} is not mocked`)
427
- }
428
- })
429
420
  client.query = jest.fn().mockImplementation(() => {
430
421
  return {
431
422
  data: accounts
432
423
  }
433
424
  })
425
+
426
+ client.queryAll = jest.fn().mockImplementation(() => {
427
+ return triggers
428
+ })
434
429
  return { client }
435
430
  }
436
431
  it('should return the right account when possible', async () => {