cozy-pouch-link 49.6.1 → 49.7.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.
@@ -136,7 +136,9 @@ var normalizeAll = function normalizeAll(client) {
136
136
 
137
137
  /**
138
138
  * @typedef {object} PouchLinkOptions
139
- * @property {number} [replicationInterval] Milliseconds between replications
139
+ * @property {boolean} initialSync Whether or not a replication process should be started. Default is false
140
+ * @property {boolean} periodicSync Whether or not the replication should be periodic. Default is true
141
+ * @property {number} [replicationInterval] Milliseconds between periodic replications
140
142
  * @property {string[]} doctypes Doctypes to replicate
141
143
  * @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")
142
144
  * @property {import('./types').LinkPlatform} platform Platform specific adapters and methods
@@ -168,7 +170,9 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
168
170
  var options = (0, _defaults.default)({}, opts, DEFAULT_OPTIONS);
169
171
  _this = _super.call(this, options);
170
172
  var doctypes = options.doctypes,
171
- doctypesReplicationOptions = options.doctypesReplicationOptions;
173
+ doctypesReplicationOptions = options.doctypesReplicationOptions,
174
+ periodicSync = options.periodicSync,
175
+ initialSync = options.initialSync;
172
176
  _this.options = options;
173
177
 
174
178
  if (!doctypes) {
@@ -179,6 +183,8 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
179
183
  _this.doctypesReplicationOptions = doctypesReplicationOptions;
180
184
  _this.indexes = {};
181
185
  _this.storage = new _localStorage.PouchLocalStorage(((_options$platform = options.platform) === null || _options$platform === void 0 ? void 0 : _options$platform.storage) || _platformWeb.platformWeb.storage);
186
+ _this.initialSync = initialSync !== null && initialSync !== void 0 ? initialSync : false;
187
+ _this.periodicSync = periodicSync !== null && periodicSync !== void 0 ? periodicSync : true;
182
188
  /** @type {Record<string, ReplicationStatus>} - Stores replication states per doctype */
183
189
 
184
190
  _this.replicationStatus = _this.replicationStatus || {};
@@ -422,7 +428,7 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
422
428
  return this.pouches.init();
423
429
 
424
430
  case 27:
425
- if (this.client && this.options.initialSync) {
431
+ if (this.client && this.initialSync) {
426
432
  this.startReplication();
427
433
  }
428
434
 
@@ -527,7 +533,12 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
527
533
  key: "startReplication",
528
534
  value: function startReplication() {
529
535
  this.client.emit('pouchlink:sync:start');
530
- this.pouches.startReplicationLoop();
536
+
537
+ if (this.periodicSync) {
538
+ this.pouches.startReplicationLoop();
539
+ } else {
540
+ this.pouches.replicateOnce();
541
+ }
531
542
 
532
543
  if (this.options.onStartReplication) {
533
544
  this.options.onStartReplication.apply(this);
package/dist/types.js CHANGED
@@ -79,23 +79,23 @@ exports.default = void 0;
79
79
 
80
80
  /**
81
81
  * @typedef {object} PouchDBInfo
82
- * @param {string} db_name - The database name
83
- * @param {number} doc_count - The number of doc in the database
84
- * @param {number} update_seq - The sequence number
82
+ * @property {string} db_name - The database name
83
+ * @property {number} doc_count - The number of doc in the database
84
+ * @property {number} update_seq - The sequence number
85
85
  */
86
86
 
87
87
  /**
88
88
  * @typedef {object} PouchDBChangesResults
89
- * @param {Array<PouchDBChanges>} results - The changes results
90
- * @param {number} last_seq - The last sequence number
89
+ * @property {Array<PouchDBChanges>} results - The changes results
90
+ * @property {number} last_seq - The last sequence number
91
91
  */
92
92
 
93
93
  /**
94
94
  * @typedef {object} PouchDBChanges
95
- * @param {string} id - The doc id
96
- * @param {boolean} deleted - Whether or not the change is a deleted doc
97
- * @param {Array<object>} changes - The list of changes revisions
98
- * @param {object} doc - The changed doc
95
+ * @property {string} id - The doc id
96
+ * @property {boolean} deleted - Whether or not the change is a deleted doc
97
+ * @property {Array<object>} changes - The list of changes revisions
98
+ * @property {object} doc - The changed doc
99
99
  */
100
100
  var _default = {};
101
101
  exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-pouch-link",
3
- "version": "49.6.1",
3
+ "version": "49.7.1",
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": "^49.6.0",
16
+ "cozy-client": "^49.7.1",
17
17
  "pouchdb-browser": "^7.2.2",
18
18
  "pouchdb-find": "^7.2.2"
19
19
  },
@@ -39,5 +39,5 @@
39
39
  "typecheck": "tsc -p tsconfig.json"
40
40
  },
41
41
  "sideEffects": false,
42
- "gitHead": "b4ca0cc319d1aacb9d1e286a13240055d1ab68d3"
42
+ "gitHead": "0cb890e76b0cf5e17c698d84d20248486baed312"
43
43
  }
@@ -5,7 +5,15 @@ export type CozyClientDocument = any;
5
5
  export type ReplicationStatus = "idle" | "replicating";
6
6
  export type PouchLinkOptions = {
7
7
  /**
8
- * Milliseconds between replications
8
+ * Whether or not a replication process should be started. Default is false
9
+ */
10
+ initialSync: boolean;
11
+ /**
12
+ * Whether or not the replication should be periodic. Default is true
13
+ */
14
+ periodicSync: boolean;
15
+ /**
16
+ * Milliseconds between periodic replications
9
17
  */
10
18
  replicationInterval?: number;
11
19
  /**
@@ -28,7 +36,9 @@ export type PouchLinkOptions = {
28
36
  */
29
37
  /**
30
38
  * @typedef {object} PouchLinkOptions
31
- * @property {number} [replicationInterval] Milliseconds between replications
39
+ * @property {boolean} initialSync Whether or not a replication process should be started. Default is false
40
+ * @property {boolean} periodicSync Whether or not the replication should be periodic. Default is true
41
+ * @property {number} [replicationInterval] Milliseconds between periodic replications
32
42
  * @property {string[]} doctypes Doctypes to replicate
33
43
  * @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")
34
44
  * @property {import('./types').LinkPlatform} platform Platform specific adapters and methods
@@ -60,6 +70,8 @@ declare class PouchLink extends CozyLink {
60
70
  doctypesReplicationOptions: Record<string, any>;
61
71
  indexes: {};
62
72
  storage: PouchLocalStorage;
73
+ initialSync: boolean;
74
+ periodicSync: boolean;
63
75
  /** @type {Record<string, ReplicationStatus>} - Stores replication states per doctype */
64
76
  replicationStatus: Record<string, ReplicationStatus>;
65
77
  getReplicationURL(doctype: any): string;
package/types/types.d.ts CHANGED
@@ -102,6 +102,45 @@ export type PouchDbIndex = {
102
102
  */
103
103
  result: 'exists' | 'created';
104
104
  };
105
- export type PouchDBInfo = any;
106
- export type PouchDBChangesResults = any;
107
- export type PouchDBChanges = any;
105
+ export type PouchDBInfo = {
106
+ /**
107
+ * - The database name
108
+ */
109
+ db_name: string;
110
+ /**
111
+ * - The number of doc in the database
112
+ */
113
+ doc_count: number;
114
+ /**
115
+ * - The sequence number
116
+ */
117
+ update_seq: number;
118
+ };
119
+ export type PouchDBChangesResults = {
120
+ /**
121
+ * - The changes results
122
+ */
123
+ results: Array<PouchDBChanges>;
124
+ /**
125
+ * - The last sequence number
126
+ */
127
+ last_seq: number;
128
+ };
129
+ export type PouchDBChanges = {
130
+ /**
131
+ * - The doc id
132
+ */
133
+ id: string;
134
+ /**
135
+ * - Whether or not the change is a deleted doc
136
+ */
137
+ deleted: boolean;
138
+ /**
139
+ * - The list of changes revisions
140
+ */
141
+ changes: Array<object>;
142
+ /**
143
+ * - The changed doc
144
+ */
145
+ doc: object;
146
+ };