cozy-client 33.0.1 → 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.1";
2639
+ CozyClient.version = "33.0.4";
2640
2640
 
2641
2641
  _microee.default.mixin(CozyClient);
2642
2642
 
@@ -100,15 +100,17 @@ var isDirectory = function isDirectory(file) {
100
100
  return file && file.type === DIR_TYPE;
101
101
  };
102
102
  /**
103
+ * Is file param a correct note
103
104
  *
104
105
  * @param {IOCozyFile} file io.cozy.files
106
+ * @returns {boolean}
105
107
  */
106
108
 
107
109
 
108
110
  exports.isDirectory = isDirectory;
109
111
 
110
112
  var isNote = function isNote(file) {
111
- if (file && file.name && file.name.endsWith('.cozy-note') && file.type === FILE_TYPE && file.metadata && file.metadata.content !== undefined && file.metadata.schema !== undefined && file.metadata.title !== undefined && file.metadata.version !== undefined) return true;
113
+ if (file && file.name && file.name.endsWith('.cozy-note') && file.type === FILE_TYPE && file.metadata && file.metadata.title !== undefined && file.metadata.version !== undefined) return true;
112
114
  return false;
113
115
  };
114
116
  /**
@@ -40,24 +40,27 @@ describe('File Model', () => {
40
40
  type: 'file',
41
41
  name: 'test.cozy-note',
42
42
  metadata: {
43
- content: 'content',
44
- schema: [],
45
- title: 'title',
46
- version: 1
43
+ title: '',
44
+ version: 0
47
45
  }
48
46
  }
49
47
  expect(fileModel.isNote(note)).toBe(true)
50
- const note2 = {
48
+ const noteMissingVersion = {
49
+ type: 'file',
50
+ name: 'test.cozy-note',
51
+ metadata: {
52
+ title: ''
53
+ }
54
+ }
55
+ expect(fileModel.isNote(noteMissingVersion)).toBe(false)
56
+ const noteMissingTitle = {
51
57
  type: 'file',
52
58
  name: 'test.cozy-note',
53
59
  metadata: {
54
- content: 'content',
55
- schema: [],
56
- title: '',
57
60
  version: 0
58
61
  }
59
62
  }
60
- expect(fileModel.isNote(note2)).toBe(true)
63
+ expect(fileModel.isNote(noteMissingTitle)).toBe(false)
61
64
  })
62
65
 
63
66
  it('should test if a file is a shortcut or not', () => {
@@ -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/dist/types.js CHANGED
@@ -163,12 +163,28 @@ var _dsl = require("./queries/dsl");
163
163
  * @property {object} [cozyMetadata] - Cozy Metadata
164
164
  */
165
165
 
166
+ /**
167
+ * Metadata on io.cozy.files documents
168
+ *
169
+ * This is a first step, to continue
170
+ *
171
+ * Filled according to:
172
+ * https://docs.cozy.io/en/cozy-doctypes/docs/io.cozy.files_metadata/
173
+ * https://docs.cozy.io/en/cozy-doctypes/docs/io.cozy.notes/
174
+ *
175
+ * @typedef {object} FileMetadata - A io.cozy.files document's metadata
176
+ * @property {object} [content] - The Note's content. See https://prosemirror.net/docs/ref/#model for more informations
177
+ * @property {object} [schema] - the schema used by prosemirror (with notes and marks serialized as arrays to preserve the order).
178
+ * @property {string} [title] - the initial title of the note (that will also be used for the file name)
179
+ * @property {number} [version] - Number of a note
180
+ */
181
+
166
182
  /**
167
183
  * @typedef {object} FileDocument - An io.cozy.files document
168
184
  * @property {string} _id - Id of the file
169
185
  * @property {FilesDoctype} _type - Doctype of the file
170
186
  * @property {string} name - Name of the file
171
- * @property {object} metadata - Metadata of the file
187
+ * @property {FileMetadata} metadata - Metadata of the file
172
188
  * @property {string} type - Type of the file
173
189
  * @property {string} class - Class of the file
174
190
  * @property {string} mime - Mime of the file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "33.0.1",
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": "4314ca7d19acb10bf4bb153e14f9152c32c8e0ff"
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;
package/types/types.d.ts CHANGED
@@ -174,6 +174,27 @@ export type CozyClientDocument = {
174
174
  */
175
175
  cozyMetadata?: object;
176
176
  };
177
+ /**
178
+ * - A io.cozy.files document's metadata
179
+ */
180
+ export type FileMetadata = {
181
+ /**
182
+ * - The Note's content. See https://prosemirror.net/docs/ref/#model for more informations
183
+ */
184
+ content?: object;
185
+ /**
186
+ * - the schema used by prosemirror (with notes and marks serialized as arrays to preserve the order).
187
+ */
188
+ schema?: object;
189
+ /**
190
+ * - the initial title of the note (that will also be used for the file name)
191
+ */
192
+ title?: string;
193
+ /**
194
+ * - Number of a note
195
+ */
196
+ version?: number;
197
+ };
177
198
  /**
178
199
  * - An io.cozy.files document
179
200
  */
@@ -193,7 +214,7 @@ export type FileDocument = {
193
214
  /**
194
215
  * - Metadata of the file
195
216
  */
196
- metadata: object;
217
+ metadata: FileMetadata;
197
218
  /**
198
219
  * - Type of the file
199
220
  */