cozy-client 27.3.2 → 27.6.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.
@@ -25,6 +25,8 @@ var _types = require("../types");
25
25
 
26
26
  var _context = require("../context");
27
27
 
28
+ var _dsl = require("../queries/dsl");
29
+
28
30
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
29
31
 
30
32
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
@@ -41,15 +43,16 @@ var generateFetchMoreQueryDefinition = function generateFetchMoreQueryDefinition
41
43
  /**
42
44
  * Fetches a queryDefinition and returns the queryState
43
45
  *
44
- * @param {object} queryDefinition - Definition created with Q()
46
+ * @param {QueryDefinition} queryDefinition - Definition created with Q()
45
47
  *
46
- * @param {object} options - Options
47
- * @param {object} options.as - Name for the query [required]
48
- * @param {boolean} options.enabled - If set to false, the query won't be executed
49
- * @param {object} options.fetchPolicy - Fetch policy
50
- * @param {object} options.singleDocData - If true, the "data" returned will be
48
+ * @typedef {object} UseQueryOptions
49
+ * @property {object} as - Name for the query [required]
50
+ * @property {boolean} enabled - If set to false, the query won't be executed
51
+ * @property {object} fetchPolicy - Fetch policy
52
+ * @property {object} singleDocData - If true, the "data" returned will be
51
53
  * a single doc instead of an array for single doc queries. Defaults to false for backward
52
54
  * compatibility but will be set to true in the future.
55
+ * @property {Function} onError - Callback if the query is errored
53
56
  *
54
57
  * @returns {UseQueryReturnValue}
55
58
  */
@@ -1,13 +1,20 @@
1
1
  import { renderHook } from '@testing-library/react-hooks'
2
2
 
3
+ import CozyClient from '../CozyClient'
4
+ import CozyLink from '../CozyLink'
3
5
  import useQuery, { useQueries } from './useQuery'
4
6
  import { Q } from '../queries/dsl'
5
7
 
6
8
  import { setupClient, makeWrapper } from '../testing/utils'
7
9
  import simpsonsFixture from '../testing/simpsons.json'
8
10
 
9
- const setupQuery = ({ queryDefinition, queryOptions, storeQueries }) => {
10
- const client = setupClient({ queries: storeQueries })
11
+ const setupQuery = ({
12
+ customClient,
13
+ queryDefinition,
14
+ queryOptions,
15
+ storeQueries
16
+ }) => {
17
+ const client = customClient || setupClient({ queries: storeQueries })
11
18
  const hookResult = renderHook(() => useQuery(queryDefinition, queryOptions), {
12
19
  wrapper: makeWrapper(client)
13
20
  })
@@ -159,6 +166,30 @@ describe('use query', () => {
159
166
  expect(lastCallArgs).toMatchObject({ skip: current.data.length })
160
167
  expect(fetchMoreResult).toEqual({ data: null })
161
168
  })
169
+
170
+ it('should call onError callback when an error is thrown. Callback passed as argument', async () => {
171
+ jest.spyOn(console, 'error').mockImplementation(() => null)
172
+ const requestHandler = jest.fn()
173
+ const client = new CozyClient({
174
+ links: [new CozyLink(requestHandler)]
175
+ })
176
+ const error = new TypeError('Failed to fetch')
177
+ requestHandler.mockReturnValue(Promise.reject(error))
178
+ const onError = jest.fn().mockReturnValue(() => true)
179
+ setupQuery({
180
+ customClient: client,
181
+ queryOptions: {
182
+ as: 'fake-query',
183
+ onError
184
+ },
185
+ queryDefinition: () => Q('io.cozy.todos')
186
+ })
187
+
188
+ // TODO find a better alternative
189
+ setTimeout(() => {
190
+ expect(onError).toBeCalled()
191
+ }, 100)
192
+ })
162
193
  })
163
194
 
