cozy-pouch-link 48.25.0 → 49.0.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 +593 -237
- package/dist/CozyPouchLink.spec.js +67 -42
- package/dist/PouchManager.js +317 -254
- package/dist/PouchManager.spec.js +91 -58
- package/dist/helpers.js +79 -0
- package/dist/helpers.spec.js +85 -1
- package/dist/jsonapi.js +54 -7
- package/dist/jsonapi.spec.js +57 -14
- package/dist/localStorage.js +646 -207
- package/dist/localStorage.spec.js +48 -0
- package/dist/mango.js +72 -20
- package/dist/mango.spec.js +1 -1
- package/dist/migrations/adapter.js +1 -1
- package/dist/platformWeb.js +120 -0
- package/dist/remote.js +39 -5
- package/dist/remote.spec.js +214 -0
- package/dist/replicateOnce.js +337 -0
- package/dist/startReplication.js +70 -45
- package/dist/startReplication.spec.js +374 -39
- package/dist/types.js +80 -0
- package/dist/utils.js +11 -2
- package/package.json +9 -5
- package/types/AccessToken.d.ts +16 -0
- package/types/CozyPouchLink.d.ts +228 -0
- package/types/PouchManager.d.ts +86 -0
- package/types/__tests__/fixtures.d.ts +48 -0
- package/types/__tests__/mocks.d.ts +4 -0
- package/types/helpers.d.ts +17 -0
- package/types/index.d.ts +1 -0
- package/types/jsonapi.d.ts +19 -0
- package/types/localStorage.d.ts +124 -0
- package/types/logger.d.ts +2 -0
- package/types/loop.d.ts +60 -0
- package/types/mango.d.ts +3 -0
- package/types/migrations/adapter.d.ts +18 -0
- package/types/platformWeb.d.ts +17 -0
- package/types/remote.d.ts +6 -0
- package/types/replicateOnce.d.ts +29 -0
- package/types/startReplication.d.ts +12 -0
- package/types/types.d.ts +104 -0
- package/types/utils.d.ts +3 -0
|
@@ -4,6 +4,8 @@ import { find, allDocs, withoutDesignDocuments } from './helpers'
|
|
|
4
4
|
jest.mock('./helpers', () => ({
|
|
5
5
|
find: jest.fn(),
|
|
6
6
|
allDocs: jest.fn(),
|
|
7
|
+
normalizeFindSelector: jest.requireActual('./helpers').default
|
|
8
|
+
.normalizeFindSelector,
|
|
7
9
|
withoutDesignDocuments: jest.fn()
|
|
8
10
|
}))
|
|
9
11
|
|
|
@@ -120,7 +122,7 @@ describe('CozyPouchLink', () => {
|
|
|
120
122
|
'io.cozy.files': { warmupQueries: [query1(), query2()] }
|
|
121
123
|
}
|
|
122
124
|
})
|
|
123
|
-
link.pouches.
|
|
125
|
+
link.pouches.getSyncStatus = jest.fn().mockReturnValue('synced')
|
|
124
126
|
|
|
125
127
|
const query = Q(TODO_DOCTYPE)
|
|
126
128
|
expect.assertions(0)
|
|
@@ -174,7 +176,7 @@ describe('CozyPouchLink', () => {
|
|
|
174
176
|
'io.cozy.todos': { strategy: 'fromRemote' }
|
|
175
177
|
}
|
|
176
178
|
})
|
|
177
|
-
link.pouches.
|
|
179
|
+
link.pouches.getSyncStatus = jest.fn().mockReturnValue('synced')
|
|
178
180
|
await link.request(
|
|
179
181
|
{
|
|
180
182
|
doctype: TODO_DOCTYPE,
|
|
@@ -194,7 +196,7 @@ describe('CozyPouchLink', () => {
|
|
|
194
196
|
'io.cozy.todos': { strategy: 'fromRemote' }
|
|
195
197
|
}
|
|
196
198
|
})
|
|
197
|
-
link.pouches.
|
|
199
|
+
link.pouches.getSyncStatus = jest.fn().mockReturnValue('synced')
|
|
198
200
|
const mock = jest.fn()
|
|
199
201
|
await link.request(Q(TODO_DOCTYPE), null, mock)
|
|
200
202
|
expect(mock).not.toHaveBeenCalled()
|
|
@@ -210,7 +212,7 @@ describe('CozyPouchLink', () => {
|
|
|
210
212
|
const docs = [TODO_1, TODO_2, TODO_3, TODO_4]
|
|
211
213
|
it('should be able to execute a query', async () => {
|
|
212
214
|
await setup()
|
|
213
|
-
link.pouches.
|
|
215
|
+
link.pouches.getSyncStatus = jest.fn().mockReturnValue('synced')
|
|
214
216
|
const db = link.getPouch(TODO_DOCTYPE)
|
|
215
217
|
db.post({
|
|
216
218
|
label: 'Make PouchDB link work',
|
|
@@ -223,7 +225,7 @@ describe('CozyPouchLink', () => {
|
|
|
223
225
|
|
|
224
226
|
it('should be possible to query only one doc', async () => {
|
|
225
227
|
await setup()
|
|
226
|
-
link.pouches.
|
|
228
|
+
link.pouches.getSyncStatus = jest.fn().mockReturnValue('synced')
|
|
227
229
|
const db = link.getPouch(TODO_DOCTYPE)
|
|
228
230
|
db.post({
|
|
229
231
|
_id: 'deadbeef',
|
|
@@ -238,7 +240,7 @@ describe('CozyPouchLink', () => {
|
|
|
238
240
|
it('should be possible to explicitly index fields', async () => {
|
|
239
241
|
find.mockReturnValue({ docs: [TODO_3, TODO_4] })
|
|
240
242
|
await setup()
|
|
241
|
-
link.pouches.
|
|
243
|
+
link.pouches.getSyncStatus = jest.fn().mockReturnValue('synced')
|
|
242
244
|
const db = link.getPouch(TODO_DOCTYPE)
|
|
243
245
|
await db.bulkDocs(docs.map(x => omit(x, '_type')))
|
|
244
246
|
const query = Q(TODO_DOCTYPE)
|
|
@@ -253,7 +255,7 @@ describe('CozyPouchLink', () => {
|
|
|
253
255
|
it('should be possible to query multiple docs', async () => {
|
|
254
256
|
withoutDesignDocuments.mockReturnValue({ docs: [TODO_1, TODO_3] })
|
|
255
257
|
await setup()
|
|
256
|
-
link.pouches.
|
|
258
|
+
link.pouches.getSyncStatus = jest.fn().mockReturnValue('synced')
|
|
257
259
|
const db = link.getPouch(TODO_DOCTYPE)
|
|
258
260
|
await db.bulkDocs(docs.map(x => omit(x, '_type')))
|
|
259
261
|
const ids = [TODO_1._id, TODO_3._id]
|
|
@@ -268,7 +270,7 @@ describe('CozyPouchLink', () => {
|
|
|
268
270
|
it('should be possible to select', async () => {
|
|
269
271
|
find.mockReturnValue({ docs: [TODO_3, TODO_4] })
|
|
270
272
|
await setup()
|
|
271
|
-
link.pouches.
|
|
273
|
+
link.pouches.getSyncStatus = jest.fn().mockReturnValue('synced')
|
|
272
274
|
const db = link.getPouch(TODO_DOCTYPE)
|
|
273
275
|
await db.bulkDocs(docs.map(x => omit(x, '_type')))
|
|
274
276
|
const query = Q(TODO_DOCTYPE)
|
|
@@ -296,32 +298,10 @@ describe('CozyPouchLink', () => {
|
|
|
296
298
|
})
|
|
297
299
|
})
|
|
298
300
|
|
|
299
|
-
it('should merge selector and partial filter definitions', () => {
|
|
300
|
-
const selector = { _id: { $gt: null } }
|
|
301
|
-
expect(link.mergePartialIndexInSelector(selector, {})).toEqual(selector)
|
|
302
|
-
|
|
303
|
-
const partialFilter = {
|
|
304
|
-
trashed: {
|
|
305
|
-
$exists: false
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
const expectedMergedSelector = {
|
|
309
|
-
_id: {
|
|
310
|
-
$gt: null
|
|
311
|
-
},
|
|
312
|
-
trashed: {
|
|
313
|
-
$exists: false
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
expect(link.mergePartialIndexInSelector(selector, partialFilter)).toEqual(
|
|
317
|
-
expectedMergedSelector
|
|
318
|
-
)
|
|
319
|
-
})
|
|
320
|
-
|
|
321
301
|
it("should add _id in the selected fields since CozyClient' store needs it", async () => {
|
|
322
302
|
find.mockReturnValue({ docs: [TODO_3, TODO_4] })
|
|
323
303
|
await setup()
|
|
324
|
-
link.pouches.
|
|
304
|
+
link.pouches.getSyncStatus = jest.fn().mockReturnValue('synced')
|
|
325
305
|
const db = link.getPouch(TODO_DOCTYPE)
|
|
326
306
|
await db.bulkDocs(docs.map(x => omit(x, '_type')))
|
|
327
307
|
const query = Q(TODO_DOCTYPE)
|
|
@@ -333,7 +313,7 @@ describe('CozyPouchLink', () => {
|
|
|
333
313
|
expect(find).toHaveBeenLastCalledWith(
|
|
334
314
|
expect.anything(),
|
|
335
315
|
expect.objectContaining({
|
|
336
|
-
fields: ['label', 'done', '_id', '
|
|
316
|
+
fields: ['label', 'done', '_id', '_rev']
|
|
337
317
|
})
|
|
338
318
|
)
|
|
339
319
|
})
|
|
@@ -342,7 +322,7 @@ describe('CozyPouchLink', () => {
|
|
|
342
322
|
describe('mutations', () => {
|
|
343
323
|
it('should be possible to save a new document', async () => {
|
|
344
324
|
await setup()
|
|
345
|
-
link.pouches.
|
|
325
|
+
link.pouches.getSyncStatus = jest.fn().mockReturnValue('synced')
|
|
346
326
|
const { _id, ...NEW_TODO } = TODO_3
|
|
347
327
|
const mutation = client.getDocumentSavePlan(NEW_TODO)
|
|
348
328
|
const res = await link.request(mutation)
|
|
@@ -360,7 +340,7 @@ describe('CozyPouchLink', () => {
|
|
|
360
340
|
|
|
361
341
|
it('should be possible to save multiple documents', async () => {
|
|
362
342
|
await setup()
|
|
363
|
-
link.pouches.
|
|
343
|
+
link.pouches.getSyncStatus = jest.fn().mockReturnValue('synced')
|
|
364
344
|
const { _id, ...NEW_TODO } = TODO_3
|
|
365
345
|
const res = await client.saveAll([TODO_3, TODO_4, NEW_TODO])
|
|
366
346
|
expect(link.executeMutation).toHaveBeenCalled()
|
|
@@ -394,7 +374,7 @@ describe('CozyPouchLink', () => {
|
|
|
394
374
|
{ ok: true, id: '3', rev: '1-cffeebabe' }
|
|
395
375
|
]
|
|
396
376
|
}
|
|
397
|
-
link.pouches.
|
|
377
|
+
link.pouches.getSyncStatus = jest.fn().mockReturnValue('synced')
|
|
398
378
|
const { _id, ...NEW_TODO } = TODO_3
|
|
399
379
|
let err
|
|
400
380
|
try {
|
|
@@ -412,7 +392,7 @@ describe('CozyPouchLink', () => {
|
|
|
412
392
|
|
|
413
393
|
it('should be possible to update a document', async () => {
|
|
414
394
|
await setup()
|
|
415
|
-
link.pouches.
|
|
395
|
+
link.pouches.getSyncStatus = jest.fn().mockReturnValue('synced')
|
|
416
396
|
const { _id, ...NEW_TODO } = TODO_3
|
|
417
397
|
const saveMutation = client.getDocumentSavePlan(NEW_TODO)
|
|
418
398
|
const saved = (await link.request(saveMutation)).data
|
|
@@ -475,7 +455,10 @@ describe('CozyPouchLink', () => {
|
|
|
475
455
|
_type: 'io.cozy.todos',
|
|
476
456
|
done: false,
|
|
477
457
|
id: '1',
|
|
478
|
-
label: 'Buy bread'
|
|
458
|
+
label: 'Buy bread',
|
|
459
|
+
relationships: {
|
|
460
|
+
referenced_by: undefined
|
|
461
|
+
}
|
|
479
462
|
}
|
|
480
463
|
]
|
|
481
464
|
})
|
|
@@ -583,21 +566,58 @@ describe('CozyPouchLink', () => {
|
|
|
583
566
|
it('uses the default index, the one from the sort', async () => {
|
|
584
567
|
spy = jest.spyOn(PouchDB.prototype, 'createIndex')
|
|
585
568
|
await setup()
|
|
586
|
-
link.pouches.
|
|
569
|
+
link.pouches.getSyncStatus = jest.fn().mockReturnValue('synced')
|
|
587
570
|
const query = Q(TODO_DOCTYPE)
|
|
588
571
|
.where({})
|
|
589
572
|
.sortBy([{ name: 'asc' }])
|
|
590
573
|
await link.request(query)
|
|
591
|
-
expect(spy).toHaveBeenCalledWith({
|
|
574
|
+
expect(spy).toHaveBeenCalledWith({
|
|
575
|
+
index: {
|
|
576
|
+
ddoc: 'by_name',
|
|
577
|
+
fields: ['name'],
|
|
578
|
+
indexName: 'by_name',
|
|
579
|
+
partial_filter_selector: undefined
|
|
580
|
+
}
|
|
581
|
+
})
|
|
592
582
|
})
|
|
593
583
|
|
|
594
584
|
it('uses indexFields if provided', async () => {
|
|
595
585
|
spy = jest.spyOn(PouchDB.prototype, 'createIndex').mockReturnValue({})
|
|
596
586
|
await setup()
|
|
597
|
-
link.ensureIndex(TODO_DOCTYPE, {
|
|
587
|
+
await link.ensureIndex(TODO_DOCTYPE, {
|
|
598
588
|
indexedFields: ['myIndex']
|
|
599
589
|
})
|
|
600
|
-
expect(spy).
|
|
590
|
+
expect(spy).toHaveBeenCalled()
|
|
591
|
+
expect(spy).toHaveBeenCalledWith({
|
|
592
|
+
index: {
|
|
593
|
+
ddoc: 'by_myIndex',
|
|
594
|
+
fields: ['myIndex'],
|
|
595
|
+
indexName: 'by_myIndex',
|
|
596
|
+
partial_filter_selector: undefined
|
|
597
|
+
}
|
|
598
|
+
})
|
|
599
|
+
})
|
|
600
|
+
|
|
601
|
+
it('should handle partial filters', async () => {
|
|
602
|
+
spy = jest.spyOn(PouchDB.prototype, 'createIndex').mockReturnValue({})
|
|
603
|
+
await setup()
|
|
604
|
+
await link.ensureIndex(TODO_DOCTYPE, {
|
|
605
|
+
indexedFields: ['myIndex'],
|
|
606
|
+
partialFilter: { SOME_FIELD: { $exists: true } }
|
|
607
|
+
})
|
|
608
|
+
expect(spy).toHaveBeenCalled()
|
|
609
|
+
expect(spy).toHaveBeenCalledWith({
|
|
610
|
+
index: {
|
|
611
|
+
ddoc: 'by_myIndex_filter_(SOME_FIELD_$exists_true)',
|
|
612
|
+
fields: ['myIndex'],
|
|
613
|
+
indexName: 'by_myIndex_filter_(SOME_FIELD_$exists_true)',
|
|
614
|
+
partial_filter_selector: {
|
|
615
|
+
SOME_FIELD: {
|
|
616
|
+
$exists: true
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
})
|
|
601
621
|
})
|
|
602
622
|
|
|
603
623
|
it('uses the specified index', async () => {
|
|
@@ -614,9 +634,14 @@ describe('CozyPouchLink', () => {
|
|
|
614
634
|
})
|
|
615
635
|
const params = {
|
|
616
636
|
sort: undefined,
|
|
617
|
-
selector: {
|
|
637
|
+
selector: {
|
|
638
|
+
myIndex2: {
|
|
639
|
+
$gt: null
|
|
640
|
+
}
|
|
641
|
+
},
|
|
618
642
|
fields: undefined,
|
|
619
643
|
limit: undefined,
|
|
644
|
+
partialFilter: undefined,
|
|
620
645
|
skip: undefined
|
|
621
646
|
}
|
|
622
647
|
|