cozy-client 27.14.3 → 27.14.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
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
+ ## [27.14.4](https://github.com/cozy/cozy-client/compare/v27.14.3...v27.14.4) (2022-01-31)
7
+
8
+ **Note:** Version bump only for package cozy-client
9
+
10
+
11
+
12
+
13
+
6
14
  ## [27.14.3](https://github.com/cozy/cozy-client/compare/v27.14.2...v27.14.3) (2022-01-28)
7
15
 
8
16
 
@@ -2464,7 +2464,7 @@ var CozyClient = /*#__PURE__*/function () {
2464
2464
  CozyClient.hooks = CozyClient.hooks || {};
2465
2465
  CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
2466
2466
 
2467
- CozyClient.version = "27.14.3";
2467
+ CozyClient.version = "27.14.4";
2468
2468
 
2469
2469
  _microee.default.mixin(CozyClient);
2470
2470
 
@@ -48,6 +48,7 @@ var normalizeDoc = function normalizeDoc(couchDBDoc, doctype) {
48
48
  * DispatchChange
49
49
  *
50
50
  * @param {CozyClient} client CozyClient instane
51
+ * @param {Doctype} doctype Doctype of the document to update
51
52
  * @param {CouchDBDocument} couchDBDoc Document to update
52
53
  * @param {Mutation} mutationDefinitionCreator Mutation to apply
53
54
  */
@@ -27,6 +27,8 @@ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime
27
27
 
28
28
  var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
29
29
 
30
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
31
+
30
32
  var _get4 = _interopRequireDefault(require("lodash/get"));
31
33
 
32
34
  var _omit = _interopRequireDefault(require("lodash/omit"));
@@ -53,11 +55,30 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
53
55
 
54
56
  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; } }
55
57
 
58
+ /**
59
+ * newCursor - Returns a CouchDB view Cursor for cursor-based pagination
60
+ *
61
+ * @param {ViewKey} key - The CouchDB key of the view which will be requested
62
+ * @param {DocId} startDocId - The first doc _id to return from the view
63
+ *
64
+ * @returns {CouchDBViewCursor}
65
+ */
66
+ var newCursor = function newCursor(_ref, startDocId) {
67
+ var _ref2 = (0, _slicedToArray2.default)(_ref, 3),
68
+ doctype = _ref2[0],
69
+ id = _ref2[1],
70
+ lastDatetime = _ref2[2];
71
+
72
+ var cursorKey = lastDatetime ? [doctype, id, lastDatetime] : [doctype, id];
73
+ return [cursorKey, startDocId];
74
+ };
56
75
  /**
57
76
  * This class is only used for photos albums relationships.
58
77
  * Behind the hood, the queries uses a view returning the files sorted
59
78
  * by datetime, with a cursor-based pagination.
60
79
  */
