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.
Files changed (41) hide show
  1. package/dist/CozyPouchLink.js +593 -237
  2. package/dist/CozyPouchLink.spec.js +67 -42
  3. package/dist/PouchManager.js +317 -254
  4. package/dist/PouchManager.spec.js +91 -58
  5. package/dist/helpers.js +79 -0
  6. package/dist/helpers.spec.js +85 -1
  7. package/dist/jsonapi.js +54 -7
  8. package/dist/jsonapi.spec.js +57 -14
  9. package/dist/localStorage.js +646 -207
  10. package/dist/localStorage.spec.js +48 -0
  11. package/dist/mango.js +72 -20
  12. package/dist/mango.spec.js +1 -1
  13. package/dist/migrations/adapter.js +1 -1
  14. package/dist/platformWeb.js +120 -0
  15. package/dist/remote.js +39 -5
  16. package/dist/remote.spec.js +214 -0
  17. package/dist/replicateOnce.js +337 -0
  18. package/dist/startReplication.js +70 -45
  19. package/dist/startReplication.spec.js +374 -39
  20. package/dist/types.js +80 -0
  21. package/dist/utils.js +11 -2
  22. package/package.json +9 -5
  23. package/types/AccessToken.d.ts +16 -0
  24. package/types/CozyPouchLink.d.ts +228 -0
  25. package/types/PouchManager.d.ts +86 -0
  26. package/types/__tests__/fixtures.d.ts +48 -0
  27. package/types/__tests__/mocks.d.ts +4 -0
  28. package/types/helpers.d.ts +17 -0
  29. package/types/index.d.ts +1 -0
  30. package/types/jsonapi.d.ts +19 -0
  31. package/types/localStorage.d.ts +124 -0
  32. package/types/logger.d.ts +2 -0
  33. package/types/loop.d.ts +60 -0
  34. package/types/mango.d.ts +3 -0
  35. package/types/migrations/adapter.d.ts +18 -0
  36. package/types/platformWeb.d.ts +17 -0
  37. package/types/remote.d.ts +6 -0
  38. package/types/replicateOnce.d.ts +29 -0
  39. package/types/startReplication.d.ts +12 -0
  40. package/types/types.d.ts +104 -0
  41. package/types/utils.d.ts +3 -0
@@ -1,3 +1,5 @@
1
+ import CozyClient from 'cozy-client'
2
+
1
3
  import { fromPouchResult, normalizeDoc } from './jsonapi'
2
4
 
3
5
  const BART_FIXTURE = {
@@ -26,21 +28,32 @@ const DELETED_DOC_FIXTURE = {
26
28
  delete: true
27
29
  }
28
30
 
31
+ const token = 'fake_token'
32
+ const uri = 'https://claude.mycozy.cloud'
33
+ const client = new CozyClient({ token, uri })
34
+
29
35
  describe('doc normalization', () => {
30
36
  it('keeps the highest between rev and _rev and removes the rev attribute', () => {
31
- const normalized = normalizeDoc({
32
- _id: 1234,
33
- _rev: '3-deadbeef',
34
- rev: '4-cffee',
35
- firstName: 'Bobba',
36
- lastName: 'Fett'
37
- })
37
+ const normalized = normalizeDoc(
38
+ {
39
+ _id: 1234,
40
+ _rev: '3-deadbeef',
41
+ rev: '4-cffee',
42
+ firstName: 'Bobba',
43
+ lastName: 'Fett'
44
+ },
45
+ 'io.cozy.contacts'
46
+ )
38
47
  expect(normalized).toEqual({
39
48
  _id: 1234,
40
49
  id: 1234,
41
50
  _rev: '4-cffee',
51
+ _type: 'io.cozy.contacts',
42
52
  firstName: 'Bobba',
43
- lastName: 'Fett'
53
+ lastName: 'Fett',
54
+ relationships: {
55
+ referenced_by: undefined
56
+ }
44
57
  })
45
58
  })
46
59
  })
@@ -50,7 +63,12 @@ describe('jsonapi', () => {
50
63
  const res = {
51
64
  rows: [BART_FIXTURE, LISA_FIXTURE, MARGE_FIXTURE, DELETED_DOC_FIXTURE]
52
65
  }
53
- const normalized = fromPouchResult(res, true, 'io.cozy.simpsons')
66
+ const normalized = fromPouchResult({
67
+ res,
68
+ withRows: true,
69
+ doctype: 'io.cozy.simpsons',
70
+ client
71
+ })
54
72
  expect(normalized.data[0].name).toBe('Bart')
55
73
  expect(normalized.data[0].id).toBe(1)
56
74
  expect(normalized.data[0]._id).toBe(1)
@@ -68,13 +86,23 @@ describe('jsonapi', () => {
68
86
  describe('pagination', () => {
69
87
  it('has no next when there is no pagination information', () => {
70
88
  const res = { rows: [BART_FIXTURE] }
71
- const normalized = fromPouchResult(res, true, 'io.cozy.simpsons')
89
+ const normalized = fromPouchResult({
90
+ res,
91
+ withRows: true,
92
+ doctype: 'io.cozy.simpsons',
93
+ client
94
+ })
72
95
  expect(normalized.next).toBe(false)
73
96
  })
74
97
 
75
98
  it('paginates when there is a total_rows field greater than the rows number', () => {
76
99
  const res = { rows: [BART_FIXTURE], total_rows: 3 }
77
- const normalized = fromPouchResult(res, true, 'io.cozy.simpsons')
100
+ const normalized = fromPouchResult({
101
+ res,
102
+ withRows: true,
103
+ doctype: 'io.cozy.simpsons',
104
+ client
105
+ })
78
106
  expect(normalized.next).toBe(true)
79
107
  })
80
108
 
@@ -83,17 +111,32 @@ describe('jsonapi', () => {
83
111
  rows: [BART_FIXTURE, MARGE_FIXTURE, LISA_FIXTURE],
84
112
  total_rows: 3
85
113
  }
86
- const normalized = fromPouchResult(res, true, 'io.cozy.simpsons')
114
+ const normalized = fromPouchResult({
115
+ res,
116
+ withRows: true,
117
+ doctype: 'io.cozy.simpsons',
118
+ client
119
+ })
87
120
  expect(normalized.next).toBe(false)
88
121
  })
89
122
 
90
123
  it('paginates when there is a limit field', () => {
91
124
  const res = { rows: [BART_FIXTURE, LISA_FIXTURE], limit: 2 }
92
- const normalized = fromPouchResult(res, true, 'io.cozy.simpsons')
125
+ const normalized = fromPouchResult({
126
+ res,
127
+ withRows: true,
128
+ doctype: 'io.cozy.simpsons',
129
+ client
130
+ })
93
131
  expect(normalized.next).toBe(true)
94
132
 
95
133
  const lastRes = { rows: [MARGE_FIXTURE], limit: 2 }
96
- const lastNormalized = fromPouchResult(lastRes, true, 'io.cozy.simpsons')
134
+ const lastNormalized = fromPouchResult({
135
+ res: lastRes,
136
+ withRows: true,
137
+ doctype: 'io.cozy.simpsons',
138
+ client
139
+ })
97
140
  expect(lastNormalized.next).toBe(false)
98
141
  })
99
142
  })