cozy-client 27.4.0 → 27.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +56 -0
- package/dist/CozyClient.js +1 -1
- package/dist/__tests__/fixtures.js +2 -1
- package/dist/associations/helpers.js +82 -2
- package/dist/associations/helpers.spec.js +213 -99
- package/dist/associations/index.js +24 -0
- package/dist/index.js +33 -3
- package/dist/models/file.js +51 -4
- package/dist/models/file.spec.js +110 -71
- package/dist/types.js +25 -4
- package/package.json +4 -4
- package/types/__tests__/fixtures.d.ts +1 -0
- package/types/associations/helpers.d.ts +7 -0
- package/types/associations/index.d.ts +1 -1
- package/types/index.d.ts +1 -0
- package/types/models/file.d.ts +4 -0
- package/types/queries/referencedBy.d.ts +7 -0
- package/types/types.d.ts +27 -4
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,62 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [27.6.2](https://github.com/cozy/cozy-client/compare/v27.6.1...v27.6.2) (2021-12-16)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* Update dependency date-fns to v2.27.0 ([5ec7911](https://github.com/cozy/cozy-client/commit/5ec7911352072a72de99ec68f545f0b36c56c990))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [27.6.1](https://github.com/cozy/cozy-client/compare/v27.6.0...v27.6.1) (2021-12-15)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* **filename:** Get illegal characters from file name and returns them ([7c00526](https://github.com/cozy/cozy-client/commit/7c00526283dd865aea929c2983d32f7a12121c65))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# [27.6.0](https://github.com/cozy/cozy-client/compare/v27.5.1...v27.6.0) (2021-12-13)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### Features
|
|
32
|
+
|
|
33
|
+
* Add some helpers for model file ([e074067](https://github.com/cozy/cozy-client/commit/e0740674bb250b979fc3a6bfeace771de3d3c2fd))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
## [27.5.1](https://github.com/cozy/cozy-client/compare/v27.5.0...v27.5.1) (2021-12-01)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
### Bug Fixes
|
|
43
|
+
|
|
44
|
+
* Re-export associations helpers ([9a8d841](https://github.com/cozy/cozy-client/commit/9a8d84135762a1cf0ce29c7da247ca9a4ec617e5)), closes [#1076](https://github.com/cozy/cozy-client/issues/1076)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
# [27.5.0](https://github.com/cozy/cozy-client/compare/v27.4.0...v27.5.0) (2021-12-01)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
### Features
|
|
54
|
+
|
|
55
|
+
* Added referencedBy helpers ([2bd77e4](https://github.com/cozy/cozy-client/commit/2bd77e451eab26b85b21b41db522a7da6378672b))
|
|
56
|
+
* Adding types around references ([6d9c8aa](https://github.com/cozy/cozy-client/commit/6d9c8aade0ece644674b9adfee1b08b8eff7482e))
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
6
62
|
# [27.4.0](https://github.com/cozy/cozy-client/compare/v27.3.2...v27.4.0) (2021-11-25)
|
|
7
63
|
|
|
8
64
|
|
package/dist/CozyClient.js
CHANGED
|
@@ -2452,7 +2452,7 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2452
2452
|
CozyClient.hooks = CozyClient.hooks || {};
|
|
2453
2453
|
CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
|
|
2454
2454
|
|
|
2455
|
-
CozyClient.version = "27.
|
|
2455
|
+
CozyClient.version = "27.6.2";
|
|
2456
2456
|
|
|
2457
2457
|
_microee.default.mixin(CozyClient);
|
|
2458
2458
|
|
|
@@ -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.create = exports.resolveClass = exports.attachRelationships = exports.responseToRelationship = exports.pickTypeAndId = void 0;
|
|
8
|
+
exports.getReferencedById = exports.getReferencedBy = exports.isReferencedById = exports.isReferencedBy = exports.create = exports.resolveClass = exports.attachRelationships = exports.responseToRelationship = exports.pickTypeAndId = void 0;
|
|
9
9
|
|
|
10
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
11
|
|
|
@@ -25,6 +25,8 @@ var _HasManyInPlace = _interopRequireDefault(require("./HasManyInPlace"));
|
|
|
25
25
|
|
|
26
26
|
var _HasManyFiles = _interopRequireDefault(require("./HasManyFiles"));
|
|
27
27
|
|
|
28
|
+
var _types = require("../types");
|
|
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; }
|
|
@@ -124,5 +126,83 @@ var create = function create(target, _ref, accessors) {
|
|
|
124
126
|
|
|
125
127
|
return new type(target, name, doctype, accessors);
|
|
126
128
|
};
|
|
129
|
+
/**
|
|
130
|
+
* Checks if the file is referenced by a specific doctype
|
|
131
|
+
*
|
|
132
|
+
* @param {IOCozyFile} file - io.cozy.files document
|
|
133
|
+
* @param {Doctype} referencedBy - Doctype where document is referenced
|
|
134
|
+
* @returns {boolean} If a reference is found
|
|
135
|
+
*/
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
exports.create = create;
|
|
139
|
+
|
|
140
|
+
var isReferencedBy = function isReferencedBy(file, referencedBy) {
|
|
141
|
+
var _file$relationships, _file$relationships$r;
|
|
142
|
+
|
|
143
|
+
var references = (file === null || file === void 0 ? void 0 : (_file$relationships = file.relationships) === null || _file$relationships === void 0 ? void 0 : (_file$relationships$r = _file$relationships.referenced_by) === null || _file$relationships$r === void 0 ? void 0 : _file$relationships$r.data) || (file === null || file === void 0 ? void 0 : file.referenced_by) || [];
|
|
144
|
+
return references.some(function (reference) {
|
|
145
|
+
return reference.type === referencedBy;
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* Checks if the file is referenced by a specific doctype and a specific Id of that reference
|
|
150
|
+
*
|
|
151
|
+
* @param {IOCozyFile} file - io.cozy.files document
|
|
152
|
+
* @param {Doctype} referencedBy - Doctype where document is referenced
|
|
153
|
+
* @param {string} referencedId - Id of the referenced document
|
|
154
|
+
* @returns {boolean} If a reference is found
|
|
155
|
+
*/
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
exports.isReferencedBy = isReferencedBy;
|
|
159
|
+
|
|
160
|
+
var isReferencedById = function isReferencedById(file, referencedBy, referencedId) {
|
|
161
|
+
var _file$relationships2, _file$relationships2$;
|
|
162
|
+
|
|
163
|
+
var references = (file === null || file === void 0 ? void 0 : (_file$relationships2 = file.relationships) === null || _file$relationships2 === void 0 ? void 0 : (_file$relationships2$ = _file$relationships2.referenced_by) === null || _file$relationships2$ === void 0 ? void 0 : _file$relationships2$.data) || (file === null || file === void 0 ? void 0 : file.referenced_by) || [];
|
|
164
|
+
return references.some(function (reference) {
|
|
165
|
+
return reference.type === referencedBy && reference.id === referencedId;
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* Get array of reference by an specific doctype
|
|
170
|
+
*
|
|
171
|
+
* @param {IOCozyFile} file - io.cozy.files document
|
|
172
|
+
* @param {Doctype} referencedBy - Doctype where document is referenced
|
|
173
|
+
* @returns {Reference[]} Array of references found
|
|
174
|
+
*/
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
exports.isReferencedById = isReferencedById;
|
|
178
|
+
|
|
179
|
+
var getReferencedBy = function getReferencedBy(file, referencedBy) {
|
|
180
|
+
var _file$relationships3, _file$relationships3$;
|
|
181
|
+
|
|
182
|
+
var references = (file === null || file === void 0 ? void 0 : (_file$relationships3 = file.relationships) === null || _file$relationships3 === void 0 ? void 0 : (_file$relationships3$ = _file$relationships3.referenced_by) === null || _file$relationships3$ === void 0 ? void 0 : _file$relationships3$.data) || (file === null || file === void 0 ? void 0 : file.referenced_by) || [];
|
|
183
|
+
return references.filter(function (reference) {
|
|
184
|
+
return reference.type === referencedBy;
|
|
185
|
+
});
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* Get array of reference by an specific doctype and a specific Id of that reference
|
|
189
|
+
*
|
|
190
|
+
* @param {IOCozyFile} file - io.cozy.files document
|
|
191
|
+
* @param {Doctype} referencedBy - Doctype where document is referenced
|
|
192
|
+
* @param {string} referencedId - Id of the referenced document
|
|
193
|
+
* @returns {Reference[]} Array of the reference found
|
|
194
|
+
*/
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
exports.getReferencedBy = getReferencedBy;
|
|
198
|
+
|
|
199
|
+
var getReferencedById = function getReferencedById(file, referencedBy, referencedId) {
|
|
200
|
+
var _file$relationships4, _file$relationships4$;
|
|
201
|
+
|
|
202
|
+
var references = (file === null || file === void 0 ? void 0 : (_file$relationships4 = file.relationships) === null || _file$relationships4 === void 0 ? void 0 : (_file$relationships4$ = _file$relationships4.referenced_by) === null || _file$relationships4$ === void 0 ? void 0 : _file$relationships4$.data) || (file === null || file === void 0 ? void 0 : file.referenced_by) || [];
|
|
203
|
+
return references.filter(function (reference) {
|
|
204
|
+
return reference.type === referencedBy && reference.id === referencedId;
|
|
205
|
+
});
|
|
206
|
+
};
|
|
127
207
|
|
|
128
|
-
exports.
|
|
208
|
+
exports.getReferencedById = getReferencedById;
|
|
@@ -1,123 +1,237 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
it('should attach to a single document', () => {
|
|
18
|
-
const doc = {
|
|
19
|
-
_id: 1
|
|
1
|
+
import {
|
|
2
|
+
attachRelationships,
|
|
3
|
+
isReferencedBy,
|
|
4
|
+
isReferencedById,
|
|
5
|
+
getReferencedBy,
|
|
6
|
+
getReferencedById
|
|
7
|
+
} from './helpers'
|
|
8
|
+
|
|
9
|
+
describe('Associations helpers', () => {
|
|
10
|
+
describe('Attaching relationships', () => {
|
|
11
|
+
const tasks = {
|
|
12
|
+
data: [
|
|
13
|
+
{ _id: 1, _type: 'io.cozy.tasks' },
|
|
14
|
+
{ _id: 2, _type: 'io.cozy.tasks' }
|
|
15
|
+
]
|
|
20
16
|
}
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
const todos = {
|
|
18
|
+
data: [
|
|
19
|
+
{ _id: 3, _type: 'io.cozy.todos' },
|
|
20
|
+
{ _id: 4, _type: 'io.cozy.todos' }
|
|
21
|
+
]
|
|
25
22
|
}
|
|
26
|
-
const withRelationships = attachRelationships({ data: doc }, relationships)
|
|
27
|
-
expect(withRelationships.data.relationships).toEqual({
|
|
28
|
-
tasks
|
|
29
|
-
})
|
|
30
|
-
})
|
|
31
23
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
{
|
|
24
|
+
it('should attach to a single document', () => {
|
|
25
|
+
const doc = {
|
|
35
26
|
_id: 1
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
_id: 2
|
|
39
27
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
28
|
+
const relationships = {
|
|
29
|
+
1: {
|
|
30
|
+
tasks
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const withRelationships = attachRelationships(
|
|
34
|
+
{ data: doc },
|
|
35
|
+
relationships
|
|
36
|
+
)
|
|
37
|
+
expect(withRelationships.data.relationships).toEqual({
|
|
43
38
|
tasks
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('should attach to multiple document', () => {
|
|
43
|
+
const docs = [
|
|
44
|
+
{
|
|
45
|
+
_id: 1
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
_id: 2
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
const relationships = {
|
|
52
|
+
1: {
|
|
53
|
+
tasks
|
|
54
|
+
},
|
|
55
|
+
2: {
|
|
56
|
+
todos
|
|
57
|
+
}
|
|
47
58
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
59
|
+
const withRelationships = attachRelationships(
|
|
60
|
+
{ data: docs },
|
|
61
|
+
relationships
|
|
62
|
+
)
|
|
63
|
+
expect(withRelationships.data[0].relationships).toEqual({
|
|
64
|
+
tasks
|
|
65
|
+
})
|
|
66
|
+
expect(withRelationships.data[1].relationships).toEqual({
|
|
67
|
+
todos
|
|
68
|
+
})
|
|
52
69
|
})
|
|
53
|
-
|
|
54
|
-
|
|
70
|
+
|
|
71
|
+
it('should add missing relationships', () => {
|
|
72
|
+
const doc = {
|
|
73
|
+
_id: 1,
|
|
74
|
+
relationships: {
|
|
75
|
+
tasks
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const relationships = {
|
|
79
|
+
1: {
|
|
80
|
+
tasks,
|
|
81
|
+
todos
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const withRelationships = attachRelationships(
|
|
85
|
+
{ data: doc },
|
|
86
|
+
relationships
|
|
87
|
+
)
|
|
88
|
+
expect(withRelationships.data.relationships.tasks).toEqual(tasks)
|
|
89
|
+
expect(withRelationships.data.relationships.todos).toEqual(todos)
|
|
55
90
|
})
|
|
56
|
-
})
|
|
57
91
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
92
|
+
it('should preserve existing relationships', () => {
|
|
93
|
+
const doc = {
|
|
94
|
+
_id: 1,
|
|
95
|
+
relationships: {
|
|
96
|
+
tasks
|
|
97
|
+
}
|
|
63
98
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
todos
|
|
99
|
+
const relationships = {
|
|
100
|
+
1: {
|
|
101
|
+
todos
|
|
102
|
+
}
|
|
69
103
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
104
|
+
const withRelationships = attachRelationships(
|
|
105
|
+
{ data: doc },
|
|
106
|
+
relationships
|
|
107
|
+
)
|
|
108
|
+
expect(withRelationships.data.relationships.tasks).toEqual(tasks)
|
|
109
|
+
expect(withRelationships.data.relationships.todos).toEqual(todos)
|
|
110
|
+
})
|
|
75
111
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
112
|
+
it('should work when there are no new relationships', () => {
|
|
113
|
+
const doc = {
|
|
114
|
+
_id: 1,
|
|
115
|
+
relationships: {
|
|
116
|
+
tasks
|
|
117
|
+
}
|
|
81
118
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
119
|
+
const relationships = {
|
|
120
|
+
2: {
|
|
121
|
+
todos
|
|
122
|
+
}
|
|
86
123
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
124
|
+
const withRelationships = attachRelationships(
|
|
125
|
+
{ data: doc },
|
|
126
|
+
relationships
|
|
127
|
+
)
|
|
128
|
+
expect(withRelationships.data.relationships.tasks).toEqual(tasks)
|
|
129
|
+
expect(Object.keys(withRelationships.data.relationships).length).toEqual(
|
|
130
|
+
1
|
|
131
|
+
)
|
|
132
|
+
})
|
|
92
133
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
tasks
|
|
134
|
+
it('should attach relationships when the document has an empty relationship object', () => {
|
|
135
|
+
const doc = {
|
|
136
|
+
_id: 1,
|
|
137
|
+
relationships: {}
|
|
98
138
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
139
|
+
const relationships = {
|
|
140
|
+
1: {
|
|
141
|
+
tasks
|
|
142
|
+
}
|
|
103
143
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
144
|
+
const withRelationships = attachRelationships(
|
|
145
|
+
{ data: doc },
|
|
146
|
+
relationships
|
|
147
|
+
)
|
|
148
|
+
expect(withRelationships.data.relationships.tasks).toEqual(tasks)
|
|
149
|
+
})
|
|
108
150
|
})
|
|
109
151
|
|
|
110
|
-
|
|
111
|
-
const
|
|
112
|
-
_id:
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
152
|
+
describe('referencedBy', () => {
|
|
153
|
+
const mockFile = {
|
|
154
|
+
_id: '123',
|
|
155
|
+
name: 'fakeFile',
|
|
156
|
+
relationships: {
|
|
157
|
+
referenced_by: {
|
|
158
|
+
data: [
|
|
159
|
+
{
|
|
160
|
+
id: '123',
|
|
161
|
+
type: 'io.cozy.contacts'
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
id: '456',
|
|
165
|
+
type: 'io.cozy.contacts'
|
|
166
|
+
}
|
|
167
|
+
]
|
|
168
|
+
}
|
|
118
169
|
}
|
|
119
170
|
}
|
|
120
|
-
|
|
121
|
-
|
|
171
|
+
describe('isReferencedBy', () => {
|
|
172
|
+
it('should return "true"', () => {
|
|
173
|
+
const result = isReferencedBy(mockFile, 'io.cozy.contacts')
|
|
174
|
+
|
|
175
|
+
expect(result).toBe(true)
|
|
176
|
+
})
|
|
177
|
+
it('should return "false"', () => {
|
|
178
|
+
const result = isReferencedBy(mockFile, 'io.cozy.xxx')
|
|
179
|
+
|
|
180
|
+
expect(result).toBe(false)
|
|
181
|
+
})
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
describe('isReferencedById', () => {
|
|
185
|
+
it('should return "true"', () => {
|
|
186
|
+
const result = isReferencedById(mockFile, 'io.cozy.contacts', '123')
|
|
187
|
+
|
|
188
|
+
expect(result).toBe(true)
|
|
189
|
+
})
|
|
190
|
+
it('should return "false"', () => {
|
|
191
|
+
const result = isReferencedById(mockFile, 'io.cozy.contacts', '789')
|
|
192
|
+
|
|
193
|
+
expect(result).toBe(false)
|
|
194
|
+
})
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
describe('getReferencedBy', () => {
|
|
198
|
+
it('should return correct array of reference', () => {
|
|
199
|
+
const result = getReferencedBy(mockFile, 'io.cozy.contacts')
|
|
200
|
+
|
|
201
|
+
expect(result).toEqual([
|
|
202
|
+
{
|
|
203
|
+
id: '123',
|
|
204
|
+
type: 'io.cozy.contacts'
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
id: '456',
|
|
208
|
+
type: 'io.cozy.contacts'
|
|
209
|
+
}
|
|
210
|
+
])
|
|
211
|
+
})
|
|
212
|
+
it('should return empty array', () => {
|
|
213
|
+
const result = getReferencedBy(mockFile, 'io.cozy.xxx')
|
|
214
|
+
|
|
215
|
+
expect(result).toEqual([])
|
|
216
|
+
})
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
describe('getReferencedById', () => {
|
|
220
|
+
it('should return array of reference with only the reference with id "123"', () => {
|
|
221
|
+
const result = getReferencedById(mockFile, 'io.cozy.contacts', '123')
|
|
222
|
+
|
|
223
|
+
expect(result).toEqual([
|
|
224
|
+
{
|
|
225
|
+
id: '123',
|
|
226
|
+
type: 'io.cozy.contacts'
|
|
227
|
+
}
|
|
228
|
+
])
|
|
229
|
+
})
|
|
230
|
+
it('should return empty array', () => {
|
|
231
|
+
const result = getReferencedById(mockFile, 'io.cozy.contacts', '789')
|
|
232
|
+
|
|
233
|
+
expect(result).toEqual([])
|
|
234
|
+
})
|
|
235
|
+
})
|
|
122
236
|
})
|
|
123
237
|
})
|
|
@@ -59,6 +59,30 @@ Object.defineProperty(exports, "create", {
|
|
|
59
59
|
return _helpers.create;
|
|
60
60
|
}
|
|
61
61
|
});
|
|
62
|
+
Object.defineProperty(exports, "isReferencedBy", {
|
|
63
|
+
enumerable: true,
|
|
64
|
+
get: function get() {
|
|
65
|
+
return _helpers.isReferencedBy;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
Object.defineProperty(exports, "isReferencedById", {
|
|
69
|
+
enumerable: true,
|
|
70
|
+
get: function get() {
|
|
71
|
+
return _helpers.isReferencedById;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
Object.defineProperty(exports, "getReferencedBy", {
|
|
75
|
+
enumerable: true,
|
|
76
|
+
get: function get() {
|
|
77
|
+
return _helpers.getReferencedBy;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
Object.defineProperty(exports, "getReferencedById", {
|
|
81
|
+
enumerable: true,
|
|
82
|
+
get: function get() {
|
|
83
|
+
return _helpers.getReferencedById;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
62
86
|
|
|
63
87
|
var _HasManyFiles = _interopRequireDefault(require("./HasManyFiles"));
|
|
64
88
|
|
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
|
|
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
|
|
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
|
|
package/dist/models/file.js
CHANGED
|
@@ -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
|
|
|
@@ -57,7 +57,7 @@ var FILENAME_WITH_EXTENSION_REGEX = /(.+)(\..*)$/;
|
|
|
57
57
|
*/
|
|
58
58
|
|
|
59
59
|
var splitFilename = function splitFilename(file) {
|
|
60
|
-
if (!(0, _isString.default)(file.name)) throw new Error('file should have a name property
|
|
60
|
+
if (!(0, _isString.default)(file.name)) throw new Error('file should have a name property');
|
|
61
61
|
|
|
62
62
|
if (file.type === 'file') {
|
|
63
63
|
var match = file.name.match(FILENAME_WITH_EXTENSION_REGEX);
|
|
@@ -483,7 +483,7 @@ var getFullpath = /*#__PURE__*/function () {
|
|
|
483
483
|
*
|
|
484
484
|
* @param {CozyClient} client - The CozyClient instance
|
|
485
485
|
* @param {string} fileId - The file's id (required)
|
|
486
|
-
* @param {object} destination
|
|
486
|
+
* @param {object} destination - The destination object containing:
|
|
487
487
|
* @param {string} destination.folderId - The destination folder's id (required)
|
|
488
488
|
* @param {string} destination.path - The file's path after the move (optional, used to optimize performance in case of conflict)
|
|
489
489
|
* @param {boolean} force - Whether we should overwrite, i.e. put to trash, the destination in case of conflict (defaults to false).
|
|
@@ -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.
|
|
1027
|
+
exports.isFromKonnector = isFromKonnector;
|
package/dist/models/file.spec.js
CHANGED
|
@@ -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,36 +230,23 @@ describe('File Model', () => {
|
|
|
183
230
|
})
|
|
184
231
|
|
|
185
232
|
describe('splitFilename', () => {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
type: 'file',
|
|
189
|
-
name:
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
{ filename: 'file', extension: '
|
|
195
|
-
{ filename: 'file', extension: '' }
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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
|
-
expect(() => fileModel.splitFilename({})).toThrow(
|
|
247
|
+
expect(() => fileModel.splitFilename({})).toThrow(
|
|
248
|
+
'file should have a name property'
|
|
249
|
+
)
|
|
216
250
|
expect(() => fileModel.splitFilename({ name: null })).toThrow()
|
|
217
251
|
expect(() => fileModel.splitFilename({ name: '' })).not.toThrow()
|
|
218
252
|
})
|
|
@@ -510,48 +544,6 @@ describe('File Model', () => {
|
|
|
510
544
|
})
|
|
511
545
|
})
|
|
512
546
|
|
|
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
547
|
describe('generateNewFileNameOnConflict', () => {
|
|
556
548
|
it('should generate the right file name with _X', () => {
|
|
557
549
|
const filename1 = fileModel.generateNewFileNameOnConflict('test')
|
|
@@ -663,6 +655,53 @@ describe('File Model', () => {
|
|
|
663
655
|
})
|
|
664
656
|
})
|
|
665
657
|
})
|
|
658
|
+
|
|
659
|
+
describe('isPlainText', () => {
|
|
660
|
+
describe('using mime types', () => {
|
|
661
|
+
it('should match mime types starting with "text/"', () => {
|
|
662
|
+
expect(fileModel.isPlainText('text/plain')).toBe(true)
|
|
663
|
+
expect(fileModel.isPlainText('text/markdown')).toBe(true)
|
|
664
|
+
expect(fileModel.isPlainText('application/text')).toBe(false)
|
|
665
|
+
expect(fileModel.isPlainText('something/text/else')).toBe(false)
|
|
666
|
+
expect(fileModel.isPlainText('text/vnd.cozy.note+markdown')).toBe(true)
|
|
667
|
+
})
|
|
668
|
+
|
|
669
|
+
it('should not match complex text formats', () => {
|
|
670
|
+
expect(fileModel.isPlainText('application/msword')).toBe(false)
|
|
671
|
+
expect(
|
|
672
|
+
fileModel.isPlainText('application/vnd.oasis.opendocument.text')
|
|
673
|
+
).toBe(false)
|
|
674
|
+
expect(
|
|
675
|
+
fileModel.isPlainText('application/x-iwork-pages-sffpages')
|
|
676
|
+
).toBe(false)
|
|
677
|
+
})
|
|
678
|
+
|
|
679
|
+
it('should not use the filename if a mime type is present', () => {
|
|
680
|
+
expect(
|
|
681
|
+
fileModel.isPlainText('application/msword', 'iswearitstext.txt')
|
|
682
|
+
).toBe(false)
|
|
683
|
+
})
|
|
684
|
+
})
|
|
685
|
+
|
|
686
|
+
describe('using file names', () => {
|
|
687
|
+
it('should match txt files', () => {
|
|
688
|
+
expect(fileModel.isPlainText(undefined, 'iswearitstext.txt')).toBe(true)
|
|
689
|
+
})
|
|
690
|
+
|
|
691
|
+
it('should match md files', () => {
|
|
692
|
+
expect(fileModel.isPlainText(undefined, 'markdown.md')).toBe(true)
|
|
693
|
+
})
|
|
694
|
+
|
|
695
|
+
it('should not match anything else', () => {
|
|
696
|
+
expect(fileModel.isPlainText(undefined, 'file.doc')).toBe(false)
|
|
697
|
+
expect(fileModel.isPlainText(undefined, 'file.docx')).toBe(false)
|
|
698
|
+
expect(fileModel.isPlainText(undefined, 'file.pages')).toBe(false)
|
|
699
|
+
expect(fileModel.isPlainText(undefined, 'file.odt')).toBe(false)
|
|
700
|
+
expect(fileModel.isPlainText(undefined, 'file.csv')).toBe(false)
|
|
701
|
+
expect(fileModel.isPlainText(undefined, 'file.vcf')).toBe(false)
|
|
702
|
+
})
|
|
703
|
+
})
|
|
704
|
+
})
|
|
666
705
|
})
|
|
667
706
|
|
|
668
707
|
describe('File qualification', () => {
|
package/dist/types.js
CHANGED
|
@@ -99,12 +99,32 @@ var _dsl = require("./queries/dsl");
|
|
|
99
99
|
*/
|
|
100
100
|
|
|
101
101
|
/**
|
|
102
|
-
* A reference to a document
|
|
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
|
|
103
123
|
* https://docs.cozy.io/en/cozy-doctypes/docs/io.cozy.files/#references
|
|
104
124
|
*
|
|
105
125
|
* @typedef {object} Reference
|
|
106
|
-
* @property {string}
|
|
107
|
-
* @property {string}
|
|
126
|
+
* @property {string} id - id of the document
|
|
127
|
+
* @property {string} type - doctype of the document
|
|
108
128
|
*/
|
|
109
129
|
|
|
110
130
|
/**
|
|
@@ -125,7 +145,8 @@ var _dsl = require("./queries/dsl");
|
|
|
125
145
|
* @property {string} [_type] - Type of the document
|
|
126
146
|
* @property {string} [_rev] - Current revision of the document
|
|
127
147
|
* @property {boolean} [_deleted] - When the document has been deleted
|
|
128
|
-
* @property {
|
|
148
|
+
* @property {ReferencedByRelationship} [relationships] - Relationships of the document
|
|
149
|
+
* @property {Reference[]} [referenced_by] - referenced by of another document
|
|
129
150
|
*/
|
|
130
151
|
|
|
131
152
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-client",
|
|
3
|
-
"version": "27.
|
|
3
|
+
"version": "27.6.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.node.js",
|
|
6
6
|
"browser": "dist/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"cozy-device-helper": "^1.12.0",
|
|
22
22
|
"cozy-flags": "2.7.1",
|
|
23
23
|
"cozy-logger": "^1.6.0",
|
|
24
|
-
"cozy-stack-client": "^27.1
|
|
24
|
+
"cozy-stack-client": "^27.6.1",
|
|
25
25
|
"json-stable-stringify": "^1.0.1",
|
|
26
26
|
"lodash": "^4.17.13",
|
|
27
27
|
"microee": "^0.0.6",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"btoa": "^1.2.1",
|
|
53
53
|
"cozy-logger": "1.7.0",
|
|
54
54
|
"cozy-ui": "48.0.0",
|
|
55
|
-
"date-fns": "2.
|
|
55
|
+
"date-fns": "2.27.0",
|
|
56
56
|
"jsdoc-plugin-intersection": "^1.0.4",
|
|
57
57
|
"mockdate": "^2.0.2",
|
|
58
58
|
"react": "16.14.0",
|
|
@@ -69,5 +69,5 @@
|
|
|
69
69
|
"react-native-inappbrowser-reborn": "^3.5.1"
|
|
70
70
|
},
|
|
71
71
|
"sideEffects": false,
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "36962d75de2e47cbcb11fa13f05fd0445a3aa39d"
|
|
73
73
|
}
|
|
@@ -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";
|
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";
|
package/types/models/file.d.ts
CHANGED
|
@@ -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";
|
package/types/types.d.ts
CHANGED
|
@@ -74,18 +74,37 @@ export type FetchMoreAble = {
|
|
|
74
74
|
};
|
|
75
75
|
export type UseQueryReturnValue = QueryState & FetchMoreAble;
|
|
76
76
|
/**
|
|
77
|
-
* A reference to a document
|
|
77
|
+
* A reference to a document
|
|
78
|
+
*/
|
|
79
|
+
export type ReferencedByRelationship = {
|
|
80
|
+
parent?: RelationshipParent;
|
|
81
|
+
referenced_by?: ReferencedBy;
|
|
82
|
+
};
|
|
83
|
+
export type RelationshipParent = {
|
|
84
|
+
links: {
|
|
85
|
+
related: string;
|
|
86
|
+
};
|
|
87
|
+
data?: Reference;
|
|
88
|
+
};
|
|
89
|
+
export type ReferencedBy = {
|
|
90
|
+
links: {
|
|
91
|
+
self: string;
|
|
92
|
+
};
|
|
93
|
+
data: Reference[] | null;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* A reference to a document
|
|
78
97
|
* https://docs.cozy.io/en/cozy-doctypes/docs/io.cozy.files/#references
|
|
79
98
|
*/
|
|
80
99
|
export type Reference = {
|
|
81
100
|
/**
|
|
82
101
|
* - id of the document
|
|
83
102
|
*/
|
|
84
|
-
|
|
103
|
+
id: string;
|
|
85
104
|
/**
|
|
86
105
|
* - doctype of the document
|
|
87
106
|
*/
|
|
88
|
-
|
|
107
|
+
type: string;
|
|
89
108
|
};
|
|
90
109
|
export type ReferenceMap = {
|
|
91
110
|
[x: string]: Reference[];
|
|
@@ -122,7 +141,11 @@ export type CozyClientDocument = {
|
|
|
122
141
|
/**
|
|
123
142
|
* - Relationships of the document
|
|
124
143
|
*/
|
|
125
|
-
relationships?:
|
|
144
|
+
relationships?: ReferencedByRelationship;
|
|
145
|
+
/**
|
|
146
|
+
* - referenced by of another document
|
|
147
|
+
*/
|
|
148
|
+
referenced_by?: Reference[];
|
|
126
149
|
};
|
|
127
150
|
/**
|
|
128
151
|
* - An io.cozy.files document
|