cozy-pouch-link 58.1.0 → 58.3.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/CozyPouchLink.js +31 -14
- package/dist/db/pouchdb/getDocs.js +27 -4
- package/dist/errors.js +9 -2
- package/dist/files.js +51 -1
- package/dist/jsonapi.js +167 -7
- package/package.json +3 -3
- package/types/CozyPouchLink.d.ts +5 -0
- package/types/errors.d.ts +1 -0
- package/types/files.d.ts +3 -0
- package/types/jsonapi.d.ts +3 -0
package/dist/CozyPouchLink.js
CHANGED
|
@@ -121,6 +121,7 @@ var doNothing = function doNothing(operation) {
|
|
|
121
121
|
* @property {number} [syncDebounceMaxDelayInMs] The maximum duration (in ms) the `startReplicationWithDebounce()` method can be delayed. Should be used only when periodicSync is false. Default is 10 minutes
|
|
122
122
|
* @property {number} [replicationInterval] Milliseconds between periodic replications
|
|
123
123
|
* @property {string[]} doctypes Doctypes to replicate
|
|
124
|
+
* @property {boolean} isReadOnly Whether or not the link is read-only and should forward any write operation
|
|
124
125
|
* @property {Record<string, object>} doctypesReplicationOptions A mapping from doctypes to replication options. All pouch replication options can be used, as well as the "strategy" option that determines which way the replication is done (can be "sync", "fromRemote" or "toRemote")
|
|
125
126
|
* @property {import('./types').LinkPlatform} platform Platform specific adapters and methods
|
|
126
127
|
* @property {import('cozy-client/src/performances/types').PerformanceAPI} [performanceApi] - The performance API that can be used to measure performances
|
|
@@ -719,6 +720,10 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
719
720
|
}, {
|
|
720
721
|
key: "supportsOperation",
|
|
721
722
|
value: function supportsOperation(operation) {
|
|
723
|
+
if (this.options.readOnly && operation.mutationType) {
|
|
724
|
+
return false;
|
|
725
|
+
}
|
|
726
|
+
|
|
722
727
|
var impactedDoctype = (0, _cozyClient.getDoctypeFromOperation)(operation); // If the Pouch is configured only to replicate from the remote,
|
|
723
728
|
// we don't want to apply the mutation on it, but to forward
|
|
724
729
|
// to the next link
|
|
@@ -768,6 +773,7 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
768
773
|
break;
|
|
769
774
|
}
|
|
770
775
|
|
|
776
|
+
// The doctype is not locally synced and thus cannot be requested: forward to next link
|
|
771
777
|
if (process.env.NODE_ENV !== 'production') {
|
|
772
778
|
_logger.default.info("Tried to access local ".concat(doctype, " but Cozy Pouch is not synced yet. Forwarding the operation to next link"));
|
|
773
779
|
}
|
|
@@ -945,41 +951,52 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
945
951
|
_context9.prev = 3;
|
|
946
952
|
sanitizedDoc.cozyLocalOnly = true;
|
|
947
953
|
engine = this.getQueryEngineFromDoctype(doc._type);
|
|
954
|
+
|
|
955
|
+
if (engine.db) {
|
|
956
|
+
_context9.next = 9;
|
|
957
|
+
break;
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
_logger.default.warn("".concat(doc._id, " is not persisted: no database found for doctype: ").concat(doc._type));
|
|
961
|
+
|
|
962
|
+
return _context9.abrupt("return", null);
|
|
963
|
+
|
|
964
|
+
case 9:
|
|
948
965
|
pouch = this.getPouch(doc._type);
|
|
949
|
-
_context9.next =
|
|
966
|
+
_context9.next = 12;
|
|
950
967
|
return (0, _helpers2.getExistingDocument)(engine, sanitizedDoc._id);
|
|
951
968
|
|
|
952
|
-
case
|
|
969
|
+
case 12:
|
|
953
970
|
resp = _context9.sent;
|
|
954
971
|
|
|
955
972
|
if (!(!(resp !== null && resp !== void 0 && resp.data) || Object.keys(resp === null || resp === void 0 ? void 0 : resp.data).length < 1)) {
|
|
956
|
-
_context9.next =
|
|
973
|
+
_context9.next = 15;
|
|
957
974
|
break;
|
|
958
975
|
}
|
|
959
976
|
|
|
960
977
|
return _context9.abrupt("return", pouch.put(sanitizedDoc));
|
|
961
978
|
|
|
962
|
-
case
|
|
979
|
+
case 15:
|
|
963
980
|
oldDoc = (0, jsonapi.sanitizeJsonApi)(resp.data);
|
|
964
981
|
|
|
965
982
|
if (!(0, _helpers2.areDocsEqual)(oldDoc, sanitizedDoc)) {
|
|
966
|
-
_context9.next =
|
|
983
|
+
_context9.next = 18;
|
|
967
984
|
break;
|
|
968
985
|
}
|
|
969
986
|
|
|
970
987
|
return _context9.abrupt("return");
|
|
971
988
|
|
|
972
|
-
case
|
|
989
|
+
case 18:
|
|
973
990
|
sanitizedDoc._rev = oldDoc._rev;
|
|
974
|
-
_context9.next =
|
|
991
|
+
_context9.next = 21;
|
|
975
992
|
return pouch.put(sanitizedDoc);
|
|
976
993
|
|
|
977
|
-
case
|
|
978
|
-
_context9.next =
|
|
994
|
+
case 21:
|
|
995
|
+
_context9.next = 27;
|
|
979
996
|
break;
|
|
980
997
|
|
|
981
|
-
case
|
|
982
|
-
_context9.prev =
|
|
998
|
+
case 23:
|
|
999
|
+
_context9.prev = 23;
|
|
983
1000
|
_context9.t0 = _context9["catch"](3);
|
|
984
1001
|
|
|
985
1002
|
_logger.default.error("PersistCozyData failed: with ".concat(_context9.t0)); // Do nothing on catch, to avoid throwing a read query
|
|
@@ -987,18 +1004,18 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
987
1004
|
|
|
988
1005
|
return _context9.abrupt("return", null);
|
|
989
1006
|
|
|
990
|
-
case
|
|
1007
|
+
case 27:
|
|
991
1008
|
this.performanceApi.measure({
|
|
992
1009
|
markName: markName,
|
|
993
1010
|
category: 'CozyPouchLink'
|
|
994
1011
|
});
|
|
995
1012
|
|
|
996
|
-
case
|
|
1013
|
+
case 28:
|
|
997
1014
|
case "end":
|
|
998
1015
|
return _context9.stop();
|
|
999
1016
|
}
|
|
1000
1017
|
}
|
|
1001
|
-
}, _callee9, this, [[3,
|
|
1018
|
+
}, _callee9, this, [[3, 23]]);
|
|
1002
1019
|
}));
|
|
1003
1020
|
|
|
1004
1021
|
function persistCozyData(_x9) {
|
|
@@ -15,6 +15,8 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"))
|
|
|
15
15
|
|
|
16
16
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
17
17
|
|
|
18
|
+
var _errors = require("../../errors");
|
|
19
|
+
|
|
18
20
|
var _helpers = _interopRequireDefault(require("../../helpers"));
|
|
19
21
|
|
|
20
22
|
var _jsonapi = require("../../jsonapi");
|
|
@@ -35,11 +37,32 @@ var getDocsAndNormalize = /*#__PURE__*/function () {
|
|
|
35
37
|
switch (_context.prev = _context.next) {
|
|
36
38
|
case 0:
|
|
37
39
|
client = _ref.client, doctype = _ref.doctype, db = _ref.db, queryFunc = _ref.queryFunc, _ref$queryParams = _ref.queryParams, queryParams = _ref$queryParams === void 0 ? {} : _ref$queryParams, _ref$withRows = _ref.withRows, withRows = _ref$withRows === void 0 ? true : _ref$withRows;
|
|
38
|
-
_context.
|
|
40
|
+
_context.prev = 1;
|
|
41
|
+
_context.next = 4;
|
|
39
42
|
return getDocs(db, queryFunc, queryParams);
|
|
40
43
|
|
|
41
|
-
case
|
|
44
|
+
case 4:
|
|
42
45
|
results = _context.sent;
|
|
46
|
+
_context.next = 14;
|
|
47
|
+
break;
|
|
48
|
+
|
|
49
|
+
case 7:
|
|
50
|
+
_context.prev = 7;
|
|
51
|
+
_context.t0 = _context["catch"](1);
|
|
52
|
+
|
|
53
|
+
if (!(0, _errors.isDocumentNotFoundPouchDBError)(_context.t0)) {
|
|
54
|
+
_context.next = 13;
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
results = [];
|
|
59
|
+
_context.next = 14;
|
|
60
|
+
break;
|
|
61
|
+
|
|
62
|
+
case 13:
|
|
63
|
+
throw _context.t0;
|
|
64
|
+
|
|
65
|
+
case 14:
|
|
43
66
|
jsonResult = (0, _jsonapi.fromPouchResult)({
|
|
44
67
|
res: results,
|
|
45
68
|
withRows: withRows,
|
|
@@ -48,12 +71,12 @@ var getDocsAndNormalize = /*#__PURE__*/function () {
|
|
|
48
71
|
});
|
|
49
72
|
return _context.abrupt("return", jsonResult);
|
|
50
73
|
|
|
51
|
-
case
|
|
74
|
+
case 16:
|
|
52
75
|
case "end":
|
|
53
76
|
return _context.stop();
|
|
54
77
|
}
|
|
55
78
|
}
|
|
56
|
-
}, _callee);
|
|
79
|
+
}, _callee, null, [[1, 7]]);
|
|
57
80
|
}));
|
|
58
81
|
|
|
59
82
|
return function getDocsAndNormalize(_x) {
|
package/dist/errors.js
CHANGED
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.isMissingPouchDBIndexError = exports.isMissingSQLiteIndexError = exports.isExpiredTokenError = void 0;
|
|
6
|
+
exports.isDocumentNotFoundPouchDBError = exports.isMissingPouchDBIndexError = exports.isMissingSQLiteIndexError = exports.isExpiredTokenError = void 0;
|
|
7
7
|
var EXPIRED_TOKEN_ERROR = /Expired token/;
|
|
8
8
|
var INVALID_TOKEN_ERROR = /Invalid JWT token/;
|
|
9
9
|
var INVALID_TOKEN_ALT_ERROR = /Invalid token/;
|
|
10
10
|
var SQLITE_MISSING_INDEX_ERROR = /no such index/;
|
|
11
11
|
var POUCHDB_MISSING_INDEX_ERROR = /Could not find that index/;
|
|
12
12
|
var POUCHDB_MISSING_INDEX_ERROR_ALT = /no index/;
|
|
13
|
+
var POUCHDB_NOT_FOUND_ERROR = /not_found/;
|
|
13
14
|
|
|
14
15
|
var expiredTokenError = function expiredTokenError(error) {
|
|
15
16
|
var errorMsg = error.message;
|
|
@@ -41,4 +42,10 @@ var isMissingPouchDBIndexError = function isMissingPouchDBIndexError(error) {
|
|
|
41
42
|
return POUCHDB_MISSING_INDEX_ERROR.test(error.message) || POUCHDB_MISSING_INDEX_ERROR_ALT.test(error.message);
|
|
42
43
|
};
|
|
43
44
|
|
|
44
|
-
exports.isMissingPouchDBIndexError = isMissingPouchDBIndexError;
|
|
45
|
+
exports.isMissingPouchDBIndexError = isMissingPouchDBIndexError;
|
|
46
|
+
|
|
47
|
+
var isDocumentNotFoundPouchDBError = function isDocumentNotFoundPouchDBError(error) {
|
|
48
|
+
return POUCHDB_NOT_FOUND_ERROR.test(error.name);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
exports.isDocumentNotFoundPouchDBError = isDocumentNotFoundPouchDBError;
|
package/dist/files.js
CHANGED
|
@@ -1 +1,51 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.queryFileById = exports.TYPE_FILE = exports.TYPE_DIRECTORY = void 0;
|
|
9
|
+
|
|
10
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
+
|
|
12
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
|
+
|
|
14
|
+
var _cozyClient = require("cozy-client");
|
|
15
|
+
|
|
16
|
+
var defaultFetchPolicy = _cozyClient.fetchPolicies.olderThan(5 * 60 * 1000); // 5 min
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
var TYPE_DIRECTORY = 'directory';
|
|
20
|
+
exports.TYPE_DIRECTORY = TYPE_DIRECTORY;
|
|
21
|
+
var TYPE_FILE = 'file';
|
|
22
|
+
exports.TYPE_FILE = TYPE_FILE;
|
|
23
|
+
|
|
24
|
+
var queryFileById = /*#__PURE__*/function () {
|
|
25
|
+
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(client, id) {
|
|
26
|
+
var queryOpts;
|
|
27
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
28
|
+
while (1) {
|
|
29
|
+
switch (_context.prev = _context.next) {
|
|
30
|
+
case 0:
|
|
31
|
+
queryOpts = {
|
|
32
|
+
as: "io.cozy.files/".concat(id),
|
|
33
|
+
fetchPolicy: defaultFetchPolicy,
|
|
34
|
+
singleDocData: true
|
|
35
|
+
};
|
|
36
|
+
return _context.abrupt("return", client.query((0, _cozyClient.Q)('io.cozy.files').getById(id), queryOpts));
|
|
37
|
+
|
|
38
|
+
case 2:
|
|
39
|
+
case "end":
|
|
40
|
+
return _context.stop();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}, _callee);
|
|
44
|
+
}));
|
|
45
|
+
|
|
46
|
+
return function queryFileById(_x, _x2) {
|
|
47
|
+
return _ref.apply(this, arguments);
|
|
48
|
+
};
|
|
49
|
+
}();
|
|
50
|
+
|
|
51
|
+
exports.queryFileById = queryFileById;
|
package/dist/jsonapi.js
CHANGED
|
@@ -7,7 +7,11 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
7
7
|
Object.defineProperty(exports, "__esModule", {
|
|
8
8
|
value: true
|
|
9
9
|
});
|
|
10
|
-
exports.sanitizeJsonApi = exports.sanitized = exports.fromPouchResult = exports.normalizeDoc = exports.normalizeDocs = void 0;
|
|
10
|
+
exports.sanitizeJsonApi = exports.sanitized = exports.fromPouchResult = exports.computeFileFullpath = exports.normalizeDoc = exports.normalizeDocs = exports.resetAllPaths = exports.getFilePath = void 0;
|
|
11
|
+
|
|
12
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
13
|
+
|
|
14
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
11
15
|
|
|
12
16
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
17
|
|
|
@@ -19,10 +23,34 @@ var _startsWith = _interopRequireDefault(require("lodash/startsWith"));
|
|
|
19
23
|
|
|
20
24
|
var _helpers = require("./db/helpers");
|
|
21
25
|
|
|
26
|
+
var _files = require("./files");
|
|
27
|
+
|
|
28
|
+
var _logger = _interopRequireDefault(require("./logger"));
|
|
29
|
+
|
|
22
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; }
|
|
23
31
|
|
|
24
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; }
|
|
25
33
|
|
|
34
|
+
/**
|
|
35
|
+
* The paths are not stored in CouchDB for files, thus there are not in PouchDB neither.
|
|
36
|
+
* So we keep all the file paths in memory to be able to quickly retrieve them
|
|
37
|
+
* at search time.
|
|
38
|
+
*/
|
|
39
|
+
var allPaths = new Map();
|
|
40
|
+
|
|
41
|
+
var getFilePath = function getFilePath(id) {
|
|
42
|
+
return id ? allPaths.get(id) : undefined;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
exports.getFilePath = getFilePath;
|
|
46
|
+
|
|
47
|
+
var setFilePath = function setFilePath(id, path) {
|
|
48
|
+
allPaths.set(id, path);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
var resetAllPaths = function resetAllPaths() {
|
|
52
|
+
allPaths.clear();
|
|
53
|
+
};
|
|
26
54
|
/**
|
|
27
55
|
* Normalize several PouchDB document
|
|
28
56
|
*
|
|
@@ -30,6 +58,10 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
30
58
|
* @param {string} doctype - The document's doctype
|
|
31
59
|
* @param {Array<import('./CozyPouchLink').CozyPouchDocument>} docs - The documents to normalize
|
|
32
60
|
*/
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
exports.resetAllPaths = resetAllPaths;
|
|
64
|
+
|
|
33
65
|
var normalizeDocs = function normalizeDocs(client, doctype, docs) {
|
|
34
66
|
for (var i = docs.length; i >= 0; i--) {
|
|
35
67
|
var doc = docs[i];
|
|
@@ -39,7 +71,7 @@ var normalizeDocs = function normalizeDocs(client, doctype, docs) {
|
|
|
39
71
|
continue;
|
|
40
72
|
}
|
|
41
73
|
|
|
42
|
-
if ((0, _startsWith.default)(doc.
|
|
74
|
+
if ((0, _startsWith.default)(doc._id, '_design/')) {
|
|
43
75
|
docs.splice(i, 1);
|
|
44
76
|
continue;
|
|
45
77
|
}
|
|
@@ -85,6 +117,10 @@ var normalizeDoc = function normalizeDoc(client, doctype, doc) {
|
|
|
85
117
|
if (doctype === 'io.cozy.apps') {
|
|
86
118
|
normalizeAppsLinks(client, doctype, doc);
|
|
87
119
|
}
|
|
120
|
+
|
|
121
|
+
if (doctype === 'io.cozy.files') {
|
|
122
|
+
computeFileFullpath(client, doc);
|
|
123
|
+
}
|
|
88
124
|
};
|
|
89
125
|
|
|
90
126
|
exports.normalizeDoc = normalizeDoc;
|
|
@@ -109,11 +145,135 @@ var normalizeAppsLinks = function normalizeAppsLinks(client, doctype, docRef) {
|
|
|
109
145
|
};
|
|
110
146
|
};
|
|
111
147
|
|
|
112
|
-
var
|
|
113
|
-
var
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
148
|
+
var buildPathWithName = function buildPathWithName(parentPath, fileName) {
|
|
149
|
+
var hasTrailingSlash = parentPath.substr(-1) === '/';
|
|
150
|
+
var path = hasTrailingSlash ? "".concat(parentPath).concat(fileName) : "".concat(parentPath, "/").concat(fileName);
|
|
151
|
+
return path;
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* Compute paths for files
|
|
155
|
+
*
|
|
156
|
+
* There are several ways to get a path:
|
|
157
|
+
* - It is already defined in the file
|
|
158
|
+
* - The file path exists in memory
|
|
159
|
+
* - The directory path exists in memory
|
|
160
|
+
* - The directory path is retrieved from db
|
|
161
|
+
*
|
|
162
|
+
* @param { CozyClient} client - The cozy client instance
|
|
163
|
+
* @param { import('cozy-client/types/types').IOCozyFile} file - The file to compute path
|
|
164
|
+
* @returns {Promise<import('cozy-client/types/types').IOCozyFile>} the completed file with path
|
|
165
|
+
*/
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
var computeFileFullpath = /*#__PURE__*/function () {
|
|
169
|
+
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(client, file) {
|
|
170
|
+
var _file$path, newPath, filePath, parentPath, path, parentDir, _path;
|
|
171
|
+
|
|
172
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
173
|
+
while (1) {
|
|
174
|
+
switch (_context.prev = _context.next) {
|
|
175
|
+
case 0:
|
|
176
|
+
if (!(file.type === _files.TYPE_DIRECTORY)) {
|
|
177
|
+
_context.next = 2;
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return _context.abrupt("return", file);
|
|
182
|
+
|
|
183
|
+
case 2:
|
|
184
|
+
if (!file.path) {
|
|
185
|
+
_context.next = 10;
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (!((_file$path = file.path) !== null && _file$path !== void 0 && _file$path.includes(file.name))) {
|
|
190
|
+
_context.next = 6;
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
setFilePath(file._id, file.path);
|
|
195
|
+
return _context.abrupt("return", file);
|
|
196
|
+
|
|
197
|
+
case 6:
|
|
198
|
+
newPath = buildPathWithName(file.path, file.name);
|
|
199
|
+
setFilePath(file._id, newPath);
|
|
200
|
+
file.path = newPath;
|
|
201
|
+
return _context.abrupt("return", file);
|
|
202
|
+
|
|
203
|
+
case 10:
|
|
204
|
+
filePath = getFilePath(file._id);
|
|
205
|
+
|
|
206
|
+
if (!filePath) {
|
|
207
|
+
_context.next = 14;
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// File path exists in memory
|
|
212
|
+
file.path = filePath;
|
|
213
|
+
return _context.abrupt("return", file);
|
|
214
|
+
|
|
215
|
+
case 14:
|
|
216
|
+
parentPath = getFilePath(file.dir_id);
|
|
217
|
+
|
|
218
|
+
if (!parentPath) {
|
|
219
|
+
_context.next = 20;
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Parent path exists in memory
|
|
224
|
+
path = buildPathWithName(parentPath, file.name);
|
|
225
|
+
setFilePath(file._id, path); // Add the path in memory
|
|
226
|
+
|
|
227
|
+
file.path = path;
|
|
228
|
+
return _context.abrupt("return", file);
|
|
229
|
+
|
|
230
|
+
case 20:
|
|
231
|
+
if (file.dir_id) {
|
|
232
|
+
_context.next = 23;
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
_logger.default.warn("Missing dir_id for file ".concat(file._id));
|
|
237
|
+
|
|
238
|
+
return _context.abrupt("return", file);
|
|
239
|
+
|
|
240
|
+
case 23:
|
|
241
|
+
_context.next = 25;
|
|
242
|
+
return (0, _files.queryFileById)(client, file.dir_id);
|
|
243
|
+
|
|
244
|
+
case 25:
|
|
245
|
+
parentDir = _context.sent;
|
|
246
|
+
|
|
247
|
+
if (parentDir !== null && parentDir !== void 0 && parentDir.path) {
|
|
248
|
+
_path = buildPathWithName(parentDir === null || parentDir === void 0 ? void 0 : parentDir.path, file.name);
|
|
249
|
+
file.path = _path; // Add the paths in memory
|
|
250
|
+
|
|
251
|
+
setFilePath(file.dir_id, parentDir.path);
|
|
252
|
+
setFilePath(file._id, _path);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
return _context.abrupt("return", file);
|
|
256
|
+
|
|
257
|
+
case 28:
|
|
258
|
+
case "end":
|
|
259
|
+
return _context.stop();
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}, _callee);
|
|
263
|
+
}));
|
|
264
|
+
|
|
265
|
+
return function computeFileFullpath(_x, _x2) {
|
|
266
|
+
return _ref.apply(this, arguments);
|
|
267
|
+
};
|
|
268
|
+
}();
|
|
269
|
+
|
|
270
|
+
exports.computeFileFullpath = computeFileFullpath;
|
|
271
|
+
|
|
272
|
+
var fromPouchResult = function fromPouchResult(_ref2) {
|
|
273
|
+
var res = _ref2.res,
|
|
274
|
+
withRows = _ref2.withRows,
|
|
275
|
+
doctype = _ref2.doctype,
|
|
276
|
+
client = _ref2.client;
|
|
117
277
|
|
|
118
278
|
if (!res) {
|
|
119
279
|
return null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-pouch-link",
|
|
3
|
-
"version": "58.
|
|
3
|
+
"version": "58.3.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"url": "git+https://github.com/cozy/cozy-client.git"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"cozy-client": "^58.
|
|
16
|
+
"cozy-client": "^58.3.0",
|
|
17
17
|
"pouchdb-browser": "^7.2.2",
|
|
18
18
|
"pouchdb-find": "^7.2.2"
|
|
19
19
|
},
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"typecheck": "tsc -p tsconfig.json"
|
|
42
42
|
},
|
|
43
43
|
"sideEffects": false,
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "648e72735558114a377f9d3afc2b549bdb6de463"
|
|
45
45
|
}
|
package/types/CozyPouchLink.d.ts
CHANGED
|
@@ -27,6 +27,10 @@ export type PouchLinkOptions = {
|
|
|
27
27
|
* Doctypes to replicate
|
|
28
28
|
*/
|
|
29
29
|
doctypes: string[];
|
|
30
|
+
/**
|
|
31
|
+
* Whether or not the link is read-only and should forward any write operation
|
|
32
|
+
*/
|
|
33
|
+
isReadOnly: boolean;
|
|
30
34
|
/**
|
|
31
35
|
* A mapping from doctypes to replication options. All pouch replication options can be used, as well as the "strategy" option that determines which way the replication is done (can be "sync", "fromRemote" or "toRemote")
|
|
32
36
|
*/
|
|
@@ -52,6 +56,7 @@ export type PouchLinkOptions = {
|
|
|
52
56
|
* @property {number} [syncDebounceMaxDelayInMs] The maximum duration (in ms) the `startReplicationWithDebounce()` method can be delayed. Should be used only when periodicSync is false. Default is 10 minutes
|
|
53
57
|
* @property {number} [replicationInterval] Milliseconds between periodic replications
|
|
54
58
|
* @property {string[]} doctypes Doctypes to replicate
|
|
59
|
+
* @property {boolean} isReadOnly Whether or not the link is read-only and should forward any write operation
|
|
55
60
|
* @property {Record<string, object>} doctypesReplicationOptions A mapping from doctypes to replication options. All pouch replication options can be used, as well as the "strategy" option that determines which way the replication is done (can be "sync", "fromRemote" or "toRemote")
|
|
56
61
|
* @property {import('./types').LinkPlatform} platform Platform specific adapters and methods
|
|
57
62
|
* @property {import('cozy-client/src/performances/types').PerformanceAPI} [performanceApi] - The performance API that can be used to measure performances
|
package/types/errors.d.ts
CHANGED
package/types/files.d.ts
CHANGED
package/types/jsonapi.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
export function getFilePath(id: any): any;
|
|
2
|
+
export function resetAllPaths(): void;
|
|
1
3
|
export function normalizeDocs(client: CozyClient, doctype: string, docs: Array<import('./CozyPouchLink').CozyPouchDocument>): void;
|
|
2
4
|
export function normalizeDoc(client: CozyClient, doctype: string, doc: import('./CozyPouchLink').CozyPouchDocument): void;
|
|
5
|
+
export function computeFileFullpath(client: CozyClient, file: import('cozy-client/types/types').IOCozyFile): Promise<import('cozy-client/types/types').IOCozyFile>;
|
|
3
6
|
export function fromPouchResult({ res, withRows, doctype, client }: {
|
|
4
7
|
res: any;
|
|
5
8
|
withRows: any;
|