node-sword-interface 1.0.97 → 1.0.98

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
@@ -39,17 +39,17 @@ This is the main class of node-sword-interface and it provides a set of static f
39
39
  * [.getAllRepoModules(repositoryName, moduleType)](#NodeSwordInterface+getAllRepoModules) ⇒ [<code>Array.&lt;ModuleObject&gt;</code>](#ModuleObject)
40
40
  * [.getRepoModulesByLang(repositoryName, language, moduleType, headersFilter, strongsFilter, hebrewStrongsKeys, greekStrongsKeys)](#NodeSwordInterface+getRepoModulesByLang) ⇒ [<code>Array.&lt;ModuleObject&gt;</code>](#ModuleObject)
41
41
  * [.getUpdatedRepoModules(repositoryName, includeBeta)](#NodeSwordInterface+getUpdatedRepoModules) ⇒ [<code>Array.&lt;ModuleObject&gt;</code>](#ModuleObject)
42
- * [.getRepoModule(moduleCode)](#NodeSwordInterface+getRepoModule) ⇒ [<code>ModuleObject</code>](#ModuleObject)
42
+ * [.getRepoModule(repositoryName, moduleCode)](#NodeSwordInterface+getRepoModule) ⇒ [<code>ModuleObject</code>](#ModuleObject)
43
43
  * [.getAllLocalModules(moduleType)](#NodeSwordInterface+getAllLocalModules) ⇒ [<code>Array.&lt;ModuleObject&gt;</code>](#ModuleObject)
44
44
  * [.getRepoModuleCount(repositoryName, moduleType)](#NodeSwordInterface+getRepoModuleCount) ⇒ <code>Number</code>
45
45
  * [.getRepoLanguageModuleCount(repositoryName, language, moduleType)](#NodeSwordInterface+getRepoLanguageModuleCount) ⇒ <code>Number</code>
46
- * [.installModule(moduleCode, progressCB)](#NodeSwordInterface+installModule) ⇒ <code>Promise</code>
46
+ * [.installModule(repositoryName, moduleCode, progressCB)](#NodeSwordInterface+installModule) ⇒ <code>Promise</code>
47
47
  * [.cancelInstallation()](#NodeSwordInterface+cancelInstallation)
48
48
  * [.uninstallModule(moduleCode)](#NodeSwordInterface+uninstallModule) ⇒ <code>Promise</code>
49
49
  * [.refreshLocalModules()](#NodeSwordInterface+refreshLocalModules)
50
50
  * [.saveModuleUnlockKey(moduleCode, key)](#NodeSwordInterface+saveModuleUnlockKey)
51
51
  * [.isModuleReadable(moduleCode)](#NodeSwordInterface+isModuleReadable) ⇒ <code>Boolean</code>
52
- * [.getModuleDescription(moduleCode)](#NodeSwordInterface+getModuleDescription) ⇒ <code>String</code>
52
+ * [.getModuleDescription(repositoryName, moduleCode)](#NodeSwordInterface+getModuleDescription) ⇒ <code>String</code>
53
53
  * [.enableMarkup()](#NodeSwordInterface+enableMarkup)
54
54
  * [.disableMarkup()](#NodeSwordInterface+disableMarkup)
55
55
  * [.enableStrongsWithNbsp()](#NodeSwordInterface+enableStrongsWithNbsp)
@@ -77,7 +77,7 @@ This is the main class of node-sword-interface and it provides a set of static f
77
77
  * [.getStrongsEntry(strongsKey)](#NodeSwordInterface+getStrongsEntry) ⇒ [<code>StrongsEntry</code>](#StrongsEntry)
78
78
  * [.getLocalModule(moduleCode)](#NodeSwordInterface+getLocalModule) ⇒ [<code>ModuleObject</code>](#ModuleObject)
79
79
  * [.isModuleInUserDir(moduleCode)](#NodeSwordInterface+isModuleInUserDir) ⇒ <code>Boolean</code>
80
- * [.isModuleAvailableInRepo(moduleCode)](#NodeSwordInterface+isModuleAvailableInRepo) ⇒ <code>Boolean</code>
80
+ * [.isModuleAvailableInRepo(moduleCode, repositoryName)](#NodeSwordInterface+isModuleAvailableInRepo) ⇒ <code>Boolean</code>
81
81
  * [.getSwordTranslation(originalString, localeCode)](#NodeSwordInterface+getSwordTranslation)
82
82
  * [.getBookAbbreviation(moduleName, bookCode, localeCode)](#NodeSwordInterface+getBookAbbreviation)
83
83
  * [.unTarGZ(filePath, destPath)](#NodeSwordInterface+unTarGZ) ⇒ <code>Boolean</code>
@@ -90,11 +90,12 @@ This is the main class of node-sword-interface and it provides a set of static f
90
90
  ### new NodeSwordInterface(customHomeDir, localesBasePath, timeoutMillis)
91
91
  Creates an instance of NodeSwordInterface.
92
92
 
93
+
93
94
  | Param | Type | Default | Description |
94
95
  | --- | --- | --- | --- |
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. |
96
+ | customHomeDir | <code>String</code> | | Optional custom home directory for SWORD data. |
97
+ | localesBasePath | <code>String</code> | | Optional base path for locales (default: __dirname). |
98
+ | timeoutMillis | <code>Number</code> | <code>20000</code> | Optional timeout in milliseconds for repository operations (default: 20000). |
98
99
 
99
100
  <a name="NodeSwordInterface+repositoryConfigExisting"></a>
100
101
 
@@ -189,13 +190,14 @@ Returns all updated modules from all repositories or one specific repository.
189
190
 
190
191
  <a name="NodeSwordInterface+getRepoModule"></a>
191
192
 
192
- ### nodeSwordInterface.getRepoModule(moduleCode) ⇒ [<code>ModuleObject</code>](#ModuleObject)
193
+ ### nodeSwordInterface.getRepoModule(repositoryName, moduleCode) ⇒ [<code>ModuleObject</code>](#ModuleObject)
193
194
  Returns an object representation of a SWORD module from a repository.
194
195
 
195
196
  **Kind**: instance method of [<code>NodeSwordInterface</code>](#NodeSwordInterface)
196
197
 
197
198
  | Param | Type | Description |
198
199
  | --- | --- | --- |
200
+ | repositoryName | <code>String</code> | The name of the repository to search in. |
199
201
  | moduleCode | <code>String</code> | The module code of the SWORD module. |
200
202
 
201
203
  <a name="NodeSwordInterface+getAllLocalModules"></a>
@@ -239,9 +241,9 @@ Returns the number of modules for a given repository and language (default: Bibl
239
241
 
240
242
  <a name="NodeSwordInterface+installModule"></a>
241
243
 
242
- ### nodeSwordInterface.installModule(moduleCode, progressCB) ⇒ <code>Promise</code>
243
- Installs a module. The repository is automatically determined. The module is downloaded
244
- from the corresponding repository and then installed in the local SWORD directory.
244
+ ### nodeSwordInterface.installModule(repositoryName, moduleCode, progressCB) ⇒ <code>Promise</code>
245
+ Installs a module. The module is downloaded from the corresponding repository
246
+ and then installed in the local SWORD directory.
245
247
  This operation may take some time depending on the available bandwidth and geographical
246
248
  distance to the SWORD repository server.
247
249
 
@@ -255,6 +257,7 @@ If the installation fails, the Promise will be rejected with the following statu
255
257
 
256
258
  | Param | Type | Description |
257
259
  | --- | --- | --- |
260
+ | repositoryName | <code>String</code> | The name of the repository from which to install. |
258
261
  | moduleCode | <code>String</code> | The module code of the SWORD module that shall be installed. |
259
262
  | progressCB | <code>function</code> | Callback function that is called on progress events. |
260
263
 
@@ -310,7 +313,7 @@ Checks whether the module is readable.
310
313
 
311
314
  <a name="NodeSwordInterface+getModuleDescription"></a>
312
315
 
313
- ### nodeSwordInterface.getModuleDescription(moduleCode) ⇒ <code>String</code>
316
+ ### nodeSwordInterface.getModuleDescription(repositoryName, moduleCode) ⇒ <code>String</code>
314
317
  Returns the description of a module.
315
318
 
316
319
  **Kind**: instance method of [<code>NodeSwordInterface</code>](#NodeSwordInterface)
@@ -318,6 +321,7 @@ Returns the description of a module.
318
321
 
319
322
  | Param | Type | Description |
320
323
  | --- | --- | --- |
324
+ | repositoryName | <code>String</code> | The name of the repository to search in. |
321
325
  | moduleCode | <code>String</code> | The module code of the SWORD module. |
322
326
 
323
327
  <a name="NodeSwordInterface+enableMarkup"></a>
@@ -623,14 +627,15 @@ Checks whether the module resides in the user directory.
623
627
 
624
628
  <a name="NodeSwordInterface+isModuleAvailableInRepo"></a>
625
629
 
626
- ### nodeSwordInterface.isModuleAvailableInRepo(moduleCode) ⇒ <code>Boolean</code>
627
- Checks whether the module is available in any repository.
630
+ ### nodeSwordInterface.isModuleAvailableInRepo(moduleCode, repositoryName) ⇒ <code>Boolean</code>
631
+ Checks whether the module is available in any repository (default) or in a specific repository.
628
632
 
629
633
  **Kind**: instance method of [<code>NodeSwordInterface</code>](#NodeSwordInterface)
630
634
 
631
- | Param | Type | Description |
632
- | --- | --- | --- |
633
- | moduleCode | <code>String</code> | The module code of the SWORD module. |
635
+ | Param | Type | Default | Description |
636
+ | --- | --- | --- | --- |
637
+ | moduleCode | <code>String</code> | | The module code of the SWORD module. |
638
+ | repositoryName | <code>String</code> | <code>all</code> | The name of the repository to check. |
634
639
 
635
640
  <a name="NodeSwordInterface+getSwordTranslation"></a>
636
641
 
@@ -27,7 +27,7 @@ async function installKJV() {
27
27
 
28
28
  console.log("Installing King James module");
29
29
  // Install the King James Version (Uses the internet connection to download and install the module)
30
- await interface.installModule('KJV');
30
+ await interface.installModule('CrossWire', 'KJV');
31
31
  }
32
32
 
33
33
  installKJV().then(() => {
package/index.js CHANGED
@@ -213,11 +213,12 @@ class NodeSwordInterface {
213
213
  /**
214
214
  * Returns an object representation of a SWORD module from a repository.
215
215
  *
216
+ * @param {String} repositoryName - The name of the repository to search in.
216
217
  * @param {String} moduleCode - The module code of the SWORD module.
217
218
  * @return {ModuleObject}
218
219
  */
219
- getRepoModule(moduleCode) {
220
- return this.nativeInterface.getRepoModule(moduleCode);
220
+ getRepoModule(repositoryName, moduleCode) {
221
+ return this.nativeInterface.getRepoModule(repositoryName, moduleCode);
221
222
  }
222
223
 
223
224
  /**
@@ -253,8 +254,8 @@ class NodeSwordInterface {
253
254
  }
254
255
 
255
256
  /**
256
- * Installs a module. The repository is automatically determined. The module is downloaded
257
- * from the corresponding repository and then installed in the local SWORD directory.
257
+ * Installs a module. The module is downloaded from the corresponding repository
258
+ * and then installed in the local SWORD directory.
258
259
  * This operation may take some time depending on the available bandwidth and geographical
259
260
  * distance to the SWORD repository server.
260
261
  *
@@ -264,17 +265,18 @@ class NodeSwordInterface {
264
265
  * -1: General installation issue
265
266
  * -9: Installation cancelled by user or internet connection suddenly interrupted
266
267
  *
268
+ * @param {String} repositoryName - The name of the repository from which to install.
267
269
  * @param {String} moduleCode - The module code of the SWORD module that shall be installed.
268
270
  * @param {Function} progressCB - Callback function that is called on progress events.
269
271
  * @return {Promise}
270
272
  */
271
- async installModule(moduleCode, progressCB=undefined) {
273
+ async installModule(repositoryName, moduleCode, progressCB=undefined) {
272
274
  if (progressCB === undefined) {
273
275
  progressCB = function(progress) {};
274
276
  }
275
277
 
276
278
  return new Promise((resolve, reject) => {
277
- this.nativeInterface.installModule(moduleCode, progressCB, function(result) {
279
+ this.nativeInterface.installModule(repositoryName, moduleCode, progressCB, function(result) {
278
280
  if (result == 0) {
279
281
  resolve();
280
282
  } else {
@@ -343,11 +345,12 @@ class NodeSwordInterface {
343
345
  /**
344
346
  * Returns the description of a module.
345
347
  *
348
+ * @param {String} repositoryName - The name of the repository to search in.
346
349
  * @param {String} moduleCode - The module code of the SWORD module.
347
350
  * @return {String} The description of the respective module.
348
351
  */
349
- getModuleDescription(moduleCode) {
350
- return this.nativeInterface.getModuleDescription(moduleCode);
352
+ getModuleDescription(repositoryName, moduleCode) {
353
+ return this.nativeInterface.getModuleDescription(repositoryName, moduleCode);
351
354
  }
352
355
 
353
356
  /**
@@ -730,13 +733,14 @@ class NodeSwordInterface {
730
733
  }
731
734
 
732
735
  /**
733
- * Checks whether the module is available in any repository.
736
+ * Checks whether the module is available in any repository (default) or in a specific repository.
734
737
  *
735
738
  * @param {String} moduleCode - The module code of the SWORD module.
739
+ * @param {String} repositoryName - The name of the repository to check.
736
740
  * @return {Boolean}
737
741
  */
738
- isModuleAvailableInRepo(moduleCode) {
739
- return this.nativeInterface.isModuleAvailableInRepo(moduleCode);
742
+ isModuleAvailableInRepo(moduleCode, repositoryName="all") {
743
+ return this.nativeInterface.isModuleAvailableInRepo(moduleCode, repositoryName);
740
744
  }
741
745
 
742
746
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-sword-interface",
3
- "version": "1.0.97",
3
+ "version": "1.0.98",
4
4
  "description": "Javascript (N-API) interface to SWORD library",
5
5
  "keywords": [
6
6
  "C++",
@@ -132,4 +132,4 @@ else
132
132
  fi
133
133
  fi
134
134
 
135
- make -j4 sword_static
135
+ make -j8 sword_static
@@ -80,7 +80,8 @@ void InstallModuleWorker::Execute(const ExecutionProgress& progress)
80
80
  this->_totalPercent = 0;
81
81
  this->_filePercent = 0;
82
82
 
83
- this->_result = this->_moduleInstaller.installModule(this->_moduleName);
83
+ // Always use repository-specific installation
84
+ this->_result = this->_moduleInstaller.installModule(this->_repoName, this->_moduleName);
84
85
 
85
86
  statusReporter.resetCallbacks();
86
87
  unlockApi();
@@ -29,12 +29,14 @@ public:
29
29
  ModuleInstaller& moduleInstaller,
30
30
  const Napi::Function& jsProgressCallback,
31
31
  const Napi::Function& callback,
32
+ std::string repoName,
32
33
  std::string moduleName)
33
34
 
34
35
  : ProgressWorker(repoInterface,
35
36
  jsProgressCallback,
36
37
  callback),
37
38
  _moduleInstaller(moduleInstaller),
39
+ _repoName(repoName),
38
40
  _moduleName(moduleName) {}
39
41
 
40
42
  void swordPreStatusCB(long totalBytes, long completedBytes, const char *message);
@@ -46,6 +48,7 @@ private:
46
48
  ModuleInstaller& _moduleInstaller;
47
49
  int _result;
48
50
  std::string _moduleName;
51
+ std::string _repoName;
49
52
  long _completedBytes = 0;
50
53
  long _totalBytes = 0;
51
54
  int _totalPercent = 0;
@@ -324,9 +324,23 @@ Napi::Value NodeSwordInterface::isModuleInUserDir(const Napi::CallbackInfo& info
324
324
  Napi::Value NodeSwordInterface::isModuleAvailableInRepo(const Napi::CallbackInfo& info)
325
325
  {
326
326
  lockApi();
327
- INIT_SCOPE_AND_VALIDATE(ParamType::string);
327
+ INIT_SCOPE_AND_VALIDATE(ParamType::string, ParamType::string);
328
328
  Napi::String moduleName = info[0].As<Napi::String>();
329
- bool moduleAvailable = this->_repoInterface->isModuleAvailableInRepo(moduleName);
329
+ Napi::String repoName = info[1].As<Napi::String>();
330
+
331
+ if (string(moduleName).empty()) {
332
+ Napi::TypeError::New(info.Env(), "Module name cannot be empty").ThrowAsJavaScriptException();
333
+ unlockApi();
334
+ return info.Env().Null();
335
+ }
336
+
337
+ if (string(repoName).empty()) {
338
+ Napi::TypeError::New(info.Env(), "Repository name cannot be empty").ThrowAsJavaScriptException();
339
+ unlockApi();
340
+ return info.Env().Null();
341
+ }
342
+
343
+ bool moduleAvailable = this->_repoInterface->isModuleAvailableInRepo(moduleName, repoName);
330
344
  unlockApi();
331
345
  return Napi::Boolean::New(info.Env(), moduleAvailable);
332
346
  }
@@ -469,11 +483,23 @@ Napi::Value NodeSwordInterface::getRepoModule(const Napi::CallbackInfo& info)
469
483
  {
470
484
  lockApi();
471
485
  Napi::Env env = info.Env();
472
- INIT_SCOPE_AND_VALIDATE(ParamType::string);
486
+ INIT_SCOPE_AND_VALIDATE(ParamType::string, ParamType::string);
473
487
  Napi::Object napiObject = Napi::Object::New(env);
474
- Napi::String moduleName = info[0].As<Napi::String>();
488
+ Napi::String repoName = info[0].As<Napi::String>();
489
+ Napi::String moduleName = info[1].As<Napi::String>();
490
+
491
+ if (string(repoName).empty()) {
492
+ Napi::TypeError::New(env, "Repository name cannot be empty").ThrowAsJavaScriptException();
493
+ unlockApi();
494
+ return env.Null();
495
+ }
475
496
 
476
- std::string repoName = this->_repoInterface->getModuleRepo(moduleName);
497
+ if (string(moduleName).empty()) {
498
+ Napi::TypeError::New(env, "Module name cannot be empty").ThrowAsJavaScriptException();
499
+ unlockApi();
500
+ return env.Null();
501
+ }
502
+
477
503
  SWModule* swordModule = this->_repoInterface->getRepoModule(moduleName, repoName);
478
504
 
479
505
  if (swordModule == 0) {
@@ -492,10 +518,23 @@ Napi::Value NodeSwordInterface::getModuleDescription(const Napi::CallbackInfo& i
492
518
  {
493
519
  lockApi();
494
520
  Napi::Env env = info.Env();
495
- INIT_SCOPE_AND_VALIDATE(ParamType::string);
496
- Napi::String moduleName = info[0].As<Napi::String>();
521
+ INIT_SCOPE_AND_VALIDATE(ParamType::string, ParamType::string);
522
+ Napi::String repoName = info[0].As<Napi::String>();
523
+ Napi::String moduleName = info[1].As<Napi::String>();
524
+
525
+ if (string(repoName).empty()) {
526
+ Napi::TypeError::New(env, "Repository name cannot be empty").ThrowAsJavaScriptException();
527
+ unlockApi();
528
+ return env.Null();
529
+ }
497
530
 
498
- SWModule* swordModule = this->_repoInterface->getRepoModule(moduleName);
531
+ if (string(moduleName).empty()) {
532
+ Napi::TypeError::New(env, "Module name cannot be empty").ThrowAsJavaScriptException();
533
+ unlockApi();
534
+ return env.Null();
535
+ }
536
+
537
+ SWModule* swordModule = this->_repoInterface->getRepoModule(moduleName, repoName);
499
538
  if (swordModule == 0) {
500
539
  string errorMessage = "getRepoModule returned 0 for '" + string(moduleName) + "'";
501
540
  THROW_JS_EXCEPTION(errorMessage);
@@ -867,15 +906,29 @@ Napi::Value NodeSwordInterface::getStrongsEntry(const Napi::CallbackInfo& info)
867
906
  Napi::Value NodeSwordInterface::installModule(const Napi::CallbackInfo& info)
868
907
  {
869
908
  lockApi();
870
- INIT_SCOPE_AND_VALIDATE(ParamType::string, ParamType::function, ParamType::function);
871
- Napi::String moduleName = info[0].As<Napi::String>();
872
- Napi::Function progressCallback = info[1].As<Napi::Function>();
873
- Napi::Function callback = info[2].As<Napi::Function>();
909
+ INIT_SCOPE_AND_VALIDATE(ParamType::string, ParamType::string, ParamType::function, ParamType::function);
910
+ Napi::String repoName = info[0].As<Napi::String>();
911
+ Napi::String moduleName = info[1].As<Napi::String>();
912
+ Napi::Function progressCallback = info[2].As<Napi::Function>();
913
+ Napi::Function callback = info[3].As<Napi::Function>();
914
+
915
+ if (string(repoName).empty()) {
916
+ Napi::TypeError::New(info.Env(), "Repository name cannot be empty").ThrowAsJavaScriptException();
917
+ unlockApi();
918
+ return info.Env().Null();
919
+ }
920
+
921
+ if (string(moduleName).empty()) {
922
+ Napi::TypeError::New(info.Env(), "Module name cannot be empty").ThrowAsJavaScriptException();
923
+ unlockApi();
924
+ return info.Env().Null();
925
+ }
874
926
 
875
927
  InstallModuleWorker* worker = new InstallModuleWorker(*(this->_repoInterface),
876
928
  *(this->_moduleInstaller),
877
929
  progressCallback,
878
930
  callback,
931
+ repoName,
879
932
  moduleName);
880
933
  worker->Queue();
881
934
  return info.Env().Undefined();
@@ -157,7 +157,7 @@ void get_dict_key_list(DictHelper& dict_helper)
157
157
  void test_unlock_key(ModuleInstaller& module_installer, ModuleStore& module_store, TextProcessor& text_processor)
158
158
  {
159
159
  module_installer.uninstallModule("NA28");
160
- module_installer.installModule("NA28");
160
+ module_installer.installModule("Deutsche Bibelgesellschaft", "NA28");
161
161
  module_installer.saveModuleUnlockKey("NA28", "");
162
162
  SWModule* m = module_store.getLocalModule("NA28");
163
163
  cout << "Module readable: " << text_processor.isModuleReadable(m) << endl;
@@ -243,7 +243,7 @@ int main(int argc, char** argv)
243
243
 
244
244
  //get_module_text(textProcessor);
245
245
 
246
- get_reference_text(moduleStore, textProcessor);
246
+ //get_reference_text(moduleStore, textProcessor);
247
247
 
248
248
  //get_book_intro(textProcessor);
249
249
 
@@ -57,18 +57,6 @@ void ModuleInstaller::resetAllMgrs()
57
57
  this->refreshMgr();
58
58
  }
59
59
 
60
- int ModuleInstaller::installModule(string moduleName)
61
- {
62
- string repoName = this->_repoInterface.getModuleRepo(moduleName);
63
-
64
- if (repoName == "") {
65
- cerr << "Could not find repository for module " << moduleName << endl;
66
- return -1;
67
- }
68
-
69
- return this->installModule(repoName, moduleName);
70
- }
71
-
72
60
  int ModuleInstaller::installModule(string repoName, string moduleName)
73
61
  {
74
62
  InstallSource* remoteSource = this->_repoInterface.getRemoteSource(repoName);
@@ -37,7 +37,6 @@ public:
37
37
  ModuleInstaller(RepositoryInterface& repoInterface, ModuleStore& moduleStore, std::string customHomeDir="");
38
38
  virtual ~ModuleInstaller();
39
39
 
40
- int installModule(std::string moduleName);
41
40
  int installModule(std::string repoName, std::string moduleName);
42
41
  void cancelInstallation();
43
42
  int uninstallModule(std::string moduleName);