mocody 0.8.2 → 0.8.4
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 +118 -22
- package/dist/index.d.cts +25 -3
- package/dist/index.d.ts +25 -3
- package/dist/index.js +118 -22
- package/package.json +2 -2
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,6 +5959,7 @@ 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 import_node_path = __toESM(require("path"), 1);
|
|
5962
5963
|
var import_pouchdb_core = __toESM(require("pouchdb-core"), 1);
|
|
5963
5964
|
var import_pouchdb_find = __toESM(require("pouchdb-find"), 1);
|
|
5964
5965
|
var import_pouchdb_adapter_http = __toESM(require("pouchdb-adapter-http"), 1);
|
|
@@ -5969,6 +5970,7 @@ var MocodyInitializerPouch = class {
|
|
|
5969
5970
|
_pouchInstance;
|
|
5970
5971
|
_docMetaFieldsObJ = this.docMetaFieldsObject();
|
|
5971
5972
|
baseConfig;
|
|
5973
|
+
pouchWithPlugins = null;
|
|
5972
5974
|
constructor(baseConfig) {
|
|
5973
5975
|
this.baseConfig = baseConfig;
|
|
5974
5976
|
}
|
|
@@ -6097,21 +6099,66 @@ var MocodyInitializerPouch = class {
|
|
|
6097
6099
|
async pouch_getDbInstance() {
|
|
6098
6100
|
return await concurrency4(() => this.pouch_getDbInstanceBase());
|
|
6099
6101
|
}
|
|
6102
|
+
// private getPouchWithPlugins() {
|
|
6103
|
+
// return (
|
|
6104
|
+
// PouchDB00.plugin(pouchdbhttp)
|
|
6105
|
+
// //
|
|
6106
|
+
// .plugin(pouchdbmapreduce)
|
|
6107
|
+
// .plugin(pouchdbreplication)
|
|
6108
|
+
// .plugin(pouchdbFind)
|
|
6109
|
+
// );
|
|
6110
|
+
// }
|
|
6100
6111
|
getPouchWithPlugins() {
|
|
6101
|
-
|
|
6112
|
+
if (!this.pouchWithPlugins) {
|
|
6113
|
+
this.pouchWithPlugins = 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);
|
|
6114
|
+
}
|
|
6115
|
+
return this.pouchWithPlugins;
|
|
6116
|
+
}
|
|
6117
|
+
createRemoteDB({
|
|
6118
|
+
proxyAuthToken,
|
|
6119
|
+
remoteConnectionUrl
|
|
6120
|
+
}) {
|
|
6121
|
+
const PouchDB = this.getPouchWithPlugins();
|
|
6122
|
+
return new PouchDB(remoteConnectionUrl, {
|
|
6123
|
+
fetch: (url, opts) => {
|
|
6124
|
+
const headers = new Headers(opts?.headers);
|
|
6125
|
+
if (proxyAuthToken) {
|
|
6126
|
+
headers.set("Authorization", `Bearer ${proxyAuthToken}`);
|
|
6127
|
+
}
|
|
6128
|
+
return PouchDB.fetch(url, {
|
|
6129
|
+
...opts,
|
|
6130
|
+
headers,
|
|
6131
|
+
credentials: "omit"
|
|
6132
|
+
});
|
|
6133
|
+
}
|
|
6134
|
+
});
|
|
6102
6135
|
}
|
|
6103
6136
|
async pouch_getDbInstanceBase() {
|
|
6104
6137
|
if (this._pouchInstance) return this._pouchInstance;
|
|
6105
6138
|
const {
|
|
6106
6139
|
//
|
|
6107
|
-
liveSync,
|
|
6108
6140
|
indexes,
|
|
6109
6141
|
connType,
|
|
6110
|
-
|
|
6111
|
-
|
|
6142
|
+
localSqliteDbConfig,
|
|
6143
|
+
remoteConnectionConfig,
|
|
6144
|
+
syncConfig
|
|
6112
6145
|
} = this.baseConfig;
|
|
6113
6146
|
const isLocalFirst = connType === "LOCAL_FIRST";
|
|
6114
6147
|
const isRemoteFirst = connType === "REMOTE_FIRST";
|
|
6148
|
+
const remoteConnectionUrl = (() => {
|
|
6149
|
+
const connUrl = remoteConnectionConfig?.connectionUrl;
|
|
6150
|
+
if (!connUrl) return void 0;
|
|
6151
|
+
return connUrl;
|
|
6152
|
+
})();
|
|
6153
|
+
const localSqliteDbFilePath = (() => {
|
|
6154
|
+
const dbName01 = localSqliteDbConfig?.fileName;
|
|
6155
|
+
const fileExtension01 = localSqliteDbConfig?.fileExt || ".sqlite";
|
|
6156
|
+
if (!localSqliteDbConfig?.folderFullPath) return void 0;
|
|
6157
|
+
if (!localSqliteDbConfig?.fileExt) return void 0;
|
|
6158
|
+
if (!dbName01) return void 0;
|
|
6159
|
+
const fileName = `${dbName01}${fileExtension01}`;
|
|
6160
|
+
return import_node_path.default.join(localSqliteDbConfig.folderFullPath, fileName);
|
|
6161
|
+
})();
|
|
6115
6162
|
if (isLocalFirst) {
|
|
6116
6163
|
if (!localSqliteDbFilePath) {
|
|
6117
6164
|
throw new MocodyGenericError("localSqliteDbFilePath not defined");
|
|
@@ -6122,8 +6169,10 @@ var MocodyInitializerPouch = class {
|
|
|
6122
6169
|
if (!remoteConnectionUrl) {
|
|
6123
6170
|
throw new MocodyGenericError("couchRemoteConnectionUrl not defined");
|
|
6124
6171
|
}
|
|
6125
|
-
|
|
6126
|
-
|
|
6172
|
+
this._pouchInstance = this.createRemoteDB({
|
|
6173
|
+
remoteConnectionUrl,
|
|
6174
|
+
proxyAuthToken: remoteConnectionConfig?.proxyAuthToken
|
|
6175
|
+
});
|
|
6127
6176
|
}
|
|
6128
6177
|
try {
|
|
6129
6178
|
if (indexes?.length) {
|
|
@@ -6134,38 +6183,85 @@ var MocodyInitializerPouch = class {
|
|
|
6134
6183
|
} catch (error) {
|
|
6135
6184
|
LoggingService.error(error);
|
|
6136
6185
|
}
|
|
6186
|
+
const filterSelector01 = syncConfig?.filterSelector || void 0;
|
|
6187
|
+
const heartbeat01 = syncConfig?.heartbeat || 2e4;
|
|
6188
|
+
const batchSize01 = syncConfig?.batchSize || 100;
|
|
6189
|
+
const backoffDelaySeconds01 = syncConfig?.backoffDelayInSeconds || 4e4;
|
|
6190
|
+
if (syncConfig?.isSyncFilterSelectorRequired && !filterSelector01) {
|
|
6191
|
+
throw new MocodyGenericError("filterSelector not defined");
|
|
6192
|
+
}
|
|
6137
6193
|
if (isLocalFirst && remoteConnectionUrl) {
|
|
6138
|
-
if (
|
|
6194
|
+
if (syncConfig?.isLiveSync) {
|
|
6139
6195
|
this._pouchInstance.sync(remoteConnectionUrl, {
|
|
6140
6196
|
live: true,
|
|
6141
|
-
retry: true
|
|
6197
|
+
retry: true,
|
|
6198
|
+
batch_size: batchSize01,
|
|
6199
|
+
heartbeat: heartbeat01,
|
|
6200
|
+
timeout: heartbeat01 * 2,
|
|
6201
|
+
selector: filterSelector01,
|
|
6202
|
+
back_off_function: (delay) => {
|
|
6203
|
+
if (delay === 0) return 2e3;
|
|
6204
|
+
return Math.min(delay * 2, backoffDelaySeconds01);
|
|
6205
|
+
}
|
|
6142
6206
|
}).on("change", (change) => {
|
|
6143
|
-
LoggingService.log({
|
|
6207
|
+
LoggingService.log({ pouch_replication_change: change });
|
|
6144
6208
|
}).on("paused", (info) => {
|
|
6145
|
-
LoggingService.log({
|
|
6209
|
+
LoggingService.log({ pouch_replication_paused: info });
|
|
6146
6210
|
}).on("error", (err) => {
|
|
6147
|
-
LoggingService.log({
|
|
6211
|
+
LoggingService.log({ pouch_replication_error: err });
|
|
6212
|
+
}).on("active", () => {
|
|
6213
|
+
LoggingService.log(`Pouch:::Connection active`);
|
|
6214
|
+
}).on("denied", (err) => {
|
|
6215
|
+
LoggingService.log(`Pouch:::Connection denied`);
|
|
6148
6216
|
});
|
|
6149
6217
|
} else {
|
|
6150
|
-
this._pouchInstance.sync(remoteConnectionUrl).on("
|
|
6151
|
-
LoggingService.log({
|
|
6218
|
+
this._pouchInstance.sync(remoteConnectionUrl, { selector: filterSelector01 }).on("change", (change) => {
|
|
6219
|
+
LoggingService.log({ pouch_replication_change: change });
|
|
6220
|
+
}).on("paused", (info) => {
|
|
6221
|
+
LoggingService.log({ pouch_replication_paused: info });
|
|
6222
|
+
}).on("error", (err) => {
|
|
6223
|
+
LoggingService.log({ pouch_replication_error: err });
|
|
6224
|
+
}).on("active", () => {
|
|
6225
|
+
LoggingService.log(`Pouch:::Connection active`);
|
|
6226
|
+
}).on("denied", (err) => {
|
|
6227
|
+
LoggingService.log(`Pouch:::Connection denied`);
|
|
6152
6228
|
});
|
|
6153
6229
|
}
|
|
6154
6230
|
} else if (isRemoteFirst && localSqliteDbFilePath) {
|
|
6155
|
-
if (
|
|
6231
|
+
if (syncConfig?.isLiveSync) {
|
|
6156
6232
|
this._pouchInstance.sync(localSqliteDbFilePath, {
|
|
6157
6233
|
live: true,
|
|
6158
|
-
retry: true
|
|
6234
|
+
retry: true,
|
|
6235
|
+
batch_size: batchSize01,
|
|
6236
|
+
heartbeat: heartbeat01,
|
|
6237
|
+
timeout: heartbeat01 * 2,
|
|
6238
|
+
selector: filterSelector01,
|
|
6239
|
+
back_off_function: (delay) => {
|
|
6240
|
+
if (delay === 0) return 2e3;
|
|
6241
|
+
return Math.min(delay * 2, backoffDelaySeconds01);
|
|
6242
|
+
}
|
|
6159
6243
|
}).on("change", (change) => {
|
|
6160
|
-
LoggingService.log({
|
|
6244
|
+
LoggingService.log({ pouch_replication_change: change });
|
|
6161
6245
|
}).on("paused", (info) => {
|
|
6162
|
-
LoggingService.log({
|
|
6246
|
+
LoggingService.log({ pouch_replication_paused: info });
|
|
6163
6247
|
}).on("error", (err) => {
|
|
6164
|
-
LoggingService.log({
|
|
6248
|
+
LoggingService.log({ pouch_replication_error: err });
|
|
6249
|
+
}).on("active", () => {
|
|
6250
|
+
LoggingService.log(`Pouch:::Connection active`);
|
|
6251
|
+
}).on("denied", (err) => {
|
|
6252
|
+
LoggingService.log(`Pouch:::Connection denied`);
|
|
6165
6253
|
});
|
|
6166
6254
|
} else {
|
|
6167
|
-
this._pouchInstance.sync(localSqliteDbFilePath).on("
|
|
6168
|
-
LoggingService.log({
|
|
6255
|
+
this._pouchInstance.sync(localSqliteDbFilePath, { selector: filterSelector01 }).on("change", (change) => {
|
|
6256
|
+
LoggingService.log({ pouch_replication_change: change });
|
|
6257
|
+
}).on("paused", (info) => {
|
|
6258
|
+
LoggingService.log({ pouch_replication_paused: info });
|
|
6259
|
+
}).on("error", (err) => {
|
|
6260
|
+
LoggingService.log({ pouch_replication_error: err });
|
|
6261
|
+
}).on("active", () => {
|
|
6262
|
+
LoggingService.log(`Pouch:::Connection active`);
|
|
6263
|
+
}).on("denied", () => {
|
|
6264
|
+
LoggingService.log(`Pouch:::Connection denied`);
|
|
6169
6265
|
});
|
|
6170
6266
|
}
|
|
6171
6267
|
}
|
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[];
|
|
@@ -747,6 +767,7 @@ declare class MocodyInitializerPouch<T extends IMocodyCoreEntityModel> {
|
|
|
747
767
|
private _pouchInstance;
|
|
748
768
|
private readonly _docMetaFieldsObJ;
|
|
749
769
|
private readonly baseConfig;
|
|
770
|
+
private pouchWithPlugins;
|
|
750
771
|
constructor(baseConfig: IOptions$1);
|
|
751
772
|
deleteIndex({ ddoc, name }: {
|
|
752
773
|
ddoc: string;
|
|
@@ -796,6 +817,7 @@ declare class MocodyInitializerPouch<T extends IMocodyCoreEntityModel> {
|
|
|
796
817
|
}): Promise<PouchDB.Core.Response>;
|
|
797
818
|
pouch_getDbInstance(): Promise<PouchDB.Database<T>>;
|
|
798
819
|
private getPouchWithPlugins;
|
|
820
|
+
private createRemoteDB;
|
|
799
821
|
private pouch_getDbInstanceBase;
|
|
800
822
|
private toBasicDoc_RemovePouchMeta;
|
|
801
823
|
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[];
|
|
@@ -747,6 +767,7 @@ declare class MocodyInitializerPouch<T extends IMocodyCoreEntityModel> {
|
|
|
747
767
|
private _pouchInstance;
|
|
748
768
|
private readonly _docMetaFieldsObJ;
|
|
749
769
|
private readonly baseConfig;
|
|
770
|
+
private pouchWithPlugins;
|
|
750
771
|
constructor(baseConfig: IOptions$1);
|
|
751
772
|
deleteIndex({ ddoc, name }: {
|
|
752
773
|
ddoc: string;
|
|
@@ -796,6 +817,7 @@ declare class MocodyInitializerPouch<T extends IMocodyCoreEntityModel> {
|
|
|
796
817
|
}): Promise<PouchDB.Core.Response>;
|
|
797
818
|
pouch_getDbInstance(): Promise<PouchDB.Database<T>>;
|
|
798
819
|
private getPouchWithPlugins;
|
|
820
|
+
private createRemoteDB;
|
|
799
821
|
private pouch_getDbInstanceBase;
|
|
800
822
|
private toBasicDoc_RemovePouchMeta;
|
|
801
823
|
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,6 +5929,7 @@ var MongoDataOperation = class extends RepoModel {
|
|
|
5929
5929
|
|
|
5930
5930
|
// src/pouch/pouch-initializer.ts
|
|
5931
5931
|
import throat4 from "throat";
|
|
5932
|
+
import path from "path";
|
|
5932
5933
|
import PouchDB00 from "pouchdb-core";
|
|
5933
5934
|
import pouchdbFind from "pouchdb-find";
|
|
5934
5935
|
import pouchdbhttp from "pouchdb-adapter-http";
|
|
@@ -5939,6 +5940,7 @@ var MocodyInitializerPouch = class {
|
|
|
5939
5940
|
_pouchInstance;
|
|
5940
5941
|
_docMetaFieldsObJ = this.docMetaFieldsObject();
|
|
5941
5942
|
baseConfig;
|
|
5943
|
+
pouchWithPlugins = null;
|
|
5942
5944
|
constructor(baseConfig) {
|
|
5943
5945
|
this.baseConfig = baseConfig;
|
|
5944
5946
|
}
|
|
@@ -6067,21 +6069,66 @@ var MocodyInitializerPouch = class {
|
|
|
6067
6069
|
async pouch_getDbInstance() {
|
|
6068
6070
|
return await concurrency4(() => this.pouch_getDbInstanceBase());
|
|
6069
6071
|
}
|
|
6072
|
+
// private getPouchWithPlugins() {
|
|
6073
|
+
// return (
|
|
6074
|
+
// PouchDB00.plugin(pouchdbhttp)
|
|
6075
|
+
// //
|
|
6076
|
+
// .plugin(pouchdbmapreduce)
|
|
6077
|
+
// .plugin(pouchdbreplication)
|
|
6078
|
+
// .plugin(pouchdbFind)
|
|
6079
|
+
// );
|
|
6080
|
+
// }
|
|
6070
6081
|
getPouchWithPlugins() {
|
|
6071
|
-
|
|
6082
|
+
if (!this.pouchWithPlugins) {
|
|
6083
|
+
this.pouchWithPlugins = PouchDB00.plugin(pouchdbhttp).plugin(pouchdbmapreduce).plugin(pouchdbreplication).plugin(pouchdbFind);
|
|
6084
|
+
}
|
|
6085
|
+
return this.pouchWithPlugins;
|
|
6086
|
+
}
|
|
6087
|
+
createRemoteDB({
|
|
6088
|
+
proxyAuthToken,
|
|
6089
|
+
remoteConnectionUrl
|
|
6090
|
+
}) {
|
|
6091
|
+
const PouchDB = this.getPouchWithPlugins();
|
|
6092
|
+
return new PouchDB(remoteConnectionUrl, {
|
|
6093
|
+
fetch: (url, opts) => {
|
|
6094
|
+
const headers = new Headers(opts?.headers);
|
|
6095
|
+
if (proxyAuthToken) {
|
|
6096
|
+
headers.set("Authorization", `Bearer ${proxyAuthToken}`);
|
|
6097
|
+
}
|
|
6098
|
+
return PouchDB.fetch(url, {
|
|
6099
|
+
...opts,
|
|
6100
|
+
headers,
|
|
6101
|
+
credentials: "omit"
|
|
6102
|
+
});
|
|
6103
|
+
}
|
|
6104
|
+
});
|
|
6072
6105
|
}
|
|
6073
6106
|
async pouch_getDbInstanceBase() {
|
|
6074
6107
|
if (this._pouchInstance) return this._pouchInstance;
|
|
6075
6108
|
const {
|
|
6076
6109
|
//
|
|
6077
|
-
liveSync,
|
|
6078
6110
|
indexes,
|
|
6079
6111
|
connType,
|
|
6080
|
-
|
|
6081
|
-
|
|
6112
|
+
localSqliteDbConfig,
|
|
6113
|
+
remoteConnectionConfig,
|
|
6114
|
+
syncConfig
|
|
6082
6115
|
} = this.baseConfig;
|
|
6083
6116
|
const isLocalFirst = connType === "LOCAL_FIRST";
|
|
6084
6117
|
const isRemoteFirst = connType === "REMOTE_FIRST";
|
|
6118
|
+
const remoteConnectionUrl = (() => {
|
|
6119
|
+
const connUrl = remoteConnectionConfig?.connectionUrl;
|
|
6120
|
+
if (!connUrl) return void 0;
|
|
6121
|
+
return connUrl;
|
|
6122
|
+
})();
|
|
6123
|
+
const localSqliteDbFilePath = (() => {
|
|
6124
|
+
const dbName01 = localSqliteDbConfig?.fileName;
|
|
6125
|
+
const fileExtension01 = localSqliteDbConfig?.fileExt || ".sqlite";
|
|
6126
|
+
if (!localSqliteDbConfig?.folderFullPath) return void 0;
|
|
6127
|
+
if (!localSqliteDbConfig?.fileExt) return void 0;
|
|
6128
|
+
if (!dbName01) return void 0;
|
|
6129
|
+
const fileName = `${dbName01}${fileExtension01}`;
|
|
6130
|
+
return path.join(localSqliteDbConfig.folderFullPath, fileName);
|
|
6131
|
+
})();
|
|
6085
6132
|
if (isLocalFirst) {
|
|
6086
6133
|
if (!localSqliteDbFilePath) {
|
|
6087
6134
|
throw new MocodyGenericError("localSqliteDbFilePath not defined");
|
|
@@ -6092,8 +6139,10 @@ var MocodyInitializerPouch = class {
|
|
|
6092
6139
|
if (!remoteConnectionUrl) {
|
|
6093
6140
|
throw new MocodyGenericError("couchRemoteConnectionUrl not defined");
|
|
6094
6141
|
}
|
|
6095
|
-
|
|
6096
|
-
|
|
6142
|
+
this._pouchInstance = this.createRemoteDB({
|
|
6143
|
+
remoteConnectionUrl,
|
|
6144
|
+
proxyAuthToken: remoteConnectionConfig?.proxyAuthToken
|
|
6145
|
+
});
|
|
6097
6146
|
}
|
|
6098
6147
|
try {
|
|
6099
6148
|
if (indexes?.length) {
|
|
@@ -6104,38 +6153,85 @@ var MocodyInitializerPouch = class {
|
|
|
6104
6153
|
} catch (error) {
|
|
6105
6154
|
LoggingService.error(error);
|
|
6106
6155
|
}
|
|
6156
|
+
const filterSelector01 = syncConfig?.filterSelector || void 0;
|
|
6157
|
+
const heartbeat01 = syncConfig?.heartbeat || 2e4;
|
|
6158
|
+
const batchSize01 = syncConfig?.batchSize || 100;
|
|
6159
|
+
const backoffDelaySeconds01 = syncConfig?.backoffDelayInSeconds || 4e4;
|
|
6160
|
+
if (syncConfig?.isSyncFilterSelectorRequired && !filterSelector01) {
|
|
6161
|
+
throw new MocodyGenericError("filterSelector not defined");
|
|
6162
|
+
}
|
|
6107
6163
|
if (isLocalFirst && remoteConnectionUrl) {
|
|
6108
|
-
if (
|
|
6164
|
+
if (syncConfig?.isLiveSync) {
|
|
6109
6165
|
this._pouchInstance.sync(remoteConnectionUrl, {
|
|
6110
6166
|
live: true,
|
|
6111
|
-
retry: true
|
|
6167
|
+
retry: true,
|
|
6168
|
+
batch_size: batchSize01,
|
|
6169
|
+
heartbeat: heartbeat01,
|
|
6170
|
+
timeout: heartbeat01 * 2,
|
|
6171
|
+
selector: filterSelector01,
|
|
6172
|
+
back_off_function: (delay) => {
|
|
6173
|
+
if (delay === 0) return 2e3;
|
|
6174
|
+
return Math.min(delay * 2, backoffDelaySeconds01);
|
|
6175
|
+
}
|
|
6112
6176
|
}).on("change", (change) => {
|
|
6113
|
-
LoggingService.log({
|
|
6177
|
+
LoggingService.log({ pouch_replication_change: change });
|
|
6114
6178
|
}).on("paused", (info) => {
|
|
6115
|
-
LoggingService.log({
|
|
6179
|
+
LoggingService.log({ pouch_replication_paused: info });
|
|
6116
6180
|
}).on("error", (err) => {
|
|
6117
|
-
LoggingService.log({
|
|
6181
|
+
LoggingService.log({ pouch_replication_error: err });
|
|
6182
|
+
}).on("active", () => {
|
|
6183
|
+
LoggingService.log(`Pouch:::Connection active`);
|
|
6184
|
+
}).on("denied", (err) => {
|
|
6185
|
+
LoggingService.log(`Pouch:::Connection denied`);
|
|
6118
6186
|
});
|
|
6119
6187
|
} else {
|
|
6120
|
-
this._pouchInstance.sync(remoteConnectionUrl).on("
|
|
6121
|
-
LoggingService.log({
|
|
6188
|
+
this._pouchInstance.sync(remoteConnectionUrl, { selector: filterSelector01 }).on("change", (change) => {
|
|
6189
|
+
LoggingService.log({ pouch_replication_change: change });
|
|
6190
|
+
}).on("paused", (info) => {
|
|
6191
|
+
LoggingService.log({ pouch_replication_paused: info });
|
|
6192
|
+
}).on("error", (err) => {
|
|
6193
|
+
LoggingService.log({ pouch_replication_error: err });
|
|
6194
|
+
}).on("active", () => {
|
|
6195
|
+
LoggingService.log(`Pouch:::Connection active`);
|
|
6196
|
+
}).on("denied", (err) => {
|
|
6197
|
+
LoggingService.log(`Pouch:::Connection denied`);
|
|
6122
6198
|
});
|
|
6123
6199
|
}
|
|
6124
6200
|
} else if (isRemoteFirst && localSqliteDbFilePath) {
|
|
6125
|
-
if (
|
|
6201
|
+
if (syncConfig?.isLiveSync) {
|
|
6126
6202
|
this._pouchInstance.sync(localSqliteDbFilePath, {
|
|
6127
6203
|
live: true,
|
|
6128
|
-
retry: true
|
|
6204
|
+
retry: true,
|
|
6205
|
+
batch_size: batchSize01,
|
|
6206
|
+
heartbeat: heartbeat01,
|
|
6207
|
+
timeout: heartbeat01 * 2,
|
|
6208
|
+
selector: filterSelector01,
|
|
6209
|
+
back_off_function: (delay) => {
|
|
6210
|
+
if (delay === 0) return 2e3;
|
|
6211
|
+
return Math.min(delay * 2, backoffDelaySeconds01);
|
|
6212
|
+
}
|
|
6129
6213
|
}).on("change", (change) => {
|
|
6130
|
-
LoggingService.log({
|
|
6214
|
+
LoggingService.log({ pouch_replication_change: change });
|
|
6131
6215
|
}).on("paused", (info) => {
|
|
6132
|
-
LoggingService.log({
|
|
6216
|
+
LoggingService.log({ pouch_replication_paused: info });
|
|
6133
6217
|
}).on("error", (err) => {
|
|
6134
|
-
LoggingService.log({
|
|
6218
|
+
LoggingService.log({ pouch_replication_error: err });
|
|
6219
|
+
}).on("active", () => {
|
|
6220
|
+
LoggingService.log(`Pouch:::Connection active`);
|
|
6221
|
+
}).on("denied", (err) => {
|
|
6222
|
+
LoggingService.log(`Pouch:::Connection denied`);
|
|
6135
6223
|
});
|
|
6136
6224
|
} else {
|
|
6137
|
-
this._pouchInstance.sync(localSqliteDbFilePath).on("
|
|
6138
|
-
LoggingService.log({
|
|
6225
|
+
this._pouchInstance.sync(localSqliteDbFilePath, { selector: filterSelector01 }).on("change", (change) => {
|
|
6226
|
+
LoggingService.log({ pouch_replication_change: change });
|
|
6227
|
+
}).on("paused", (info) => {
|
|
6228
|
+
LoggingService.log({ pouch_replication_paused: info });
|
|
6229
|
+
}).on("error", (err) => {
|
|
6230
|
+
LoggingService.log({ pouch_replication_error: err });
|
|
6231
|
+
}).on("active", () => {
|
|
6232
|
+
LoggingService.log(`Pouch:::Connection active`);
|
|
6233
|
+
}).on("denied", () => {
|
|
6234
|
+
LoggingService.log(`Pouch:::Connection denied`);
|
|
6139
6235
|
});
|
|
6140
6236
|
}
|
|
6141
6237
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mocody",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.4",
|
|
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": [
|