80
+
81
+
61
82
  var HasManyFiles = /*#__PURE__*/function (_HasMany) {
62
83
  (0, _inherits2.default)(HasManyFiles, _HasMany);
63
84
 
@@ -87,8 +108,8 @@ var HasManyFiles = /*#__PURE__*/function (_HasMany) {
87
108
  lastRelationship = relationships[relationships.length - 1];
88
109
  _context2.next = 5;
89
110
  return this.dispatch( /*#__PURE__*/function () {
90
- var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(dispatch, getState) {
91
- var lastRelDoc, lastDatetime, cursorKey, startDocId, cursorView, response;
111
+ var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(dispatch, getState) {
112
+ var lastRelDoc, lastDatetime, cursor, response;
92
113
  return _regenerator.default.wrap(function _callee$(_context) {
93
114
  while (1) {
94
115
  switch (_context.prev = _context.next) {
@@ -97,17 +118,15 @@ var HasManyFiles = /*#__PURE__*/function (_HasMany) {
97
118
 
98
119
  lastDatetime = lastRelDoc.attributes.metadata.datetime; // cursor-based pagination
99
120
 
100
- cursorKey = [_this.target._type, _this.target._id, lastDatetime];
101
- startDocId = relationships[relationships.length - 1]._id;
102
- cursorView = [cursorKey, startDocId];
103
- _context.next = 7;
104
- return _this.query(queryDef.referencedBy(_this.target).offsetCursor(cursorView));
121
+ cursor = newCursor([_this.target._type, _this.target._id, lastDatetime], relationships[relationships.length - 1]._id);
122
+ _context.next = 5;
123
+ return _this.query(queryDef.referencedBy(_this.target).offsetCursor(cursor));
105
124
 
106
- case 7:
125
+ case 5:
107
126
  response = _context.sent;
108
127
  // Remove first returned element, used as starting point for the query
109
128
  response.data.shift();
110
- _context.next = 11;
129
+ _context.next = 9;
111
130
  return _this.dispatch(_this.updateRelationshipData(function (previousRelationshipData) {
112
131
  return _objectSpread(_objectSpread({}, previousRelationshipData), {}, {
113
132
  data: [].concat((0, _toConsumableArray2.default)(previousRelationshipData.data), (0, _toConsumableArray2.default)(response.data)),
@@ -115,7 +134,7 @@ var HasManyFiles = /*#__PURE__*/function (_HasMany) {
115
134
  });
116
135
  }));
117
136
 
118
- case 11:
137
+ case 9:
119
138
  case "end":
120
139
  return _context.stop();
121
140
  }
@@ -124,7 +143,7 @@ var HasManyFiles = /*#__PURE__*/function (_HasMany) {
124
143
  }));
125
144
 
126
145
  return function (_x, _x2) {
127
- return _ref.apply(this, arguments);
146
+ return _ref3.apply(this, arguments);
128
147
  };
129
148
  }());
130
149
 
@@ -261,9 +280,9 @@ var HasManyFiles = /*#__PURE__*/function (_HasMany) {
261
280
 
262
281
  if (this.target._type === _const.DOCTYPE_FILES) {
263
282
  var refs = (0, _get4.default)(this.target, 'referenced_by', []);
264
- return refs.map(function (_ref2) {
265
- var id = _ref2.id,
266
- type = _ref2.type;
283
+ return refs.map(function (_ref4) {
284
+ var id = _ref4.id,
285
+ type = _ref4.type;
267
286
  return _this4.get(type, id);
268
287
  }).filter(Boolean);
269
288
  } else {
@@ -282,8 +301,7 @@ var HasManyFiles = /*#__PURE__*/function (_HasMany) {
282
301
  }));
283
302
  return ids.length > 0 ? (0, _dsl.Q)(assoc.doctype).getByIds(ids) : null;
284
303
  } else {
285
- var key = [document._type, document._id];
286
- var cursor = [key, ''];
304
+ var cursor = newCursor([document._type, document._id], '');
287
305
  return (0, _dsl.Q)(assoc.doctype).referencedBy(document).offsetCursor(cursor);
288
306
  }
289
307
  }
@@ -1,24 +1,20 @@
1
1
  /**
2
- * A JSON Web Signature
3
- * @typedef {string} jws
2
+ * @typedef {string} jws - A JSON Web Signature
4
3
  */
5
4
 
6
5
  /**
7
- * A JSON Web Signature
8
- * @typedef {string} base64string
6
+ * @typedef {string} base64string - A JSON Web Signature
9
7
  */
10
8
 
11
9
  /**
12
- * An app attestation from the app store
13
- * @typedef {object} AttestationResult
10
+ * @typedef {object} AttestationResult - An app attestation from the app store
14
11
  * @property {string} platform
15
12
  * @property {jws|base64string} attestation
16
13
  * @property {string} [keyId]
17
14
  */
18
15
 
19
16
  /**
20
- * Configuration to access the stores certification API
21
- * @typedef {object} CertificationConfig
17
+ * @typedef {object} CertificationConfig - Configuration to access the stores certification API
22
18
  * @property {string} androidSafetyNetApiKey
23
19
  */
24
20
  "use strict";
@@ -36,7 +36,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
36
36
  */
37
37
 
38
38
  /**
39
- * @typedef {Array} Cursor
39
+ * @typedef {object} MangoPartialFilter
40
40
  */
41
41
 
42
42
  /**
@@ -50,19 +50,19 @@ var QueryDefinition = /*#__PURE__*/function () {
50
50
  * @class
51
51
  *
52
52
  * @param {object} options Initial options for the query definition
53
- * @param {string} [options.doctype] - The doctype of the doc.
54
- * @param {string} [options.id] - The id of the doc.
55
- * @param {Array} [options.ids] - The ids of the docs.
56
- * @param {object} [options.selector] - The selector to query the docs.
57
- * @param {Array} [options.fields] - The fields to return.
58
- * @param {Array} [options.indexedFields] - The fields to index.
59
- * @param {object} [options.partialFilter] - The partial index definition to filter docs.
60
- * @param {Array} [options.sort] - The sorting params.
53
+ * @param {Doctype} [options.doctype] - The doctype of the doc.
54
+ * @param {DocId|null} [options.id] - The id of the doc.
55
+ * @param {Array<DocId>} [options.ids] - The ids of the docs.
56
+ * @param {MangoSelector} [options.selector] - The selector to query the docs.
57
+ * @param {Array<string>} [options.fields] - The fields to return.
58
+ * @param {Array<string>} [options.indexedFields] - The fields to index.
59
+ * @param {MangoPartialFilter} [options.partialFilter] - The partial index definition to filter docs.
60
+ * @param {Array<object>} [options.sort] - The sorting params.
61
61
  * @param {Array<string>} [options.includes] - The docs to include.
62
- * @param {string} [options.referenced] - The referenced document.
62
+ * @param {string|null} [options.referenced] - The referenced document.
63
63
  * @param {number|null} [options.limit] - The document's limit to return.
64
- * @param {number} [options.skip] - The number of docs to skip.
65
- * @param {Cursor} [options.cursor] - The cursor to paginate views.
64
+ * @param {number|null} [options.skip] - The number of docs to skip.
65
+ * @param {CouchDBViewCursor} [options.cursor] - The cursor to paginate views.
66
66
  * @param {string} [options.bookmark] - The bookmark to paginate mango queries.
67
67
  */
68
68
  function QueryDefinition() {
@@ -342,7 +342,7 @@ var QueryDefinition = /*#__PURE__*/function () {
342
342
  * the starting document of the query, e.g. "file-id".
343
343
  * Use the last docid of each query as startkey_docid to paginate or leave blank for the first query.
344
344
  *
345
- * @param {Cursor} cursor The cursor for pagination.
345
+ * @param {CouchDBViewCursor} cursor The cursor for pagination.
346
346
  * @returns {QueryDefinition} The QueryDefinition object.
347
347
  */
348
348
 
@@ -50,8 +50,9 @@ describe('QueryDefinition', () => {
50
50
  expect(withSkip.bookmark).toBeUndefined()
51
51
  expect(withSkip.cursor).toBeUndefined()
52
52
 
53
- const withCursor = withSkip.offsetCursor('cursor-id')
54
- expect(withCursor.cursor).toEqual('cursor-id')
53
+ const cursor = [['io.cozy.files', '1234'], 'xyz']
54
+ const withCursor = withSkip.offsetCursor(cursor)
55
+ expect(withCursor.cursor).toEqual(cursor)
55
56
  expect(withCursor.bookmark).toBeUndefined()
56
57
  expect(withCursor.skip).toBeUndefined()
57
58
 
package/dist/types.js CHANGED
@@ -167,7 +167,7 @@ var _dsl = require("./queries/dsl");
167
167
  * @property {string} name - Name of the folder
168
168
  * @property {object} metadata - Metadata of the folder
169
169
  * @property {object} type - Type of the folder
170
- * @typedef {CozyClientDocument & FileDocument} IOCozyFolder - An io.cozy.files document
170
+ * @typedef {CozyClientDocument & FolderDocument} IOCozyFolder - An io.cozy.files document
171
171
  */
172
172
 
173
173
  /**
@@ -253,6 +253,12 @@ var _dsl = require("./queries/dsl");
253
253
  * @property {string?} reason?
254
254
  */
255
255
 
256
+ /**
257
+ * @typedef {Array<string>|string} ViewKey
258
+ * @typedef {string} DocId
259
+ * @typedef {[ViewKey, DocId]} CouchDBViewCursor
260
+ */
261
+
256
262
  /**
257
263
  * @typedef {object} Theme
258
264
  * @property {string} id
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "27.14.3",
3
+ "version": "27.14.4",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.node.js",
6
6
  "browser": "dist/index.js",
@@ -21,7 +21,7 @@
21
21
  "cozy-device-helper": "^1.12.0",
22
22
  "cozy-flags": "2.7.1",
23
23
  "cozy-logger": "^1.6.0",
24
- "cozy-stack-client": "^27.14.1",
24
+ "cozy-stack-client": "^27.14.4",
25
25
  "json-stable-stringify": "^1.0.1",
26
26
  "lodash": "^4.17.13",
27
27
  "microee": "^0.0.6",
@@ -71,5 +71,5 @@
71
71
  "react-native-ios11-devicecheck": "https://github.com/cozy/react-native-devicecheck#app-attest-v0.1"
72
72
  },
73
73
  "sideEffects": false,
74
- "gitHead": "786f6d73d3d1cc0f423776e2af642f8bdd3fba2c"
74
+ "gitHead": "df8a41fff60d8b4492e240932dd6858641c861d3"
75
75
  }
@@ -1,13 +1,13 @@
1
1
  /**
2
- * A JSON Web Signature
2
+ * - A JSON Web Signature
3
3
  */
4
4
  type jws = string;
5
5
  /**
6
- * A JSON Web Signature
6
+ * - A JSON Web Signature
7
7
  */
8
8
  type base64string = string;
9
9
  /**
10
- * An app attestation from the app store
10
+ * - An app attestation from the app store
11
11
  */
12
12
  type AttestationResult = {
13
13
  platform: string;
@@ -15,7 +15,7 @@ type AttestationResult = {
15
15
  keyId?: string;
16
16
  };
17
17
  /**
18
- * Configuration to access the stores certification API
18
+ * - Configuration to access the stores certification API
19
19
  */
20
20
  type CertificationConfig = {
21
21
  androidSafetyNetApiKey: string;
@@ -70,7 +70,7 @@ export type PartialQueryDefinition = {
70
70
  selector?: object;
71
71
  };
72
72
  export type MangoSelector = any;
73
- export type Cursor = any[];
73
+ export type MangoPartialFilter = any;
74
74
  import { Doctype } from "../types";
75
75
  /**
76
76
  * @typedef PartialQueryDefinition
@@ -83,7 +83,7 @@ import { Doctype } from "../types";
83
83
  * @typedef {object} MangoSelector
84
84
  */
85
85
  /**
86
- * @typedef {Array} Cursor
86
+ * @typedef {object} MangoPartialFilter
87
87
  */
88
88
  /**
89
89
  * Chainable API to create query definitions to retrieve documents
@@ -96,50 +96,50 @@ export class QueryDefinition {
96
96
  * @class
97
97
  *
98
98
  * @param {object} options Initial options for the query definition
99
- * @param {string} [options.doctype] - The doctype of the doc.
100
- * @param {string} [options.id] - The id of the doc.
101
- * @param {Array} [options.ids] - The ids of the docs.
102
- * @param {object} [options.selector] - The selector to query the docs.
103
- * @param {Array} [options.fields] - The fields to return.
104
- * @param {Array} [options.indexedFields] - The fields to index.
105
- * @param {object} [options.partialFilter] - The partial index definition to filter docs.
106
- * @param {Array} [options.sort] - The sorting params.
99
+ * @param {Doctype} [options.doctype] - The doctype of the doc.
100
+ * @param {DocId|null} [options.id] - The id of the doc.
101
+ * @param {Array<DocId>} [options.ids] - The ids of the docs.
102
+ * @param {MangoSelector} [options.selector] - The selector to query the docs.
103
+ * @param {Array<string>} [options.fields] - The fields to return.
104
+ * @param {Array<string>} [options.indexedFields] - The fields to index.
105
+ * @param {MangoPartialFilter} [options.partialFilter] - The partial index definition to filter docs.
106
+ * @param {Array<object>} [options.sort] - The sorting params.
107
107
  * @param {Array<string>} [options.includes] - The docs to include.
108
- * @param {string} [options.referenced] - The referenced document.
108
+ * @param {string|null} [options.referenced] - The referenced document.
109
109
  * @param {number|null} [options.limit] - The document's limit to return.
110
- * @param {number} [options.skip] - The number of docs to skip.
111
- * @param {Cursor} [options.cursor] - The cursor to paginate views.
110
+ * @param {number|null} [options.skip] - The number of docs to skip.
111
+ * @param {CouchDBViewCursor} [options.cursor] - The cursor to paginate views.
112
112
  * @param {string} [options.bookmark] - The bookmark to paginate mango queries.
113
113
  */
114
114
  constructor(options?: {
115
- doctype: string;
116
- id: string;
117
- ids: any[];
118
- selector: object;
119
- fields: any[];
120
- indexedFields: any[];
121
- partialFilter: object;
122
- sort: any[];
115
+ doctype: Doctype;
116
+ id: DocId | null;
117
+ ids: Array<DocId>;
118
+ selector: MangoSelector;
119
+ fields: Array<string>;
120
+ indexedFields: Array<string>;
121
+ partialFilter: MangoPartialFilter;
122
+ sort: Array<object>;
123
123
  includes: Array<string>;
124
- referenced: string;
124
+ referenced: string | null;
125
125
  limit: number | null;
126
- skip: number;
127
- cursor: Cursor;
126
+ skip: number | null;
127
+ cursor: CouchDBViewCursor;
128
128
  bookmark: string;
129
129
  });
130
130
  doctype: string;
131
131
  id: string;
132
- ids: any[];
132
+ ids: string[];
133
133
  selector: any;
134
- fields: any[];
135
- indexedFields: any[];
134
+ fields: string[];
135
+ indexedFields: string[];
136
136
  partialFilter: any;
137
137
  sort: any[];
138
138
  includes: string[];
139
139
  referenced: string;
140
140
  limit: number;
141
141
  skip: number;
142
- cursor: Cursor;
142
+ cursor: CouchDBViewCursor;
143
143
  bookmark: string;
144
144
  /**
145
145
  * Checks if the sort order matches the index' fields order.
@@ -249,10 +249,10 @@ export class QueryDefinition {
249
249
  * the starting document of the query, e.g. "file-id".
250
250
  * Use the last docid of each query as startkey_docid to paginate or leave blank for the first query.
251
251
  *
252
- * @param {Cursor} cursor The cursor for pagination.
252
+ * @param {CouchDBViewCursor} cursor The cursor for pagination.
253
253
  * @returns {QueryDefinition} The QueryDefinition object.
254
254
  */
255
- offsetCursor(cursor: Cursor): QueryDefinition;
255
+ offsetCursor(cursor: CouchDBViewCursor): QueryDefinition;
256
256
  /**
257
257
  * Use [bookmark](https://docs.couchdb.org/en/2.2.0/api/database/find.html#pagination) pagination.
258
258
  * Note this only applies for mango-queries (not views) and is way more efficient than skip pagination.
@@ -273,17 +273,17 @@ export class QueryDefinition {
273
273
  toDefinition(): {
274
274
  doctype: string;
275
275
  id: string;
276
- ids: any[];
276
+ ids: string[];
277
277
  selector: any;
278
- fields: any[];
279
- indexedFields: any[];
278
+ fields: string[];
279
+ indexedFields: string[];
280
280
  partialFilter: any;
281
281
  sort: any[];
282
282
  includes: string[];
283
283
  referenced: string;
284
284
  limit: number;
285
285
  skip: number;
286
- cursor: Cursor;
286
+ cursor: CouchDBViewCursor;
287
287
  bookmark: string;
288
288
  };
289
289
  }
@@ -296,4 +296,6 @@ declare const REMOVE_REFERENCES_TO: "REMOVE_REFERENCES_TO";
296
296
  declare const ADD_REFERENCED_BY: "ADD_REFERENCED_BY";
297
297
  declare const REMOVE_REFERENCED_BY: "REMOVE_REFERENCED_BY";
298
298
  declare const UPLOAD_FILE: "UPLOAD_FILE";
299
+ import { CouchDBViewCursor } from "../types";
300
+ import { DocId } from "../types";
299
301
  export {};
package/types/types.d.ts CHANGED
@@ -208,7 +208,7 @@ export type FolderDocument = {
208
208
  /**
209
209
  * - An io.cozy.files document
210
210
  */
211
- export type IOCozyFolder = CozyClientDocument & FileDocument;
211
+ export type IOCozyFolder = CozyClientDocument & FolderDocument;
212
212
  /**
213
213
  * - An io.cozy.oauth.clients document
214
214
  */
@@ -299,6 +299,9 @@ export type CouchDBBulkResult = {
299
299
  */
300
300
  reason: string | null;
301
301
  };
302
+ export type ViewKey = string | string[];
303
+ export type DocId = string;
304
+ export type CouchDBViewCursor = [string | string[], string];
302
305
  export type Theme = {
303
306
  id: string;
304
307
  label: string;