cozy-client 59.4.0 → 60.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 +180 -341
- package/dist/CozyClient.spec.js +69 -14
- package/dist/Query.spec.jsx +2 -0
- package/dist/__tests__/fixtures.js +17 -1
- package/dist/hooks/useQuery.js +3 -1
- package/dist/hooks/useQuery.spec.jsx +3 -1
- package/dist/links/StackLink.js +13 -2
- package/dist/links/StackLink.spec.js +20 -5
- package/dist/models/file.spec.js +4 -2
- package/dist/queries/dsl.js +18 -1
- package/dist/storage.js +5 -0
- package/dist/store/__snapshots__/queries.spec.js.snap +60 -0
- package/dist/store/queries.js +3 -1
- package/dist/store/selector.js +138 -0
- package/dist/store/selector.spec.js +238 -0
- package/dist/store.spec.js +3 -1
- package/dist/types.js +9 -2
- package/package.json +3 -3
- package/types/CozyClient.d.ts +15 -27
- package/types/__tests__/fixtures.d.ts +39 -17
- package/types/queries/dsl.d.ts +11 -0
- package/types/storage.d.ts +4 -0
- package/types/store/selector.d.ts +1 -0
- package/types/types.d.ts +19 -2
package/dist/store.spec.js
CHANGED
package/dist/types.js
CHANGED
|
@@ -276,16 +276,22 @@ var _dsl = require("./queries/dsl");
|
|
|
276
276
|
* @property {number} fetchedPagesCount
|
|
277
277
|
* @property {string} bookmark
|
|
278
278
|
* @property {object} [execution_stats]
|
|
279
|
+
* @property {Array<string>} relationshipNames - The relationships names, used to check hydrated documents
|
|
279
280
|
* @property {QueryOptions} [options]
|
|
280
281
|
*/
|
|
281
282
|
|
|
282
283
|
/**
|
|
283
284
|
* @typedef {object} QueryStateData
|
|
284
|
-
* @property {object|Array} data
|
|
285
|
+
* @property {object|Array} data - Collection of hydrated documents
|
|
285
286
|
*/
|
|
286
287
|
|
|
287
288
|
/**
|
|
288
|
-
* @typedef {
|
|
289
|
+
* @typedef {object} QueryStateStoreData
|
|
290
|
+
* @property {object|Array} storeData - Collection of store's documents
|
|
291
|
+
*/
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* @typedef {QueryStateWithoutData & QueryStateData & QueryStateStoreData} QueryState
|
|
289
295
|
*/
|
|
290
296
|
|
|
291
297
|
/**
|
|
@@ -458,6 +464,7 @@ var _dsl = require("./queries/dsl");
|
|
|
458
464
|
* @property {CozyMetadata} [cozyMetadata] - Cozy Metadata
|
|
459
465
|
* @property {CozyClientDocumentMeta} [meta] - Pouch Metadata
|
|
460
466
|
* @property {boolean} [cozyLocalOnly] - When true the document should NOT be replicated to the remote database
|
|
467
|
+
* @property {string} [driveId] - Id of a shared drive, only for shared io.cozy.files
|
|
461
468
|
*/
|
|
462
469
|
|
|
463
470
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-client",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "60.1.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.node.js",
|
|
6
6
|
"browser": "dist/index.js",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"@types/jest": "^26.0.20",
|
|
20
20
|
"@types/lodash": "^4.14.170",
|
|
21
21
|
"btoa": "^1.2.1",
|
|
22
|
-
"cozy-stack-client": "^
|
|
22
|
+
"cozy-stack-client": "^60.1.0",
|
|
23
23
|
"date-fns": "2.29.3",
|
|
24
24
|
"fast-deep-equal": "^3.1.3",
|
|
25
25
|
"json-stable-stringify": "^1.0.1",
|
|
@@ -74,5 +74,5 @@
|
|
|
74
74
|
"react-native-ios11-devicecheck": "^0.0.3"
|
|
75
75
|
},
|
|
76
76
|
"sideEffects": false,
|
|
77
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "78342f53c89c0c28a1559e6f0224249f4713c47b"
|
|
78
78
|
}
|
package/types/CozyClient.d.ts
CHANGED
|
@@ -40,6 +40,10 @@ export type CozyClientDocument = {
|
|
|
40
40
|
* - When true the document should NOT be replicated to the remote database
|
|
41
41
|
*/
|
|
42
42
|
cozyLocalOnly?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* - Id of a shared drive, only for shared io.cozy.files
|
|
45
|
+
*/
|
|
46
|
+
driveId?: string;
|
|
43
47
|
};
|
|
44
48
|
export type ClientOptions = {
|
|
45
49
|
client?: object;
|
|
@@ -49,6 +53,9 @@ export type ClientOptions = {
|
|
|
49
53
|
uri?: string;
|
|
50
54
|
stackClient?: object;
|
|
51
55
|
warningForCustomHandlers?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* - If set to true, all documents will be hydrated w.r.t. the provided schema's relationships, even if the relationship does not exist on the doc.
|
|
58
|
+
*/
|
|
52
59
|
autoHydrate?: boolean;
|
|
53
60
|
/**
|
|
54
61
|
* - If set to true, backgroundFetching will be enabled by default on every query. Meaning that, when the fetchStatus has already been loaded, it won't be updated during future fetches. Instead, a `isFetching` attribute will be used to indicate when background fetching is started.
|
|
@@ -96,7 +103,7 @@ export type ClientOptions = {
|
|
|
96
103
|
* @property {string} [uri]
|
|
97
104
|
* @property {object} [stackClient]
|
|
98
105
|
* @property {boolean} [warningForCustomHandlers]
|
|
99
|
-
* @property {boolean} [autoHydrate]
|
|
106
|
+
* @property {boolean} [autoHydrate] - If set to true, all documents will be hydrated w.r.t. the provided schema's relationships, even if the relationship does not exist on the doc.
|
|
100
107
|
* @property {boolean} [backgroundFetching] - If set to true, backgroundFetching will be enabled by default on every query. Meaning that, when the fetchStatus has already been loaded, it won't be updated during future fetches. Instead, a `isFetching` attribute will be used to indicate when background fetching is started.
|
|
101
108
|
* @property {object} [oauth]
|
|
102
109
|
* @property {Function} [onTokenRefresh]
|
|
@@ -108,7 +115,6 @@ export type ClientOptions = {
|
|
|
108
115
|
* @property {import("./types").ClientCapabilities} [capabilities] - Capabilities sent by the stack
|
|
109
116
|
* @property {boolean} [useCustomStore=false] - If set to true, the client will not instantiate a Redux store automatically. Use this if you want to merge cozy-client's store with your own redux store. Note will have to call `setStore` eventually. See [here](https://docs.cozy.io/en/cozy-client/react-integration/#1b-use-your-own-redux-store) for more information.
|
|
110
117
|
* @property {boolean} [disableStoreForQueries=false] - If set to true, the client will not leverage the redux store to execute queries and store data.
|
|
111
|
-
|
|
112
118
|
* @property {import('./performances/types').PerformanceAPI} [performanceApi] - The performance API that can be used to measure performances
|
|
113
119
|
*/
|
|
114
120
|
/**
|
|
@@ -210,6 +216,9 @@ declare class CozyClient {
|
|
|
210
216
|
uri?: string;
|
|
211
217
|
stackClient?: object;
|
|
212
218
|
warningForCustomHandlers?: boolean;
|
|
219
|
+
/**
|
|
220
|
+
* - If set to true, all documents will be hydrated w.r.t. the provided schema's relationships, even if the relationship does not exist on the doc.
|
|
221
|
+
*/
|
|
213
222
|
autoHydrate?: boolean;
|
|
214
223
|
/**
|
|
215
224
|
* - If set to true, backgroundFetching will be enabled by default on every query. Meaning that, when the fetchStatus has already been loaded, it won't be updated during future fetches. Instead, a `isFetching` attribute will be used to indicate when background fetching is started.
|
|
@@ -255,6 +264,7 @@ declare class CozyClient {
|
|
|
255
264
|
*/
|
|
256
265
|
storeAccesors: object;
|
|
257
266
|
useCustomStore: boolean;
|
|
267
|
+
autoHydrate: boolean;
|
|
258
268
|
disableStoreForQueries: boolean;
|
|
259
269
|
/**
|
|
260
270
|
* Gets overrided by MicroEE.mixin
|
|
@@ -355,9 +365,10 @@ declare class CozyClient {
|
|
|
355
365
|
* a [DocumentCollection]{@link https://docs.cozy.io/en/cozy-client/api/cozy-stack-client/#DocumentCollection} instance.
|
|
356
366
|
*
|
|
357
367
|
* @param {string} doctype The collection doctype.
|
|
368
|
+
* @param {object} options Options to pass to the collection
|
|
358
369
|
* @returns {import("./types").DocumentCollection} Collection corresponding to the doctype
|
|
359
370
|
*/
|
|
360
|
-
collection(doctype: string): import("./types").DocumentCollection;
|
|
371
|
+
collection(doctype: string, options?: object): import("./types").DocumentCollection;
|
|
361
372
|
fetch(method: any, path: any, body: any, options?: {}): any;
|
|
362
373
|
all(doctype: any): QueryDefinition;
|
|
363
374
|
find(doctype: any, selector?: any): QueryDefinition;
|
|
@@ -553,23 +564,6 @@ declare class CozyClient {
|
|
|
553
564
|
* @returns {Promise<import("./types").ClientResponse>}
|
|
554
565
|
*/
|
|
555
566
|
private requestQuery;
|
|
556
|
-
/**
|
|
557
|
-
* Save the document or array of documents into the persisted storage (if any)
|
|
558
|
-
*
|
|
559
|
-
* @private
|
|
560
|
-
* @param {CozyClientDocument | Array<CozyClientDocument>} data - Document or array of documents to be saved
|
|
561
|
-
* @returns {Promise<void>}
|
|
562
|
-
*/
|
|
563
|
-
private persistVirtualDocuments;
|
|
564
|
-
/**
|
|
565
|
-
* Save the document or array of documents into the persisted storage (if any)
|
|
566
|
-
*
|
|
567
|
-
* @private
|
|
568
|
-
* @param {CozyClientDocument} document - Document to be saved
|
|
569
|
-
* @param {boolean} enforce - When true, save the document even if `meta.rev` or `_rev` exist
|
|
570
|
-
* @returns {Promise<void>}
|
|
571
|
-
*/
|
|
572
|
-
private persistVirtualDocument;
|
|
573
567
|
/**
|
|
574
568
|
* Fetch relationships for a response (can be several docs).
|
|
575
569
|
* Fills the `relationships` attribute of each documents.
|
|
@@ -607,12 +601,6 @@ declare class CozyClient {
|
|
|
607
601
|
hydrateRelationships(document: any, schemaRelationships: any): {
|
|
608
602
|
[x: string]: any;
|
|
609
603
|
};
|
|
610
|
-
/**
|
|
611
|
-
* Creates (locally) a new document for the given doctype.
|
|
612
|
-
* This document is hydrated : its relationships are there
|
|
613
|
-
* and working.
|
|
614
|
-
*/
|
|
615
|
-
makeNewDocument(doctype: any): any;
|
|
616
604
|
generateRandomId(): string;
|
|
617
605
|
/**
|
|
618
606
|
* Creates an association that is linked to the store.
|
|
@@ -662,7 +650,7 @@ declare class CozyClient {
|
|
|
662
650
|
*
|
|
663
651
|
* @param {string} id - Id of the query (set via Query.props.as)
|
|
664
652
|
* @param {object} options - Options
|
|
665
|
-
* @param {boolean} [options.hydrated] - Whether documents should be returned already hydrated
|
|
653
|
+
* @param {boolean} [options.hydrated] - Whether documents should be returned already hydrated
|
|
666
654
|
* @param {object} [options.singleDocData] - If true, the "data" returned will be
|
|
667
655
|
* a single doc instead of an array for single doc queries. Defaults to false for backward
|
|
668
656
|
* compatibility but will be set to true in the future.
|
|
@@ -94,7 +94,7 @@ export namespace TODO_WITH_AUTHOR {
|
|
|
94
94
|
}
|
|
95
95
|
export { relationships_1 as relationships };
|
|
96
96
|
}
|
|
97
|
-
export namespace
|
|
97
|
+
export namespace TODO_WITH_NONEXISTING_RELATIONSHIP {
|
|
98
98
|
const _id_6: number;
|
|
99
99
|
export { _id_6 as _id };
|
|
100
100
|
const _rev_6: string;
|
|
@@ -103,9 +103,20 @@ export namespace FILE_1 {
|
|
|
103
103
|
export { _type_6 as _type };
|
|
104
104
|
const label_6: string;
|
|
105
105
|
export { label_6 as label };
|
|
106
|
-
export
|
|
106
|
+
export namespace relationships_2 {
|
|
107
|
+
namespace broken {
|
|
108
|
+
const doctype_2: string;
|
|
109
|
+
export { doctype_2 as doctype };
|
|
110
|
+
const data_1: {
|
|
111
|
+
_type: string;
|
|
112
|
+
_id: number;
|
|
113
|
+
}[];
|
|
114
|
+
export { data_1 as data };
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
export { relationships_2 as relationships };
|
|
107
118
|
}
|
|
108
|
-
export namespace
|
|
119
|
+
export namespace FILE_1 {
|
|
109
120
|
const _id_7: number;
|
|
110
121
|
export { _id_7 as _id };
|
|
111
122
|
const _rev_7: string;
|
|
@@ -114,6 +125,17 @@ export namespace FILE_2 {
|
|
|
114
125
|
export { _type_7 as _type };
|
|
115
126
|
const label_7: string;
|
|
116
127
|
export { label_7 as label };
|
|
128
|
+
export const name: string;
|
|
129
|
+
}
|
|
130
|
+
export namespace FILE_2 {
|
|
131
|
+
const _id_8: number;
|
|
132
|
+
export { _id_8 as _id };
|
|
133
|
+
const _rev_8: string;
|
|
134
|
+
export { _rev_8 as _rev };
|
|
135
|
+
const _type_8: string;
|
|
136
|
+
export { _type_8 as _type };
|
|
137
|
+
const label_8: string;
|
|
138
|
+
export { label_8 as label };
|
|
117
139
|
}
|
|
118
140
|
export const APP_NAME: "cozy-client-test";
|
|
119
141
|
export const APP_VERSION: 2;
|
|
@@ -122,38 +144,38 @@ export const SOURCE_ACCOUNT_ID: "123-456-abc";
|
|
|
122
144
|
export const SOURCE_ACCOUNT_IDENTIFIER: "testSourceAccountIdentifier";
|
|
123
145
|
export namespace SCHEMA {
|
|
124
146
|
export namespace todos {
|
|
125
|
-
const
|
|
126
|
-
export {
|
|
147
|
+
const doctype_3: string;
|
|
148
|
+
export { doctype_3 as doctype };
|
|
127
149
|
export { DOCTYPE_VERSION as doctypeVersion };
|
|
128
|
-
export namespace
|
|
150
|
+
export namespace relationships_3 {
|
|
129
151
|
export namespace attachments_1 {
|
|
130
152
|
export const type: string;
|
|
131
|
-
const
|
|
132
|
-
export {
|
|
153
|
+
const doctype_4: string;
|
|
154
|
+
export { doctype_4 as doctype };
|
|
133
155
|
}
|
|
134
156
|
export { attachments_1 as attachments };
|
|
135
157
|
export namespace authors_1 {
|
|
136
158
|
const type_1: string;
|
|
137
159
|
export { type_1 as type };
|
|
138
|
-
const
|
|
139
|
-
export {
|
|
160
|
+
const doctype_5: string;
|
|
161
|
+
export { doctype_5 as doctype };
|
|
140
162
|
}
|
|
141
163
|
export { authors_1 as authors };
|
|
142
164
|
}
|
|
143
|
-
export {
|
|
165
|
+
export { relationships_3 as relationships };
|
|
144
166
|
}
|
|
145
167
|
export namespace files_1 {
|
|
146
|
-
const
|
|
147
|
-
export {
|
|
148
|
-
export namespace
|
|
168
|
+
const doctype_6: string;
|
|
169
|
+
export { doctype_6 as doctype };
|
|
170
|
+
export namespace relationships_4 {
|
|
149
171
|
namespace icons {
|
|
150
172
|
const type_2: string;
|
|
151
173
|
export { type_2 as type };
|
|
152
|
-
const
|
|
153
|
-
export {
|
|
174
|
+
const doctype_7: string;
|
|
175
|
+
export { doctype_7 as doctype };
|
|
154
176
|
}
|
|
155
177
|
}
|
|
156
|
-
export {
|
|
178
|
+
export { relationships_4 as relationships };
|
|
157
179
|
}
|
|
158
180
|
export { files_1 as files };
|
|
159
181
|
}
|
package/types/queries/dsl.d.ts
CHANGED
|
@@ -125,6 +125,7 @@ export class QueryDefinition {
|
|
|
125
125
|
* @param {number|null} [options.skip] - The number of docs to skip.
|
|
126
126
|
* @param {import('../types').CouchDBViewCursor} [options.cursor] - The cursor to paginate views.
|
|
127
127
|
* @param {string} [options.bookmark] - The bookmark to paginate mango queries.
|
|
128
|
+
* @param {string} [options.sharingId] - The id of the sharing
|
|
128
129
|
*/
|
|
129
130
|
constructor(options?: {
|
|
130
131
|
doctype: import('../types').Doctype;
|
|
@@ -141,6 +142,7 @@ export class QueryDefinition {
|
|
|
141
142
|
skip: number | null;
|
|
142
143
|
cursor: import('../types').CouchDBViewCursor;
|
|
143
144
|
bookmark: string;
|
|
145
|
+
sharingId: string;
|
|
144
146
|
});
|
|
145
147
|
doctype: string;
|
|
146
148
|
id: string;
|
|
@@ -156,6 +158,7 @@ export class QueryDefinition {
|
|
|
156
158
|
skip: number;
|
|
157
159
|
cursor: import("../types").CouchDBViewCursor;
|
|
158
160
|
bookmark: string;
|
|
161
|
+
sharingId: string;
|
|
159
162
|
/**
|
|
160
163
|
* Checks if the sort order matches the index' fields order.
|
|
161
164
|
*
|
|
@@ -291,6 +294,13 @@ export class QueryDefinition {
|
|
|
291
294
|
* @returns {QueryDefinition} The QueryDefinition object.
|
|
292
295
|
*/
|
|
293
296
|
referencedBy(document: object): QueryDefinition;
|
|
297
|
+
/**
|
|
298
|
+
* Use a sharingId to query documents coming from a sharing
|
|
299
|
+
*
|
|
300
|
+
* @param {string} id - The sharing doc id
|
|
301
|
+
* @returns {QueryDefinition} The QueryDefinition object.
|
|
302
|
+
*/
|
|
303
|
+
sharingById(id: string): QueryDefinition;
|
|
294
304
|
toDefinition(): {
|
|
295
305
|
doctype: string;
|
|
296
306
|
id: string;
|
|
@@ -306,6 +316,7 @@ export class QueryDefinition {
|
|
|
306
316
|
skip: number;
|
|
307
317
|
cursor: import("../types").CouchDBViewCursor;
|
|
308
318
|
bookmark: string;
|
|
319
|
+
sharingId: string;
|
|
309
320
|
};
|
|
310
321
|
}
|
|
311
322
|
declare const CREATE_DOCUMENT: "CREATE_DOCUMENT";
|
package/types/storage.d.ts
CHANGED
|
@@ -43,6 +43,10 @@ export type CozyClientDocument = {
|
|
|
43
43
|
* - When true the document should NOT be replicated to the remote database
|
|
44
44
|
*/
|
|
45
45
|
cozyLocalOnly?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* - Id of a shared drive, only for shared io.cozy.files
|
|
48
|
+
*/
|
|
49
|
+
driveId?: string;
|
|
46
50
|
};
|
|
47
51
|
import CozyClient from "./CozyClient";
|
|
48
52
|
import { QueryDefinition } from "./queries/dsl";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function equalityCheckForQuery(queryResA: import("../types").QueryState, queryResB: import("../types").QueryState): boolean;
|
package/types/types.d.ts
CHANGED
|
@@ -503,12 +503,25 @@ export type QueryStateWithoutData = {
|
|
|
503
503
|
fetchedPagesCount: number;
|
|
504
504
|
bookmark: string;
|
|
505
505
|
execution_stats?: object;
|
|
506
|
+
/**
|
|
507
|
+
* - The relationships names, used to check hydrated documents
|
|
508
|
+
*/
|
|
509
|
+
relationshipNames: Array<string>;
|
|
506
510
|
options?: QueryOptions;
|
|
507
511
|
};
|
|
508
512
|
export type QueryStateData = {
|
|
513
|
+
/**
|
|
514
|
+
* - Collection of hydrated documents
|
|
515
|
+
*/
|
|
509
516
|
data: object | any[];
|
|
510
517
|
};
|
|
511
|
-
export type
|
|
518
|
+
export type QueryStateStoreData = {
|
|
519
|
+
/**
|
|
520
|
+
* - Collection of store's documents
|
|
521
|
+
*/
|
|
522
|
+
storeData: object | any[];
|
|
523
|
+
};
|
|
524
|
+
export type QueryState = QueryStateWithoutData & QueryStateData & QueryStateStoreData;
|
|
512
525
|
export type AutoUpdateOptions = any;
|
|
513
526
|
export type QueryOptions = {
|
|
514
527
|
/**
|
|
@@ -568,7 +581,7 @@ export type FetchMoreAble = {
|
|
|
568
581
|
export type FetchAble = {
|
|
569
582
|
fetch: Function;
|
|
570
583
|
};
|
|
571
|
-
export type UseQueryReturnValue = QueryStateWithoutData & QueryStateData & FetchMoreAble & FetchAble;
|
|
584
|
+
export type UseQueryReturnValue = QueryStateWithoutData & QueryStateData & QueryStateStoreData & FetchMoreAble & FetchAble;
|
|
572
585
|
export type UseMutationWithoutMutate = {
|
|
573
586
|
/**
|
|
574
587
|
* - Status of the current mutation
|
|
@@ -802,6 +815,10 @@ export type CozyClientDocument = {
|
|
|
802
815
|
* - When true the document should NOT be replicated to the remote database
|
|
803
816
|
*/
|
|
804
817
|
cozyLocalOnly?: boolean;
|
|
818
|
+
/**
|
|
819
|
+
* - Id of a shared drive, only for shared io.cozy.files
|
|
820
|
+
*/
|
|
821
|
+
driveId?: string;
|
|
805
822
|
};
|
|
806
823
|
/**
|
|
807
824
|
* - A io.cozy.files document's metadata
|