cozy-client 48.23.0 → 48.24.1
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/RealTimeQueries.js +13 -66
- package/dist/index.js +21 -0
- package/dist/store/index.js +20 -0
- package/dist/store/realtime.js +96 -0
- package/package.json +2 -2
- package/types/index.d.ts +1 -1
- package/types/store/index.d.ts +1 -0
- package/types/store/realtime.d.ts +3 -0
package/dist/CozyClient.js
CHANGED
|
@@ -2844,7 +2844,7 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2844
2844
|
CozyClient.hooks = CozyClient.hooks || {};
|
|
2845
2845
|
CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
|
|
2846
2846
|
|
|
2847
|
-
CozyClient.version = "48.
|
|
2847
|
+
CozyClient.version = "48.24.1";
|
|
2848
2848
|
|
|
2849
2849
|
_microee.default.mixin(CozyClient);
|
|
2850
2850
|
|
package/dist/RealTimeQueries.js
CHANGED
|
@@ -11,55 +11,12 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"))
|
|
|
11
11
|
|
|
12
12
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
13
|
|
|
14
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
-
|
|
16
14
|
var _react = require("react");
|
|
17
15
|
|
|
18
16
|
var _useClient = _interopRequireDefault(require("./hooks/useClient"));
|
|
19
17
|
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
var _store = require("./store");
|
|
23
|
-
|
|
24
|
-
var _CozyClient = _interopRequireDefault(require("./CozyClient"));
|
|
25
|
-
|
|
26
|
-
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; }
|
|
27
|
-
|
|
28
|
-
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; }
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Normalizes an object representing a CouchDB document
|
|
32
|
-
*
|
|
33
|
-
* Ensures existence of `_type`
|
|
34
|
-
*
|
|
35
|
-
* @public
|
|
36
|
-
* @param {import("./types").CouchDBDocument} couchDBDoc - object representing the document
|
|
37
|
-
* @returns {import("./types").CozyClientDocument} full normalized document
|
|
38
|
-
*/
|
|
39
|
-
var normalizeDoc = function normalizeDoc(couchDBDoc, doctype) {
|
|
40
|
-
return _objectSpread({
|
|
41
|
-
id: couchDBDoc._id,
|
|
42
|
-
_type: doctype
|
|
43
|
-
}, couchDBDoc);
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* DispatchChange
|
|
47
|
-
*
|
|
48
|
-
* @param {CozyClient} client CozyClient instane
|
|
49
|
-
* @param {import("./types").Doctype} doctype Doctype of the document to update
|
|
50
|
-
* @param {import("./types").CouchDBDocument} couchDBDoc Document to update
|
|
51
|
-
* @param {import("./types").Mutation} mutationDefinitionCreator Mutation to apply
|
|
52
|
-
*/
|
|
53
|
-
|
|
18
|
+
var _realtime = require("./store/realtime");
|
|
54
19
|
|
|
55
|
-
var dispatchChange = function dispatchChange(client, doctype, couchDBDoc, mutationDefinitionCreator) {
|
|
56
|
-
var data = normalizeDoc(couchDBDoc, doctype);
|
|
57
|
-
var response = {
|
|
58
|
-
data: data
|
|
59
|
-
};
|
|
60
|
-
var options = {};
|
|
61
|
-
client.dispatch((0, _store.receiveMutationResult)(client.generateRandomId(), response, options, mutationDefinitionCreator(data)));
|
|
62
|
-
};
|
|
63
20
|
/**
|
|
64
21
|
* Component that subscribes to a doctype changes and keep the
|
|
65
22
|
* internal store updated.
|
|
@@ -68,8 +25,6 @@ var dispatchChange = function dispatchChange(client, doctype, couchDBDoc, mutati
|
|
|
68
25
|
* @param {import("./types").Doctype} options.doctype - The doctype to watch
|
|
69
26
|
* @returns {null} The component does not display anything.
|
|
70
27
|
*/
|
|
71
|
-
|
|
72
|
-
|
|
73
28
|
var RealTimeQueries = function RealTimeQueries(_ref) {
|
|
74
29
|
var doctype = _ref.doctype;
|
|
75
30
|
var client = (0, _useClient.default)();
|
|
@@ -80,20 +35,6 @@ var RealTimeQueries = function RealTimeQueries(_ref) {
|
|
|
80
35
|
throw new Error('You must include the realtime plugin to use RealTimeQueries');
|
|
81
36
|
}
|
|
82
37
|
|
|
83
|
-
var dispatchCreate = function dispatchCreate(couchDBDoc) {
|
|
84
|
-
dispatchChange(client, doctype, couchDBDoc, _dsl.Mutations.createDocument);
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
var dispatchUpdate = function dispatchUpdate(couchDBDoc) {
|
|
88
|
-
dispatchChange(client, doctype, couchDBDoc, _dsl.Mutations.updateDocument);
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
var dispatchDelete = function dispatchDelete(couchDBDoc) {
|
|
92
|
-
dispatchChange(client, doctype, _objectSpread(_objectSpread({}, couchDBDoc), {}, {
|
|
93
|
-
_deleted: true
|
|
94
|
-
}), _dsl.Mutations.deleteDocument);
|
|
95
|
-
};
|
|
96
|
-
|
|
97
38
|
var subscribe = /*#__PURE__*/function () {
|
|
98
39
|
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
99
40
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
@@ -101,15 +42,21 @@ var RealTimeQueries = function RealTimeQueries(_ref) {
|
|
|
101
42
|
switch (_context.prev = _context.next) {
|
|
102
43
|
case 0:
|
|
103
44
|
_context.next = 2;
|
|
104
|
-
return realtime.subscribe('created', doctype,
|
|
45
|
+
return realtime.subscribe('created', doctype, function (data) {
|
|
46
|
+
return (0, _realtime.dispatchCreate)(client, doctype, data);
|
|
47
|
+
});
|
|
105
48
|
|
|
106
49
|
case 2:
|
|
107
50
|
_context.next = 4;
|
|
108
|
-
return realtime.subscribe('updated', doctype,
|
|
51
|
+
return realtime.subscribe('updated', doctype, function (data) {
|
|
52
|
+
return (0, _realtime.dispatchUpdate)(client, doctype, data);
|
|
53
|
+
});
|
|
109
54
|
|
|
110
55
|
case 4:
|
|
111
56
|
_context.next = 6;
|
|
112
|
-
return realtime.subscribe('deleted', doctype,
|
|
57
|
+
return realtime.subscribe('deleted', doctype, function (data) {
|
|
58
|
+
return (0, _realtime.dispatchDelete)(client, doctype, data);
|
|
59
|
+
});
|
|
113
60
|
|
|
114
61
|
case 6:
|
|
115
62
|
case "end":
|
|
@@ -126,9 +73,9 @@ var RealTimeQueries = function RealTimeQueries(_ref) {
|
|
|
126
73
|
|
|
127
74
|
subscribe();
|
|
128
75
|
return function () {
|
|
129
|
-
realtime.unsubscribe('created', doctype, dispatchCreate);
|
|
130
|
-
realtime.unsubscribe('updated', doctype, dispatchUpdate);
|
|
131
|
-
realtime.unsubscribe('deleted', doctype, dispatchDelete);
|
|
76
|
+
realtime.unsubscribe('created', doctype, _realtime.dispatchCreate);
|
|
77
|
+
realtime.unsubscribe('updated', doctype, _realtime.dispatchUpdate);
|
|
78
|
+
realtime.unsubscribe('deleted', doctype, _realtime.dispatchDelete);
|
|
132
79
|
};
|
|
133
80
|
}, [client, doctype]);
|
|
134
81
|
return null;
|
package/dist/index.js
CHANGED
|
@@ -42,6 +42,9 @@ var _exportNames = {
|
|
|
42
42
|
isQueriesLoading: true,
|
|
43
43
|
hasQueriesBeenLoaded: true,
|
|
44
44
|
getQueryFromState: true,
|
|
45
|
+
dispatchCreate: true,
|
|
46
|
+
dispatchUpdate: true,
|
|
47
|
+
dispatchDelete: true,
|
|
45
48
|
Registry: true,
|
|
46
49
|
RealTimeQueries: true,
|
|
47
50
|
manifest: true,
|
|
@@ -266,6 +269,24 @@ Object.defineProperty(exports, "getQueryFromState", {
|
|
|
266
269
|
return _store.getQueryFromState;
|
|
267
270
|
}
|
|
268
271
|
});
|
|
272
|
+
Object.defineProperty(exports, "dispatchCreate", {
|
|
273
|
+
enumerable: true,
|
|
274
|
+
get: function get() {
|
|
275
|
+
return _store.dispatchCreate;
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
Object.defineProperty(exports, "dispatchUpdate", {
|
|
279
|
+
enumerable: true,
|
|
280
|
+
get: function get() {
|
|
281
|
+
return _store.dispatchUpdate;
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
Object.defineProperty(exports, "dispatchDelete", {
|
|
285
|
+
enumerable: true,
|
|
286
|
+
get: function get() {
|
|
287
|
+
return _store.dispatchDelete;
|
|
288
|
+
}
|
|
289
|
+
});
|
|
269
290
|
Object.defineProperty(exports, "Registry", {
|
|
270
291
|
enumerable: true,
|
|
271
292
|
get: function get() {
|
package/dist/store/index.js
CHANGED
|
@@ -103,6 +103,24 @@ Object.defineProperty(exports, "isQueryExisting", {
|
|
|
103
103
|
return _stateHelpers.isQueryExisting;
|
|
104
104
|
}
|
|
105
105
|
});
|
|
106
|
+
Object.defineProperty(exports, "dispatchCreate", {
|
|
107
|
+
enumerable: true,
|
|
108
|
+
get: function get() {
|
|
109
|
+
return _realtime.dispatchCreate;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
Object.defineProperty(exports, "dispatchUpdate", {
|
|
113
|
+
enumerable: true,
|
|
114
|
+
get: function get() {
|
|
115
|
+
return _realtime.dispatchUpdate;
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
Object.defineProperty(exports, "dispatchDelete", {
|
|
119
|
+
enumerable: true,
|
|
120
|
+
get: function get() {
|
|
121
|
+
return _realtime.dispatchDelete;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
106
124
|
exports.resetState = exports.createStore = exports.default = exports.StoreProxy = void 0;
|
|
107
125
|
|
|
108
126
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
@@ -125,6 +143,8 @@ var _mutations = require("./mutations");
|
|
|
125
143
|
|
|
126
144
|
var _stateHelpers = require("./stateHelpers");
|
|
127
145
|
|
|
146
|
+
var _realtime = require("./realtime");
|
|
147
|
+
|
|
128
148
|
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; }
|
|
129
149
|
|
|
130
150
|
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; }
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.dispatchDelete = exports.dispatchUpdate = exports.dispatchCreate = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _dsl = require("../queries/dsl");
|
|
13
|
+
|
|
14
|
+
var _mutations = require("./mutations");
|
|
15
|
+
|
|
16
|
+
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; }
|
|
17
|
+
|
|
18
|
+
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; }
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Normalizes an object representing a CouchDB document
|
|
22
|
+
*
|
|
23
|
+
* Ensures existence of `_type`
|
|
24
|
+
*
|
|
25
|
+
* @public
|
|
26
|
+
* @param {import("../types").CouchDBDocument} couchDBDoc - object representing the document
|
|
27
|
+
* @returns {import("../types").CozyClientDocument} full normalized document
|
|
28
|
+
*/
|
|
29
|
+
var normalizeDoc = function normalizeDoc(couchDBDoc, doctype) {
|
|
30
|
+
return _objectSpread({
|
|
31
|
+
id: couchDBDoc._id,
|
|
32
|
+
_type: doctype
|
|
33
|
+
}, couchDBDoc);
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* DispatchChange
|
|
37
|
+
*
|
|
38
|
+
* @param {object} client CozyClient instane
|
|
39
|
+
* @param {import("../types").Doctype} doctype Doctype of the document to update
|
|
40
|
+
* @param {import("../types").CouchDBDocument} couchDBDoc Document to update
|
|
41
|
+
* @param {import("../types").Mutation} mutationDefinitionCreator Mutation to apply
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
var dispatchChange = function dispatchChange(client, doctype, couchDBDoc, mutationDefinitionCreator) {
|
|
46
|
+
var data = normalizeDoc(couchDBDoc, doctype);
|
|
47
|
+
var response = {
|
|
48
|
+
data: data
|
|
49
|
+
};
|
|
50
|
+
var options = {};
|
|
51
|
+
client.dispatch((0, _mutations.receiveMutationResult)(client.generateRandomId(), response, options, mutationDefinitionCreator(data)));
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Dispatches a create action for a document to update CozyClient store from realtime callbacks.
|
|
55
|
+
*
|
|
56
|
+
* @param {object} client - CozyClient instance
|
|
57
|
+
* @param {import("../types").Doctype} doctype - Doctype of the document to create
|
|
58
|
+
* @param {import("../types").CouchDBDocument} couchDBDoc - Document to create
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
var dispatchCreate = function dispatchCreate(client, doctype, couchDBDoc) {
|
|
63
|
+
dispatchChange(client, doctype, couchDBDoc, _dsl.Mutations.createDocument);
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Dispatches a update action for a document to update CozyClient store from realtime callbacks.
|
|
67
|
+
*
|
|
68
|
+
* @param {object} client - CozyClient instance
|
|
69
|
+
* @param {import("../types").Doctype} doctype - Doctype of the document to create
|
|
70
|
+
* @param {import("../types").CouchDBDocument} couchDBDoc - Document to create
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
exports.dispatchCreate = dispatchCreate;
|
|
75
|
+
|
|
76
|
+
var dispatchUpdate = function dispatchUpdate(client, doctype, couchDBDoc) {
|
|
77
|
+
dispatchChange(client, doctype, couchDBDoc, _dsl.Mutations.updateDocument);
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Dispatches a delete action for a document to update CozyClient store from realtime callbacks.
|
|
81
|
+
*
|
|
82
|
+
* @param {object} client - CozyClient instance
|
|
83
|
+
* @param {import("../types").Doctype} doctype - Doctype of the document to create
|
|
84
|
+
* @param {import("../types").CouchDBDocument} couchDBDoc - Document to create
|
|
85
|
+
*/
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
exports.dispatchUpdate = dispatchUpdate;
|
|
89
|
+
|
|
90
|
+
var dispatchDelete = function dispatchDelete(client, doctype, couchDBDoc) {
|
|
91
|
+
dispatchChange(client, doctype, _objectSpread(_objectSpread({}, couchDBDoc), {}, {
|
|
92
|
+
_deleted: true
|
|
93
|
+
}), _dsl.Mutations.deleteDocument);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
exports.dispatchDelete = dispatchDelete;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-client",
|
|
3
|
-
"version": "48.
|
|
3
|
+
"version": "48.24.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.node.js",
|
|
6
6
|
"browser": "dist/index.js",
|
|
@@ -75,5 +75,5 @@
|
|
|
75
75
|
"react-native-ios11-devicecheck": "https://github.com/cozy/react-native-devicecheck#app-attest-v0.1"
|
|
76
76
|
},
|
|
77
77
|
"sideEffects": false,
|
|
78
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "86377c27c1fc75c719be30ed58ea8513e49b08a2"
|
|
79
79
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ export { default } from "./CozyClient";
|
|
|
2
2
|
export { default as CozyLink } from "./CozyLink";
|
|
3
3
|
export { default as StackLink } from "./StackLink";
|
|
4
4
|
export { default as compose } from "lodash/flow";
|
|
5
|
-
export { getQueryFromState } from "./store";
|
|
6
5
|
export { default as Registry } from "./registry";
|
|
7
6
|
export { default as RealTimeQueries } from "./RealTimeQueries";
|
|
8
7
|
export { default as CozyProvider } from "./Provider";
|
|
@@ -21,4 +20,5 @@ export { Association, HasMany, HasOne, HasOneInPlace, HasManyInPlace, HasManyTri
|
|
|
21
20
|
export { isReferencedBy, isReferencedById, getReferencedBy, getReferencedById } from "./associations/helpers";
|
|
22
21
|
export { deconstructCozyWebLinkWithSlug, deconstructRedirectLink, dehydrate, generateWebLink, ensureFirstSlash, rootCozyUrl, InvalidRedirectLinkError, InvalidCozyUrlError, InvalidProtocolError, BlockedCozyError } from "./helpers";
|
|
23
22
|
export { cancelable, isQueryLoading, hasQueryBeenLoaded, isQueriesLoading, hasQueriesBeenLoaded } from "./utils";
|
|
23
|
+
export { getQueryFromState, dispatchCreate, dispatchUpdate, dispatchDelete } from "./store";
|
|
24
24
|
export { queryConnect, queryConnectFlat, withClient } from "./hoc";
|
package/types/store/index.d.ts
CHANGED
|
@@ -21,3 +21,4 @@ export function resetState(): {
|
|
|
21
21
|
export { getStateRoot, getCollectionFromState, getDocumentFromState, getQueryFromStore, getQueryFromState, getRawQueryFromState, isQueryExisting } from "./stateHelpers";
|
|
22
22
|
export { initQuery, loadQuery, resetQuery, receiveQueryResult, receiveQueryError, executeQueryFromState } from "./queries";
|
|
23
23
|
export { initMutation, receiveMutationResult, receiveMutationError } from "./mutations";
|
|
24
|
+
export { dispatchCreate, dispatchUpdate, dispatchDelete } from "./realtime";
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export function dispatchCreate(client: object, doctype: import("../types").Doctype, couchDBDoc: import("../types").CouchDBDocument): void;
|
|
2
|
+
export function dispatchUpdate(client: object, doctype: import("../types").Doctype, couchDBDoc: import("../types").CouchDBDocument): void;
|
|
3
|
+
export function dispatchDelete(client: object, doctype: import("../types").Doctype, couchDBDoc: import("../types").CouchDBDocument): void;
|