mocody 0.8.1 → 0.8.3
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/index.cjs +113 -24
- package/dist/index.d.cts +25 -3
- package/dist/index.d.ts +25 -3
- package/dist/index.js +112 -23
- package/package.json +10 -4
package/dist/index.cjs
CHANGED
|
@@ -3750,12 +3750,12 @@ var MocodyInitializerCouch = class {
|
|
|
3750
3750
|
this.baseConfig = baseConfig;
|
|
3751
3751
|
}
|
|
3752
3752
|
async deleteIndex({ ddoc, name }) {
|
|
3753
|
-
const
|
|
3753
|
+
const path2 = ["_index", ddoc, "json", name].join("/");
|
|
3754
3754
|
const instance = await this.getInstance();
|
|
3755
3755
|
const result = await instance.relax({
|
|
3756
3756
|
db: this.baseConfig.couchConfig.databaseName,
|
|
3757
3757
|
method: "DELETE",
|
|
3758
|
-
path,
|
|
3758
|
+
path: path2,
|
|
3759
3759
|
content_type: "application/json"
|
|
3760
3760
|
});
|
|
3761
3761
|
return result;
|
|
@@ -5959,8 +5959,12 @@ var MongoDataOperation = class extends RepoModel {
|
|
|
5959
5959
|
|
|
5960
5960
|
// src/pouch/pouch-initializer.ts
|
|
5961
5961
|
var import_throat4 = __toESM(require("throat"), 1);
|
|
5962
|
-
var
|
|
5962
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
5963
|
+
var import_pouchdb_core = __toESM(require("pouchdb-core"), 1);
|
|
5963
5964
|
var import_pouchdb_find = __toESM(require("pouchdb-find"), 1);
|
|
5965
|
+
var import_pouchdb_adapter_http = __toESM(require("pouchdb-adapter-http"), 1);
|
|
5966
|
+
var import_pouchdb_mapreduce = __toESM(require("pouchdb-mapreduce"), 1);
|
|
5967
|
+
var import_pouchdb_replication = __toESM(require("pouchdb-replication"), 1);
|
|
5964
5968
|
var concurrency4 = (0, import_throat4.default)(1);
|
|
5965
5969
|
var MocodyInitializerPouch = class {
|
|
5966
5970
|
_pouchInstance;
|
|
@@ -6094,30 +6098,68 @@ var MocodyInitializerPouch = class {
|
|
|
6094
6098
|
async pouch_getDbInstance() {
|
|
6095
6099
|
return await concurrency4(() => this.pouch_getDbInstanceBase());
|
|
6096
6100
|
}
|
|
6101
|
+
getPouchWithPlugins() {
|
|
6102
|
+
return import_pouchdb_core.default.plugin(import_pouchdb_adapter_http.default).plugin(import_pouchdb_mapreduce.default).plugin(import_pouchdb_replication.default).plugin(import_pouchdb_find.default);
|
|
6103
|
+
}
|
|
6104
|
+
createRemoteDB({
|
|
6105
|
+
proxyAuthToken,
|
|
6106
|
+
remoteConnectionUrl
|
|
6107
|
+
}) {
|
|
6108
|
+
const PouchDB = this.getPouchWithPlugins();
|
|
6109
|
+
return new PouchDB(remoteConnectionUrl, {
|
|
6110
|
+
fetch: (url, opts) => {
|
|
6111
|
+
const headers = new Headers(opts?.headers);
|
|
6112
|
+
if (proxyAuthToken) {
|
|
6113
|
+
headers.set("Authorization", `Bearer ${proxyAuthToken}`);
|
|
6114
|
+
}
|
|
6115
|
+
return PouchDB.fetch(url, {
|
|
6116
|
+
...opts,
|
|
6117
|
+
headers,
|
|
6118
|
+
credentials: "omit"
|
|
6119
|
+
});
|
|
6120
|
+
}
|
|
6121
|
+
});
|
|
6122
|
+
}
|
|
6097
6123
|
async pouch_getDbInstanceBase() {
|
|
6098
6124
|
if (this._pouchInstance) return this._pouchInstance;
|
|
6099
6125
|
const {
|
|
6100
6126
|
//
|
|
6101
|
-
liveSync,
|
|
6102
6127
|
indexes,
|
|
6103
6128
|
connType,
|
|
6104
|
-
|
|
6105
|
-
|
|
6129
|
+
localSqliteDbConfig,
|
|
6130
|
+
remoteConnectionConfig,
|
|
6131
|
+
syncConfig
|
|
6106
6132
|
} = this.baseConfig;
|
|
6107
6133
|
const isLocalFirst = connType === "LOCAL_FIRST";
|
|
6108
6134
|
const isRemoteFirst = connType === "REMOTE_FIRST";
|
|
6135
|
+
const remoteConnectionUrl = (() => {
|
|
6136
|
+
const connUrl = remoteConnectionConfig?.connectionUrl;
|
|
6137
|
+
if (!connUrl) return void 0;
|
|
6138
|
+
return connUrl;
|
|
6139
|
+
})();
|
|
6140
|
+
const localSqliteDbFilePath = (() => {
|
|
6141
|
+
const dbName01 = localSqliteDbConfig?.fileName;
|
|
6142
|
+
const fileExtension01 = localSqliteDbConfig?.fileExt || ".sqlite";
|
|
6143
|
+
if (!localSqliteDbConfig?.folderFullPath) return void 0;
|
|
6144
|
+
if (!localSqliteDbConfig?.fileExt) return void 0;
|
|
6145
|
+
if (!dbName01) return void 0;
|
|
6146
|
+
const fileName = `${dbName01}${fileExtension01}`;
|
|
6147
|
+
return import_node_path.default.join(localSqliteDbConfig.folderFullPath, fileName);
|
|
6148
|
+
})();
|
|
6109
6149
|
if (isLocalFirst) {
|
|
6110
6150
|
if (!localSqliteDbFilePath) {
|
|
6111
6151
|
throw new MocodyGenericError("localSqliteDbFilePath not defined");
|
|
6112
6152
|
}
|
|
6113
|
-
|
|
6114
|
-
this._pouchInstance = new
|
|
6153
|
+
const PouchDB = this.getPouchWithPlugins();
|
|
6154
|
+
this._pouchInstance = new PouchDB(localSqliteDbFilePath, { adapter: "nodesqlite" });
|
|
6115
6155
|
} else {
|
|
6116
6156
|
if (!remoteConnectionUrl) {
|
|
6117
6157
|
throw new MocodyGenericError("couchRemoteConnectionUrl not defined");
|
|
6118
6158
|
}
|
|
6119
|
-
|
|
6120
|
-
|
|
6159
|
+
this._pouchInstance = this.createRemoteDB({
|
|
6160
|
+
remoteConnectionUrl,
|
|
6161
|
+
proxyAuthToken: remoteConnectionConfig?.proxyAuthToken
|
|
6162
|
+
});
|
|
6121
6163
|
}
|
|
6122
6164
|
try {
|
|
6123
6165
|
if (indexes?.length) {
|
|
@@ -6128,38 +6170,85 @@ var MocodyInitializerPouch = class {
|
|
|
6128
6170
|
} catch (error) {
|
|
6129
6171
|
LoggingService.error(error);
|
|
6130
6172
|
}
|
|
6173
|
+
const filterSelector01 = syncConfig?.filterSelector || void 0;
|
|
6174
|
+
const heartbeat01 = syncConfig?.heartbeat || 2e4;
|
|
6175
|
+
const batchSize01 = syncConfig?.batchSize || 100;
|
|
6176
|
+
const backoffDelaySeconds01 = syncConfig?.backoffDelayInSeconds || 4e4;
|
|
6177
|
+
if (syncConfig?.isSyncFilterSelectorRequired && !filterSelector01) {
|
|
6178
|
+
throw new MocodyGenericError("filterSelector not defined");
|
|
6179
|
+
}
|
|
6131
6180
|
if (isLocalFirst && remoteConnectionUrl) {
|
|
6132
|
-
if (
|
|
6181
|
+
if (syncConfig?.isLiveSync) {
|
|
6133
6182
|
this._pouchInstance.sync(remoteConnectionUrl, {
|
|
6134
6183
|
live: true,
|
|
6135
|
-
retry: true
|
|
6184
|
+
retry: true,
|
|
6185
|
+
batch_size: batchSize01,
|
|
6186
|
+
heartbeat: heartbeat01,
|
|
6187
|
+
timeout: heartbeat01 * 2,
|
|
6188
|
+
selector: filterSelector01,
|
|
6189
|
+
back_off_function: (delay) => {
|
|
6190
|
+
if (delay === 0) return 2e3;
|
|
6191
|
+
return Math.min(delay * 2, backoffDelaySeconds01);
|
|
6192
|
+
}
|
|
6136
6193
|
}).on("change", (change) => {
|
|
6137
|
-
LoggingService.log({
|
|
6194
|
+
LoggingService.log({ pouch_replication_change: change });
|
|
6138
6195
|
}).on("paused", (info) => {
|
|
6139
|
-
LoggingService.log({
|
|
6196
|
+
LoggingService.log({ pouch_replication_paused: info });
|
|
6140
6197
|
}).on("error", (err) => {
|
|
6141
|
-
LoggingService.log({
|
|
6198
|
+
LoggingService.log({ pouch_replication_error: err });
|
|
6199
|
+
}).on("active", () => {
|
|
6200
|
+
LoggingService.log(`Pouch:::Connection active`);
|
|
6201
|
+
}).on("denied", (err) => {
|
|
6202
|
+
LoggingService.log(`Pouch:::Connection denied`);
|
|
6142
6203
|
});
|
|
6143
6204
|
} else {
|
|
6144
|
-
this._pouchInstance.sync(remoteConnectionUrl).on("
|
|
6145
|
-
LoggingService.log({
|
|
6205
|
+
this._pouchInstance.sync(remoteConnectionUrl, { selector: filterSelector01 }).on("change", (change) => {
|
|
6206
|
+
LoggingService.log({ pouch_replication_change: change });
|
|
6207
|
+
}).on("paused", (info) => {
|
|
6208
|
+
LoggingService.log({ pouch_replication_paused: info });
|
|
6209
|
+
}).on("error", (err) => {
|
|
6210
|
+
LoggingService.log({ pouch_replication_error: err });
|
|
6211
|
+
}).on("active", () => {
|
|
6212
|
+
LoggingService.log(`Pouch:::Connection active`);
|
|
6213
|
+
}).on("denied", (err) => {
|
|
6214
|
+
LoggingService.log(`Pouch:::Connection denied`);
|
|
6146
6215
|
});
|
|
6147
6216
|
}
|
|
6148
6217
|
} else if (isRemoteFirst && localSqliteDbFilePath) {
|
|
6149
|
-
if (
|
|
6218
|
+
if (syncConfig?.isLiveSync) {
|
|
6150
6219
|
this._pouchInstance.sync(localSqliteDbFilePath, {
|
|
6151
6220
|
live: true,
|
|
6152
|
-
retry: true
|
|
6221
|
+
retry: true,
|
|
6222
|
+
batch_size: batchSize01,
|
|
6223
|
+
heartbeat: heartbeat01,
|
|
6224
|
+
timeout: heartbeat01 * 2,
|
|
6225
|
+
selector: filterSelector01,
|
|
6226
|
+
back_off_function: (delay) => {
|
|
6227
|
+
if (delay === 0) return 2e3;
|
|
6228
|
+
return Math.min(delay * 2, backoffDelaySeconds01);
|
|
6229
|
+
}
|
|
6153
6230
|
}).on("change", (change) => {
|
|
6154
|
-
LoggingService.log({
|
|
6231
|
+
LoggingService.log({ pouch_replication_change: change });
|
|
6155
6232
|
}).on("paused", (info) => {
|
|
6156
|
-
LoggingService.log({
|
|
6233
|
+
LoggingService.log({ pouch_replication_paused: info });
|
|
6157
6234
|
}).on("error", (err) => {
|
|
6158
|
-
LoggingService.log({
|
|
6235
|
+
LoggingService.log({ pouch_replication_error: err });
|
|
6236
|
+
}).on("active", () => {
|
|
6237
|
+
LoggingService.log(`Pouch:::Connection active`);
|
|
6238
|
+
}).on("denied", (err) => {
|
|
6239
|
+
LoggingService.log(`Pouch:::Connection denied`);
|
|
6159
6240
|
});
|
|
6160
6241
|
} else {
|
|
6161
|
-
this._pouchInstance.sync(localSqliteDbFilePath).on("
|
|
6162
|
-
LoggingService.log({
|
|
6242
|
+
this._pouchInstance.sync(localSqliteDbFilePath, { selector: filterSelector01 }).on("change", (change) => {
|
|
6243
|
+
LoggingService.log({ pouch_replication_change: change });
|
|
6244
|
+
}).on("paused", (info) => {
|
|
6245
|
+
LoggingService.log({ pouch_replication_paused: info });
|
|
6246
|
+
}).on("error", (err) => {
|
|
6247
|
+
LoggingService.log({ pouch_replication_error: err });
|
|
6248
|
+
}).on("active", () => {
|
|
6249
|
+
LoggingService.log(`Pouch:::Connection active`);
|
|
6250
|
+
}).on("denied", () => {
|
|
6251
|
+
LoggingService.log(`Pouch:::Connection denied`);
|
|
6163
6252
|
});
|
|
6164
6253
|
}
|
|
6165
6254
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -735,9 +735,29 @@ type IFindOptions = {
|
|
|
735
735
|
};
|
|
736
736
|
type IOptions$1 = {
|
|
737
737
|
connType: "LOCAL_FIRST" | "REMOTE_FIRST";
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
738
|
+
localSqliteDbConfig?: {
|
|
739
|
+
fileName: string;
|
|
740
|
+
folderFullPath: string;
|
|
741
|
+
fileExt?: ".sqlite" | ".db";
|
|
742
|
+
};
|
|
743
|
+
remoteConnectionConfig?: {
|
|
744
|
+
connectionUrl: string;
|
|
745
|
+
databaseName?: string;
|
|
746
|
+
proxyAuthToken?: string;
|
|
747
|
+
isProxy?: boolean;
|
|
748
|
+
};
|
|
749
|
+
syncConfig?: {
|
|
750
|
+
isLiveSync?: boolean;
|
|
751
|
+
backoffDelayInSeconds?: number;
|
|
752
|
+
heartbeat?: number;
|
|
753
|
+
batchSize?: number;
|
|
754
|
+
filterSelector?: {
|
|
755
|
+
[field: string]: {
|
|
756
|
+
$eq: string;
|
|
757
|
+
};
|
|
758
|
+
};
|
|
759
|
+
isSyncFilterSelectorRequired: boolean;
|
|
760
|
+
};
|
|
741
761
|
indexes?: {
|
|
742
762
|
indexName: string;
|
|
743
763
|
fields: string[];
|
|
@@ -795,6 +815,8 @@ declare class MocodyInitializerPouch<T extends IMocodyCoreEntityModel> {
|
|
|
795
815
|
nativeId: string;
|
|
796
816
|
}): Promise<PouchDB.Core.Response>;
|
|
797
817
|
pouch_getDbInstance(): Promise<PouchDB.Database<T>>;
|
|
818
|
+
private getPouchWithPlugins;
|
|
819
|
+
private createRemoteDB;
|
|
798
820
|
private pouch_getDbInstanceBase;
|
|
799
821
|
private toBasicDoc_RemovePouchMeta;
|
|
800
822
|
private docMetaFieldsObject;
|
package/dist/index.d.ts
CHANGED
|
@@ -735,9 +735,29 @@ type IFindOptions = {
|
|
|
735
735
|
};
|
|
736
736
|
type IOptions$1 = {
|
|
737
737
|
connType: "LOCAL_FIRST" | "REMOTE_FIRST";
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
738
|
+
localSqliteDbConfig?: {
|
|
739
|
+
fileName: string;
|
|
740
|
+
folderFullPath: string;
|
|
741
|
+
fileExt?: ".sqlite" | ".db";
|
|
742
|
+
};
|
|
743
|
+
remoteConnectionConfig?: {
|
|
744
|
+
connectionUrl: string;
|
|
745
|
+
databaseName?: string;
|
|
746
|
+
proxyAuthToken?: string;
|
|
747
|
+
isProxy?: boolean;
|
|
748
|
+
};
|
|
749
|
+
syncConfig?: {
|
|
750
|
+
isLiveSync?: boolean;
|
|
751
|
+
backoffDelayInSeconds?: number;
|
|
752
|
+
heartbeat?: number;
|
|
753
|
+
batchSize?: number;
|
|
754
|
+
filterSelector?: {
|
|
755
|
+
[field: string]: {
|
|
756
|
+
$eq: string;
|
|
757
|
+
};
|
|
758
|
+
};
|
|
759
|
+
isSyncFilterSelectorRequired: boolean;
|
|
760
|
+
};
|
|
741
761
|
indexes?: {
|
|
742
762
|
indexName: string;
|
|
743
763
|
fields: string[];
|
|
@@ -795,6 +815,8 @@ declare class MocodyInitializerPouch<T extends IMocodyCoreEntityModel> {
|
|
|
795
815
|
nativeId: string;
|
|
796
816
|
}): Promise<PouchDB.Core.Response>;
|
|
797
817
|
pouch_getDbInstance(): Promise<PouchDB.Database<T>>;
|
|
818
|
+
private getPouchWithPlugins;
|
|
819
|
+
private createRemoteDB;
|
|
798
820
|
private pouch_getDbInstanceBase;
|
|
799
821
|
private toBasicDoc_RemovePouchMeta;
|
|
800
822
|
private docMetaFieldsObject;
|
package/dist/index.js
CHANGED
|
@@ -3720,12 +3720,12 @@ var MocodyInitializerCouch = class {
|
|
|
3720
3720
|
this.baseConfig = baseConfig;
|
|
3721
3721
|
}
|
|
3722
3722
|
async deleteIndex({ ddoc, name }) {
|
|
3723
|
-
const
|
|
3723
|
+
const path2 = ["_index", ddoc, "json", name].join("/");
|
|
3724
3724
|
const instance = await this.getInstance();
|
|
3725
3725
|
const result = await instance.relax({
|
|
3726
3726
|
db: this.baseConfig.couchConfig.databaseName,
|
|
3727
3727
|
method: "DELETE",
|
|
3728
|
-
path,
|
|
3728
|
+
path: path2,
|
|
3729
3729
|
content_type: "application/json"
|
|
3730
3730
|
});
|
|
3731
3731
|
return result;
|
|
@@ -5929,8 +5929,12 @@ var MongoDataOperation = class extends RepoModel {
|
|
|
5929
5929
|
|
|
5930
5930
|
// src/pouch/pouch-initializer.ts
|
|
5931
5931
|
import throat4 from "throat";
|
|
5932
|
-
import
|
|
5932
|
+
import path from "path";
|
|
5933
|
+
import PouchDB00 from "pouchdb-core";
|
|
5933
5934
|
import pouchdbFind from "pouchdb-find";
|
|
5935
|
+
import pouchdbhttp from "pouchdb-adapter-http";
|
|
5936
|
+
import pouchdbmapreduce from "pouchdb-mapreduce";
|
|
5937
|
+
import pouchdbreplication from "pouchdb-replication";
|
|
5934
5938
|
var concurrency4 = throat4(1);
|
|
5935
5939
|
var MocodyInitializerPouch = class {
|
|
5936
5940
|
_pouchInstance;
|
|
@@ -6064,30 +6068,68 @@ var MocodyInitializerPouch = class {
|
|
|
6064
6068
|
async pouch_getDbInstance() {
|
|
6065
6069
|
return await concurrency4(() => this.pouch_getDbInstanceBase());
|
|
6066
6070
|
}
|
|
6071
|
+
getPouchWithPlugins() {
|
|
6072
|
+
return PouchDB00.plugin(pouchdbhttp).plugin(pouchdbmapreduce).plugin(pouchdbreplication).plugin(pouchdbFind);
|
|
6073
|
+
}
|
|
6074
|
+
createRemoteDB({
|
|
6075
|
+
proxyAuthToken,
|
|
6076
|
+
remoteConnectionUrl
|
|
6077
|
+
}) {
|
|
6078
|
+
const PouchDB = this.getPouchWithPlugins();
|
|
6079
|
+
return new PouchDB(remoteConnectionUrl, {
|
|
6080
|
+
fetch: (url, opts) => {
|
|
6081
|
+
const headers = new Headers(opts?.headers);
|
|
6082
|
+
if (proxyAuthToken) {
|
|
6083
|
+
headers.set("Authorization", `Bearer ${proxyAuthToken}`);
|
|
6084
|
+
}
|
|
6085
|
+
return PouchDB.fetch(url, {
|
|
6086
|
+
...opts,
|
|
6087
|
+
headers,
|
|
6088
|
+
credentials: "omit"
|
|
6089
|
+
});
|
|
6090
|
+
}
|
|
6091
|
+
});
|
|
6092
|
+
}
|
|
6067
6093
|
async pouch_getDbInstanceBase() {
|
|
6068
6094
|
if (this._pouchInstance) return this._pouchInstance;
|
|
6069
6095
|
const {
|
|
6070
6096
|
//
|
|
6071
|
-
liveSync,
|
|
6072
6097
|
indexes,
|
|
6073
6098
|
connType,
|
|
6074
|
-
|
|
6075
|
-
|
|
6099
|
+
localSqliteDbConfig,
|
|
6100
|
+
remoteConnectionConfig,
|
|
6101
|
+
syncConfig
|
|
6076
6102
|
} = this.baseConfig;
|
|
6077
6103
|
const isLocalFirst = connType === "LOCAL_FIRST";
|
|
6078
6104
|
const isRemoteFirst = connType === "REMOTE_FIRST";
|
|
6105
|
+
const remoteConnectionUrl = (() => {
|
|
6106
|
+
const connUrl = remoteConnectionConfig?.connectionUrl;
|
|
6107
|
+
if (!connUrl) return void 0;
|
|
6108
|
+
return connUrl;
|
|
6109
|
+
})();
|
|
6110
|
+
const localSqliteDbFilePath = (() => {
|
|
6111
|
+
const dbName01 = localSqliteDbConfig?.fileName;
|
|
6112
|
+
const fileExtension01 = localSqliteDbConfig?.fileExt || ".sqlite";
|
|
6113
|
+
if (!localSqliteDbConfig?.folderFullPath) return void 0;
|
|
6114
|
+
if (!localSqliteDbConfig?.fileExt) return void 0;
|
|
6115
|
+
if (!dbName01) return void 0;
|
|
6116
|
+
const fileName = `${dbName01}${fileExtension01}`;
|
|
6117
|
+
return path.join(localSqliteDbConfig.folderFullPath, fileName);
|
|
6118
|
+
})();
|
|
6079
6119
|
if (isLocalFirst) {
|
|
6080
6120
|
if (!localSqliteDbFilePath) {
|
|
6081
6121
|
throw new MocodyGenericError("localSqliteDbFilePath not defined");
|
|
6082
6122
|
}
|
|
6083
|
-
PouchDB.
|
|
6123
|
+
const PouchDB = this.getPouchWithPlugins();
|
|
6084
6124
|
this._pouchInstance = new PouchDB(localSqliteDbFilePath, { adapter: "nodesqlite" });
|
|
6085
6125
|
} else {
|
|
6086
6126
|
if (!remoteConnectionUrl) {
|
|
6087
6127
|
throw new MocodyGenericError("couchRemoteConnectionUrl not defined");
|
|
6088
6128
|
}
|
|
6089
|
-
|
|
6090
|
-
|
|
6129
|
+
this._pouchInstance = this.createRemoteDB({
|
|
6130
|
+
remoteConnectionUrl,
|
|
6131
|
+
proxyAuthToken: remoteConnectionConfig?.proxyAuthToken
|
|
6132
|
+
});
|
|
6091
6133
|
}
|
|
6092
6134
|
try {
|
|
6093
6135
|
if (indexes?.length) {
|
|
@@ -6098,38 +6140,85 @@ var MocodyInitializerPouch = class {
|
|
|
6098
6140
|
} catch (error) {
|
|
6099
6141
|
LoggingService.error(error);
|
|
6100
6142
|
}
|
|
6143
|
+
const filterSelector01 = syncConfig?.filterSelector || void 0;
|
|
6144
|
+
const heartbeat01 = syncConfig?.heartbeat || 2e4;
|
|
6145
|
+
const batchSize01 = syncConfig?.batchSize || 100;
|
|
6146
|
+
const backoffDelaySeconds01 = syncConfig?.backoffDelayInSeconds || 4e4;
|
|
6147
|
+
if (syncConfig?.isSyncFilterSelectorRequired && !filterSelector01) {
|
|
6148
|
+
throw new MocodyGenericError("filterSelector not defined");
|
|
6149
|
+
}
|
|
6101
6150
|
if (isLocalFirst && remoteConnectionUrl) {
|
|
6102
|
-
if (
|
|
6151
|
+
if (syncConfig?.isLiveSync) {
|
|
6103
6152
|
this._pouchInstance.sync(remoteConnectionUrl, {
|
|
6104
6153
|
live: true,
|
|
6105
|
-
retry: true
|
|
6154
|
+
retry: true,
|
|
6155
|
+
batch_size: batchSize01,
|
|
6156
|
+
heartbeat: heartbeat01,
|
|
6157
|
+
timeout: heartbeat01 * 2,
|
|
6158
|
+
selector: filterSelector01,
|
|
6159
|
+
back_off_function: (delay) => {
|
|
6160
|
+
if (delay === 0) return 2e3;
|
|
6161
|
+
return Math.min(delay * 2, backoffDelaySeconds01);
|
|
6162
|
+
}
|
|
6106
6163
|
}).on("change", (change) => {
|
|
6107
|
-
LoggingService.log({
|
|
6164
|
+
LoggingService.log({ pouch_replication_change: change });
|
|
6108
6165
|
}).on("paused", (info) => {
|
|
6109
|
-
LoggingService.log({
|
|
6166
|
+
LoggingService.log({ pouch_replication_paused: info });
|
|
6110
6167
|
}).on("error", (err) => {
|
|
6111
|
-
LoggingService.log({
|
|
6168
|
+
LoggingService.log({ pouch_replication_error: err });
|
|
6169
|
+
}).on("active", () => {
|
|
6170
|
+
LoggingService.log(`Pouch:::Connection active`);
|
|
6171
|
+
}).on("denied", (err) => {
|
|
6172
|
+
LoggingService.log(`Pouch:::Connection denied`);
|
|
6112
6173
|
});
|
|
6113
6174
|
} else {
|
|
6114
|
-
this._pouchInstance.sync(remoteConnectionUrl).on("
|
|
6115
|
-
LoggingService.log({
|
|
6175
|
+
this._pouchInstance.sync(remoteConnectionUrl, { selector: filterSelector01 }).on("change", (change) => {
|
|
6176
|
+
LoggingService.log({ pouch_replication_change: change });
|
|
6177
|
+
}).on("paused", (info) => {
|
|
6178
|
+
LoggingService.log({ pouch_replication_paused: info });
|
|
6179
|
+
}).on("error", (err) => {
|
|
6180
|
+
LoggingService.log({ pouch_replication_error: err });
|
|
6181
|
+
}).on("active", () => {
|
|
6182
|
+
LoggingService.log(`Pouch:::Connection active`);
|
|
6183
|
+
}).on("denied", (err) => {
|
|
6184
|
+
LoggingService.log(`Pouch:::Connection denied`);
|
|
6116
6185
|
});
|
|
6117
6186
|
}
|
|
6118
6187
|
} else if (isRemoteFirst && localSqliteDbFilePath) {
|
|
6119
|
-
if (
|
|
6188
|
+
if (syncConfig?.isLiveSync) {
|
|
6120
6189
|
this._pouchInstance.sync(localSqliteDbFilePath, {
|
|
6121
6190
|
live: true,
|
|
6122
|
-
retry: true
|
|
6191
|
+
retry: true,
|
|
6192
|
+
batch_size: batchSize01,
|
|
6193
|
+
heartbeat: heartbeat01,
|
|
6194
|
+
timeout: heartbeat01 * 2,
|
|
6195
|
+
selector: filterSelector01,
|
|
6196
|
+
back_off_function: (delay) => {
|
|
6197
|
+
if (delay === 0) return 2e3;
|
|
6198
|
+
return Math.min(delay * 2, backoffDelaySeconds01);
|
|
6199
|
+
}
|
|
6123
6200
|
}).on("change", (change) => {
|
|
6124
|
-
LoggingService.log({
|
|
6201
|
+
LoggingService.log({ pouch_replication_change: change });
|
|
6125
6202
|
}).on("paused", (info) => {
|
|
6126
|
-
LoggingService.log({
|
|
6203
|
+
LoggingService.log({ pouch_replication_paused: info });
|
|
6127
6204
|
}).on("error", (err) => {
|
|
6128
|
-
LoggingService.log({
|
|
6205
|
+
LoggingService.log({ pouch_replication_error: err });
|
|
6206
|
+
}).on("active", () => {
|
|
6207
|
+
LoggingService.log(`Pouch:::Connection active`);
|
|
6208
|
+
}).on("denied", (err) => {
|
|
6209
|
+
LoggingService.log(`Pouch:::Connection denied`);
|
|
6129
6210
|
});
|
|
6130
6211
|
} else {
|
|
6131
|
-
this._pouchInstance.sync(localSqliteDbFilePath).on("
|
|
6132
|
-
LoggingService.log({
|
|
6212
|
+
this._pouchInstance.sync(localSqliteDbFilePath, { selector: filterSelector01 }).on("change", (change) => {
|
|
6213
|
+
LoggingService.log({ pouch_replication_change: change });
|
|
6214
|
+
}).on("paused", (info) => {
|
|
6215
|
+
LoggingService.log({ pouch_replication_paused: info });
|
|
6216
|
+
}).on("error", (err) => {
|
|
6217
|
+
LoggingService.log({ pouch_replication_error: err });
|
|
6218
|
+
}).on("active", () => {
|
|
6219
|
+
LoggingService.log(`Pouch:::Connection active`);
|
|
6220
|
+
}).on("denied", () => {
|
|
6221
|
+
LoggingService.log(`Pouch:::Connection denied`);
|
|
6133
6222
|
});
|
|
6134
6223
|
}
|
|
6135
6224
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mocody",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.3",
|
|
4
4
|
"description": "Implementation of single table design, and unified query access for MongoDB, CouchDB, and dynamoDB",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"dist"
|
|
56
56
|
],
|
|
57
57
|
"engines": {
|
|
58
|
-
"node": ">=26"
|
|
58
|
+
"node": ">= 26"
|
|
59
59
|
},
|
|
60
60
|
"tsup": {
|
|
61
61
|
"entry": [
|
|
@@ -78,15 +78,21 @@
|
|
|
78
78
|
"mongodb": "7.7.0",
|
|
79
79
|
"nano": "11.0.7",
|
|
80
80
|
"nanoid": "6.0.2",
|
|
81
|
-
"pouchdb": "9.0.0",
|
|
81
|
+
"pouchdb-adapter-http": "^9.0.0",
|
|
82
|
+
"pouchdb-core": "^9.0.0",
|
|
82
83
|
"pouchdb-find": "9.0.0",
|
|
84
|
+
"pouchdb-mapreduce": "^9.0.0",
|
|
85
|
+
"pouchdb-replication": "^9.0.0",
|
|
83
86
|
"throat": "6.0.2"
|
|
84
87
|
},
|
|
85
88
|
"devDependencies": {
|
|
86
89
|
"@eslint/js": "^10.0.1",
|
|
87
90
|
"@types/node": "^26",
|
|
88
|
-
"@types/pouchdb": "^6.
|
|
91
|
+
"@types/pouchdb-adapter-http": "^6.1.6",
|
|
92
|
+
"@types/pouchdb-core": "^7.0.15",
|
|
89
93
|
"@types/pouchdb-find": "^7.3.3",
|
|
94
|
+
"@types/pouchdb-mapreduce": "^6.1.10",
|
|
95
|
+
"@types/pouchdb-replication": "^6.4.7",
|
|
90
96
|
"@typescript-eslint/eslint-plugin": "^8.71.1",
|
|
91
97
|
"@typescript-eslint/parser": "^8.71.1",
|
|
92
98
|
"eslint": "^10.12.0",
|