164
195
  describe('use queries', () => {
package/dist/index.js CHANGED
@@ -22,6 +22,10 @@ var _exportNames = {
22
22
  HasOneInPlace: true,
23
23
  HasManyInPlace: true,
24
24
  HasManyTriggers: true,
25
+ isReferencedBy: true,
26
+ isReferencedById: true,
27
+ getReferencedBy: true,
28
+ getReferencedById: true,
25
29
  dehydrate: true,
26
30
  generateWebLink: true,
27
31
  cancelable: true,
@@ -132,16 +136,40 @@ Object.defineProperty(exports, "HasManyTriggers", {
132
136
  return _associations.HasManyTriggers;
133
137
  }
134
138
  });
139
+ Object.defineProperty(exports, "isReferencedBy", {
140
+ enumerable: true,
141
+ get: function get() {
142
+ return _helpers.isReferencedBy;
143
+ }
144
+ });
145
+ Object.defineProperty(exports, "isReferencedById", {
146
+ enumerable: true,
147
+ get: function get() {
148
+ return _helpers.isReferencedById;
149
+ }
150
+ });
151
+ Object.defineProperty(exports, "getReferencedBy", {
152
+ enumerable: true,
153
+ get: function get() {
154
+ return _helpers.getReferencedBy;
155
+ }
156
+ });
157
+ Object.defineProperty(exports, "getReferencedById", {
158
+ enumerable: true,
159
+ get: function get() {
160
+ return _helpers.getReferencedById;
161
+ }
162
+ });
135
163
  Object.defineProperty(exports, "dehydrate", {
136
164
  enumerable: true,
137
165
  get: function get() {
138
- return _helpers.dehydrate;
166
+ return _helpers2.dehydrate;
139
167
  }
140
168
  });
141
169
  Object.defineProperty(exports, "generateWebLink", {
142
170
  enumerable: true,
143
171
  get: function get() {
144
- return _helpers.generateWebLink;
172
+ return _helpers2.generateWebLink;
145
173
  }
146
174
  });
147
175
  Object.defineProperty(exports, "cancelable", {
@@ -248,7 +276,9 @@ var _dsl = require("./queries/dsl");
248
276
 
249
277
  var _associations = require("./associations");
250
278
 
251
- var _helpers = require("./helpers");
279
+ var _helpers = require("./associations/helpers");
280
+
281
+ var _helpers2 = require("./helpers");
252
282
 
253
283
  var _utils = require("./utils");
254
284
 
@@ -8,7 +8,7 @@ Object.defineProperty(exports, "__esModule", {
8
8
  exports.normalize = normalize;
9
9
  exports.ensureFilePath = ensureFilePath;
10
10
  exports.getParentFolderId = getParentFolderId;
11
- exports.doMobileUpload = exports.readMobileFile = exports.uploadFileWithConflictStrategy = exports.generateFileNameForRevision = exports.generateNewFileNameOnConflict = exports.overrideFileForPath = exports.move = exports.getFullpath = exports.hasMetadataAttribute = exports.isReferencedByAlbum = exports.fetchFilesByQualificationRules = exports.saveFileQualification = exports.isSharingShorcutNew = exports.isSharingShortcutNew = exports.isSharingShorcut = exports.isSharingShortcut = exports.getSharingShortcutTargetDoctype = exports.getSharingShortcutTargetMime = exports.getSharingShortcutStatus = exports.isShortcut = exports.shouldBeOpenedByOnlyOffice = exports.isOnlyOfficeFile = exports.isNote = exports.isDirectory = exports.isFile = exports.splitFilename = exports.ALBUMS_DOCTYPE = void 0;
11
+ exports.isFromKonnector = exports.hasCertifications = exports.hasQualifications = exports.isPlainText = exports.doMobileUpload = exports.readMobileFile = exports.uploadFileWithConflictStrategy = exports.generateFileNameForRevision = exports.generateNewFileNameOnConflict = exports.overrideFileForPath = exports.move = exports.getFullpath = exports.hasMetadataAttribute = exports.isReferencedByAlbum = exports.fetchFilesByQualificationRules = exports.saveFileQualification = exports.isSharingShorcutNew = exports.isSharingShortcutNew = exports.isSharingShorcut = exports.isSharingShortcut = exports.getSharingShortcutTargetDoctype = exports.getSharingShortcutTargetMime = exports.getSharingShortcutStatus = exports.isShortcut = exports.shouldBeOpenedByOnlyOffice = exports.isOnlyOfficeFile = exports.isNote = exports.isDirectory = exports.isFile = exports.splitFilename = exports.ALBUMS_DOCTYPE = void 0;
12
12
 
13
13
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
14
14
 
@@ -976,5 +976,52 @@ var doMobileUpload = /*#__PURE__*/function () {
976
976
  return _ref12.apply(this, arguments);
977
977
  };
978
978
  }();
979
+ /**
980
+ * @param {string} [mimeType=''] - Mime type of file
981
+ * @param {string} [fileName=''] - Name of file
982
+ * @returns {boolean}
983
+ */
984
+
985
+
986
+ exports.doMobileUpload = doMobileUpload;
987
+
988
+ var isPlainText = function isPlainText() {
989
+ var mimeType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
990
+ var fileName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
991
+ return mimeType ? /^text\//.test(mimeType) : /\.(txt|md)$/.test(fileName);
992
+ };
993
+ /**
994
+ * @param {IOCozyFile} file - io.cozy.files document
995
+ * @returns {boolean}
996
+ */
997
+
998
+
999
+ exports.isPlainText = isPlainText;
1000
+
1001
+ var hasQualifications = function hasQualifications(file) {
1002
+ return (0, _has.default)(file, 'metadata.qualification');
1003
+ };
1004
+ /**
1005
+ * @param {IOCozyFile} file - io.cozy.files document
1006
+ * @returns {boolean}
1007
+ */
1008
+
1009
+
1010
+ exports.hasQualifications = hasQualifications;
1011
+
1012
+ var hasCertifications = function hasCertifications(file) {
1013
+ return (0, _get.default)(file, 'metadata.carbonCopy', false) || (0, _get.default)(file, 'metadata.electronicSafe', false);
1014
+ };
1015
+ /**
1016
+ * @param {IOCozyFile} file - io.cozy.files document
1017
+ * @returns {boolean}
1018
+ */
1019
+
1020
+
1021
+ exports.hasCertifications = hasCertifications;
1022
+
1023
+ var isFromKonnector = function isFromKonnector(file) {
1024
+ return (0, _has.default)(file, 'cozyMetadata.sourceAccount');
1025
+ };
979
1026
 
980
- exports.doMobileUpload = doMobileUpload;
1027
+ exports.isFromKonnector = isFromKonnector;
@@ -154,6 +154,53 @@ describe('File Model', () => {
154
154
  ).toBe(false)
155
155
  })
156
156
 
157
+ describe('hasQualifications', () => {
158
+ it.each`
159
+ file | result
160
+ ${{ name: 'file01', metadata: { qualification: { label: 'passport' } } }} | ${true}
161
+ ${{ name: 'file02', metadata: {} }} | ${false}
162
+ ${{ name: 'file03' }} | ${false}
163
+ `(
164
+ `should test if a $file.name has a qualification or not`,
165
+ ({ file, result }) => {
166
+ expect(fileModel.hasQualifications(file)).toEqual(result)
167
+ }
168
+ )
169
+ })
170
+
171
+ describe('hasCertifications', () => {
172
+ it.each`
173
+ file | result
174
+ ${{ name: 'file01', metadata: { carbonCopy: true } }} | ${true}
175
+ ${{ name: 'file02', metadata: { electronicSafe: true } }} | ${true}
176
+ ${{ name: 'file03', metadata: { carbonCopy: true, electronicSafe: false } }} | ${true}
177
+ ${{ name: 'file04', metadata: { carbonCopy: false, electronicSafe: true } }} | ${true}
178
+ ${{ name: 'file05', metadata: { carbonCopy: true, electronicSafe: true } }} | ${true}
179
+ ${{ name: 'file06', metadata: { carbonCopy: false, electronicSafe: false } }} | ${false}
180
+ ${{ name: 'file07', metadata: {} }} | ${false}
181
+ ${{ name: 'file08' }} | ${false}
182
+ `(
183
+ `should test if a $file.name has a certification or not`,
184
+ ({ file, result }) => {
185
+ expect(fileModel.hasCertifications(file)).toEqual(result)
186
+ }
187
+ )
188
+ })
189
+
190
+ describe('isFromKonnector', () => {
191
+ it.each`
192
+ file | result
193
+ ${{ name: 'file01', cozyMetadata: { sourceAccount: 'sourceAccountId' } }} | ${true}
194
+ ${{ name: 'file02', cozyMetadata: {} }} | ${false}
195
+ ${{ name: 'file03' }} | ${false}
196
+ `(
197
+ `should test if a $file.name is from connector or not`,
198
+ ({ file, result }) => {
199
+ expect(fileModel.isFromKonnector(file)).toEqual(result)
200
+ }
201
+ )
202
+ })
203
+
157
204
  describe('normalizeFile', () => {
158
205
  const id = 'uuid123'
159
206
  const type = 'directory'
@@ -183,34 +230,19 @@ describe('File Model', () => {
183
230
  })
184
231
 
185
232
  describe('splitFilename', () => {
186
- const joinName = ({ filename, extension }) => filename + extension
187
- const mkFile = expectation => ({
188
- type: 'file',
189
- name: joinName(expectation)
190
- })
191
- const { stringify } = JSON
192
-
193
- const scenarios = [
194
- { filename: 'file', extension: '.ext' },
195
- { filename: 'file', extension: '' },
196
- { filename: 'file.html', extension: '.ejs' },
197
- { filename: 'file', extension: '.' },
198
- { filename: 'file.', extension: '.' },
199
- { filename: 'file.', extension: '.ext' },
200
- { filename: '.file', extension: '' },
201
- { filename: '.file', extension: '.ext' }
202
- ]
203
-
204
- for (const expectation of scenarios) {
205
- it(`splits ${stringify(joinName(expectation))} into ${stringify(
206
- expectation
207
- )}`, () => {
208
- expect(fileModel.splitFilename(mkFile(expectation))).toEqual(
209
- expectation
210
- )
211
- })
212
- }
213
-
233
+ it.each`
234
+ opts | result
235
+ ${{ type: 'file', name: 'file.ext' }} | ${{ filename: 'file', extension: '.ext' }}
236
+ ${{ type: 'file', name: 'file' }} | ${{ filename: 'file', extension: '' }}
237
+ ${{ type: 'file', name: 'file.html.ext' }} | ${{ filename: 'file.html', extension: '.ext' }}
238
+ ${{ type: 'file', name: 'file.' }} | ${{ filename: 'file', extension: '.' }}
239
+ ${{ type: 'file', name: 'file..' }} | ${{ filename: 'file.', extension: '.' }}
240
+ ${{ type: 'file', name: 'file..ext' }} | ${{ filename: 'file.', extension: '.ext' }}
241
+ ${{ type: 'file', name: '.file' }} | ${{ filename: '.file', extension: '' }}
242
+ ${{ type: 'file', name: '.file.ext' }} | ${{ filename: '.file', extension: '.ext' }}
243
+ `(`should splits $opts.name into $result`, ({ opts, result }) => {
244
+ expect(fileModel.splitFilename(opts)).toEqual(result)
245
+ })
214
246
  it('should throw an error if the file is not correct', () => {
215
247
  expect(() => fileModel.splitFilename({})).toThrow()
216
248
  expect(() => fileModel.splitFilename({ name: null })).toThrow()
@@ -510,48 +542,6 @@ describe('File Model', () => {
510
542
  })
511
543
  })
512
544
 
513
- describe('splitFilename', () => {
514
- const name = ({ filename, extension }) => filename + extension
515
- const file = expectation => ({ type: 'file', name: name(expectation) })
516
- const { stringify } = JSON
517
-
518
- const scenarios = [
519
- { filename: 'file', extension: '.ext' },
520
- { filename: 'file', extension: '' },
521
- { filename: 'file.html', extension: '.ejs' },
522
- { filename: 'file', extension: '.' },
523
- { filename: 'file.', extension: '.' },
524
- { filename: 'file.', extension: '.ext' },
525
- { filename: '.file', extension: '' },
526
- { filename: '.file', extension: '.ext' }
527
- ]
528
-
529
- for (const expectation of scenarios) {
530
- it(`splits ${stringify(name(expectation))} into ${stringify(
531
- expectation
532
- )}`, () => {
533
- expect(fileModel.splitFilename(file(expectation))).toEqual(expectation)
534
- })
535
- }
536
-
537
- it('should throw an error if the file is not correct', () => {
538
- const file = {}
539
-
540
- expect(() => fileModel.splitFilename(file)).toThrow()
541
- })
542
- it('should return only the folder name if its a folder', () => {
543
- const file = {
544
- name: 'foo',
545
- type: 'directory'
546
- }
547
- const result = fileModel.splitFilename(file)
548
- expect(result).toEqual({
549
- filename: 'foo',
550
- extension: ''
551
- })
552
- })
553
- })
554
-
555
545
  describe('generateNewFileNameOnConflict', () => {
556
546
  it('should generate the right file name with _X', () => {
557
547
  const filename1 = fileModel.generateNewFileNameOnConflict('test')
@@ -663,6 +653,53 @@ describe('File Model', () => {
663
653
  })
664
654
  })
665
655
  })
656
+
657
+ describe('isPlainText', () => {
658
+ describe('using mime types', () => {
659
+ it('should match mime types starting with "text/"', () => {
660
+ expect(fileModel.isPlainText('text/plain')).toBe(true)
661
+ expect(fileModel.isPlainText('text/markdown')).toBe(true)
662
+ expect(fileModel.isPlainText('application/text')).toBe(false)
663
+ expect(fileModel.isPlainText('something/text/else')).toBe(false)
664
+ expect(fileModel.isPlainText('text/vnd.cozy.note+markdown')).toBe(true)
665
+ })
666
+
667
+ it('should not match complex text formats', () => {
668
+ expect(fileModel.isPlainText('application/msword')).toBe(false)
669
+ expect(
670
+ fileModel.isPlainText('application/vnd.oasis.opendocument.text')
671
+ ).toBe(false)
672
+ expect(
673
+ fileModel.isPlainText('application/x-iwork-pages-sffpages')
674
+ ).toBe(false)
675
+ })
676
+
677
+ it('should not use the filename if a mime type is present', () => {
678
+ expect(
679
+ fileModel.isPlainText('application/msword', 'iswearitstext.txt')
680
+ ).toBe(false)
681
+ })
682
+ })
683
+
684
+ describe('using file names', () => {
685
+ it('should match txt files', () => {
686
+ expect(fileModel.isPlainText(undefined, 'iswearitstext.txt')).toBe(true)
687
+ })
688
+
689
+ it('should match md files', () => {
690
+ expect(fileModel.isPlainText(undefined, 'markdown.md')).toBe(true)
691
+ })
692
+
693
+ it('should not match anything else', () => {
694
+ expect(fileModel.isPlainText(undefined, 'file.doc')).toBe(false)
695
+ expect(fileModel.isPlainText(undefined, 'file.docx')).toBe(false)
696
+ expect(fileModel.isPlainText(undefined, 'file.pages')).toBe(false)
697
+ expect(fileModel.isPlainText(undefined, 'file.odt')).toBe(false)
698
+ expect(fileModel.isPlainText(undefined, 'file.csv')).toBe(false)
699
+ expect(fileModel.isPlainText(undefined, 'file.vcf')).toBe(false)
700
+ })
701
+ })
702
+ })
666
703
  })
667
704
 
668
705
  describe('File qualification', () => {
package/dist/types.js CHANGED
@@ -85,7 +85,8 @@ var _dsl = require("./queries/dsl");
85
85
  * @property {string} [as] - Name of the query
86
86
  * @property {Function} [fetchPolicy] - Fetch policy to bypass fetching based on what's already inside the state. See "Fetch policies"
87
87
  * @property {AutoUpdateOptions} [autoUpdate] - Options for the query auto update
88
- * @property {string} [options.update] - Does not seem to be used
88
+ * @property {string} [update] - Does not seem to be used
89
+ * @property {Function} [onError] - Callback when the query is errored
89
90
  */
90
91
 
91
92
  /**
@@ -98,12 +99,32 @@ var _dsl = require("./queries/dsl");
98
99
  */
99
100
 
100
101
  /**
101
- * A reference to a document (special case of a relationship used between photos and albums)
102
+ * A reference to a document
103
+ *
104
+ * @typedef {object} ReferencedByRelationship
105
+ * @property {RelationshipParent} [parent]
106
+ * @property {ReferencedBy} [referenced_by]
107
+ */
108
+
109
+ /**
110
+ * @typedef {object} RelationshipParent
111
+ * @property {{related: string}} links
112
+ * @property {Reference} [data]
113
+ */
114
+
115
+ /**
116
+ * @typedef {object} ReferencedBy
117
+ * @property {{self: string}} links
118
+ * @property {Reference[]|null} data
119
+ */
120
+
121
+ /**
122
+ * A reference to a document
102
123
  * https://docs.cozy.io/en/cozy-doctypes/docs/io.cozy.files/#references
103
124
  *
104
125
  * @typedef {object} Reference
105
- * @property {string} _id - id of the document
106
- * @property {string} _type - doctype of the document
126
+ * @property {string} id - id of the document
127
+ * @property {string} type - doctype of the document
107
128
  */
108
129
 
109
130
  /**
@@ -124,7 +145,8 @@ var _dsl = require("./queries/dsl");
124
145
  * @property {string} [_type] - Type of the document
125
146
  * @property {string} [_rev] - Current revision of the document
126
147
  * @property {boolean} [_deleted] - When the document has been deleted
127
- * @property {object} [relationships] - Relationships of the document
148
+ * @property {ReferencedByRelationship} [relationships] - Relationships of the document
149
+ * @property {Reference[]} [referenced_by] - referenced by of another document
128
150
  */
129
151
 
130
152
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "27.3.2",
3
+ "version": "27.6.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.node.js",
6
6
  "browser": "dist/index.js",
@@ -69,5 +69,5 @@
69
69
  "react-native-inappbrowser-reborn": "^3.5.1"
70
70
  },
71
71
  "sideEffects": false,
72
- "gitHead": "826f995c85378bdcd76f3a62428c1d9857f0136d"
72
+ "gitHead": "4228ec1287e3b18892f2e57128a09a77e87cae2e"
73
73
  }
@@ -10,6 +10,10 @@ export type ClientOptions = {
10
10
  autoHydrate?: boolean;
11
11
  oauth?: object;
12
12
  onTokenRefresh?: Function;
13
+ /**
14
+ * - Default callback if a query is errored
15
+ */
16
+ onError?: Function;
13
17
  /**
14
18
  * - Schema description for each doctypes
15
19
  */
@@ -39,7 +43,7 @@ export type ClientOptions = {
39
43
  * @property {boolean} [autoHydrate]
40
44
  * @property {object} [oauth]
41
45
  * @property {Function} [onTokenRefresh]
42
- * @property {Function} [onTokenRefresh]
46
+ * @property {Function} [onError] - Default callback if a query is errored
43
47
  * @property {Link} [link] - Backward compatibility
44
48
  * @property {Array<Link>} [links] - List of links
45
49
  * @property {object} [schema] - Schema description for each doctypes
@@ -146,6 +150,10 @@ declare class CozyClient {
146
150
  autoHydrate?: boolean;
147
151
  oauth?: object;
148
152
  onTokenRefresh?: Function;
153
+ /**
154
+ * - Default callback if a query is errored
155
+ */
156
+ onError?: Function;
149
157
  /**
150
158
  * - If set to false, the client will not instantiate a Redux store automatically. Use this if you want to merge cozy-client's store with your own redux store. See [here](https://docs.cozy.io/en/cozy-client/react-integration/#1b-use-your-own-redux-store) for more information.
151
159
  */
@@ -640,6 +648,12 @@ declare class CozyClient {
640
648
  * @param {object} data - Data that is inserted in the store. Shape: { doctype: [data] }
641
649
  */
642
650
  setData(data: object): void;
651
+ /**
652
+ * At any time put an error function
653
+ *
654
+ * @param {Function} [onError] - Set a callback for queries which are errored
655
+ */
656
+ setOnError(onError?: Function): void;
643
657
  toJSON(): SnapshotClient;
644
658
  }
645
659
  declare namespace CozyClient {
@@ -7,3 +7,10 @@ export function create(target: any, { name, type, doctype }: {
7
7
  type: any;
8
8
  doctype: any;
9
9
  }, accessors: any): any;
10
+ export function isReferencedBy(file: IOCozyFile, referencedBy: Doctype): boolean;
11
+ export function isReferencedById(file: IOCozyFile, referencedBy: Doctype, referencedId: string): boolean;
12
+ export function getReferencedBy(file: IOCozyFile, referencedBy: Doctype): Reference[];
13
+ export function getReferencedById(file: IOCozyFile, referencedBy: Doctype, referencedId: string): Reference[];
14
+ import { IOCozyFile } from "../types";
15
+ import { Doctype } from "../types";
16
+ import { Reference } from "../types";
@@ -6,4 +6,4 @@ import HasOneInPlace from "./HasOneInPlace";
6
6
  import HasManyInPlace from "./HasManyInPlace";
7
7
  import HasManyTriggers from "./HasManyTriggers";
8
8
  export { Association, HasManyFiles, HasMany, HasOne, HasOneInPlace, HasManyInPlace, HasManyTriggers };
9
- export { resolveClass, create } from "./helpers";
9
+ export { resolveClass, create, isReferencedBy, isReferencedById, getReferencedBy, getReferencedById } from "./helpers";
@@ -1,24 +1,48 @@
1
1
  export function useQueries(querySpecs: any): {};
2
2
  export default useQuery;
3
+ /**
4
+ * Fetches a queryDefinition and returns the queryState
5
+ */
6
+ export type UseQueryOptions = {
7
+ /**
8
+ * - Name for the query [required]
9
+ */
10
+ as: object;
11
+ /**
12
+ * - If set to false, the query won't be executed
13
+ */
14
+ enabled: boolean;
15
+ /**
16
+ * - Fetch policy
17
+ */
18
+ fetchPolicy: object;
19
+ /**
20
+ * - If true, the "data" returned will be
21
+ * a single doc instead of an array for single doc queries. Defaults to false for backward
22
+ * compatibility but will be set to true in the future.
23
+ */
24
+ singleDocData: object;
25
+ /**
26
+ * - Callback if the query is errored
27
+ */
28
+ onError: Function;
29
+ };
3
30
  /**
4
31
  * Fetches a queryDefinition and returns the queryState
5
32
  *
6
- * @param {object} queryDefinition - Definition created with Q()
33
+ * @param {QueryDefinition} queryDefinition - Definition created with Q()
7
34
  *
8
- * @param {object} options - Options
9
- * @param {object} options.as - Name for the query [required]
10
- * @param {boolean} options.enabled - If set to false, the query won't be executed
11
- * @param {object} options.fetchPolicy - Fetch policy
12
- * @param {object} options.singleDocData - If true, the "data" returned will be
35
+ * @typedef {object} UseQueryOptions
36
+ * @property {object} as - Name for the query [required]
37
+ * @property {boolean} enabled - If set to false, the query won't be executed
38
+ * @property {object} fetchPolicy - Fetch policy
39
+ * @property {object} singleDocData - If true, the "data" returned will be
13
40
  * a single doc instead of an array for single doc queries. Defaults to false for backward
14
41
  * compatibility but will be set to true in the future.
42
+ * @property {Function} onError - Callback if the query is errored
15
43
  *
16
44
  * @returns {UseQueryReturnValue}
17
45
  */
18
- declare function useQuery(queryDefinition: object, options: {
19
- as: object;
20
- enabled: boolean;
21
- fetchPolicy: object;
22
- singleDocData: object;
23
- }): UseQueryReturnValue;
46
+ declare function useQuery(queryDefinition: QueryDefinition, options: any): UseQueryReturnValue;
47
+ import { QueryDefinition } from "../queries/dsl";
24
48
  import { UseQueryReturnValue } from "../types";
package/types/index.d.ts CHANGED
@@ -18,6 +18,7 @@ import * as models from "./models";
18
18
  export { manifest, models };
19
19
  export { QueryDefinition, Q, Mutations, MutationTypes, getDoctypeFromOperation } from "./queries/dsl";
20
20
  export { Association, HasMany, HasOne, HasOneInPlace, HasManyInPlace, HasManyTriggers } from "./associations";
21
+ export { isReferencedBy, isReferencedById, getReferencedBy, getReferencedById } from "./associations/helpers";
21
22
  export { dehydrate, generateWebLink } from "./helpers";
22
23
  export { cancelable, isQueryLoading, hasQueryBeenLoaded } from "./utils";
23
24
  export { queryConnect, queryConnectFlat, withClient } from "./hoc";
@@ -57,6 +57,10 @@ export function generateFileNameForRevision(file: IOCozyFile, revision: object,
57
57
  export function uploadFileWithConflictStrategy(client: CozyClient, file: string | ArrayBuffer, options: FileUploadOptions): any;
58
58
  export function readMobileFile(fileURL: string): Promise<any>;
59
59
  export function doMobileUpload(client: CozyClient, fileURL: string, options: FileUploadOptions): Promise<any>;
60
+ export function isPlainText(mimeType?: string, fileName?: string): boolean;
61
+ export function hasQualifications(file: IOCozyFile): boolean;
62
+ export function hasCertifications(file: IOCozyFile): boolean;
63
+ export function isFromKonnector(file: IOCozyFile): boolean;
60
64
  export type FileUploadOptions = {
61
65
  /**
62
66
  * - The file name to upload
@@ -0,0 +1,7 @@
1
+ export function isReferencedBy(file: IOCozyFile, referencedBy: Doctype): boolean;
2
+ export function isReferencedById(file: IOCozyFile, referencedBy: Doctype, referencedId: string): boolean;
3
+ export function getReferencedBy(file: IOCozyFile, referencedBy: Doctype): Reference[];
4
+ export function getReferencedById(file: IOCozyFile, referencedBy: Doctype, referencedId: string): Reference[];
5
+ import { IOCozyFile } from "../types";
6
+ import { Doctype } from "../types";
7
+ import { Reference } from "../types";