cozy-client 57.0.0 → 57.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CozyClient.js +1 -1
- package/dist/associations/HasManyFiles.js +2 -1
- package/dist/store/documents.js +47 -2
- package/dist/store/queries.js +14 -5
- package/dist/store/queries.spec.js +7 -0
- package/dist/store/stateHelpers.js +7 -1
- package/package.json +2 -2
- package/types/store/documents.d.ts +2 -1
- package/types/store/stateHelpers.d.ts +2 -1
package/dist/CozyClient.js
CHANGED
|
@@ -3097,7 +3097,7 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
3097
3097
|
CozyClient.hooks = CozyClient.hooks || {};
|
|
3098
3098
|
CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
|
|
3099
3099
|
|
|
3100
|
-
CozyClient.version = "57.
|
|
3100
|
+
CozyClient.version = "57.1.0";
|
|
3101
3101
|
|
|
3102
3102
|
_microee.default.mixin(CozyClient);
|
|
3103
3103
|
|
|
@@ -128,7 +128,8 @@ var HasManyFiles = /*#__PURE__*/function (_HasMany) {
|
|
|
128
128
|
while (1) {
|
|
129
129
|
switch (_context.prev = _context.next) {
|
|
130
130
|
case 0:
|
|
131
|
-
lastRelDoc = (0, _store.getDocumentFromState)(getState(), lastRelationship._type, lastRelationship._id);
|
|
131
|
+
lastRelDoc = (0, _store.getDocumentFromState)(getState(), lastRelationship._type, lastRelationship._id); // @ts-ignore
|
|
132
|
+
|
|
132
133
|
lastDatetime = getFileDatetime(lastRelDoc); // cursor-based pagination
|
|
133
134
|
|
|
134
135
|
cursor = newCursor([_this.target._type, _this.target._id, lastDatetime], relationships[relationships.length - 1]._id);
|
package/dist/store/documents.js
CHANGED
|
@@ -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.extractAndMergeDocument = exports.getCollectionFromSlice = exports.getDocumentFromSlice = exports.default = exports.mergeDocumentsWithRelationships = void 0;
|
|
8
|
+
exports.extractAndMergeDocument = exports.getCollectionFromSlice = exports.getDocumentsFromSlice = exports.getDocumentFromSlice = exports.default = exports.mergeDocumentsWithRelationships = void 0;
|
|
9
9
|
|
|
10
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
11
|
|
|
@@ -104,7 +104,15 @@ var documents = function documents() {
|
|
|
104
104
|
return extractAndMergeDocument(data, updatedStateWithIncluded);
|
|
105
105
|
};
|
|
106
106
|
|
|
107
|
-
var _default = documents;
|
|
107
|
+
var _default = documents;
|
|
108
|
+
/**
|
|
109
|
+
* Get document from state, by its id
|
|
110
|
+
*
|
|
111
|
+
* @param {import('../types').DocumentsStateSlice} state The documents' slice
|
|
112
|
+
* @param {string} doctype The doctype to target
|
|
113
|
+
* @param {string} id The document id to get
|
|
114
|
+
* @returns {import('../types').CozyClientDocument} the document found by its id
|
|
115
|
+
*/
|
|
108
116
|
|
|
109
117
|
exports.default = _default;
|
|
110
118
|
|
|
@@ -137,9 +145,46 @@ var getDocumentFromSlice = function getDocumentFromSlice() {
|
|
|
137
145
|
|
|
138
146
|
return state[doctype][id];
|
|
139
147
|
};
|
|
148
|
+
/**
|
|
149
|
+
* Get documents from state, by their ids
|
|
150
|
+
*
|
|
151
|
+
* @param {import('../types').DocumentsStateSlice} state The documents' slice
|
|
152
|
+
* @param {string} doctype The doctype to target
|
|
153
|
+
* @param {Array<string>} ids The list of document ids to get
|
|
154
|
+
* @returns {Array<import('../types').CozyClientDocument>} the list of documents found by their ids
|
|
155
|
+
*/
|
|
156
|
+
|
|
140
157
|
|
|
141
158
|
exports.getDocumentFromSlice = getDocumentFromSlice;
|
|
142
159
|
|
|
160
|
+
var getDocumentsFromSlice = function getDocumentsFromSlice() {
|
|
161
|
+
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
162
|
+
var doctype = arguments.length > 1 ? arguments[1] : undefined;
|
|
163
|
+
var ids = arguments.length > 2 ? arguments[2] : undefined;
|
|
164
|
+
|
|
165
|
+
if (!doctype) {
|
|
166
|
+
throw new Error('getDocumentsFromSlice: Cannot retrieve documents with undefined doctype');
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (!ids || ids.length < 1) {
|
|
170
|
+
throw new Error('getDocumentsFromSlice: Cannot retrieve documents with undefined ids');
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (!state[doctype]) {
|
|
174
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
175
|
+
_logger.default.info("getDocumentsFromSlice: ".concat(doctype, " is absent from the store's documents. State is"), state);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return [];
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return ids.map(function (id) {
|
|
182
|
+
return state[doctype][id];
|
|
183
|
+
}).filter(Boolean);
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
exports.getDocumentsFromSlice = getDocumentsFromSlice;
|
|
187
|
+
|
|
143
188
|
var getCollectionFromSlice = function getCollectionFromSlice() {
|
|
144
189
|
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
145
190
|
var doctype = arguments.length > 1 ? arguments[1] : undefined;
|
package/dist/store/queries.js
CHANGED
|
@@ -391,20 +391,29 @@ var getSelectorFilterFn = function getSelectorFilterFn(queryDefinition) {
|
|
|
391
391
|
|
|
392
392
|
|
|
393
393
|
var executeQueryFromState = function executeQueryFromState(state, queryDefinition) {
|
|
394
|
-
var documents = (0, _stateHelpers.getCollectionFromState)(state, queryDefinition.doctype);
|
|
395
394
|
var isSingleObjectResponse = !!queryDefinition.id;
|
|
395
|
+
var res; // XXX - For getById and getByIds queries, do not iterate over all collection, but rather
|
|
396
|
+
// directly access the document from state, making it O(1) rather than O(n)
|
|
396
397
|
|
|
397
|
-
if (
|
|
398
|
+
if (queryDefinition.id) {
|
|
399
|
+
var doc = (0, _stateHelpers.getDocumentFromState)(state, queryDefinition.doctype, queryDefinition.id);
|
|
400
|
+
res = doc ? [doc] : [];
|
|
401
|
+
} else if (queryDefinition.ids) {
|
|
402
|
+
res = (0, _stateHelpers.getDocumentsFromState)(state, queryDefinition.doctype, queryDefinition.ids);
|
|
403
|
+
} else {
|
|
404
|
+
var documents = (0, _stateHelpers.getCollectionFromState)(state, queryDefinition.doctype);
|
|
405
|
+
res = documents === null || documents === void 0 ? void 0 : documents.filter(makeFilterDocumentFn(queryDefinition));
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
if (!res || res.length < 1) {
|
|
398
409
|
return {
|
|
399
410
|
data: isSingleObjectResponse ? null : []
|
|
400
411
|
};
|
|
401
412
|
}
|
|
402
413
|
|
|
403
|
-
var res = documents.filter(makeFilterDocumentFn(queryDefinition));
|
|
404
|
-
|
|
405
414
|
if (isSingleObjectResponse) {
|
|
406
415
|
return {
|
|
407
|
-
data: res
|
|
416
|
+
data: res[0]
|
|
408
417
|
};
|
|
409
418
|
}
|
|
410
419
|
|
|
@@ -779,6 +779,13 @@ describe('execute query from state', () => {
|
|
|
779
779
|
}
|
|
780
780
|
const res3 = executeQueryFromState(state, query3)
|
|
781
781
|
expect(res3.data).toEqual(null)
|
|
782
|
+
|
|
783
|
+
const query4 = {
|
|
784
|
+
doctype: 'io.cozy.files',
|
|
785
|
+
ids: ['-1', '123']
|
|
786
|
+
}
|
|
787
|
+
const res4 = executeQueryFromState(state, query4)
|
|
788
|
+
expect(res4.data[0]).toEqual(docState['io.cozy.files']['123'])
|
|
782
789
|
})
|
|
783
790
|
|
|
784
791
|
it('should get all the docs from state for the doctype when no filter', () => {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.isQueryExisting = exports.getRawQueryFromState = exports.getQueryFromState = exports.getQueryFromStore = exports.getDocumentFromState = exports.getCollectionFromState = exports.getStateRoot = void 0;
|
|
6
|
+
exports.isQueryExisting = exports.getRawQueryFromState = exports.getQueryFromState = exports.getQueryFromStore = exports.getDocumentsFromState = exports.getDocumentFromState = exports.getCollectionFromState = exports.getStateRoot = void 0;
|
|
7
7
|
|
|
8
8
|
var _documents = require("./documents");
|
|
9
9
|
|
|
@@ -27,6 +27,12 @@ var getDocumentFromState = function getDocumentFromState(state, doctype, id) {
|
|
|
27
27
|
|
|
28
28
|
exports.getDocumentFromState = getDocumentFromState;
|
|
29
29
|
|
|
30
|
+
var getDocumentsFromState = function getDocumentsFromState(state, doctype, ids) {
|
|
31
|
+
return (0, _documents.getDocumentsFromSlice)(getStateRoot(state).documents, doctype, ids);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
exports.getDocumentsFromState = getDocumentsFromState;
|
|
35
|
+
|
|
30
36
|
var getQueryFromStore = function getQueryFromStore(store, queryId) {
|
|
31
37
|
return getQueryFromState(store.getState(), queryId);
|
|
32
38
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-client",
|
|
3
|
-
"version": "57.
|
|
3
|
+
"version": "57.1.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.node.js",
|
|
6
6
|
"browser": "dist/index.js",
|
|
@@ -72,5 +72,5 @@
|
|
|
72
72
|
"react-native-ios11-devicecheck": "https://github.com/cozy/react-native-devicecheck#app-attest-v0.1"
|
|
73
73
|
},
|
|
74
74
|
"sideEffects": false,
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "436dadf9bf4e26390d28677ab4ab07e1fc58ff28"
|
|
76
76
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export function mergeDocumentsWithRelationships(prevDocument?: {}, nextDocument?: {}): import("../types").CozyClientDocument;
|
|
2
2
|
export default documents;
|
|
3
|
-
export function getDocumentFromSlice(state:
|
|
3
|
+
export function getDocumentFromSlice(state: import('../types').DocumentsStateSlice, doctype: string, id: string): import('../types').CozyClientDocument;
|
|
4
|
+
export function getDocumentsFromSlice(state: import('../types').DocumentsStateSlice, doctype: string, ids: Array<string>): Array<import('../types').CozyClientDocument>;
|
|
4
5
|
export function getCollectionFromSlice(state: {}, doctype: any): any[];
|
|
5
6
|
export function extractAndMergeDocument(data: any, updatedStateWithIncluded: any): any;
|
|
6
7
|
declare function documents(state: {}, action: any): any;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export function getStateRoot(state: any): any;
|
|
2
2
|
export function getCollectionFromState(state: any, doctype: any): any[];
|
|
3
|
-
export function getDocumentFromState(state: any, doctype: any, id: any):
|
|
3
|
+
export function getDocumentFromState(state: any, doctype: any, id: any): import("../types").CozyClientDocument;
|
|
4
|
+
export function getDocumentsFromState(state: any, doctype: any, ids: any): import("../types").CozyClientDocument[];
|
|
4
5
|
export function getQueryFromStore(store: any, queryId: any): any;
|
|
5
6
|
export function getQueryFromState(state: any, queryId: any): any;
|
|
6
7
|
export function getRawQueryFromState(state: any, queryId: any): any;
|