cozy-pouch-link 60.10.0 → 60.11.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/jsonapi.js +26 -21
- package/dist/jsonapi.spec.js +79 -1
- package/package.json +3 -3
package/dist/jsonapi.js
CHANGED
|
@@ -167,7 +167,7 @@ var buildPathWithName = function buildPathWithName(parentPath, fileName) {
|
|
|
167
167
|
|
|
168
168
|
var computeFileFullpath = /*#__PURE__*/function () {
|
|
169
169
|
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(client, file) {
|
|
170
|
-
var _file$path, newPath, filePath, parentPath, path, parentDir, _path;
|
|
170
|
+
var _file$path, newPath, filePath, parentPath, builtPath, path, _yield$queryFileById, parentDir, _path;
|
|
171
171
|
|
|
172
172
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
173
173
|
while (1) {
|
|
@@ -202,34 +202,38 @@ var computeFileFullpath = /*#__PURE__*/function () {
|
|
|
202
202
|
|
|
203
203
|
case 10:
|
|
204
204
|
filePath = getFilePath(file._id);
|
|
205
|
+
parentPath = getFilePath(file.dir_id);
|
|
205
206
|
|
|
206
|
-
if (!filePath) {
|
|
207
|
-
_context.next =
|
|
207
|
+
if (!(parentPath && filePath)) {
|
|
208
|
+
_context.next = 17;
|
|
208
209
|
break;
|
|
209
210
|
}
|
|
210
211
|
|
|
211
|
-
//
|
|
212
|
-
|
|
213
|
-
return _context.abrupt("return", file);
|
|
212
|
+
// Check if file path is up to date
|
|
213
|
+
builtPath = buildPathWithName(parentPath, file.name);
|
|
214
214
|
|
|
215
|
-
|
|
216
|
-
|
|
215
|
+
if (filePath !== builtPath) {
|
|
216
|
+
setFilePath(file._id, builtPath);
|
|
217
|
+
}
|
|
217
218
|
|
|
219
|
+
file.path = builtPath;
|
|
220
|
+
return _context.abrupt("return", file);
|
|
221
|
+
|
|
222
|
+
case 17:
|
|
218
223
|
if (!parentPath) {
|
|
219
|
-
_context.next =
|
|
224
|
+
_context.next = 22;
|
|
220
225
|
break;
|
|
221
226
|
}
|
|
222
227
|
|
|
223
|
-
// Parent path exists in memory
|
|
228
|
+
// Parent path exists in memory: use it to compute file path and save in memory
|
|
224
229
|
path = buildPathWithName(parentPath, file.name);
|
|
225
|
-
setFilePath(file._id, path);
|
|
226
|
-
|
|
230
|
+
setFilePath(file._id, path);
|
|
227
231
|
file.path = path;
|
|
228
232
|
return _context.abrupt("return", file);
|
|
229
233
|
|
|
230
|
-
case
|
|
234
|
+
case 22:
|
|
231
235
|
if (file.dir_id) {
|
|
232
|
-
_context.next =
|
|
236
|
+
_context.next = 25;
|
|
233
237
|
break;
|
|
234
238
|
}
|
|
235
239
|
|
|
@@ -237,16 +241,17 @@ var computeFileFullpath = /*#__PURE__*/function () {
|
|
|
237
241
|
|
|
238
242
|
return _context.abrupt("return", file);
|
|
239
243
|
|
|
240
|
-
case
|
|
241
|
-
_context.next =
|
|
244
|
+
case 25:
|
|
245
|
+
_context.next = 27;
|
|
242
246
|
return (0, _files.queryFileById)(client, file.dir_id);
|
|
243
247
|
|
|
244
|
-
case
|
|
245
|
-
|
|
248
|
+
case 27:
|
|
249
|
+
_yield$queryFileById = _context.sent;
|
|
250
|
+
parentDir = _yield$queryFileById.data;
|
|
246
251
|
|
|
247
252
|
if (parentDir !== null && parentDir !== void 0 && parentDir.path) {
|
|
248
|
-
_path = buildPathWithName(parentDir
|
|
249
|
-
file.path = _path; // Add the paths in memory
|
|
253
|
+
_path = buildPathWithName(parentDir.path, file.name);
|
|
254
|
+
file.path = _path; // Add the computed paths in memory
|
|
250
255
|
|
|
251
256
|
setFilePath(file.dir_id, parentDir.path);
|
|
252
257
|
setFilePath(file._id, _path);
|
|
@@ -254,7 +259,7 @@ var computeFileFullpath = /*#__PURE__*/function () {
|
|
|
254
259
|
|
|
255
260
|
return _context.abrupt("return", file);
|
|
256
261
|
|
|
257
|
-
case
|
|
262
|
+
case 31:
|
|
258
263
|
case "end":
|
|
259
264
|
return _context.stop();
|
|
260
265
|
}
|
package/dist/jsonapi.spec.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import CozyClient from 'cozy-client'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
computeFileFullpath,
|
|
5
|
+
fromPouchResult,
|
|
6
|
+
normalizeDoc,
|
|
7
|
+
resetAllPaths
|
|
8
|
+
} from './jsonapi'
|
|
9
|
+
import { queryFileById } from './files'
|
|
10
|
+
|
|
11
|
+
jest.mock('./files', () => ({
|
|
12
|
+
queryFileById: jest.fn()
|
|
13
|
+
}))
|
|
4
14
|
|
|
5
15
|
const BART_FIXTURE = {
|
|
6
16
|
id: 1,
|
|
@@ -642,3 +652,71 @@ const multipleDocRes = {
|
|
|
642
652
|
}
|
|
643
653
|
]
|
|
644
654
|
}
|
|
655
|
+
|
|
656
|
+
describe('computeFileFullpath', () => {
|
|
657
|
+
afterEach(() => {
|
|
658
|
+
resetAllPaths()
|
|
659
|
+
})
|
|
660
|
+
const dir = {
|
|
661
|
+
_id: '123',
|
|
662
|
+
_type: 'io.cozy.files',
|
|
663
|
+
type: 'directory',
|
|
664
|
+
dir_id: 'ROOT',
|
|
665
|
+
name: 'MYDIR',
|
|
666
|
+
path: 'ROOT/MYDIR'
|
|
667
|
+
}
|
|
668
|
+
const fileWithFullpath = {
|
|
669
|
+
_id: '456',
|
|
670
|
+
_type: 'io.cozy.files',
|
|
671
|
+
type: 'file',
|
|
672
|
+
dir_id: '123',
|
|
673
|
+
name: 'file1',
|
|
674
|
+
path: 'ROOT/MYDIR/file1'
|
|
675
|
+
}
|
|
676
|
+
const fileWithStackPath = {
|
|
677
|
+
_id: '789',
|
|
678
|
+
_type: 'io.cozy.files',
|
|
679
|
+
type: 'file',
|
|
680
|
+
dir_id: '123',
|
|
681
|
+
name: 'file2',
|
|
682
|
+
path: 'ROOT/MYDIR'
|
|
683
|
+
}
|
|
684
|
+
const filewithNoPath = {
|
|
685
|
+
_id: '000',
|
|
686
|
+
_type: 'io.cozy.files',
|
|
687
|
+
type: 'file',
|
|
688
|
+
dir_id: '123',
|
|
689
|
+
name: 'file3'
|
|
690
|
+
}
|
|
691
|
+
it('should handle directory', async () => {
|
|
692
|
+
const res = await computeFileFullpath(client, dir)
|
|
693
|
+
expect(res).toEqual(dir)
|
|
694
|
+
})
|
|
695
|
+
|
|
696
|
+
it('should handle file with complete path', async () => {
|
|
697
|
+
const res = await computeFileFullpath(client, fileWithFullpath)
|
|
698
|
+
expect(res).toEqual(fileWithFullpath)
|
|
699
|
+
})
|
|
700
|
+
|
|
701
|
+
it('should compute fullpath for file with incomplete path', async () => {
|
|
702
|
+
const res = await computeFileFullpath(client, fileWithStackPath)
|
|
703
|
+
expect(res.path).toEqual('ROOT/MYDIR/file2')
|
|
704
|
+
})
|
|
705
|
+
|
|
706
|
+
it('should compute fullpath for file with no path', async () => {
|
|
707
|
+
// eslint-disable-next-line prettier/prettier
|
|
708
|
+
queryFileById.mockResolvedValue({ data: dir })
|
|
709
|
+
const res = await computeFileFullpath(client, filewithNoPath)
|
|
710
|
+
expect(res.path).toEqual('ROOT/MYDIR/file3')
|
|
711
|
+
})
|
|
712
|
+
|
|
713
|
+
it('should handle updates on path', async () => {
|
|
714
|
+
queryFileById.mockResolvedValue({ data: dir })
|
|
715
|
+
const res1 = await computeFileFullpath(client, filewithNoPath)
|
|
716
|
+
expect(res1.path).toEqual('ROOT/MYDIR/file3')
|
|
717
|
+
|
|
718
|
+
const updFile = { ...filewithNoPath, name: 'file3.1', path: undefined }
|
|
719
|
+
const res2 = await computeFileFullpath(client, updFile)
|
|
720
|
+
expect(res2.path).toEqual('ROOT/MYDIR/file3.1')
|
|
721
|
+
})
|
|
722
|
+
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-pouch-link",
|
|
3
|
-
"version": "60.
|
|
3
|
+
"version": "60.11.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": "^60.
|
|
16
|
+
"cozy-client": "^60.11.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": "8a114254c6f27a0358b0d79338f452337745b297"
|
|
45
45
|
}
|