cozy-client 49.1.1 → 49.3.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.
@@ -2997,7 +2997,7 @@ var CozyClient = /*#__PURE__*/function () {
2997
2997
  CozyClient.hooks = CozyClient.hooks || {};
2998
2998
  CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
2999
2999
 
3000
- CozyClient.version = "49.1.1";
3000
+ CozyClient.version = "49.3.0";
3001
3001
 
3002
3002
  _microee.default.mixin(CozyClient);
3003
3003
 
@@ -17,12 +17,14 @@ var _useClient = _interopRequireDefault(require("./hooks/useClient"));
17
17
 
18
18
  var _realtime = require("./store/realtime");
19
19
 
20
+ var _realtime2 = require("./helpers/realtime");
21
+
20
22
  /**
21
23
  * Component that subscribes to a doctype changes and keep the
22
24
  * internal store updated.
23
25
  *
24
- * @param {object} options - Options
25
- * @param {import("./types").Doctype} options.doctype - The doctype to watch
26
+ * @param {object} options - Options
27
+ * @param {import("./types").Doctype} options.doctype - The doctype to watch
26
28
  * @returns {null} The component does not display anything.
27
29
  */
28
30
  var RealTimeQueries = function RealTimeQueries(_ref) {
@@ -35,6 +37,24 @@ var RealTimeQueries = function RealTimeQueries(_ref) {
35
37
  throw new Error('You must include the realtime plugin to use RealTimeQueries');
36
38
  }
37
39
 
40
+ var options = {};
41
+
42
+ if (doctype === 'io.cozy.files') {
43
+ options.enhanceDocFn = _realtime2.ensureFilePath;
44
+ }
45
+
46
+ var handleCreated = function handleCreated(data) {
47
+ (0, _realtime.dispatchCreate)(client, doctype, data, options);
48
+ };
49
+
50
+ var handleUpdated = function handleUpdated(data) {
51
+ (0, _realtime.dispatchUpdate)(client, doctype, data, options);
52
+ };
53
+
54
+ var handleDeleted = function handleDeleted(data) {
55
+ (0, _realtime.dispatchDelete)(client, doctype, data, options);
56
+ };
57
+
38
58
  var subscribe = /*#__PURE__*/function () {
39
59
  var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
40
60
  return _regenerator.default.wrap(function _callee$(_context) {
@@ -42,21 +62,15 @@ var RealTimeQueries = function RealTimeQueries(_ref) {
42
62
  switch (_context.prev = _context.next) {
43
63
  case 0:
44
64
  _context.next = 2;
45
- return realtime.subscribe('created', doctype, function (data) {
46
- return (0, _realtime.dispatchCreate)(client, doctype, data);
47
- });
65
+ return realtime.subscribe('created', doctype, handleCreated);
48
66
 
49
67
  case 2:
50
68
  _context.next = 4;
51
- return realtime.subscribe('updated', doctype, function (data) {
52
- return (0, _realtime.dispatchUpdate)(client, doctype, data);
53
- });
69
+ return realtime.subscribe('updated', doctype, handleUpdated);
54
70
 
55
71
  case 4:
56
72
  _context.next = 6;
57
- return realtime.subscribe('deleted', doctype, function (data) {
58
- return (0, _realtime.dispatchDelete)(client, doctype, data);
59
- });
73
+ return realtime.subscribe('deleted', doctype, handleDeleted);
60
74
 
61
75
  case 6:
62
76
  case "end":
@@ -6,7 +6,26 @@ import CozyProvider from './Provider'
6
6
 
7
7
  const setup = async doctype => {
8
8
  const realtimeCallbacks = {}
9
- const client = new createMockClient({})
9
+ const client = new createMockClient({
10
+ queries: {
11
+ 'io.cozy.files/parent': {
12
+ doctype: 'io.cozy.files',
13
+ definition: {
14
+ doctype: 'io.cozy.files',
15
+ id: 'parent'
16
+ },
17
+ data: [
18
+ {
19
+ _id: 'parent',
20
+ _type: 'io.cozy.files',
21
+ name: 'Parent folder',
22
+ path: '/Parent'
23
+ }
24
+ ]
25
+ }
26
+ }
27
+ })
28
+
10
29
  client.plugins.realtime = {
11
30
  subscribe: jest.fn((event, doctype, callback) => {
12
31
  realtimeCallbacks[event] = callback
@@ -29,17 +48,26 @@ const setup = async doctype => {
29
48
  }
30
49
 
31
50
  describe('RealTimeQueries', () => {
32
- it('notifies the cozy-client store', async () => {
51
+ it('should dispatch CREATE_DOCUMENT mutation for created io.cozy.files', async () => {
33
52
  const { client, realtimeCallbacks, unmount } = await setup('io.cozy.files')
34
53
 
35
- realtimeCallbacks['created']({ _id: 'mock-created', type: 'file' })
36
- expect(client.dispatch).toHaveBeenCalledWith(
37
- expect.objectContaining({
54
+ realtimeCallbacks['created']({
55
+ _id: 'mock-created',
56
+ type: 'file',
57
+ name: 'mock-created',
58
+ dir_id: 'parent'
59
+ })
60
+
61
+ await waitFor(() => {
62
+ expect(client.dispatch).toHaveBeenCalledWith({
38
63
  definition: {
39
64
  document: {
40
65
  _id: 'mock-created',
41
- id: 'mock-created',
42
66
  _type: 'io.cozy.files',
67
+ dir_id: 'parent',
68
+ id: 'mock-created',
69
+ name: 'mock-created',
70
+ path: '/Parent/mock-created',
43
71
  type: 'file'
44
72
  },
45
73
  mutationType: 'CREATE_DOCUMENT'
@@ -48,103 +76,152 @@ describe('RealTimeQueries', () => {
48
76
  response: {
49
77
  data: {
50
78
  _id: 'mock-created',
51
- id: 'mock-created',
52
79
  _type: 'io.cozy.files',
80
+ dir_id: 'parent',
81
+ id: 'mock-created',
82
+ name: 'mock-created',
83
+ path: '/Parent/mock-created',
53
84
  type: 'file'
54
85
  }
55
86
  },
56
87
  type: 'RECEIVE_MUTATION_RESULT'
57
88
  })
58
- )
89
+ })
59
90
 
60
- realtimeCallbacks['updated']({ _id: 'mock-updated', type: 'file' })
61
- expect(client.dispatch).toHaveBeenCalledWith({
62
- definition: {
63
- document: {
64
- _id: 'mock-updated',
65
- id: 'mock-updated',
66
- _type: 'io.cozy.files',
67
- type: 'file'
68
- },
69
- mutationType: 'UPDATE_DOCUMENT'
70
- },
71
- mutationId: '2',
72
- response: {
73
- data: {
74
- _id: 'mock-updated',
75
- id: 'mock-updated',
76
- _type: 'io.cozy.files',
77
- type: 'file'
78
- }
79
- },
80
- type: 'RECEIVE_MUTATION_RESULT'
91
+ unmount()
92
+ await waitFor(() => {
93
+ expect(client.plugins.realtime.unsubscribe).toHaveBeenCalledTimes(3)
94
+ })
95
+ })
96
+
97
+ it('should dispatch UPDATE_DOCUMENT mutation for updated io.cozy.files', async () => {
98
+ const { client, realtimeCallbacks, unmount } = await setup('io.cozy.files')
99
+
100
+ realtimeCallbacks['updated']({
101
+ _id: 'mock-updated',
102
+ type: 'file',
103
+ name: 'mock-updated',
104
+ dir_id: 'parent'
81
105
  })
82
106
 
83
- realtimeCallbacks['deleted']({ _id: 'mock-deleted', type: 'file' })
84
- expect(client.dispatch).toHaveBeenCalledWith({
85
- definition: {
86
- document: {
87
- _id: 'mock-deleted',
88
- id: 'mock-deleted',
89
- _type: 'io.cozy.files',
90
- type: 'file',
91
- _deleted: true
107
+ await waitFor(() => {
108
+ expect(client.dispatch).toHaveBeenCalledWith({
109
+ definition: {
110
+ document: {
111
+ _id: 'mock-updated',
112
+ _type: 'io.cozy.files',
113
+ dir_id: 'parent',
114
+ id: 'mock-updated',
115
+ name: 'mock-updated',
116
+ path: '/Parent/mock-updated',
117
+ type: 'file'
118
+ },
119
+ mutationType: 'UPDATE_DOCUMENT'
92
120
  },
93
- mutationType: 'DELETE_DOCUMENT'
94
- },
95
- mutationId: '3',
96
- response: {
97
- data: {
98
- _id: 'mock-deleted',
99
- id: 'mock-deleted',
100
- _type: 'io.cozy.files',
101
- type: 'file',
102
- _deleted: true
103
- }
104
- },
105
- type: 'RECEIVE_MUTATION_RESULT'
121
+ mutationId: '1',
122
+ response: {
123
+ data: {
124
+ _id: 'mock-updated',
125
+ _type: 'io.cozy.files',
126
+ dir_id: 'parent',
127
+ id: 'mock-updated',
128
+ name: 'mock-updated',
129
+ path: '/Parent/mock-updated',
130
+ type: 'file'
131
+ }
132
+ },
133
+ type: 'RECEIVE_MUTATION_RESULT'
134
+ })
106
135
  })
107
136
 
108
137
  unmount()
109
138
  expect(client.plugins.realtime.unsubscribe).toHaveBeenCalledTimes(3)
110
139
  })
111
140
 
112
- it('deals with other doctypes than io.cozy.files', async () => {
113
- const { client, realtimeCallbacks, unmount } = await setup(
114
- 'io.cozy.oauth.clients'
115
- )
141
+ it('should dispatch DELETE_DOCUMENT mutation for deleted io.cozy.files', async () => {
142
+ const { client, realtimeCallbacks, unmount } = await setup('io.cozy.files')
116
143
 
117
- realtimeCallbacks['created']({
118
- _id: 'mock-created',
119
- client_kind: 'desktop',
120
- client_name: 'Cozy Drive (hostname)'
144
+ realtimeCallbacks['deleted']({
145
+ _id: 'mock-deleted',
146
+ type: 'file',
147
+ name: 'mock-deleted',
148
+ dir_id: 'parent'
121
149
  })
122
- expect(client.dispatch).toHaveBeenCalledWith(
123
- expect.objectContaining({
150
+
151
+ await waitFor(() => {
152
+ expect(client.dispatch).toHaveBeenCalledWith({
124
153
  definition: {
125
154
  document: {
126
- _id: 'mock-created',
127
- id: 'mock-created',
128
- _type: 'io.cozy.oauth.clients',
129
- client_kind: 'desktop',
130
- client_name: 'Cozy Drive (hostname)'
155
+ _deleted: true,
156
+ _type: 'io.cozy.files',
157
+ _id: 'mock-deleted',
158
+ dir_id: 'parent',
159
+ id: 'mock-deleted',
160
+ name: 'mock-deleted',
161
+ path: '/Parent/mock-deleted',
162
+ type: 'file'
131
163
  },
132
- mutationType: 'CREATE_DOCUMENT'
164
+ mutationType: 'DELETE_DOCUMENT'
133
165
  },
134
166
  mutationId: '1',
135
167
  response: {
136
168
  data: {
137
- _id: 'mock-created',
138
- id: 'mock-created',
139
- _type: 'io.cozy.oauth.clients',
140
- client_kind: 'desktop',
141
- client_name: 'Cozy Drive (hostname)'
169
+ _deleted: true,
170
+ _type: 'io.cozy.files',
171
+ _id: 'mock-deleted',
172
+ dir_id: 'parent',
173
+ id: 'mock-deleted',
174
+ name: 'mock-deleted',
175
+ path: '/Parent/mock-deleted',
176
+ type: 'file'
142
177
  }
143
178
  },
144
179
  type: 'RECEIVE_MUTATION_RESULT'
145
180
  })
181
+ })
182
+
183
+ unmount()
184
+ expect(client.plugins.realtime.unsubscribe).toHaveBeenCalledTimes(3)
185
+ })
186
+
187
+ it('should handle realtime events for other doctypes than io.cozy.files', async () => {
188
+ const { client, realtimeCallbacks, unmount } = await setup(
189
+ 'io.cozy.oauth.clients'
146
190
  )
147
191
 
192
+ realtimeCallbacks['created']({
193
+ _id: 'mock-created',
194
+ client_kind: 'desktop',
195
+ client_name: 'Cozy Drive (hostname)'
196
+ })
197
+ await waitFor(() => {
198
+ expect(client.dispatch).toHaveBeenCalledWith(
199
+ expect.objectContaining({
200
+ definition: {
201
+ document: {
202
+ _id: 'mock-created',
203
+ id: 'mock-created',
204
+ _type: 'io.cozy.oauth.clients',
205
+ client_kind: 'desktop',
206
+ client_name: 'Cozy Drive (hostname)'
207
+ },
208
+ mutationType: 'CREATE_DOCUMENT'
209
+ },
210
+ mutationId: '1',
211
+ response: {
212
+ data: {
213
+ _id: 'mock-created',
214
+ id: 'mock-created',
215
+ _type: 'io.cozy.oauth.clients',
216
+ client_kind: 'desktop',
217
+ client_name: 'Cozy Drive (hostname)'
218
+ }
219
+ },
220
+ type: 'RECEIVE_MUTATION_RESULT'
221
+ })
222
+ )
223
+ })
224
+
148
225
  unmount()
149
226
  })
150
227
  })
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.ensureFilePath = void 0;
9
+
10
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
+
12
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
+
14
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
15
+
16
+ var _dsl = require("../queries/dsl");
17
+
18
+ var _CozyClient = _interopRequireDefault(require("../CozyClient"));
19
+
20
+ 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; }
21
+
22
+ 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; }
23
+
24
+ var buildFileByIdQuery = function buildFileByIdQuery(id) {
25
+ return {
26
+ definition: function definition() {
27
+ return (0, _dsl.Q)('io.cozy.files').getById(id);
28
+ },
29
+ options: {
30
+ as: "io.cozy.files/".concat(id),
31
+ singleDocData: true,
32
+ fetchPolicy: _CozyClient.default.fetchPolicies.olderThan(30 * 1000)
33
+ }
34
+ };
35
+ };
36
+ /**
37
+ * Ensures existence of `path` inside the io.cozy.files document
38
+ *
39
+ * @public
40
+ * @param {import("../types").IOCozyFile} couchDBDoc - object representing the document
41
+ * @param {object} options Options
42
+ * @param {string} [options.doctype] - Doctype of the document
43
+ * @param {CozyClient} [options.client] - CozyClient instance
44
+ *
45
+ * @returns {Promise<import("../types").CozyClientDocument>} full normalized document
46
+ */
47
+
48
+
49
+ var ensureFilePath = /*#__PURE__*/function () {
50
+ var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(couchDBDoc) {
51
+ var options,
52
+ parentQuery,
53
+ parentResult,
54
+ path,
55
+ _args = arguments;
56
+ return _regenerator.default.wrap(function _callee$(_context) {
57
+ while (1) {
58
+ switch (_context.prev = _context.next) {
59
+ case 0:
60
+ options = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
61
+
62
+ if (!couchDBDoc.path) {
63
+ _context.next = 3;
64
+ break;
65
+ }
66
+
67
+ return _context.abrupt("return", couchDBDoc);
68
+
69
+ case 3:
70
+ parentQuery = buildFileByIdQuery(couchDBDoc.dir_id);
71
+ _context.next = 6;
72
+ return options.client.fetchQueryAndGetFromState({
73
+ definition: parentQuery.definition(),
74
+ options: parentQuery.options
75
+ });
76
+
77
+ case 6:
78
+ parentResult = _context.sent;
79
+
80
+ if (!(!parentResult.data || !parentResult.data.path)) {
81
+ _context.next = 9;
82
+ break;
83
+ }
84
+
85
+ throw new Error("Could not define a file path for ".concat(couchDBDoc._id || couchDBDoc.id));
86
+
87
+ case 9:
88
+ path = parentResult.data.path + '/' + couchDBDoc.name;
89
+ return _context.abrupt("return", _objectSpread({
90
+ path: path
91
+ }, couchDBDoc));
92
+
93
+ case 11:
94
+ case "end":
95
+ return _context.stop();
96
+ }
97
+ }
98
+ }, _callee);
99
+ }));
100
+
101
+ return function ensureFilePath(_x) {
102
+ return _ref.apply(this, arguments);
103
+ };
104
+ }();
105
+
106
+ exports.ensureFilePath = ensureFilePath;
@@ -7,6 +7,10 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.dispatchDelete = exports.dispatchUpdate = exports.dispatchCreate = void 0;
9
9
 
10
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
+
12
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
+
10
14
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
15
 
12
16
  var _dsl = require("../queries/dsl");
@@ -24,6 +28,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
24
28
  *
25
29
  * @public
26
30
  * @param {import("../types").CouchDBDocument} couchDBDoc - object representing the document
31
+ * @param {string} doctype - Doctype of the document
27
32
  * @returns {import("../types").CozyClientDocument} full normalized document
28
33
  */
29
34
  var normalizeDoc = function normalizeDoc(couchDBDoc, doctype) {
@@ -32,65 +37,211 @@ var normalizeDoc = function normalizeDoc(couchDBDoc, doctype) {
32
37
  _type: doctype
33
38
  }, couchDBDoc);
34
39
  };
40
+ /**
41
+ * Enhances a document with additional attributes
42
+ *
43
+ * @async
44
+ * @param {import("../types").CozyClientDocument} doc - The document to enhance
45
+ * @param {Object} options - Options for enhancing the document
46
+ * @param {Function} [options.enhanceDocFn] - Function to enhance document attributes
47
+ * @param {object} options.client - CozyClient instance
48
+ * @returns {Promise<import("../types").CozyClientDocument>} Enhanced document
49
+ */
50
+
51
+
52
+ var enhanceDoc = /*#__PURE__*/function () {
53
+ var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(doc, options) {
54
+ return _regenerator.default.wrap(function _callee$(_context) {
55
+ while (1) {
56
+ switch (_context.prev = _context.next) {
57
+ case 0:
58
+ if (!(typeof options.enhanceDocFn === 'function')) {
59
+ _context.next = 4;
60
+ break;
61
+ }
62
+
63
+ _context.next = 3;
64
+ return options.enhanceDocFn(doc, {
65
+ client: options.client
66
+ });
67
+
68
+ case 3:
69
+ return _context.abrupt("return", _context.sent);
70
+
71
+ case 4:
72
+ return _context.abrupt("return", doc);
73
+
74
+ case 5:
75
+ case "end":
76
+ return _context.stop();
77
+ }
78
+ }
79
+ }, _callee);
80
+ }));
81
+
82
+ return function enhanceDoc(_x, _x2) {
83
+ return _ref.apply(this, arguments);
84
+ };
85
+ }();
35
86
  /**
36
87
  * DispatchChange
37
88
  *
38
- * @param {object} client CozyClient instane
39
- * @param {import("../types").Doctype} doctype Doctype of the document to update
40
- * @param {import("../types").CouchDBDocument} couchDBDoc Document to update
89
+ * @param {object} client CozyClient instance
90
+ * @param {import("../types").CozyClientDocument} document Document to update
41
91
  * @param {import("../types").Mutation} mutationDefinitionCreator Mutation to apply
92
+ *
42
93
  */
43
94
 
44
95
 
45
- var dispatchChange = function dispatchChange(client, doctype, couchDBDoc, mutationDefinitionCreator) {
46
- var data = normalizeDoc(couchDBDoc, doctype);
96
+ var dispatchChange = function dispatchChange(client, document, mutationDefinitionCreator) {
47
97
  var response = {
48
- data: data
98
+ data: document
49
99
  };
50
100
  var options = {};
51
- client.dispatch((0, _mutations.receiveMutationResult)(client.generateRandomId(), response, options, mutationDefinitionCreator(data)));
101
+ client.dispatch((0, _mutations.receiveMutationResult)(client.generateRandomId(), response, options, mutationDefinitionCreator(document)));
52
102
  };
103
+ /**
104
+ * @typedef {Object} DispatchOptions
105
+ * @property {function} [enhanceDocFn] Optional function to enhance the document attributes before dispatch
106
+ */
107
+
53
108
  /**
54
109
  * Dispatches a create action for a document to update CozyClient store from realtime callbacks.
55
110
  *
56
111
  * @param {object} client - CozyClient instance
57
112
  * @param {import("../types").Doctype} doctype - Doctype of the document to create
58
113
  * @param {import("../types").CouchDBDocument} couchDBDoc - Document to create
114
+ * @param {DispatchOptions} [options] Options
59
115
  */
60
116
 
61
117
 
62
- var dispatchCreate = function dispatchCreate(client, doctype, couchDBDoc) {
63
- dispatchChange(client, doctype, couchDBDoc, _dsl.Mutations.createDocument);
64
- };
118
+ var dispatchCreate = /*#__PURE__*/function () {
119
+ var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(client, doctype, couchDBDoc) {
120
+ var options,
121
+ normalizedDoc,
122
+ enhancedDoc,
123
+ _args2 = arguments;
124
+ return _regenerator.default.wrap(function _callee2$(_context2) {
125
+ while (1) {
126
+ switch (_context2.prev = _context2.next) {
127
+ case 0:
128
+ options = _args2.length > 3 && _args2[3] !== undefined ? _args2[3] : {};
129
+ normalizedDoc = normalizeDoc(couchDBDoc, doctype);
130
+ _context2.next = 4;
131
+ return enhanceDoc(normalizedDoc, {
132
+ client: client,
133
+ enhanceDocFn: options === null || options === void 0 ? void 0 : options.enhanceDocFn
134
+ });
135
+
136
+ case 4:
137
+ enhancedDoc = _context2.sent;
138
+ dispatchChange(client, enhancedDoc, _dsl.Mutations.createDocument);
139
+
140
+ case 6:
141
+ case "end":
142
+ return _context2.stop();
143
+ }
144
+ }
145
+ }, _callee2);
146
+ }));
147
+
148
+ return function dispatchCreate(_x3, _x4, _x5) {
149
+ return _ref2.apply(this, arguments);
150
+ };
151
+ }();
65
152
  /**
66
153
  * Dispatches a update action for a document to update CozyClient store from realtime callbacks.
67
154
  *
68
155
  * @param {object} client - CozyClient instance
69
156
  * @param {import("../types").Doctype} doctype - Doctype of the document to create
70
157
  * @param {import("../types").CouchDBDocument} couchDBDoc - Document to create
158
+ * @param {DispatchOptions} [options] Options
71
159
  */
72
160
 
73
161
 
74
162
  exports.dispatchCreate = dispatchCreate;
75
163
 
76
- var dispatchUpdate = function dispatchUpdate(client, doctype, couchDBDoc) {
77
- dispatchChange(client, doctype, couchDBDoc, _dsl.Mutations.updateDocument);
78
- };
164
+ var dispatchUpdate = /*#__PURE__*/function () {
165
+ var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(client, doctype, couchDBDoc) {
166
+ var options,
167
+ normalizedDoc,
168
+ enhancedDoc,
169
+ _args3 = arguments;
170
+ return _regenerator.default.wrap(function _callee3$(_context3) {
171
+ while (1) {
172
+ switch (_context3.prev = _context3.next) {
173
+ case 0:
174
+ options = _args3.length > 3 && _args3[3] !== undefined ? _args3[3] : {};
175
+ normalizedDoc = normalizeDoc(couchDBDoc, doctype);
176
+ _context3.next = 4;
177
+ return enhanceDoc(normalizedDoc, {
178
+ client: client,
179
+ enhanceDocFn: options === null || options === void 0 ? void 0 : options.enhanceDocFn
180
+ });
181
+
182
+ case 4:
183
+ enhancedDoc = _context3.sent;
184
+ dispatchChange(client, enhancedDoc, _dsl.Mutations.updateDocument);
185
+
186
+ case 6:
187
+ case "end":
188
+ return _context3.stop();
189
+ }
190
+ }
191
+ }, _callee3);
192
+ }));
193
+
194
+ return function dispatchUpdate(_x6, _x7, _x8) {
195
+ return _ref3.apply(this, arguments);
196
+ };
197
+ }();
79
198
  /**
80
199
  * Dispatches a delete action for a document to update CozyClient store from realtime callbacks.
81
200
  *
82
201
  * @param {object} client - CozyClient instance
83
202
  * @param {import("../types").Doctype} doctype - Doctype of the document to create
84
203
  * @param {import("../types").CouchDBDocument} couchDBDoc - Document to create
204
+ * @param {DispatchOptions} [options] Options
85
205
  */
86
206
 
87
207
 
88
208
  exports.dispatchUpdate = dispatchUpdate;
89
209
 
90
- var dispatchDelete = function dispatchDelete(client, doctype, couchDBDoc) {
91
- dispatchChange(client, doctype, _objectSpread(_objectSpread({}, couchDBDoc), {}, {
92
- _deleted: true
93
- }), _dsl.Mutations.deleteDocument);
94
- };
210
+ var dispatchDelete = /*#__PURE__*/function () {
211
+ var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(client, doctype, couchDBDoc) {
212
+ var options,
213
+ normalizedDoc,
214
+ enhancedDoc,
215
+ _args4 = arguments;
216
+ return _regenerator.default.wrap(function _callee4$(_context4) {
217
+ while (1) {
218
+ switch (_context4.prev = _context4.next) {
219
+ case 0:
220
+ options = _args4.length > 3 && _args4[3] !== undefined ? _args4[3] : {};
221
+ normalizedDoc = normalizeDoc(_objectSpread(_objectSpread({}, couchDBDoc), {}, {
222
+ _deleted: true
223
+ }), doctype);
224
+ _context4.next = 4;
225
+ return enhanceDoc(normalizedDoc, {
226
+ client: client,
227
+ enhanceDocFn: options === null || options === void 0 ? void 0 : options.enhanceDocFn
228
+ });
229
+
230
+ case 4:
231
+ enhancedDoc = _context4.sent;
232
+ dispatchChange(client, enhancedDoc, _dsl.Mutations.deleteDocument);
233
+
234
+ case 6:
235
+ case "end":
236
+ return _context4.stop();
237
+ }
238
+ }
239
+ }, _callee4);
240
+ }));
241
+
242
+ return function dispatchDelete(_x9, _x10, _x11) {
243
+ return _ref4.apply(this, arguments);
244
+ };
245
+ }();
95
246
 
96
247
  exports.dispatchDelete = dispatchDelete;
package/dist/types.js CHANGED
@@ -472,6 +472,7 @@ var _dsl = require("./queries/dsl");
472
472
  * @property {string} [target.category] - The category of the application
473
473
  * @property {object} [externalDataSource] - Additional information to maintain link with external data source
474
474
  * @property {string} [externalDataSource.source] - The space to which the application belongs
475
+ * @property {string} [externalDataSource.creator] - The creator of the data source
475
476
  */
476
477
 
477
478
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "49.1.1",
3
+ "version": "49.3.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.node.js",
6
6
  "browser": "dist/index.js",
@@ -75,5 +75,5 @@
75
75
  "react-native-ios11-devicecheck": "https://github.com/cozy/react-native-devicecheck#app-attest-v0.1"
76
76
  },
77
77
  "sideEffects": false,
78
- "gitHead": "1743f0008b06d89bacda019231dd2292748c68d5"
78
+ "gitHead": "d4e710d23db0b18a50f17bd1b2e22e5f082a7635"
79
79
  }
@@ -0,0 +1,5 @@
1
+ export function ensureFilePath(couchDBDoc: import("../types").IOCozyFile, options?: {
2
+ doctype: string;
3
+ client: CozyClient;
4
+ }): Promise<import("../types").CozyClientDocument>;
5
+ import CozyClient from "../CozyClient";
@@ -1,3 +1,9 @@
1
- export function dispatchCreate(client: object, doctype: import("../types").Doctype, couchDBDoc: import("../types").CouchDBDocument): void;
2
- export function dispatchUpdate(client: object, doctype: import("../types").Doctype, couchDBDoc: import("../types").CouchDBDocument): void;
3
- export function dispatchDelete(client: object, doctype: import("../types").Doctype, couchDBDoc: import("../types").CouchDBDocument): void;
1
+ export function dispatchCreate(client: object, doctype: import("../types").Doctype, couchDBDoc: import("../types").CouchDBDocument, options?: DispatchOptions): Promise<void>;
2
+ export function dispatchUpdate(client: object, doctype: import("../types").Doctype, couchDBDoc: import("../types").CouchDBDocument, options?: DispatchOptions): Promise<void>;
3
+ export function dispatchDelete(client: object, doctype: import("../types").Doctype, couchDBDoc: import("../types").CouchDBDocument, options?: DispatchOptions): Promise<void>;
4
+ export type DispatchOptions = {
5
+ /**
6
+ * Optional function to enhance the document attributes before dispatch
7
+ */
8
+ enhanceDocFn?: Function;
9
+ };
package/types/types.d.ts CHANGED
@@ -823,6 +823,7 @@ export type FileMetadata = {
823
823
  */
824
824
  externalDataSource?: {
825
825
  source: string;
826
+ creator: string;
826
827
  };
827
828
  };
828
829
  /**