cozy-client 33.0.3 → 33.0.4

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.
@@ -2636,7 +2636,7 @@ var CozyClient = /*#__PURE__*/function () {
2636
2636
  CozyClient.hooks = CozyClient.hooks || {};
2637
2637
  CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
2638
2638
 
2639
- CozyClient.version = "33.0.3";
2639
+ CozyClient.version = "33.0.4";
2640
2640
 
2641
2641
  _microee.default.mixin(CozyClient);
2642
2642
 
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.QueryIDGenerator = exports.getQueryFromSlice = exports.receiveQueryError = exports.receiveQueryResult = exports.loadQuery = exports.initQuery = exports.default = exports.makeSorterFromDefinition = exports.mergeSelectorAndPartialIndex = exports.convert$gtNullSelectors = exports.sortAndLimitDocsIds = exports.isReceivingData = exports.isQueryAction = void 0;
8
+ exports.QueryIDGenerator = exports.getQueryFromSlice = exports.receiveQueryError = exports.receiveQueryResult = exports.loadQuery = exports.initQuery = exports.default = exports.updateData = exports.makeSorterFromDefinition = exports.mergeSelectorAndPartialIndex = exports.convert$gtNullSelectors = exports.sortAndLimitDocsIds = exports.isReceivingData = exports.isQueryAction = void 0;
9
9
 
10
10
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
11
 
@@ -446,15 +446,14 @@ var updateData = function updateData(query, newData, documents) {
446
446
  // It is also faster than union.
447
447
 
448
448
  var updatedData = (0, _difference.default)((0, _concat.default)(originalIds, toAdd), toRemove);
449
- var count = query.count,
450
- fetchedPagesCount = query.fetchedPagesCount;
449
+ var fetchedPagesCount = query.fetchedPagesCount;
451
450
  var docsIds = sortAndLimitDocsIds(query, documents, updatedData, {
452
- count: count,
451
+ count: updatedData.length,
453
452
  fetchedPagesCount: fetchedPagesCount
454
453
  });
455
454
  return _objectSpread(_objectSpread({}, query), {}, {
456
455
  data: docsIds,
457
- count: updatedData.length,
456
+ count: docsIds.length,
458
457
  fetchedPagesCount: fetchedPagesCount,
459
458
  lastUpdate: changed ? Date.now() : query.lastUpdate
460
459
  });
@@ -469,6 +468,8 @@ var updateData = function updateData(query, newData, documents) {
469
468
  */
470
469
 
471
470
 
471
+ exports.updateData = updateData;
472
+
472
473
  var autoQueryUpdater = function autoQueryUpdater(action, documents) {
473
474
  return function (query) {
474
475
  var data = (0, _get.default)(action, 'response.data') || (0, _get.default)(action, 'definition.document');
@@ -6,7 +6,8 @@ import queries, {
6
6
  mergeSelectorAndPartialIndex,
7
7
  sortAndLimitDocsIds,
8
8
  loadQuery,
9
- receiveQueryError
9
+ receiveQueryError,
10
+ updateData
10
11
  } from './queries'
11
12
  import { Q } from '../queries/dsl'
12
13
  import { TODO_1, TODO_2, TODO_3 } from '../__tests__/fixtures'
@@ -545,3 +546,69 @@ describe('sortAndLimitDocsIds', () => {
545
546
  expect(ids2.length).toEqual(3)
546
547
  })
547
548
  })
549
+
550
+ describe('updateData', () => {
551
+ it('should update correctly the data after a create mutation', () => {
552
+ const queryState = {
553
+ definition: {
554
+ doctype: 'io.cozy.files',
555
+ selector: {
556
+ dir_id: 'd6fa040d335c5f49e8c4b674a001849a',
557
+ type: 'file',
558
+ name: {
559
+ $gt: null
560
+ },
561
+ _id: {
562
+ $ne: 'io.cozy.files.trash-dir'
563
+ }
564
+ },
565
+ sort: [
566
+ {
567
+ dir_id: 'asc'
568
+ }
569
+ ],
570
+ limit: 100
571
+ }
572
+ }
573
+
574
+ const createdDocument = {
575
+ id: 'd6fa040d335c5f49e8c4b674a00216d2',
576
+ _type: 'io.cozy.files',
577
+ type: 'file',
578
+ _id: 'd6fa040d335c5f49e8c4b674a00216d2',
579
+ _rev: '1-b8663df3d2a468171ceaccc7049421ba',
580
+ name: 'cozy.url',
581
+ dir_id: 'd6fa040d335c5f49e8c4b674a001849a',
582
+ created_at: '2022-09-01T10:39:01.759905+02:00',
583
+ updated_at: '2022-09-01T10:39:01.759905+02:00'
584
+ }
585
+ const newData = [createdDocument]
586
+
587
+ const documents = {
588
+ 'io.cozy.files': {
589
+ d6fa040d335c5f49e8c4b674a001849a: {
590
+ id: 'd6fa040d335c5f49e8c4b674a001849a',
591
+ _id: 'd6fa040d335c5f49e8c4b674a001849a',
592
+ _type: 'io.cozy.files',
593
+ type: 'directory',
594
+ attributes: {
595
+ type: 'directory',
596
+ name: 'test',
597
+ dir_id: 'io.cozy.files.root-dir',
598
+ created_at: '2022-08-31T13:07:19.976349+02:00',
599
+ updated_at: '2022-08-31T13:07:19.976349+02:00',
600
+ path: '/test'
601
+ },
602
+ name: 'test',
603
+ dir_id: 'io.cozy.files.root-dir'
604
+ },
605
+ [createdDocument.id]: {
606
+ ...createdDocument
607
+ }
608
+ }
609
+ }
610
+ const updatedDataToCheck = updateData(queryState, newData, documents)
611
+ expect(updatedDataToCheck.data.length).toEqual(1)
612
+ expect(updatedDataToCheck.count).toEqual(1)
613
+ })
614
+ })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "33.0.3",
3
+ "version": "33.0.4",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.node.js",
6
6
  "browser": "dist/index.js",
@@ -73,5 +73,5 @@
73
73
  "react-native-ios11-devicecheck": "https://github.com/cozy/react-native-devicecheck#app-attest-v0.1"
74
74
  },
75
75
  "sideEffects": false,
76
- "gitHead": "97b71b70c86c57c887979e154045be077bad191f"
76
+ "gitHead": "ecb3b54d6ccdae2c0a4ad872a5702f1119095419"
77
77
  }
@@ -7,6 +7,7 @@ export function sortAndLimitDocsIds(queryState: QueryState, documents: Documents
7
7
  export function convert$gtNullSelectors(selector: any): object;
8
8
  export function mergeSelectorAndPartialIndex(queryDefinition: object): object;
9
9
  export function makeSorterFromDefinition(definition: QueryDefinition): (arg0: Array<CozyClientDocument>) => Array<CozyClientDocument>;
10
+ export function updateData(query: QueryState, newData: Array<CozyClientDocument>, documents: DocumentsStateSlice): QueryState;
10
11
  export default queries;
11
12
  export function initQuery(queryId: string, queryDefinition: QueryDefinition, options?: QueryOptions): object;
12
13
  export function loadQuery(queryId: string, options?: QueryOptions): object;