node-sword-interface 1.0.95 → 1.0.96

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/API.md CHANGED
@@ -31,6 +31,7 @@ This is the main class of node-sword-interface and it provides a set of static f
31
31
  **Kind**: global class
32
32
 
33
33
  * [NodeSwordInterface](#NodeSwordInterface)
34
+ * [new NodeSwordInterface(customHomeDir, localesBasePath, timeoutMillis)](#new_NodeSwordInterface_new)
34
35
  * [.repositoryConfigExisting()](#NodeSwordInterface+repositoryConfigExisting) ⇒ <code>Boolean</code>
35
36
  * [.updateRepositoryConfig(progressCB)](#NodeSwordInterface+updateRepositoryConfig) ⇒ <code>Promise</code>
36
37
  * [.getRepoNames()](#NodeSwordInterface+getRepoNames) ⇒ <code>Array.&lt;String&gt;</code>
@@ -84,6 +85,17 @@ This is the main class of node-sword-interface and it provides a set of static f
84
85
  * [.getSwordVersion()](#NodeSwordInterface+getSwordVersion) ⇒ <code>String</code>
85
86
  * [.getSwordPath()](#NodeSwordInterface+getSwordPath) ⇒ <code>String</code>
86
87
 
88
+ <a name="new_NodeSwordInterface_new"></a>
89
+
90
+ ### new NodeSwordInterface(customHomeDir, localesBasePath, timeoutMillis)
91
+ Creates an instance of NodeSwordInterface.
92
+
93
+ | Param | Type | Default | Description |
94
+ | --- | --- | --- | --- |
95
+ | customHomeDir | <code>String</code> | <code>undefined</code> | Optional custom home directory for SWORD data. |
96
+ | localesBasePath | <code>String</code> | <code>__dirname</code> | Optional base path for locales. |
97
+ | timeoutMillis | <code>Number</code> | <code>20000</code> | Optional timeout in milliseconds for repository operations. Invalid values (≤ 0 or non-numeric) trigger a warning and fallback to the default. |
98
+
87
99
  <a name="NodeSwordInterface+repositoryConfigExisting"></a>
88
100
 
89
101
  ### nodeSwordInterface.repositoryConfigExisting() ⇒ <code>Boolean</code>
package/index.js CHANGED
@@ -105,9 +105,15 @@ const searchMutex = new Mutex();
105
105
 
106
106
  /** This is the main class of node-sword-interface and it provides a set of static functions that wrap SWORD library functionality. */
107
107
  class NodeSwordInterface {
108
- constructor(customHomeDir=undefined, localesBasePath=__dirname) {
108
+ /**
109
+ * Creates an instance of NodeSwordInterface.
110
+ * @param {String} customHomeDir - Optional custom home directory for SWORD data.
111
+ * @param {String} localesBasePath - Optional base path for locales (default: __dirname).
112
+ * @param {Number} timeoutMillis - Optional timeout in milliseconds for repository operations (default: 20000).
113
+ */
114
+ constructor(customHomeDir=undefined, localesBasePath=__dirname, timeoutMillis=20000) {
109
115
  var localesDir = path.join(localesBasePath, './locales.d');
110
- this.nativeInterface = new nodeSwordInterfaceModule.NodeSwordInterface(customHomeDir, localesDir);
116
+ this.nativeInterface = new nodeSwordInterfaceModule.NodeSwordInterface(customHomeDir, localesDir, timeoutMillis);
111
117
  }
112
118
 
113
119
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-sword-interface",
3
- "version": "1.0.95",
3
+ "version": "1.0.96",
4
4
  "description": "Javascript (N-API) interface to SWORD library",
5
5
  "keywords": [
6
6
  "C++",
@@ -151,6 +151,7 @@ NodeSwordInterface::NodeSwordInterface(const Napi::CallbackInfo& info) : Napi::O
151
151
 
152
152
  std::string localeDir = "";
153
153
  this->customHomeDir = "";
154
+ long timeoutMillis = 20000;
154
155
 
155
156
  bool homeDirError = false;
156
157
  bool localeDirError = false;
@@ -177,11 +178,17 @@ NodeSwordInterface::NodeSwordInterface(const Napi::CallbackInfo& info) : Napi::O
177
178
  localeDirError = true;
178
179
  }
179
180
 
181
+ if (info[2].IsNumber()) {
182
+ timeoutMillis = info[2].As<Napi::Number>().Int64Value();
183
+ } else if (!info[2].IsUndefined() && !info[2].IsNull()) {
184
+ cerr << "Warning: Invalid timeoutMillis value (not a number), using default (20000)" << endl;
185
+ }
186
+
180
187
  if (!homeDirError && !localeDirError) { // We only proceed if there has not been any issue with the homeDir or localeDir
181
188
  this->_moduleStore = new ModuleStore(this->customHomeDir);
182
189
  this->_moduleHelper = new ModuleHelper(*(this->_moduleStore));
183
190
  this->_dictHelper = new DictHelper(*(this->_moduleStore));
184
- this->_repoInterface = new RepositoryInterface(this->_swordStatusReporter, *(this->_moduleHelper), *(this->_moduleStore), this->customHomeDir);
191
+ this->_repoInterface = new RepositoryInterface(this->_swordStatusReporter, *(this->_moduleHelper), *(this->_moduleStore), this->customHomeDir, timeoutMillis);
185
192
  this->_moduleInstaller = new ModuleInstaller(*(this->_repoInterface), *(this->_moduleStore), this->customHomeDir);
186
193
  this->_napiSwordHelper = new NapiSwordHelper(*(this->_moduleHelper), *(this->_moduleStore));
187
194
  this->_textProcessor = new TextProcessor(*(this->_moduleStore), *(this->_moduleHelper));
@@ -183,7 +183,8 @@ int main(int argc, char** argv)
183
183
  ModuleHelper moduleHelper(moduleStore);
184
184
  DictHelper dictHelper(moduleStore);
185
185
  SwordStatusReporter statusReporter;
186
- RepositoryInterface repoInterface(statusReporter, moduleHelper, moduleStore);
186
+ long timeoutMillis = 20000;
187
+ RepositoryInterface repoInterface(statusReporter, moduleHelper, moduleStore, "", timeoutMillis);
187
188
  ModuleInstaller moduleInstaller(repoInterface, moduleStore);
188
189
  TextProcessor textProcessor(moduleStore, moduleHelper);
189
190
  ModuleSearch moduleSearch(moduleStore, moduleHelper, textProcessor);
@@ -53,9 +53,16 @@ static Mutex remoteSourceUpdateMutex;
53
53
  RepositoryInterface::RepositoryInterface(SwordStatusReporter& statusReporter,
54
54
  ModuleHelper& moduleHelper,
55
55
  ModuleStore& moduleStore,
56
- string customHomeDir)
56
+ string customHomeDir,
57
+ long timeoutMillis)
57
58
  : _statusReporter(statusReporter), _moduleHelper(moduleHelper), _moduleStore(moduleStore)
58
59
  {
60
+ if (timeoutMillis <= 0) {
61
+ cerr << "Warning: Invalid timeoutMillis value (" << timeoutMillis << "), using default (20000)" << endl;
62
+ this->_timeoutMillis = 20000;
63
+ } else {
64
+ this->_timeoutMillis = timeoutMillis;
65
+ }
59
66
  this->_fileSystemHelper.setCustomHomeDir(customHomeDir);
60
67
  this->resetMgr();
61
68
  remoteSourceUpdateMutex.init();
@@ -72,8 +79,7 @@ void RepositoryInterface::resetMgr()
72
79
  this->_installMgr = new InstallMgr(this->_fileSystemHelper.getInstallMgrDir().c_str(), &this->_statusReporter);
73
80
  this->_installMgr->setUserDisclaimerConfirmed(true);
74
81
 
75
- long timeoutMillis = 20000;
76
- this->_installMgr->setTimeoutMillis(timeoutMillis);
82
+ this->_installMgr->setTimeoutMillis(this->_timeoutMillis);
77
83
  }
78
84
 
79
85
  int RepositoryInterface::refreshRepositoryConfig()
@@ -43,7 +43,8 @@ public:
43
43
  RepositoryInterface(SwordStatusReporter& statusReporter,
44
44
  ModuleHelper& moduleHelper,
45
45
  ModuleStore& moduleStore,
46
- std::string customHomeDir="");
46
+ std::string customHomeDir="",
47
+ long timeoutMillis=20000);
47
48
 
48
49
  virtual ~RepositoryInterface(){}
49
50
 
@@ -115,6 +116,7 @@ private:
115
116
  FileSystemHelper _fileSystemHelper;
116
117
  ModuleHelper& _moduleHelper;
117
118
  ModuleStore& _moduleStore;
119
+ long _timeoutMillis = 20000;
118
120
  };
119
121
 
120
122
  #endif // _REPOSITORY_INTERFACE