cozy-client 60.0.0 → 60.1.1

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.
@@ -288,7 +288,12 @@ var StackLink = /*#__PURE__*/function (_CozyLink) {
288
288
  id = query.id,
289
289
  ids = query.ids,
290
290
  referenced = query.referenced,
291
- options = (0, _objectWithoutProperties2.default)(query, ["doctype", "selector", "id", "ids", "referenced"]);
291
+ sharingId = query.sharingId,
292
+ rawOptions = (0, _objectWithoutProperties2.default)(query, ["doctype", "selector", "id", "ids", "referenced", "sharingId"]);
293
+
294
+ var options = _objectSpread(_objectSpread({}, rawOptions), {}, {
295
+ driveId: undefined
296
+ });
292
297
 
293
298
  if (!doctype) {
294
299
  _logger.default.warn('Bad query', query);
@@ -296,7 +301,13 @@ var StackLink = /*#__PURE__*/function (_CozyLink) {
296
301
  throw new Error('No doctype found in a query definition');
297
302
  }
298
303
 
299
- var collection = this.stackClient.collection(doctype);
304
+ if (doctype === _const.DOCTYPE_FILES && sharingId) {
305
+ options = _objectSpread(_objectSpread({}, options), {}, {
306
+ driveId: sharingId
307
+ });
308
+ }
309
+
310
+ var collection = this.stackClient.collection(doctype, options);
300
311
 
301
312
  if (id) {
302
313
  return collection.get(id, query);
@@ -18,7 +18,10 @@ describe('StackLink', () => {
18
18
  stackClient.collection().all.mockReset()
19
19
  await link.request(query)
20
20
  expect(stackClient.collection().all).toHaveBeenCalled()
21
- expect(stackClient.collection).toHaveBeenCalledWith('io.cozy.todos')
21
+ expect(stackClient.collection).toHaveBeenCalledWith(
22
+ 'io.cozy.todos',
23
+ expect.anything()
24
+ )
22
25
  })
23
26
 
24
27
  it('should execute queries with a selector', async () => {
@@ -36,7 +39,10 @@ describe('StackLink', () => {
36
39
  stackClient.collection().find.mockReset()
37
40
  await link.request(query)
38
41
  expect(stackClient.collection().find).toHaveBeenCalled()
39
- expect(stackClient.collection).toHaveBeenCalledWith('io.cozy.todos')
42
+ expect(stackClient.collection).toHaveBeenCalledWith(
43
+ 'io.cozy.todos',
44
+ expect.anything()
45
+ )
40
46
  })
41
47
 
42
48
  it('should use all if a no sort option is given', async () => {
@@ -44,7 +50,10 @@ describe('StackLink', () => {
44
50
  stackClient.collection().all.mockReset()
45
51
  await link.request(query)
46
52
  expect(stackClient.collection().all).toHaveBeenCalled()
47
- expect(stackClient.collection).toHaveBeenCalledWith('io.cozy.todos')
53
+ expect(stackClient.collection).toHaveBeenCalledWith(
54
+ 'io.cozy.todos',
55
+ expect.anything()
56
+ )
48
57
  })
49
58
 
50
59
  it('should use find if a partialFilter is given', async () => {
@@ -52,7 +61,10 @@ describe('StackLink', () => {
52
61
  stackClient.collection().find.mockReset()
53
62
  await link.request(query)
54
63
  expect(stackClient.collection().find).toHaveBeenCalled()
55
- expect(stackClient.collection).toHaveBeenCalledWith('io.cozy.todos')
64
+ expect(stackClient.collection).toHaveBeenCalledWith(
65
+ 'io.cozy.todos',
66
+ expect.anything()
67
+ )
56
68
  })
57
69
 
58
70
  it('should use find if fields are given', async () => {
@@ -60,7 +72,10 @@ describe('StackLink', () => {
60
72
  stackClient.collection().find.mockReset()
61
73
  await link.request(query)
62
74
  expect(stackClient.collection().find).toHaveBeenCalled()
63
- expect(stackClient.collection).toHaveBeenCalledWith('io.cozy.todos')
75
+ expect(stackClient.collection).toHaveBeenCalledWith(
76
+ 'io.cozy.todos',
77
+ expect.anything()
78
+ )
64
79
  })
65
80
  })
66
81
 
@@ -430,7 +430,8 @@ describe('File Model', () => {
430
430
  'mydoc.odt'
431
431
  )
432
432
  expect(cozyClient.stackClient.collection).toHaveBeenCalledWith(
433
- 'io.cozy.files'
433
+ 'io.cozy.files',
434
+ expect.anything()
434
435
  )
435
436
  expect(getSpy).toHaveBeenCalledWith(
436
437
  'parent',
@@ -447,7 +448,8 @@ describe('File Model', () => {
447
448
  'mydoc.odt'
448
449
  )
449
450
  expect(cozyClient.stackClient.collection).toHaveBeenCalledWith(
450
- 'io.cozy.files'
451
+ 'io.cozy.files',
452
+ expect.anything()
451
453
  )
452
454
  expect(getSpy).toHaveBeenCalledWith(
453
455
  'parent',
@@ -64,6 +64,7 @@ var QueryDefinition = /*#__PURE__*/function () {
64
64
  * @param {number|null} [options.skip] - The number of docs to skip.
65
65
  * @param {import('../types').CouchDBViewCursor} [options.cursor] - The cursor to paginate views.
66
66
  * @param {string} [options.bookmark] - The bookmark to paginate mango queries.
67
+ * @param {string} [options.sharingId] - The id of the sharing
67
68
  */
68
69
  function QueryDefinition() {
69
70
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -82,6 +83,7 @@ var QueryDefinition = /*#__PURE__*/function () {
82
83
  this.skip = options.skip;
83
84
  this.cursor = options.cursor;
84
85
  this.bookmark = options.bookmark;
86
+ this.sharingId = options.sharingId;
85
87
  }
86
88
  /**
87
89
  * Checks if the sort order matches the index' fields order.
@@ -444,6 +446,20 @@ var QueryDefinition = /*#__PURE__*/function () {
444
446
  referenced: document
445
447
  }));
446
448
  }
449
+ /**
450
+ * Use a sharingId to query documents coming from a sharing
451
+ *
452
+ * @param {string} id - The sharing doc id
453
+ * @returns {QueryDefinition} The QueryDefinition object.
454
+ */
455
+
456
+ }, {
457
+ key: "sharingById",
458
+ value: function sharingById(id) {
459
+ return new QueryDefinition(_objectSpread(_objectSpread({}, this.toDefinition()), {}, {
460
+ sharingId: id
461
+ }));
462
+ }
447
463
  }, {
448
464
  key: "toDefinition",
449
465
  value: function toDefinition() {
@@ -461,7 +477,8 @@ var QueryDefinition = /*#__PURE__*/function () {
461
477
  limit: this.limit,
462
478
  skip: this.skip,
463
479
  cursor: this.cursor,
464
- bookmark: this.bookmark
480
+ bookmark: this.bookmark,
481
+ sharingId: this.sharingId
465
482
  };
466
483
  }
467
484
  }]);
package/dist/storage.js CHANGED
@@ -54,6 +54,11 @@ var shouldDocumentBePersisted = function shouldDocumentBePersisted(document) {
54
54
  return true;
55
55
  }
56
56
 
57
+ if (document.driveId && document._type === 'io.cozy.files') {
58
+ // Special case for files in shared drives, so remote files could be locally persisted
59
+ return true;
60
+ }
61
+
57
62
  return false;
58
63
  };
59
64
  /**
@@ -19,6 +19,7 @@ Object {
19
19
  "partialFilter": undefined,
20
20
  "referenced": undefined,
21
21
  "selector": undefined,
22
+ "sharingId": undefined,
22
23
  "skip": undefined,
23
24
  "sort": undefined,
24
25
  },
@@ -60,6 +61,7 @@ Object {
60
61
  "partialFilter": undefined,
61
62
  "referenced": undefined,
62
63
  "selector": undefined,
64
+ "sharingId": undefined,
63
65
  "skip": undefined,
64
66
  "sort": undefined,
65
67
  },
@@ -100,6 +102,7 @@ Object {
100
102
  "partialFilter": undefined,
101
103
  "referenced": undefined,
102
104
  "selector": undefined,
105
+ "sharingId": undefined,
103
106
  "skip": undefined,
104
107
  "sort": undefined,
105
108
  },
@@ -140,6 +143,7 @@ Object {
140
143
  },
141
144
  "done": true,
142
145
  },
146
+ "sharingId": undefined,
143
147
  "skip": undefined,
144
148
  "sort": undefined,
145
149
  },
@@ -180,6 +184,7 @@ Object {
180
184
  "partialFilter": undefined,
181
185
  "referenced": undefined,
182
186
  "selector": undefined,
187
+ "sharingId": undefined,
183
188
  "skip": undefined,
184
189
  "sort": undefined,
185
190
  },
@@ -217,6 +222,7 @@ Object {
217
222
  "selector": Object {
218
223
  "done": true,
219
224
  },
225
+ "sharingId": undefined,
220
226
  "skip": undefined,
221
227
  "sort": undefined,
222
228
  },
@@ -259,6 +265,7 @@ Object {
259
265
  "selector": Object {
260
266
  "done": false,
261
267
  },
268
+ "sharingId": undefined,
262
269
  "skip": undefined,
263
270
  "sort": Array [
264
271
  Object {
@@ -298,6 +305,7 @@ Object {
298
305
  "selector": Object {
299
306
  "done": true,
300
307
  },
308
+ "sharingId": undefined,
301
309
  "skip": undefined,
302
310
  "sort": undefined,
303
311
  },
@@ -339,6 +347,7 @@ Object {
339
347
  "partialFilter": undefined,
340
348
  "referenced": undefined,
341
349
  "selector": undefined,
350
+ "sharingId": undefined,
342
351
  "skip": undefined,
343
352
  "sort": undefined,
344
353
  },
@@ -375,6 +384,7 @@ Object {
375
384
  "partialFilter": undefined,
376
385
  "referenced": undefined,
377
386
  "selector": undefined,
387
+ "sharingId": undefined,
378
388
  "skip": undefined,
379
389
  "sort": undefined,
380
390
  },
@@ -415,6 +425,7 @@ Object {
415
425
  "partialFilter": undefined,
416
426
  "referenced": undefined,
417
427
  "selector": undefined,
428
+ "sharingId": undefined,
418
429
  "skip": undefined,
419
430
  "sort": undefined,
420
431
  },
@@ -450,6 +461,7 @@ Object {
450
461
  "selector": Object {
451
462
  "done": true,
452
463
  },
464
+ "sharingId": undefined,
453
465
  "skip": undefined,
454
466
  "sort": undefined,
455
467
  },
@@ -492,6 +504,7 @@ Object {
492
504
  "partialFilter": undefined,
493
505
  "referenced": undefined,
494
506
  "selector": undefined,
507
+ "sharingId": undefined,
495
508
  "skip": undefined,
496
509
  "sort": undefined,
497
510
  },
@@ -525,6 +538,7 @@ Object {
525
538
  "partialFilter": undefined,
526
539
  "referenced": undefined,
527
540
  "selector": undefined,
541
+ "sharingId": undefined,
528
542
  "skip": undefined,
529
543
  "sort": undefined,
530
544
  },
@@ -565,6 +579,7 @@ Object {
565
579
  "partialFilter": undefined,
566
580
  "referenced": undefined,
567
581
  "selector": undefined,
582
+ "sharingId": undefined,
568
583
  "skip": undefined,
569
584
  "sort": undefined,
570
585
  },
@@ -602,6 +617,7 @@ Object {
602
617
  "selector": Object {
603
618
  "done": true,
604
619
  },
620
+ "sharingId": undefined,
605
621
  "skip": undefined,
606
622
  "sort": undefined,
607
623
  },
@@ -646,6 +662,7 @@ Object {
646
662
  "partialFilter": undefined,
647
663
  "referenced": undefined,
648
664
  "selector": undefined,
665
+ "sharingId": undefined,
649
666
  "skip": undefined,
650
667
  "sort": undefined,
651
668
  },
@@ -681,6 +698,7 @@ Object {
681
698
  "selector": Object {
682
699
  "done": false,
683
700
  },
701
+ "sharingId": undefined,
684
702
  "skip": undefined,
685
703
  "sort": undefined,
686
704
  },
@@ -723,6 +741,7 @@ Object {
723
741
  "partialFilter": undefined,
724
742
  "referenced": undefined,
725
743
  "selector": undefined,
744
+ "sharingId": undefined,
726
745
  "skip": undefined,
727
746
  "sort": undefined,
728
747
  },
@@ -761,6 +780,7 @@ Object {
761
780
  },
762
781
  "referenced": undefined,
763
782
  "selector": undefined,
783
+ "sharingId": undefined,
764
784
  "skip": undefined,
765
785
  "sort": undefined,
766
786
  },
package/dist/types.js CHANGED
@@ -464,6 +464,7 @@ var _dsl = require("./queries/dsl");
464
464
  * @property {CozyMetadata} [cozyMetadata] - Cozy Metadata
465
465
  * @property {CozyClientDocumentMeta} [meta] - Pouch Metadata
466
466
  * @property {boolean} [cozyLocalOnly] - When true the document should NOT be replicated to the remote database
467
+ * @property {string} [driveId] - Id of a shared drive, only for shared io.cozy.files
467
468
  */
468
469
 
469
470
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "60.0.0",
3
+ "version": "60.1.1",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.node.js",
6
6
  "browser": "dist/index.js",
@@ -19,7 +19,7 @@
19
19
  "@types/jest": "^26.0.20",
20
20
  "@types/lodash": "^4.14.170",
21
21
  "btoa": "^1.2.1",
22
- "cozy-stack-client": "^60.0.0",
22
+ "cozy-stack-client": "^60.1.0",
23
23
  "date-fns": "2.29.3",
24
24
  "fast-deep-equal": "^3.1.3",
25
25
  "json-stable-stringify": "^1.0.1",
@@ -74,5 +74,5 @@
74
74
  "react-native-ios11-devicecheck": "^0.0.3"
75
75
  },
76
76
  "sideEffects": false,
77
- "gitHead": "a89eb840497357fb366bc97d92e4a5880fd55099"
77
+ "gitHead": "a944c176ad97aa07f7145d97642716a9dc231990"
78
78
  }
@@ -40,6 +40,10 @@ export type CozyClientDocument = {
40
40
  * - When true the document should NOT be replicated to the remote database
41
41
  */
42
42
  cozyLocalOnly?: boolean;
43
+ /**
44
+ * - Id of a shared drive, only for shared io.cozy.files
45
+ */
46
+ driveId?: string;
43
47
  };
44
48
  export type ClientOptions = {
45
49
  client?: object;
@@ -361,9 +365,10 @@ declare class CozyClient {
361
365
  * a [DocumentCollection]{@link https://docs.cozy.io/en/cozy-client/api/cozy-stack-client/#DocumentCollection} instance.
362
366
  *
363
367
  * @param {string} doctype The collection doctype.
368
+ * @param {object} options Options to pass to the collection
364
369
  * @returns {import("./types").DocumentCollection} Collection corresponding to the doctype
365
370
  */
366
- collection(doctype: string): import("./types").DocumentCollection;
371
+ collection(doctype: string, options?: object): import("./types").DocumentCollection;
367
372
  fetch(method: any, path: any, body: any, options?: {}): any;
368
373
  all(doctype: any): QueryDefinition;
369
374
  find(doctype: any, selector?: any): QueryDefinition;
@@ -559,23 +564,6 @@ declare class CozyClient {
559
564
  * @returns {Promise<import("./types").ClientResponse>}
560
565
  */
561
566
  private requestQuery;
562
- /**
563
- * Save the document or array of documents into the persisted storage (if any)
564
- *
565
- * @private
566
- * @param {CozyClientDocument | Array<CozyClientDocument>} data - Document or array of documents to be saved
567
- * @returns {Promise<void>}
568
- */
569
- private persistVirtualDocuments;
570
- /**
571
- * Save the document or array of documents into the persisted storage (if any)
572
- *
573
- * @private
574
- * @param {CozyClientDocument} document - Document to be saved
575
- * @param {boolean} enforce - When true, save the document even if `meta.rev` or `_rev` exist
576
- * @returns {Promise<void>}
577
- */
578
- private persistVirtualDocument;
579
567
  /**
580
568
  * Fetch relationships for a response (can be several docs).
581
569
  * Fills the `relationships` attribute of each documents.
@@ -596,9 +584,13 @@ declare class CozyClient {
596
584
  *
597
585
  * @param {string} doctype - Doctype of the documents being hydrated
598
586
  * @param {Array<import("./types").CozyClientDocument>} documents - Documents to be hydrated
587
+ * @param {object} [options] - Options
588
+ * @param {boolean} [options.forceHydratation=false] - If set to true, all documents will be hydrated w.r.t. the provided schema's relationships, even if the relationship does not exist on the doc.
599
589
  * @returns {Array<import("./types").HydratedDocument>}
600
590
  */
601
- hydrateDocuments(doctype: string, documents: Array<import("./types").CozyClientDocument>): Array<import("./types").HydratedDocument>;
591
+ hydrateDocuments(doctype: string, documents: Array<import("./types").CozyClientDocument>, { forceHydratation }?: {
592
+ forceHydratation?: boolean;
593
+ }): Array<import("./types").HydratedDocument>;
602
594
  /**
603
595
  * Resolves relationships on a document.
604
596
  *
@@ -606,11 +598,17 @@ declare class CozyClient {
606
598
  * the relationship
607
599
  *
608
600
  * @param {import("./types").CozyClientDocument} document - for which relationships must be resolved
609
- * @param {Schema} [schemaArg] - Optional
601
+ * @param {Schema} [schemaArg] - The schema describing the relationships
602
+ * @param {object} [options] - Options
603
+ * @param {boolean} [options.forceHydratation=false] - If set to true, the doc will be hydrated w.r.t. the provided schema's relationships, even if the relationship does not exist on the doc.
610
604
  * @returns {import("./types").HydratedDocument}
611
605
  */
612
- hydrateDocument(document: import("./types").CozyClientDocument, schemaArg?: Schema): import("./types").HydratedDocument;
613
- hydrateRelationships(document: any, schemaRelationships: any): {
606
+ hydrateDocument(document: import("./types").CozyClientDocument, schemaArg?: Schema, { forceHydratation }?: {
607
+ forceHydratation?: boolean;
608
+ }): import("./types").HydratedDocument;
609
+ hydrateRelationships(document: any, schemaRelationships: any, { forceHydratation }?: {
610
+ forceHydratation?: boolean;
611
+ }): {
614
612
  [x: string]: any;
615
613
  };
616
614
  generateRandomId(): string;
@@ -125,6 +125,7 @@ export class QueryDefinition {
125
125
  * @param {number|null} [options.skip] - The number of docs to skip.
126
126
  * @param {import('../types').CouchDBViewCursor} [options.cursor] - The cursor to paginate views.
127
127
  * @param {string} [options.bookmark] - The bookmark to paginate mango queries.
128
+ * @param {string} [options.sharingId] - The id of the sharing
128
129
  */
129
130
  constructor(options?: {
130
131
  doctype: import('../types').Doctype;
@@ -141,6 +142,7 @@ export class QueryDefinition {
141
142
  skip: number | null;
142
143
  cursor: import('../types').CouchDBViewCursor;
143
144
  bookmark: string;
145
+ sharingId: string;
144
146
  });
145
147
  doctype: string;
146
148
  id: string;
@@ -156,6 +158,7 @@ export class QueryDefinition {
156
158
  skip: number;
157
159
  cursor: import("../types").CouchDBViewCursor;
158
160
  bookmark: string;
161
+ sharingId: string;
159
162
  /**
160
163
  * Checks if the sort order matches the index' fields order.
161
164
  *
@@ -291,6 +294,13 @@ export class QueryDefinition {
291
294
  * @returns {QueryDefinition} The QueryDefinition object.
292
295
  */
293
296
  referencedBy(document: object): QueryDefinition;
297
+ /**
298
+ * Use a sharingId to query documents coming from a sharing
299
+ *
300
+ * @param {string} id - The sharing doc id
301
+ * @returns {QueryDefinition} The QueryDefinition object.
302
+ */
303
+ sharingById(id: string): QueryDefinition;
294
304
  toDefinition(): {
295
305
  doctype: string;
296
306
  id: string;
@@ -306,6 +316,7 @@ export class QueryDefinition {
306
316
  skip: number;
307
317
  cursor: import("../types").CouchDBViewCursor;
308
318
  bookmark: string;
319
+ sharingId: string;
309
320
  };
310
321
  }
311
322
  declare const CREATE_DOCUMENT: "CREATE_DOCUMENT";
@@ -43,6 +43,10 @@ export type CozyClientDocument = {
43
43
  * - When true the document should NOT be replicated to the remote database
44
44
  */
45
45
  cozyLocalOnly?: boolean;
46
+ /**
47
+ * - Id of a shared drive, only for shared io.cozy.files
48
+ */
49
+ driveId?: string;
46
50
  };
47
51
  import CozyClient from "./CozyClient";
48
52
  import { QueryDefinition } from "./queries/dsl";
package/types/types.d.ts CHANGED
@@ -815,6 +815,10 @@ export type CozyClientDocument = {
815
815
  * - When true the document should NOT be replicated to the remote database
816
816
  */
817
817
  cozyLocalOnly?: boolean;
818
+ /**
819
+ * - Id of a shared drive, only for shared io.cozy.files
820
+ */
821
+ driveId?: string;
818
822
  };
819
823
  /**
820
824
  * - A io.cozy.files document's metadata