cozy-client 58.5.0 → 59.1.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.
@@ -327,7 +327,7 @@ var StackLink = /*#__PURE__*/function (_CozyLink) {
327
327
  case 0:
328
328
  mutationType = mutation.mutationType, doc = mutation.document, docs = mutation.documents, props = (0, _objectWithoutProperties2.default)(mutation, ["mutationType", "document", "documents"]);
329
329
  _context4.t0 = mutationType;
330
- _context4.next = _context4.t0 === _dsl.MutationTypes.CREATE_DOCUMENT ? 4 : _context4.t0 === _dsl.MutationTypes.UPDATE_DOCUMENTS ? 5 : _context4.t0 === _dsl.MutationTypes.UPDATE_DOCUMENT ? 9 : _context4.t0 === _dsl.MutationTypes.DELETE_DOCUMENT ? 10 : _context4.t0 === _dsl.MutationTypes.ADD_REFERENCES_TO ? 11 : _context4.t0 === _dsl.MutationTypes.REMOVE_REFERENCES_TO ? 12 : _context4.t0 === _dsl.MutationTypes.ADD_REFERENCED_BY ? 13 : _context4.t0 === _dsl.MutationTypes.REMOVE_REFERENCED_BY ? 18 : _context4.t0 === _dsl.MutationTypes.UPLOAD_FILE ? 23 : 24;
330
+ _context4.next = _context4.t0 === _dsl.MutationTypes.CREATE_DOCUMENT ? 4 : _context4.t0 === _dsl.MutationTypes.UPDATE_DOCUMENTS ? 5 : _context4.t0 === _dsl.MutationTypes.UPDATE_DOCUMENT ? 9 : _context4.t0 === _dsl.MutationTypes.DELETE_DOCUMENT ? 10 : _context4.t0 === _dsl.MutationTypes.DELETE_DOCUMENTS ? 11 : _context4.t0 === _dsl.MutationTypes.ADD_REFERENCES_TO ? 12 : _context4.t0 === _dsl.MutationTypes.REMOVE_REFERENCES_TO ? 13 : _context4.t0 === _dsl.MutationTypes.ADD_REFERENCED_BY ? 14 : _context4.t0 === _dsl.MutationTypes.REMOVE_REFERENCED_BY ? 19 : _context4.t0 === _dsl.MutationTypes.UPLOAD_FILE ? 24 : 25;
331
331
  break;
332
332
 
333
333
  case 4:
@@ -348,40 +348,43 @@ var StackLink = /*#__PURE__*/function (_CozyLink) {
348
348
  return _context4.abrupt("return", this.stackClient.collection(doc._type).destroy(doc));
349
349
 
350
350
  case 11:
351
- return _context4.abrupt("return", this.stackClient.collection(props.referencedDocuments[0]._type).addReferencesTo(doc, props.referencedDocuments));
351
+ return _context4.abrupt("return", this.stackClient.collection(doc._type).destroyAll(docs));
352
352
 
353
353
  case 12:
354
- return _context4.abrupt("return", this.stackClient.collection(props.referencedDocuments[0]._type).removeReferencesTo(doc, props.referencedDocuments));
354
+ return _context4.abrupt("return", this.stackClient.collection(props.referencedDocuments[0]._type).addReferencesTo(doc, props.referencedDocuments));
355
355
 
356
356
  case 13:
357
+ return _context4.abrupt("return", this.stackClient.collection(props.referencedDocuments[0]._type).removeReferencesTo(doc, props.referencedDocuments));
358
+
359
+ case 14:
357
360
  if (!(doc._type === _const.DOCTYPE_FILES)) {
358
- _context4.next = 17;
361
+ _context4.next = 18;
359
362
  break;
360
363
  }
361
364
 
362
365
  return _context4.abrupt("return", this.stackClient.collection(_const.DOCTYPE_FILES).addReferencedBy(doc, props.referencedDocuments));
363
366
 
364
- case 17:
367
+ case 18:
365
368
  throw new Error('The document type should be io.cozy.files');
366
369
 
367
- case 18:
370
+ case 19:
368
371
  if (!(doc._type === _const.DOCTYPE_FILES)) {
369
- _context4.next = 22;
372
+ _context4.next = 23;
370
373
  break;
371
374
  }
372
375
 
373
376
  return _context4.abrupt("return", this.stackClient.collection(_const.DOCTYPE_FILES).removeReferencedBy(doc, props.referencedDocuments));
374
377
 
375
- case 22:
378
+ case 23:
376
379
  throw new Error('The document type should be io.cozy.files');
377
380
 
378
- case 23:
381
+ case 24:
379
382
  return _context4.abrupt("return", this.stackClient.collection(_const.DOCTYPE_FILES).upload(props.file, props.dirPath));
380
383
 
381
- case 24:
384
+ case 25:
382
385
  return _context4.abrupt("return", forward(mutation, options, result));
383
386
 
384
- case 25:
387
+ case 26:
385
388
  case "end":
386
389
  return _context4.stop();
387
390
  }
@@ -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.QueryDefinition = exports.MutationTypes = exports.Mutations = exports.getDoctypeFromOperation = exports.uploadFile = exports.removeReferencedBy = exports.addReferencedBy = exports.removeReferencesTo = exports.addReferencesTo = exports.deleteDocument = exports.updateDocuments = exports.updateDocument = exports.createDocument = exports.isAGetByIdQuery = exports.Q = void 0;
8
+ exports.QueryDefinition = exports.MutationTypes = exports.Mutations = exports.getDoctypeFromOperation = exports.uploadFile = exports.removeReferencedBy = exports.addReferencedBy = exports.removeReferencesTo = exports.addReferencesTo = exports.deleteDocuments = exports.deleteDocument = exports.updateDocuments = exports.updateDocument = exports.createDocuments = exports.createDocument = exports.isAGetByIdQuery = exports.Q = void 0;
9
9
 
10
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
11
 
@@ -513,9 +513,11 @@ var isAGetByIdQuery = function isAGetByIdQuery(queryDefinition) {
513
513
 
514
514
  exports.isAGetByIdQuery = isAGetByIdQuery;
515
515
  var CREATE_DOCUMENT = 'CREATE_DOCUMENT';
516
+ var CREATE_DOCUMENTS = 'CREATE_DOCUMENTS';
516
517
  var UPDATE_DOCUMENT = 'UPDATE_DOCUMENT';
517
518
  var UPDATE_DOCUMENTS = 'UPDATE_DOCUMENTS';
518
519
  var DELETE_DOCUMENT = 'DELETE_DOCUMENT';
520
+ var DELETE_DOCUMENTS = 'DELETE_DOCUMENTS';
519
521
  var ADD_REFERENCES_TO = 'ADD_REFERENCES_TO';
520
522
  var REMOVE_REFERENCES_TO = 'REMOVE_REFERENCES_TO';
521
523
  var ADD_REFERENCED_BY = 'ADD_REFERENCED_BY';
@@ -531,6 +533,15 @@ var createDocument = function createDocument(document) {
531
533
 
532
534
  exports.createDocument = createDocument;
533
535
 
536
+ var createDocuments = function createDocuments(documents) {
537
+ return {
538
+ mutationType: MutationTypes.CREATE_DOCUMENTS,
539
+ documents: documents
540
+ };
541
+ };
542
+
543
+ exports.createDocuments = createDocuments;
544
+
534
545
  var updateDocument = function updateDocument(document) {
535
546
  return {
536
547
  mutationType: MutationTypes.UPDATE_DOCUMENT,
@@ -558,6 +569,15 @@ var deleteDocument = function deleteDocument(document) {
558
569
 
559
570
  exports.deleteDocument = deleteDocument;
560
571
 
572
+ var deleteDocuments = function deleteDocuments(documents) {
573
+ return {
574
+ mutationType: MutationTypes.DELETE_DOCUMENTS,
575
+ documents: documents
576
+ };
577
+ };
578
+
579
+ exports.deleteDocuments = deleteDocuments;
580
+
561
581
  var addReferencesTo = function addReferencesTo(document, referencedDocuments) {
562
582
  return {
563
583
  mutationType: MutationTypes.ADD_REFERENCES_TO,
@@ -616,6 +636,9 @@ var getDoctypeFromOperation = function getDoctypeFromOperation(operation) {
616
636
  case CREATE_DOCUMENT:
617
637
  return operation.document._type;
618
638
 
639
+ case CREATE_DOCUMENTS:
640
+ return operation.documents[0]._type;
641
+
619
642
  case UPDATE_DOCUMENT:
620
643
  return operation.document._type;
621
644
 
@@ -625,6 +648,9 @@ var getDoctypeFromOperation = function getDoctypeFromOperation(operation) {
625
648
  case DELETE_DOCUMENT:
626
649
  return operation.document._type;
627
650
 
651
+ case DELETE_DOCUMENTS:
652
+ return operation.documents[0]._type;
653
+
628
654
  case ADD_REFERENCES_TO:
629
655
  throw new Error('Not implemented');
630
656
 
@@ -642,9 +668,11 @@ var getDoctypeFromOperation = function getDoctypeFromOperation(operation) {
642
668
  exports.getDoctypeFromOperation = getDoctypeFromOperation;
643
669
  var Mutations = {
644
670
  createDocument: createDocument,
671
+ createDocuments: createDocuments,
645
672
  updateDocument: updateDocument,
646
673
  updateDocuments: updateDocuments,
647
674
  deleteDocument: deleteDocument,
675
+ deleteDocuments: deleteDocuments,
648
676
  addReferencesTo: addReferencesTo,
649
677
  removeReferencesTo: removeReferencesTo,
650
678
  addReferencedBy: addReferencedBy,
@@ -654,9 +682,11 @@ var Mutations = {
654
682
  exports.Mutations = Mutations;
655
683
  var MutationTypes = {
656
684
  CREATE_DOCUMENT: CREATE_DOCUMENT,
685
+ CREATE_DOCUMENTS: CREATE_DOCUMENTS,
657
686
  UPDATE_DOCUMENT: UPDATE_DOCUMENT,
658
687
  UPDATE_DOCUMENTS: UPDATE_DOCUMENTS,
659
688
  DELETE_DOCUMENT: DELETE_DOCUMENT,
689
+ DELETE_DOCUMENTS: DELETE_DOCUMENTS,
660
690
  ADD_REFERENCES_TO: ADD_REFERENCES_TO,
661
691
  REMOVE_REFERENCES_TO: REMOVE_REFERENCES_TO,
662
692
  ADD_REFERENCED_BY: ADD_REFERENCED_BY,
package/dist/types.js CHANGED
@@ -401,9 +401,9 @@ var _dsl = require("./queries/dsl");
401
401
 
402
402
  /**
403
403
  * @typedef {object} MutationOptions
404
- * @property {string} [as]
405
- * @property {Function} [update]
406
- * @property {Function} [updateQueries]
404
+ * @property {string} as - Mutation id
405
+ @property {Function} update - Function to update the document
406
+ * @property {Function} updateQueries - Function to update queries
407
407
  */
408
408
 
409
409
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "58.5.0",
3
+ "version": "59.1.0",
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": "^58.4.0",
22
+ "cozy-stack-client": "^59.0.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": "78dc8e951c833ce39ede1027789d3e293fd6213e"
77
+ "gitHead": "b1b84902b2139a368f54b6ffaee654fe6cb1b03e"
78
78
  }
@@ -362,6 +362,7 @@ declare class CozyClient {
362
362
  all(doctype: any): QueryDefinition;
363
363
  find(doctype: any, selector?: any): QueryDefinition;
364
364
  get(doctype: any, id: any): QueryDefinition;
365
+ validate(document: any): Promise<{}>;
365
366
  /**
366
367
  * Creates a document and saves it on the server
367
368
  *
@@ -387,32 +388,46 @@ declare class CozyClient {
387
388
  * @returns {Promise}
388
389
  */
389
390
  create(type: string, doc: object, references?: import("./types").ReferenceMap, options?: object): Promise<any>;
390
- validate(document: any): Promise<{}>;
391
391
  /**
392
- * Create or update a document on the server
392
+ * Create multiple documents in one batch.
393
+ * WARNING: this method is currently not supported by the stack, but
394
+ * works with PouchDB
395
+ *
396
+ * @param {import("./types").CozyClientDocument[]} docs - Documents to create. Should not have _id nor _rev
397
+ * @param {object} [options] - options
398
+ * @returns {Promise}
399
+ */
400
+ createAll(docs: import("./types").CozyClientDocument[], options?: object): Promise<any>;
401
+ /**
402
+ * Create or update a document
393
403
  *
394
404
  * @param {object} doc - Document to save
395
- * @param {object} mutationOptions - Mutation options
405
+ * @param {object} [options] - options
396
406
  * @returns {Promise}
397
407
  */
398
- save(doc: object, mutationOptions?: object): Promise<any>;
408
+ save(doc: object, options?: object): Promise<any>;
399
409
  /**
400
- * Saves multiple documents in one batch
410
+ * Updates multiple documents in one batch. Should have _id and _rev
411
+ *
412
+ * @param {import("./types").CozyClientDocument[]} docs - Documents from the same doctype
413
+ * @param {object} [options] - options
414
+ * @returns {Promise<void>}
415
+ */
416
+ updateAll(docs: import("./types").CozyClientDocument[], options?: object): Promise<void>;
417
+ /**
418
+ * Create or update multiple documents in one batch
401
419
  * - Can only be called with documents from the same doctype
420
+ * - Can either be creation (no _id nor _rev) or update, not both
402
421
  * - Does not support automatic creation of references
403
422
  *
423
+ * WARNING: multiple creations is currently not supported by the stack, but
424
+ * works with PouchDB
425
+ *
404
426
  * @param {import("./types").CozyClientDocument[]} docs - Documents from the same doctype
405
- * @param {Object} mutationOptions - Mutation Options
406
- * @param {string} [mutationOptions.as] - Mutation id
407
- * @param {Function} [mutationOptions.update] - Function to update the document
408
- * @param {Function} [mutationOptions.updateQueries] - Function to update queries
427
+ * @param {object} [options] - options
409
428
  * @returns {Promise<void>}
410
429
  */
411
- saveAll(docs: import("./types").CozyClientDocument[], mutationOptions?: {
412
- as?: string;
413
- update?: Function;
414
- updateQueries?: Function;
415
- }): Promise<void>;
430
+ saveAll(docs: import("./types").CozyClientDocument[], options?: object): Promise<void>;
416
431
  /**
417
432
  * @param {import("./types").CozyClientDocument} document - Document that will be saved
418
433
  * @param {object} [options={event: DOC_CREATION}] - Event
@@ -456,10 +471,27 @@ declare class CozyClient {
456
471
  * Destroys a document. {before,after}:destroy hooks will be fired.
457
472
  *
458
473
  * @param {import("./types").CozyClientDocument} document - Document to be deleted
474
+ * @param {object} [options] - options
459
475
  * @returns {Promise<import("./types").CozyClientDocument>} The document that has been deleted
460
476
  */
461
- destroy(document: import("./types").CozyClientDocument, mutationOptions?: {}): Promise<import("./types").CozyClientDocument>;
462
- upload(file: any, dirPath: any, mutationOptions?: {}): Promise<any>;
477
+ destroy(document: import("./types").CozyClientDocument, options?: object): Promise<import("./types").CozyClientDocument>;
478
+ /**
479
+ * Destroy multiple documents
480
+ *
481
+ * @param {Array<import("./types").CozyClientDocument>} documents - Documents to be deleted
482
+ * @param {object} [options] - options
483
+ * @returns {Promise<Array<import("./types").CozyClientDocument>>} The deleted documents
484
+ */
485
+ destroyAll(documents: Array<import("./types").CozyClientDocument>, options?: object): Promise<Array<import("./types").CozyClientDocument>>;
486
+ /**
487
+ * Upload a file
488
+ *
489
+ * @param {File|Blob|import('cozy-stack-client/dist/FileCollection').Stream|string|ArrayBuffer} file - File to be uploaded
490
+ * @param {string} dirPath - Path to upload the file to. ie : /Administative/XXX/
491
+ * @param {object} [options] - Optionnal request options
492
+ * @returns {Promise<object>} Created io.cozy.files
493
+ */
494
+ upload(file: File | Blob | import('cozy-stack-client/dist/FileCollection').Stream | string | ArrayBuffer, dirPath: string, options?: object): Promise<object>;
463
495
  /**
464
496
  * Makes sure that the query exists in the store
465
497
  *
@@ -499,17 +531,19 @@ declare class CozyClient {
499
531
  /**
500
532
  * Mutate a document
501
533
  *
502
- * @param {object} mutationDefinition - Describe the mutation
503
- * @param {object} [options] - Options
504
- * @param {string} [options.as] - Mutation id
505
- * @param {Function} [options.update] - Function to update the document
506
- * @param {Function} [options.updateQueries] - Function to update queries
534
+ * @param {object} mutationDefinition - Describe the mutation
535
+ * @param {object} [params] The mutation params
536
+ * @param {function} [params.update] - update function from MutationOptions
537
+ * @param {function} [params.updateQueries] - updateQueries function from MutationOptions
538
+ * @param {string} [params.as] - Mutation id
539
+ * @param {Object} [params.options={}] - Additional options
507
540
  * @returns {Promise}
508
541
  */
509
542
  mutate(mutationDefinition: object, { update, updateQueries, ...options }?: {
510
- as?: string;
511
543
  update?: Function;
512
544
  updateQueries?: Function;
545
+ as?: string;
546
+ options?: any;
513
547
  }): Promise<any>;
514
548
  /**
515
549
  * Executes a query through links and fetches relationships
@@ -4,6 +4,10 @@ export function createDocument(document: any): {
4
4
  mutationType: string;
5
5
  document: any;
6
6
  };
7
+ export function createDocuments(documents: any): {
8
+ mutationType: string;
9
+ documents: any;
10
+ };
7
11
  export function updateDocument(document: any): {
8
12
  mutationType: string;
9
13
  document: any;
@@ -16,6 +20,10 @@ export function deleteDocument(document: any): {
16
20
  mutationType: string;
17
21
  document: any;
18
22
  };
23
+ export function deleteDocuments(documents: any): {
24
+ mutationType: string;
25
+ documents: any;
26
+ };
19
27
  export function addReferencesTo(document: any, referencedDocuments: any): {
20
28
  mutationType: string;
21
29
  referencedDocuments: any;
@@ -44,9 +52,11 @@ export function uploadFile(file: any, dirPath: any): {
44
52
  export function getDoctypeFromOperation(operation: any): any;
45
53
  export namespace Mutations {
46
54
  export { createDocument };
55
+ export { createDocuments };
47
56
  export { updateDocument };
48
57
  export { updateDocuments };
49
58
  export { deleteDocument };
59
+ export { deleteDocuments };
50
60
  export { addReferencesTo };
51
61
  export { removeReferencesTo };
52
62
  export { addReferencedBy };
@@ -55,9 +65,11 @@ export namespace Mutations {
55
65
  }
56
66
  export namespace MutationTypes {
57
67
  export { CREATE_DOCUMENT };
68
+ export { CREATE_DOCUMENTS };
58
69
  export { UPDATE_DOCUMENT };
59
70
  export { UPDATE_DOCUMENTS };
60
71
  export { DELETE_DOCUMENT };
72
+ export { DELETE_DOCUMENTS };
61
73
  export { ADD_REFERENCES_TO };
62
74
  export { REMOVE_REFERENCES_TO };
63
75
  export { ADD_REFERENCED_BY };
@@ -297,9 +309,11 @@ export class QueryDefinition {
297
309
  };
298
310
  }
299
311
  declare const CREATE_DOCUMENT: "CREATE_DOCUMENT";
312
+ declare const CREATE_DOCUMENTS: "CREATE_DOCUMENTS";
300
313
  declare const UPDATE_DOCUMENT: "UPDATE_DOCUMENT";
301
314
  declare const UPDATE_DOCUMENTS: "UPDATE_DOCUMENTS";
302
315
  declare const DELETE_DOCUMENT: "DELETE_DOCUMENT";
316
+ declare const DELETE_DOCUMENTS: "DELETE_DOCUMENTS";
303
317
  declare const ADD_REFERENCES_TO: "ADD_REFERENCES_TO";
304
318
  declare const REMOVE_REFERENCES_TO: "REMOVE_REFERENCES_TO";
305
319
  declare const ADD_REFERENCED_BY: "ADD_REFERENCED_BY";
package/types/types.d.ts CHANGED
@@ -649,9 +649,18 @@ export type ReferenceMap = {
649
649
  [x: string]: Reference[];
650
650
  };
651
651
  export type MutationOptions = {
652
- as?: string;
653
- update?: Function;
654
- updateQueries?: Function;
652
+ /**
653
+ * - Mutation id
654
+ */
655
+ as: string;
656
+ /**
657
+ * - Function to update the document
658
+ */
659
+ update: Function;
660
+ /**
661
+ * - Function to update queries
662
+ */
663
+ updateQueries: Function;
655
664
  };
656
665
  export type UpdatedByApp = {
657
666
  /**