cozy-client 27.14.0 → 27.14.4
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 +35 -0
- package/dist/CozyClient.js +2 -1
- package/dist/CozyClient.spec.js +56 -54
- package/dist/RealTimeQueries.js +1 -0
- package/dist/assets/qualifications.json +1 -1
- package/dist/associations/HasManyFiles.js +34 -16
- package/dist/associations.spec.js +1 -1
- package/dist/flagship-certification/typedefs.js +4 -8
- package/dist/hooks/useQuery.spec.jsx +1 -1
- package/dist/queries/dsl.js +13 -13
- package/dist/queries/dsl.spec.js +3 -2
- package/dist/types.js +7 -1
- package/dist/utils.spec.js +1 -0
- package/package.json +3 -3
- package/types/CozyClient.d.ts +1 -0
- package/types/flagship-certification/typedefs.d.ts +4 -4
- package/types/queries/dsl.d.ts +36 -34
- package/types/types.d.ts +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,41 @@
|
|
|
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.14.4](https://github.com/cozy/cozy-client/compare/v27.14.3...v27.14.4) (2022-01-31)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package cozy-client
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [27.14.3](https://github.com/cozy/cozy-client/compare/v27.14.2...v27.14.3) (2022-01-28)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* **qualification:** Fix typo in identity ([e89aa8d](https://github.com/cozy/cozy-client/commit/e89aa8de0b6b25d5eecd8dc1ba41baa80dff5ec2))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## [27.14.2](https://github.com/cozy/cozy-client/compare/v27.14.1...v27.14.2) (2022-01-28)
|
|
26
|
+
|
|
27
|
+
**Note:** Version bump only for package cozy-client
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
## [27.14.1](https://github.com/cozy/cozy-client/compare/v27.14.0...v27.14.1) (2022-01-28)
|
|
34
|
+
|
|
35
|
+
**Note:** Version bump only for package cozy-client
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
6
41
|
# [27.14.0](https://github.com/cozy/cozy-client/compare/v27.13.0...v27.14.0) (2022-01-25)
|
|
7
42
|
|
|
8
43
|
|
package/dist/CozyClient.js
CHANGED
|
@@ -2293,6 +2293,7 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2293
2293
|
* At any time put an error function
|
|
2294
2294
|
*
|
|
2295
2295
|
* @param {Function} [onError] - Set a callback for queries which are errored
|
|
2296
|
+
* @throws {Error} onError should not have been defined yet
|
|
2296
2297
|
*/
|
|
2297
2298
|
|
|
2298
2299
|
}, {
|
|
@@ -2463,7 +2464,7 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2463
2464
|
CozyClient.hooks = CozyClient.hooks || {};
|
|
2464
2465
|
CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
|
|
2465
2466
|
|
|
2466
|
-
CozyClient.version = "27.14.
|
|
2467
|
+
CozyClient.version = "27.14.4";
|
|
2467
2468
|
|
|
2468
2469
|
_microee.default.mixin(CozyClient);
|
|
2469
2470
|
|
package/dist/CozyClient.spec.js
CHANGED
|
@@ -1140,7 +1140,7 @@ describe('CozyClient', () => {
|
|
|
1140
1140
|
})
|
|
1141
1141
|
|
|
1142
1142
|
it('should first dispatch a INIT_QUERY action', async () => {
|
|
1143
|
-
requestHandler.
|
|
1143
|
+
requestHandler.mockResolvedValueOnce(fakeResponse)
|
|
1144
1144
|
await client.query(query, { as: 'allTodos' })
|
|
1145
1145
|
expect(client.store.dispatch.mock.calls[0][0]).toEqual(
|
|
1146
1146
|
initQuery('allTodos', { doctype: 'io.cozy.todos' }, { as: 'allTodos' })
|
|
@@ -1148,7 +1148,7 @@ describe('CozyClient', () => {
|
|
|
1148
1148
|
})
|
|
1149
1149
|
|
|
1150
1150
|
it('should then dispatch a RECEIVE_QUERY_RESULT action', async () => {
|
|
1151
|
-
requestHandler.
|
|
1151
|
+
requestHandler.mockResolvedValueOnce(fakeResponse)
|
|
1152
1152
|
await client.query(query, { as: 'allTodos' })
|
|
1153
1153
|
const dispatchCalls = client.store.dispatch.mock.calls
|
|
1154
1154
|
const lastDispatchCall = dispatchCalls[dispatchCalls.length - 1]
|
|
@@ -1159,7 +1159,7 @@ describe('CozyClient', () => {
|
|
|
1159
1159
|
|
|
1160
1160
|
it('should dispatch a RECEIVE_QUERY_ERROR action if an error occurs', async () => {
|
|
1161
1161
|
const error = new Error('Fake error')
|
|
1162
|
-
requestHandler.
|
|
1162
|
+
requestHandler.mockRejectedValueOnce(error)
|
|
1163
1163
|
try {
|
|
1164
1164
|
await client.query(query, { as: 'allTodos' })
|
|
1165
1165
|
} catch (e) {} // eslint-disable-line no-empty
|
|
@@ -1169,13 +1169,13 @@ describe('CozyClient', () => {
|
|
|
1169
1169
|
})
|
|
1170
1170
|
|
|
1171
1171
|
it('should resolve to the query response', async () => {
|
|
1172
|
-
requestHandler.
|
|
1172
|
+
requestHandler.mockResolvedValueOnce(fakeResponse)
|
|
1173
1173
|
const resp = await client.query(query)
|
|
1174
1174
|
expect(resp).toEqual(fakeResponse)
|
|
1175
1175
|
})
|
|
1176
1176
|
|
|
1177
1177
|
it('should call the link with the query', async () => {
|
|
1178
|
-
requestHandler.
|
|
1178
|
+
requestHandler.mockResolvedValueOnce(fakeResponse)
|
|
1179
1179
|
await client.query(query)
|
|
1180
1180
|
expect(requestHandler).toHaveBeenCalledTimes(1)
|
|
1181
1181
|
expect(requestHandler.mock.calls[0][0]).toBe(query)
|
|
@@ -1200,8 +1200,8 @@ describe('CozyClient', () => {
|
|
|
1200
1200
|
]
|
|
1201
1201
|
})
|
|
1202
1202
|
)
|
|
1203
|
-
.
|
|
1204
|
-
.
|
|
1203
|
+
.mockResolvedValueOnce({ data: [], included: [] })
|
|
1204
|
+
.mockResolvedValueOnce({ data: [], included: [] })
|
|
1205
1205
|
|
|
1206
1206
|
const resp = await client.query(
|
|
1207
1207
|
Q('io.cozy.todos').include(['attachments'])
|
|
@@ -1246,7 +1246,7 @@ describe('CozyClient', () => {
|
|
|
1246
1246
|
})
|
|
1247
1247
|
|
|
1248
1248
|
it('should set the correct name to the query', async () => {
|
|
1249
|
-
requestHandler.
|
|
1249
|
+
requestHandler.mockResolvedValueOnce(fakeResponse)
|
|
1250
1250
|
const getById = Q('io.cozy.files').getById('1')
|
|
1251
1251
|
await client.query(getById)
|
|
1252
1252
|
expect(client.store.dispatch.mock.calls[0][0]).toEqual(
|
|
@@ -1256,7 +1256,7 @@ describe('CozyClient', () => {
|
|
|
1256
1256
|
)
|
|
1257
1257
|
})
|
|
1258
1258
|
it('should use the name passed as an argument', async () => {
|
|
1259
|
-
requestHandler.
|
|
1259
|
+
requestHandler.mockResolvedValueOnce(fakeResponse)
|
|
1260
1260
|
const getById = Q('io.cozy.files').getById('1')
|
|
1261
1261
|
await client.query(getById, { as: 'toto' })
|
|
1262
1262
|
expect(client.store.dispatch.mock.calls[0][0]).toEqual(
|
|
@@ -1266,7 +1266,7 @@ describe('CozyClient', () => {
|
|
|
1266
1266
|
)
|
|
1267
1267
|
})
|
|
1268
1268
|
it('should name the query correctly', async () => {
|
|
1269
|
-
requestHandler.
|
|
1269
|
+
requestHandler.mockResolvedValueOnce(fakeResponse)
|
|
1270
1270
|
await client.query(query, { as: 'allTodos' })
|
|
1271
1271
|
expect(client.store.dispatch.mock.calls[0][0]).toEqual(
|
|
1272
1272
|
initQuery('allTodos', { doctype: 'io.cozy.todos' }, { as: 'allTodos' })
|
|
@@ -1353,7 +1353,7 @@ describe('CozyClient', () => {
|
|
|
1353
1353
|
})
|
|
1354
1354
|
|
|
1355
1355
|
it('should dispatch a INIT_QUERY action if status is not loaded', async () => {
|
|
1356
|
-
requestHandler.
|
|
1356
|
+
requestHandler.mockResolvedValueOnce(fakeResponse)
|
|
1357
1357
|
getQueryFromState.mockReturnValueOnce({
|
|
1358
1358
|
fetchStatus: 'pending'
|
|
1359
1359
|
})
|
|
@@ -1364,7 +1364,7 @@ describe('CozyClient', () => {
|
|
|
1364
1364
|
})
|
|
1365
1365
|
|
|
1366
1366
|
it('should dispatch a INIT_QUERY action if no skip and no bookmark', async () => {
|
|
1367
|
-
requestHandler.
|
|
1367
|
+
requestHandler.mockResolvedValueOnce(fakeResponse)
|
|
1368
1368
|
getQueryFromState.mockReturnValueOnce({
|
|
1369
1369
|
fetchStatus: 'loaded'
|
|
1370
1370
|
})
|
|
@@ -1375,7 +1375,7 @@ describe('CozyClient', () => {
|
|
|
1375
1375
|
})
|
|
1376
1376
|
|
|
1377
1377
|
it('should dispatch a RECEIVE_QUERY_RESULT action if query has skip', async () => {
|
|
1378
|
-
requestHandler.
|
|
1378
|
+
requestHandler.mockResolvedValueOnce(fakeResponse)
|
|
1379
1379
|
getQueryFromState.mockReturnValueOnce({
|
|
1380
1380
|
fetchStatus: 'loaded'
|
|
1381
1381
|
})
|
|
@@ -1389,7 +1389,7 @@ describe('CozyClient', () => {
|
|
|
1389
1389
|
})
|
|
1390
1390
|
|
|
1391
1391
|
it('should dispatch a RECEIVE_QUERY_RESULT action if query has bookmark', async () => {
|
|
1392
|
-
requestHandler.
|
|
1392
|
+
requestHandler.mockResolvedValueOnce(fakeResponse)
|
|
1393
1393
|
getQueryFromState.mockReturnValueOnce({
|
|
1394
1394
|
fetchStatus: 'loaded'
|
|
1395
1395
|
})
|
|
@@ -1402,52 +1402,54 @@ describe('CozyClient', () => {
|
|
|
1402
1402
|
)
|
|
1403
1403
|
})
|
|
1404
1404
|
|
|
1405
|
-
|
|
1406
|
-
const
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1405
|
+
describe('setupOnError', () => {
|
|
1406
|
+
const setupOnError = () => {
|
|
1407
|
+
const error = new TypeError('Failed to fetch')
|
|
1408
|
+
requestHandler.mockRejectedValueOnce(error)
|
|
1409
|
+
return jest.fn().mockReturnValueOnce(() => true)
|
|
1410
|
+
}
|
|
1411
1411
|
|
|
1412
|
-
|
|
1413
|
-
|
|
1412
|
+
it('should call onError callback when an error is thrown. Callback passed as argument', async () => {
|
|
1413
|
+
const onError = setupOnError()
|
|
1414
1414
|
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1415
|
+
await client.query(query, { as: 'allTodos', onError })
|
|
1416
|
+
expect(onError).toBeCalled()
|
|
1417
|
+
})
|
|
1418
1418
|
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1419
|
+
it('should call onError callback when an error is caught. It is passed during instantiation', async () => {
|
|
1420
|
+
const setupOnError = () => jest.fn().mockReturnValueOnce(() => true)
|
|
1421
|
+
const onError = setupOnError()
|
|
1422
|
+
const client = new CozyClient({ onError })
|
|
1422
1423
|
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1424
|
+
await client.query(query, { as: 'allTodos' })
|
|
1425
|
+
expect(onError).toBeCalled()
|
|
1426
|
+
})
|
|
1426
1427
|
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1428
|
+
it('should call onError callback when an error is catched. It is passed with setOnError', async () => {
|
|
1429
|
+
const onError = setupOnError()
|
|
1430
|
+
client.setOnError(onError)
|
|
1430
1431
|
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1432
|
+
await client.query(query, { as: 'allTodos' })
|
|
1433
|
+
expect(onError).toBeCalled()
|
|
1434
|
+
})
|
|
1434
1435
|
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1436
|
+
it('should throw an error when we call setOnError twice (or several times)', async () => {
|
|
1437
|
+
const client = new CozyClient({})
|
|
1438
|
+
const onError = () => true
|
|
1438
1439
|
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1440
|
+
const funcShouldThrow = () => client.setOnError(onError)
|
|
1441
|
+
expect(funcShouldThrow).not.toThrow()
|
|
1442
|
+
expect(funcShouldThrow).toThrow('On Error is already defined')
|
|
1443
|
+
})
|
|
1443
1444
|
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1445
|
+
it('should throw an error when there is no onError callback', async () => {
|
|
1446
|
+
const error = new TypeError('Failed to fetch')
|
|
1447
|
+
requestHandler.mockRejectedValueOnce(error)
|
|
1447
1448
|
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1449
|
+
await expect(client.query(query, { as: 'allTodos' })).rejects.toThrow(
|
|
1450
|
+
'Failed to fetch'
|
|
1451
|
+
)
|
|
1452
|
+
})
|
|
1451
1453
|
})
|
|
1452
1454
|
})
|
|
1453
1455
|
|
|
@@ -1546,7 +1548,7 @@ describe('CozyClient', () => {
|
|
|
1546
1548
|
})
|
|
1547
1549
|
|
|
1548
1550
|
it('should then dispatch a RECEIVE_MUTATION_RESULT action', async () => {
|
|
1549
|
-
requestHandler.
|
|
1551
|
+
requestHandler.mockResolvedValueOnce(fakeResponse)
|
|
1550
1552
|
await client.mutate(mutation, { as: 'updateTodo' })
|
|
1551
1553
|
expect(client.store.dispatch.mock.calls[1][0]).toEqual(
|
|
1552
1554
|
receiveMutationResult('updateTodo', fakeResponse, {}, mutation)
|
|
@@ -1554,14 +1556,14 @@ describe('CozyClient', () => {
|
|
|
1554
1556
|
})
|
|
1555
1557
|
|
|
1556
1558
|
it('should resolve to the mutation response', async () => {
|
|
1557
|
-
requestHandler.
|
|
1559
|
+
requestHandler.mockResolvedValueOnce(fakeResponse)
|
|
1558
1560
|
const resp = await client.mutate(mutation)
|
|
1559
1561
|
expect(resp).toEqual(fakeResponse)
|
|
1560
1562
|
})
|
|
1561
1563
|
|
|
1562
1564
|
it('should dispatch a RECEIVE_MUTATION_ERROR action if an error occurs', async () => {
|
|
1563
1565
|
const error = new Error('Fake error')
|
|
1564
|
-
requestHandler.
|
|
1566
|
+
requestHandler.mockRejectedValueOnce(error)
|
|
1565
1567
|
try {
|
|
1566
1568
|
await client.mutate(mutation, { as: 'updateTodo' })
|
|
1567
1569
|
} catch (e) {} // eslint-disable-line no-empty
|
|
@@ -1573,7 +1575,7 @@ describe('CozyClient', () => {
|
|
|
1573
1575
|
it('should handle an array of mutations (including mutation creators)', async () => {
|
|
1574
1576
|
const FAKE_MUTATION_1 = { mutationType: 'FAKE_1' }
|
|
1575
1577
|
const FAKE_MUTATION_2 = resp => ({ mutationType: 'FAKE_2', resp })
|
|
1576
|
-
requestHandler.
|
|
1578
|
+
requestHandler.mockResolvedValue(fakeResponse)
|
|
1577
1579
|
await client.mutate([mutation, FAKE_MUTATION_1, FAKE_MUTATION_2])
|
|
1578
1580
|
expect(requestHandler).toHaveBeenCalledTimes(3)
|
|
1579
1581
|
expect(requestHandler.mock.calls[0][0]).toBe(mutation)
|
package/dist/RealTimeQueries.js
CHANGED
|
@@ -48,6 +48,7 @@ var normalizeDoc = function normalizeDoc(couchDBDoc, doctype) {
|
|
|
48
48
|
* DispatchChange
|
|
49
49
|
*
|
|
50
50
|
* @param {CozyClient} client CozyClient instane
|
|
51
|
+
* @param {Doctype} doctype Doctype of the document to update
|
|
51
52
|
* @param {CouchDBDocument} couchDBDoc Document to update
|
|
52
53
|
* @param {Mutation} mutationDefinitionCreator Mutation to apply
|
|
53
54
|
*/
|
|
@@ -27,6 +27,8 @@ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime
|
|
|
27
27
|
|
|
28
28
|
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
29
29
|
|
|
30
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
31
|
+
|
|
30
32
|
var _get4 = _interopRequireDefault(require("lodash/get"));
|
|
31
33
|
|
|
32
34
|
var _omit = _interopRequireDefault(require("lodash/omit"));
|
|
@@ -53,11 +55,30 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
|
|
|
53
55
|
|
|
54
56
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
55
57
|
|
|
58
|
+
/**
|
|
59
|
+
* newCursor - Returns a CouchDB view Cursor for cursor-based pagination
|
|
60
|
+
*
|
|
61
|
+
* @param {ViewKey} key - The CouchDB key of the view which will be requested
|
|
62
|
+
* @param {DocId} startDocId - The first doc _id to return from the view
|
|
63
|
+
*
|
|
64
|
+
* @returns {CouchDBViewCursor}
|
|
65
|
+
*/
|
|
66
|
+
var newCursor = function newCursor(_ref, startDocId) {
|
|
67
|
+
var _ref2 = (0, _slicedToArray2.default)(_ref, 3),
|
|
68
|
+
doctype = _ref2[0],
|
|
69
|
+
id = _ref2[1],
|
|
70
|
+
lastDatetime = _ref2[2];
|
|
71
|
+
|
|
72
|
+
var cursorKey = lastDatetime ? [doctype, id, lastDatetime] : [doctype, id];
|
|
73
|
+
return [cursorKey, startDocId];
|
|
74
|
+
};
|
|
56
75
|
/**
|
|
57
76
|
* This class is only used for photos albums relationships.
|
|
58
77
|
* Behind the hood, the queries uses a view returning the files sorted
|
|
59
78
|
* by datetime, with a cursor-based pagination.
|
|
60
79
|
*/
|
|
80
|
+
|
|
81
|
+
|
|
61
82
|
var HasManyFiles = /*#__PURE__*/function (_HasMany) {
|
|
62
83
|
(0, _inherits2.default)(HasManyFiles, _HasMany);
|
|
63
84
|
|
|
@@ -87,8 +108,8 @@ var HasManyFiles = /*#__PURE__*/function (_HasMany) {
|
|
|
87
108
|
lastRelationship = relationships[relationships.length - 1];
|
|
88
109
|
_context2.next = 5;
|
|
89
110
|
return this.dispatch( /*#__PURE__*/function () {
|
|
90
|
-
var
|
|
91
|
-
var lastRelDoc, lastDatetime,
|
|
111
|
+
var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(dispatch, getState) {
|
|
112
|
+
var lastRelDoc, lastDatetime, cursor, response;
|
|
92
113
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
93
114
|
while (1) {
|
|
94
115
|
switch (_context.prev = _context.next) {
|
|
@@ -97,17 +118,15 @@ var HasManyFiles = /*#__PURE__*/function (_HasMany) {
|
|
|
97
118
|
|
|
98
119
|
lastDatetime = lastRelDoc.attributes.metadata.datetime; // cursor-based pagination
|
|
99
120
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
_context.next = 7;
|
|
104
|
-
return _this.query(queryDef.referencedBy(_this.target).offsetCursor(cursorView));
|
|
121
|
+
cursor = newCursor([_this.target._type, _this.target._id, lastDatetime], relationships[relationships.length - 1]._id);
|
|
122
|
+
_context.next = 5;
|
|
123
|
+
return _this.query(queryDef.referencedBy(_this.target).offsetCursor(cursor));
|
|
105
124
|
|
|
106
|
-
case
|
|
125
|
+
case 5:
|
|
107
126
|
response = _context.sent;
|
|
108
127
|
// Remove first returned element, used as starting point for the query
|
|
109
128
|
response.data.shift();
|
|
110
|
-
_context.next =
|
|
129
|
+
_context.next = 9;
|
|
111
130
|
return _this.dispatch(_this.updateRelationshipData(function (previousRelationshipData) {
|
|
112
131
|
return _objectSpread(_objectSpread({}, previousRelationshipData), {}, {
|
|
113
132
|
data: [].concat((0, _toConsumableArray2.default)(previousRelationshipData.data), (0, _toConsumableArray2.default)(response.data)),
|
|
@@ -115,7 +134,7 @@ var HasManyFiles = /*#__PURE__*/function (_HasMany) {
|
|
|
115
134
|
});
|
|
116
135
|
}));
|
|
117
136
|
|
|
118
|
-
case
|
|
137
|
+
case 9:
|
|
119
138
|
case "end":
|
|
120
139
|
return _context.stop();
|
|
121
140
|
}
|
|
@@ -124,7 +143,7 @@ var HasManyFiles = /*#__PURE__*/function (_HasMany) {
|
|
|
124
143
|
}));
|
|
125
144
|
|
|
126
145
|
return function (_x, _x2) {
|
|
127
|
-
return
|
|
146
|
+
return _ref3.apply(this, arguments);
|
|
128
147
|
};
|
|
129
148
|
}());
|
|
130
149
|
|
|
@@ -261,9 +280,9 @@ var HasManyFiles = /*#__PURE__*/function (_HasMany) {
|
|
|
261
280
|
|
|
262
281
|
if (this.target._type === _const.DOCTYPE_FILES) {
|
|
263
282
|
var refs = (0, _get4.default)(this.target, 'referenced_by', []);
|
|
264
|
-
return refs.map(function (
|
|
265
|
-
var id =
|
|
266
|
-
type =
|
|
283
|
+
return refs.map(function (_ref4) {
|
|
284
|
+
var id = _ref4.id,
|
|
285
|
+
type = _ref4.type;
|
|
267
286
|
return _this4.get(type, id);
|
|
268
287
|
}).filter(Boolean);
|
|
269
288
|
} else {
|
|
@@ -282,8 +301,7 @@ var HasManyFiles = /*#__PURE__*/function (_HasMany) {
|
|
|
282
301
|
}));
|
|
283
302
|
return ids.length > 0 ? (0, _dsl.Q)(assoc.doctype).getByIds(ids) : null;
|
|
284
303
|
} else {
|
|
285
|
-
var
|
|
286
|
-
var cursor = [key, ''];
|
|
304
|
+
var cursor = newCursor([document._type, document._id], '');
|
|
287
305
|
return (0, _dsl.Q)(assoc.doctype).referencedBy(document).offsetCursor(cursor);
|
|
288
306
|
}
|
|
289
307
|
}
|
|
@@ -119,7 +119,7 @@ describe('Associations', () => {
|
|
|
119
119
|
],
|
|
120
120
|
next: false
|
|
121
121
|
}
|
|
122
|
-
requestHandler.
|
|
122
|
+
requestHandler.mockResolvedValueOnce(FAKE_RESPONSE)
|
|
123
123
|
|
|
124
124
|
const queryBefore = getQueryFromStore(client.store, 'allTodos')
|
|
125
125
|
await getTodo(TODO_1._id).attachments.fetchMore()
|
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A JSON Web Signature
|
|
3
|
-
* @typedef {string} jws
|
|
2
|
+
* @typedef {string} jws - A JSON Web Signature
|
|
4
3
|
*/
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
|
-
* A JSON Web Signature
|
|
8
|
-
* @typedef {string} base64string
|
|
6
|
+
* @typedef {string} base64string - A JSON Web Signature
|
|
9
7
|
*/
|
|
10
8
|
|
|
11
9
|
/**
|
|
12
|
-
* An app attestation from the app store
|
|
13
|
-
* @typedef {object} AttestationResult
|
|
10
|
+
* @typedef {object} AttestationResult - An app attestation from the app store
|
|
14
11
|
* @property {string} platform
|
|
15
12
|
* @property {jws|base64string} attestation
|
|
16
13
|
* @property {string} [keyId]
|
|
17
14
|
*/
|
|
18
15
|
|
|
19
16
|
/**
|
|
20
|
-
* Configuration to access the stores certification API
|
|
21
|
-
* @typedef {object} CertificationConfig
|
|
17
|
+
* @typedef {object} CertificationConfig - Configuration to access the stores certification API
|
|
22
18
|
* @property {string} androidSafetyNetApiKey
|
|
23
19
|
*/
|
|
24
20
|
"use strict";
|
|
@@ -214,7 +214,7 @@ describe('use query', () => {
|
|
|
214
214
|
links: [new CozyLink(requestHandler)]
|
|
215
215
|
})
|
|
216
216
|
const error = new TypeError('Failed to fetch')
|
|
217
|
-
requestHandler.
|
|
217
|
+
requestHandler.mockRejectedValue(error)
|
|
218
218
|
const onError = jest.fn().mockReturnValue(() => true)
|
|
219
219
|
setupQuery({
|
|
220
220
|
customClient: client,
|
package/dist/queries/dsl.js
CHANGED
|
@@ -36,7 +36,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
36
36
|
*/
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
* @typedef {
|
|
39
|
+
* @typedef {object} MangoPartialFilter
|
|
40
40
|
*/
|
|
41
41
|
|
|
42
42
|
/**
|
|
@@ -50,19 +50,19 @@ var QueryDefinition = /*#__PURE__*/function () {
|
|
|
50
50
|
* @class
|
|
51
51
|
*
|
|
52
52
|
* @param {object} options Initial options for the query definition
|
|
53
|
-
* @param {
|
|
54
|
-
* @param {
|
|
55
|
-
* @param {Array} [options.ids] - The ids of the docs.
|
|
56
|
-
* @param {
|
|
57
|
-
* @param {Array} [options.fields] - The fields to return.
|
|
58
|
-
* @param {Array} [options.indexedFields] - The fields to index.
|
|
59
|
-
* @param {
|
|
60
|
-
* @param {Array} [options.sort] - The sorting params.
|
|
53
|
+
* @param {Doctype} [options.doctype] - The doctype of the doc.
|
|
54
|
+
* @param {DocId|null} [options.id] - The id of the doc.
|
|
55
|
+
* @param {Array<DocId>} [options.ids] - The ids of the docs.
|
|
56
|
+
* @param {MangoSelector} [options.selector] - The selector to query the docs.
|
|
57
|
+
* @param {Array<string>} [options.fields] - The fields to return.
|
|
58
|
+
* @param {Array<string>} [options.indexedFields] - The fields to index.
|
|
59
|
+
* @param {MangoPartialFilter} [options.partialFilter] - The partial index definition to filter docs.
|
|
60
|
+
* @param {Array<object>} [options.sort] - The sorting params.
|
|
61
61
|
* @param {Array<string>} [options.includes] - The docs to include.
|
|
62
|
-
* @param {string} [options.referenced] - The referenced document.
|
|
62
|
+
* @param {string|null} [options.referenced] - The referenced document.
|
|
63
63
|
* @param {number|null} [options.limit] - The document's limit to return.
|
|
64
|
-
* @param {number} [options.skip] - The number of docs to skip.
|
|
65
|
-
* @param {
|
|
64
|
+
* @param {number|null} [options.skip] - The number of docs to skip.
|
|
65
|
+
* @param {CouchDBViewCursor} [options.cursor] - The cursor to paginate views.
|
|
66
66
|
* @param {string} [options.bookmark] - The bookmark to paginate mango queries.
|
|
67
67
|
*/
|
|
68
68
|
function QueryDefinition() {
|
|
@@ -342,7 +342,7 @@ var QueryDefinition = /*#__PURE__*/function () {
|
|
|
342
342
|
* the starting document of the query, e.g. "file-id".
|
|
343
343
|
* Use the last docid of each query as startkey_docid to paginate or leave blank for the first query.
|
|
344
344
|
*
|
|
345
|
-
* @param {
|
|
345
|
+
* @param {CouchDBViewCursor} cursor The cursor for pagination.
|
|
346
346
|
* @returns {QueryDefinition} The QueryDefinition object.
|
|
347
347
|
*/
|
|
348
348
|
|
package/dist/queries/dsl.spec.js
CHANGED
|
@@ -50,8 +50,9 @@ describe('QueryDefinition', () => {
|
|
|
50
50
|
expect(withSkip.bookmark).toBeUndefined()
|
|
51
51
|
expect(withSkip.cursor).toBeUndefined()
|
|
52
52
|
|
|
53
|
-
const
|
|
54
|
-
|
|
53
|
+
const cursor = [['io.cozy.files', '1234'], 'xyz']
|
|
54
|
+
const withCursor = withSkip.offsetCursor(cursor)
|
|
55
|
+
expect(withCursor.cursor).toEqual(cursor)
|
|
55
56
|
expect(withCursor.bookmark).toBeUndefined()
|
|
56
57
|
expect(withCursor.skip).toBeUndefined()
|
|
57
58
|
|
package/dist/types.js
CHANGED
|
@@ -167,7 +167,7 @@ var _dsl = require("./queries/dsl");
|
|
|
167
167
|
* @property {string} name - Name of the folder
|
|
168
168
|
* @property {object} metadata - Metadata of the folder
|
|
169
169
|
* @property {object} type - Type of the folder
|
|
170
|
-
* @typedef {CozyClientDocument &
|
|
170
|
+
* @typedef {CozyClientDocument & FolderDocument} IOCozyFolder - An io.cozy.files document
|
|
171
171
|
*/
|
|
172
172
|
|
|
173
173
|
/**
|
|
@@ -253,6 +253,12 @@ var _dsl = require("./queries/dsl");
|
|
|
253
253
|
* @property {string?} reason?
|
|
254
254
|
*/
|
|
255
255
|
|
|
256
|
+
/**
|
|
257
|
+
* @typedef {Array<string>|string} ViewKey
|
|
258
|
+
* @typedef {string} DocId
|
|
259
|
+
* @typedef {[ViewKey, DocId]} CouchDBViewCursor
|
|
260
|
+
*/
|
|
261
|
+
|
|
256
262
|
/**
|
|
257
263
|
* @typedef {object} Theme
|
|
258
264
|
* @property {string} id
|
package/dist/utils.spec.js
CHANGED
|
@@ -22,6 +22,7 @@ describe('cancelable', () => {
|
|
|
22
22
|
})
|
|
23
23
|
|
|
24
24
|
it('should reject with the rejection of the promise', done => {
|
|
25
|
+
jest.spyOn(console, 'log').mockImplementation()
|
|
25
26
|
const error = 'normal-rejection-from-cancelable-test'
|
|
26
27
|
const { reject, wrapped } = setup()
|
|
27
28
|
expect.assertions(1)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-client",
|
|
3
|
-
"version": "27.14.
|
|
3
|
+
"version": "27.14.4",
|
|
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.
|
|
24
|
+
"cozy-stack-client": "^27.14.4",
|
|
25
25
|
"json-stable-stringify": "^1.0.1",
|
|
26
26
|
"lodash": "^4.17.13",
|
|
27
27
|
"microee": "^0.0.6",
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
"react-native-ios11-devicecheck": "https://github.com/cozy/react-native-devicecheck#app-attest-v0.1"
|
|
72
72
|
},
|
|
73
73
|
"sideEffects": false,
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "df8a41fff60d8b4492e240932dd6858641c861d3"
|
|
75
75
|
}
|
package/types/CozyClient.d.ts
CHANGED
|
@@ -652,6 +652,7 @@ declare class CozyClient {
|
|
|
652
652
|
* At any time put an error function
|
|
653
653
|
*
|
|
654
654
|
* @param {Function} [onError] - Set a callback for queries which are errored
|
|
655
|
+
* @throws {Error} onError should not have been defined yet
|
|
655
656
|
*/
|
|
656
657
|
setOnError(onError?: Function): void;
|
|
657
658
|
toJSON(): SnapshotClient;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A JSON Web Signature
|
|
2
|
+
* - A JSON Web Signature
|
|
3
3
|
*/
|
|
4
4
|
type jws = string;
|
|
5
5
|
/**
|
|
6
|
-
* A JSON Web Signature
|
|
6
|
+
* - A JSON Web Signature
|
|
7
7
|
*/
|
|
8
8
|
type base64string = string;
|
|
9
9
|
/**
|
|
10
|
-
* An app attestation from the app store
|
|
10
|
+
* - An app attestation from the app store
|
|
11
11
|
*/
|
|
12
12
|
type AttestationResult = {
|
|
13
13
|
platform: string;
|
|
@@ -15,7 +15,7 @@ type AttestationResult = {
|
|
|
15
15
|
keyId?: string;
|
|
16
16
|
};
|
|
17
17
|
/**
|
|
18
|
-
* Configuration to access the stores certification API
|
|
18
|
+
* - Configuration to access the stores certification API
|
|
19
19
|
*/
|
|
20
20
|
type CertificationConfig = {
|
|
21
21
|
androidSafetyNetApiKey: string;
|
package/types/queries/dsl.d.ts
CHANGED
|
@@ -70,7 +70,7 @@ export type PartialQueryDefinition = {
|
|
|
70
70
|
selector?: object;
|
|
71
71
|
};
|
|
72
72
|
export type MangoSelector = any;
|
|
73
|
-
export type
|
|
73
|
+
export type MangoPartialFilter = any;
|
|
74
74
|
import { Doctype } from "../types";
|
|
75
75
|
/**
|
|
76
76
|
* @typedef PartialQueryDefinition
|
|
@@ -83,7 +83,7 @@ import { Doctype } from "../types";
|
|
|
83
83
|
* @typedef {object} MangoSelector
|
|
84
84
|
*/
|
|
85
85
|
/**
|
|
86
|
-
* @typedef {
|
|
86
|
+
* @typedef {object} MangoPartialFilter
|
|
87
87
|
*/
|
|
88
88
|
/**
|
|
89
89
|
* Chainable API to create query definitions to retrieve documents
|
|
@@ -96,50 +96,50 @@ export class QueryDefinition {
|
|
|
96
96
|
* @class
|
|
97
97
|
*
|
|
98
98
|
* @param {object} options Initial options for the query definition
|
|
99
|
-
* @param {
|
|
100
|
-
* @param {
|
|
101
|
-
* @param {Array} [options.ids] - The ids of the docs.
|
|
102
|
-
* @param {
|
|
103
|
-
* @param {Array} [options.fields] - The fields to return.
|
|
104
|
-
* @param {Array} [options.indexedFields] - The fields to index.
|
|
105
|
-
* @param {
|
|
106
|
-
* @param {Array} [options.sort] - The sorting params.
|
|
99
|
+
* @param {Doctype} [options.doctype] - The doctype of the doc.
|
|
100
|
+
* @param {DocId|null} [options.id] - The id of the doc.
|
|
101
|
+
* @param {Array<DocId>} [options.ids] - The ids of the docs.
|
|
102
|
+
* @param {MangoSelector} [options.selector] - The selector to query the docs.
|
|
103
|
+
* @param {Array<string>} [options.fields] - The fields to return.
|
|
104
|
+
* @param {Array<string>} [options.indexedFields] - The fields to index.
|
|
105
|
+
* @param {MangoPartialFilter} [options.partialFilter] - The partial index definition to filter docs.
|
|
106
|
+
* @param {Array<object>} [options.sort] - The sorting params.
|
|
107
107
|
* @param {Array<string>} [options.includes] - The docs to include.
|
|
108
|
-
* @param {string} [options.referenced] - The referenced document.
|
|
108
|
+
* @param {string|null} [options.referenced] - The referenced document.
|
|
109
109
|
* @param {number|null} [options.limit] - The document's limit to return.
|
|
110
|
-
* @param {number} [options.skip] - The number of docs to skip.
|
|
111
|
-
* @param {
|
|
110
|
+
* @param {number|null} [options.skip] - The number of docs to skip.
|
|
111
|
+
* @param {CouchDBViewCursor} [options.cursor] - The cursor to paginate views.
|
|
112
112
|
* @param {string} [options.bookmark] - The bookmark to paginate mango queries.
|
|
113
113
|
*/
|
|
114
114
|
constructor(options?: {
|
|
115
|
-
doctype:
|
|
116
|
-
id:
|
|
117
|
-
ids:
|
|
118
|
-
selector:
|
|
119
|
-
fields:
|
|
120
|
-
indexedFields:
|
|
121
|
-
partialFilter:
|
|
122
|
-
sort:
|
|
115
|
+
doctype: Doctype;
|
|
116
|
+
id: DocId | null;
|
|
117
|
+
ids: Array<DocId>;
|
|
118
|
+
selector: MangoSelector;
|
|
119
|
+
fields: Array<string>;
|
|
120
|
+
indexedFields: Array<string>;
|
|
121
|
+
partialFilter: MangoPartialFilter;
|
|
122
|
+
sort: Array<object>;
|
|
123
123
|
includes: Array<string>;
|
|
124
|
-
referenced: string;
|
|
124
|
+
referenced: string | null;
|
|
125
125
|
limit: number | null;
|
|
126
|
-
skip: number;
|
|
127
|
-
cursor:
|
|
126
|
+
skip: number | null;
|
|
127
|
+
cursor: CouchDBViewCursor;
|
|
128
128
|
bookmark: string;
|
|
129
129
|
});
|
|
130
130
|
doctype: string;
|
|
131
131
|
id: string;
|
|
132
|
-
ids:
|
|
132
|
+
ids: string[];
|
|
133
133
|
selector: any;
|
|
134
|
-
fields:
|
|
135
|
-
indexedFields:
|
|
134
|
+
fields: string[];
|
|
135
|
+
indexedFields: string[];
|
|
136
136
|
partialFilter: any;
|
|
137
137
|
sort: any[];
|
|
138
138
|
includes: string[];
|
|
139
139
|
referenced: string;
|
|
140
140
|
limit: number;
|
|
141
141
|
skip: number;
|
|
142
|
-
cursor:
|
|
142
|
+
cursor: CouchDBViewCursor;
|
|
143
143
|
bookmark: string;
|
|
144
144
|
/**
|
|
145
145
|
* Checks if the sort order matches the index' fields order.
|
|
@@ -249,10 +249,10 @@ export class QueryDefinition {
|
|
|
249
249
|
* the starting document of the query, e.g. "file-id".
|
|
250
250
|
* Use the last docid of each query as startkey_docid to paginate or leave blank for the first query.
|
|
251
251
|
*
|
|
252
|
-
* @param {
|
|
252
|
+
* @param {CouchDBViewCursor} cursor The cursor for pagination.
|
|
253
253
|
* @returns {QueryDefinition} The QueryDefinition object.
|
|
254
254
|
*/
|
|
255
|
-
offsetCursor(cursor:
|
|
255
|
+
offsetCursor(cursor: CouchDBViewCursor): QueryDefinition;
|
|
256
256
|
/**
|
|
257
257
|
* Use [bookmark](https://docs.couchdb.org/en/2.2.0/api/database/find.html#pagination) pagination.
|
|
258
258
|
* Note this only applies for mango-queries (not views) and is way more efficient than skip pagination.
|
|
@@ -273,17 +273,17 @@ export class QueryDefinition {
|
|
|
273
273
|
toDefinition(): {
|
|
274
274
|
doctype: string;
|
|
275
275
|
id: string;
|
|
276
|
-
ids:
|
|
276
|
+
ids: string[];
|
|
277
277
|
selector: any;
|
|
278
|
-
fields:
|
|
279
|
-
indexedFields:
|
|
278
|
+
fields: string[];
|
|
279
|
+
indexedFields: string[];
|
|
280
280
|
partialFilter: any;
|
|
281
281
|
sort: any[];
|
|
282
282
|
includes: string[];
|
|
283
283
|
referenced: string;
|
|
284
284
|
limit: number;
|
|
285
285
|
skip: number;
|
|
286
|
-
cursor:
|
|
286
|
+
cursor: CouchDBViewCursor;
|
|
287
287
|
bookmark: string;
|
|
288
288
|
};
|
|
289
289
|
}
|
|
@@ -296,4 +296,6 @@ declare const REMOVE_REFERENCES_TO: "REMOVE_REFERENCES_TO";
|
|
|
296
296
|
declare const ADD_REFERENCED_BY: "ADD_REFERENCED_BY";
|
|
297
297
|
declare const REMOVE_REFERENCED_BY: "REMOVE_REFERENCED_BY";
|
|
298
298
|
declare const UPLOAD_FILE: "UPLOAD_FILE";
|
|
299
|
+
import { CouchDBViewCursor } from "../types";
|
|
300
|
+
import { DocId } from "../types";
|
|
299
301
|
export {};
|
package/types/types.d.ts
CHANGED
|
@@ -208,7 +208,7 @@ export type FolderDocument = {
|
|
|
208
208
|
/**
|
|
209
209
|
* - An io.cozy.files document
|
|
210
210
|
*/
|
|
211
|
-
export type IOCozyFolder = CozyClientDocument &
|
|
211
|
+
export type IOCozyFolder = CozyClientDocument & FolderDocument;
|
|
212
212
|
/**
|
|
213
213
|
* - An io.cozy.oauth.clients document
|
|
214
214
|
*/
|
|
@@ -299,6 +299,9 @@ export type CouchDBBulkResult = {
|
|
|
299
299
|
*/
|
|
300
300
|
reason: string | null;
|
|
301
301
|
};
|
|
302
|
+
export type ViewKey = string | string[];
|
|
303
|
+
export type DocId = string;
|
|
304
|
+
export type CouchDBViewCursor = [string | string[], string];
|
|
302
305
|
export type Theme = {
|
|
303
306
|
id: string;
|
|
304
307
|
label: string;
|