node-sword-interface 0.237.0 → 0.241.0

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.
@@ -10,7 +10,7 @@ jobs:
10
10
  - uses: actions/checkout@v2
11
11
  - uses: actions/setup-node@v2
12
12
  with:
13
- node-version: '10'
13
+ node-version: '12'
14
14
 
15
15
  - run: sudo apt update && sudo apt install -y libcurl4-gnutls-dev
16
16
  - run: npm install
package/API.md CHANGED
@@ -61,7 +61,7 @@ This is the main class of node-sword-interface and it provides a set of static f
61
61
  * [.getBibleText(moduleCode)](#NodeSwordInterface+getBibleText) ⇒ [<code>Array.&lt;VerseObject&gt;</code>](#VerseObject)
62
62
  * [.getBookIntroduction(moduleCode, bookCode)](#NodeSwordInterface+getBookIntroduction) ⇒ <code>String</code>
63
63
  * [.moduleHasBook(moduleCode, bookCode)](#NodeSwordInterface+moduleHasBook) ⇒ <code>Boolean</code>
64
- * [.getModuleSearchResults(moduleCode, searchTerm, progressCB, searchType, isCaseSensitive, useExtendedVerseBoundaries)](#NodeSwordInterface+getModuleSearchResults) ⇒ <code>Promise</code>
64
+ * [.getModuleSearchResults(moduleCode, searchTerm, progressCB, searchType, searchScope, isCaseSensitive, useExtendedVerseBoundaries)](#NodeSwordInterface+getModuleSearchResults) ⇒ <code>Promise</code>
65
65
  * [.terminateModuleSearch()](#NodeSwordInterface+terminateModuleSearch)
66
66
  * [.hebrewStrongsAvailable()](#NodeSwordInterface+hebrewStrongsAvailable) ⇒ <code>Boolean</code>
67
67
  * [.greekStrongsAvailable()](#NodeSwordInterface+greekStrongsAvailable) ⇒ <code>Boolean</code>
@@ -91,7 +91,8 @@ This function must be called initially before using any other repository-related
91
91
  initialized, the use of this function is optional. However, the cached repository configuration may not contain the latest information
92
92
  if this function is not called.
93
93
 
94
- This function works asynchronously and returns a Promise object.
94
+ This function works asynchronously and returns a Promise object. The Promise delivers a detailed status object which contains one
95
+ entry for each of the repositories of the master repo list as well as one result entry.
95
96
 
96
97
  **Kind**: instance method of [<code>NodeSwordInterface</code>](#NodeSwordInterface)
97
98
 
@@ -446,7 +447,7 @@ Checks whether a module has a certain book
446
447
 
447
448
  <a name="NodeSwordInterface+getModuleSearchResults"></a>
448
449
 
449
- ### nodeSwordInterface.getModuleSearchResults(moduleCode, searchTerm, progressCB, searchType, isCaseSensitive, useExtendedVerseBoundaries) ⇒ <code>Promise</code>
450
+ ### nodeSwordInterface.getModuleSearchResults(moduleCode, searchTerm, progressCB, searchType, searchScope, isCaseSensitive, useExtendedVerseBoundaries) ⇒ <code>Promise</code>
450
451
  Returns the results of a module search.
451
452
 
452
453
  **Kind**: instance method of [<code>NodeSwordInterface</code>](#NodeSwordInterface)
@@ -457,6 +458,7 @@ Returns the results of a module search.
457
458
  | searchTerm | <code>String</code> | | The term to search for. |
458
459
  | progressCB | <code>function</code> | | Optional callback function that is called on progress events. |
459
460
  | searchType | <code>String</code> | <code>phrase</code> | Options: phrase, multiWord, strongsNumber |
461
+ | searchScope | <code>String</code> | <code>BIBLE</code> | Options: BIBLE, OT, NT |
460
462
  | isCaseSensitive | <code>Boolean</code> | <code>false</code> | Whether the search is case sensitive |
461
463
  | useExtendedVerseBoundaries | <code>Boolean</code> | <code>false</code> | Whether the search should use extended verse boundaries (Two verses instead of one) in case of a multi word search. |
462
464
 
package/README.md CHANGED
@@ -112,10 +112,11 @@ To install the dependencies issue the following command on a Debian/Ubuntu based
112
112
 
113
113
  #### Install dependencies on Windows
114
114
 
115
- 1. Install [git](https://git-scm.com/download/win) and [nodejs](https://nodejs.org).
116
- 2. Install [windows-build-tools][windows-build-tools] (VS 2015 Compiler) by running the following command in an administrator powershell:<br/> `npm install --vs2015 --global windows-build-tools`.
115
+ 1. Install [git](https://git-scm.com/download/win).
116
+ 2. Install [nodejs](https://nodejs.org). Important note: Ensure to install the *x86 version* (32-bit) of nodejs 14.x.
117
+ Furthermore, when the setup assistant asks about *Tools for native modules*, make sure to tick the checkbox *Automatically install the necessary tools*. This will then install the windows build tools required to build node-sword-interface.
117
118
 
118
- [windows-build-tools]: https://www.npmjs.com/package/windows-build-tools
119
+ ![Tools for native addons](https://raw.githubusercontent.com/ezra-bible-app/ezrabibleapp.net/master/assets/screenshots/nodejs_tools_for_native_addons.png)
119
120
 
120
121
  ### Install from npmjs
121
122
 
package/index.js CHANGED
@@ -104,7 +104,8 @@ class NodeSwordInterface {
104
104
  * initialized, the use of this function is optional. However, the cached repository configuration may not contain the latest information
105
105
  * if this function is not called.
106
106
  *
107
- * This function works asynchronously and returns a Promise object.
107
+ * This function works asynchronously and returns a Promise object. The Promise delivers a detailed status object which contains one
108
+ * entry for each of the repositories of the master repo list as well as one result entry.
108
109
  *
109
110
  * @param {Function} progressCB - Optional callback function that is called on progress events.
110
111
  * @return {Promise}
@@ -115,12 +116,8 @@ class NodeSwordInterface {
115
116
  progressCB = function(progress) {};
116
117
  }
117
118
 
118
- this.nativeInterface.updateRepositoryConfig(true, progressCB, function(updateSuccessful) {
119
- if (updateSuccessful) {
120
- resolve(0);
121
- } else {
122
- reject(-1);
123
- }
119
+ this.nativeInterface.updateRepositoryConfig(true, progressCB, function(repoUpdateStatus) {
120
+ resolve(repoUpdateStatus);
124
121
  });
125
122
  });
126
123
  }
@@ -462,20 +459,33 @@ class NodeSwordInterface {
462
459
  * @param {String} searchTerm - The term to search for.
463
460
  * @param {Function} progressCB - Optional callback function that is called on progress events.
464
461
  * @param {String} searchType - Options: phrase, multiWord, strongsNumber
462
+ * @param {String} searchScope - Options: BIBLE, OT, NT
465
463
  * @param {Boolean} isCaseSensitive - Whether the search is case sensitive
466
464
  * @param {Boolean} useExtendedVerseBoundaries - Whether the search should use extended verse boundaries (Two verses instead of one) in case of a multi word search.
467
465
  * @return {Promise}
468
466
  */
469
- getModuleSearchResults(moduleCode, searchTerm, progressCB=undefined, searchType="phrase", isCaseSensitive=false, useExtendedVerseBoundaries=false) {
467
+ getModuleSearchResults(moduleCode,
468
+ searchTerm,
469
+ progressCB=undefined,
470
+ searchType="phrase",
471
+ searchScope="BIBLE",
472
+ isCaseSensitive=false,
473
+ useExtendedVerseBoundaries=false) {
474
+
470
475
  if (progressCB === undefined) {
471
476
  progressCB = function(progress) {};
472
477
  }
473
478
 
474
479
  return new Promise((resolve, reject) => {
475
480
  try {
476
- this.nativeInterface.getModuleSearchResults(moduleCode, searchTerm, searchType, isCaseSensitive, useExtendedVerseBoundaries, progressCB, function(searchResults) {
477
- resolve(searchResults);
478
- });
481
+ this.nativeInterface.getModuleSearchResults(moduleCode,
482
+ searchTerm,
483
+ searchType,
484
+ searchScope,
485
+ isCaseSensitive,
486
+ useExtendedVerseBoundaries,
487
+ progressCB,
488
+ function(searchResults) { resolve(searchResults); });
479
489
  } catch (error) {
480
490
  reject(error);
481
491
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-sword-interface",
3
- "version": "0.237.0",
3
+ "version": "0.241.0",
4
4
  "description": "Javascript (N-API) interface to SWORD library",
5
5
  "keywords": [
6
6
  "C++",
@@ -21,14 +21,14 @@
21
21
  "author": "Tobias Klein",
22
22
  "license": "GPL-2.0+",
23
23
  "dependencies": {
24
- "node-addon-api": "^3.2.0"
24
+ "node-addon-api": "^4.2.0"
25
25
  },
26
26
  "repository": {
27
27
  "type": "git",
28
28
  "url": "https://github.com/ezra-project/node-sword-interface.git"
29
29
  },
30
30
  "devDependencies": {
31
- "jsdoc-to-markdown": "^7.0.1",
31
+ "jsdoc-to-markdown": "^7.1.0",
32
32
  "node-gyp": "^8.0.0"
33
33
  }
34
34
  }
@@ -35,6 +35,7 @@ void ModuleSearchWorker::Execute(const ExecutionProgress& progress)
35
35
  this->_stdSearchResults = this->_moduleSearch.getModuleSearchResults(this->_moduleName,
36
36
  this->_searchTerm,
37
37
  this->_searchType,
38
+ this->_searchScope,
38
39
  this->_isCaseSensitive,
39
40
  this->_useExtendedVerseBoundaries);
40
41
 
@@ -36,6 +36,7 @@ public:
36
36
  std::string moduleName,
37
37
  std::string searchTerm,
38
38
  SearchType searchType,
39
+ SearchScope searchScope,
39
40
  bool isCaseSensitive=false,
40
41
  bool useExtendedVerseBoundaries=false)
41
42
 
@@ -45,6 +46,7 @@ public:
45
46
  _moduleName(moduleName),
46
47
  _searchTerm(searchTerm),
47
48
  _searchType(searchType),
49
+ _searchScope(searchScope),
48
50
  _isCaseSensitive(isCaseSensitive),
49
51
  _useExtendedVerseBoundaries(useExtendedVerseBoundaries),
50
52
  _searchTerminated(false) {
@@ -66,6 +68,7 @@ private:
66
68
  std::string _moduleName;
67
69
  std::string _searchTerm;
68
70
  SearchType _searchType;
71
+ SearchScope _searchScope;
69
72
  bool _isCaseSensitive;
70
73
  bool _useExtendedVerseBoundaries;
71
74
  bool _searchTerminated;
@@ -695,6 +695,7 @@ Napi::Value NodeSwordInterface::getModuleSearchResults(const Napi::CallbackInfo&
695
695
  INIT_SCOPE_AND_VALIDATE(ParamType::string, // moduleName
696
696
  ParamType::string, // searchTerm
697
697
  ParamType::string, // searchType
698
+ ParamType::string, // searchScope
698
699
  ParamType::boolean, // isCaseSensitive
699
700
  ParamType::boolean, // useExtendedVerseBoundaries
700
701
  ParamType::function, // progressCallback
@@ -703,10 +704,11 @@ Napi::Value NodeSwordInterface::getModuleSearchResults(const Napi::CallbackInfo&
703
704
  Napi::String moduleName = info[0].As<Napi::String>();
704
705
  Napi::String searchTerm = info[1].As<Napi::String>();
705
706
  string searchTypeString = string(info[2].As<Napi::String>());
706
- Napi::Boolean isCaseSensitive = info[3].As<Napi::Boolean>();
707
- Napi::Boolean useExtendedVerseBoundaries = info[4].As<Napi::Boolean>();
708
- Napi::Function jsProgressCallback = info[5].As<Napi::Function>();
709
- Napi::Function callback = info[6].As<Napi::Function>();
707
+ string searchScopeString = string(info[3].As<Napi::String>());
708
+ Napi::Boolean isCaseSensitive = info[4].As<Napi::Boolean>();
709
+ Napi::Boolean useExtendedVerseBoundaries = info[5].As<Napi::Boolean>();
710
+ Napi::Function jsProgressCallback = info[6].As<Napi::Function>();
711
+ Napi::Function callback = info[7].As<Napi::Function>();
710
712
  SearchType searchType = SearchType::multiWord;
711
713
 
712
714
  if (searchTypeString == "phrase") {
@@ -725,6 +727,18 @@ Napi::Value NodeSwordInterface::getModuleSearchResults(const Napi::CallbackInfo&
725
727
  }
726
728
  }
727
729
 
730
+ SearchScope searchScope = SearchScope::BIBLE;
731
+
732
+ if (searchScopeString == "BIBLE") {
733
+ searchScope = SearchScope::BIBLE;
734
+ } else if (searchScopeString == "OT") {
735
+ searchScope = SearchScope::OT;
736
+ } else if (searchScopeString == "NT") {
737
+ searchScope = SearchScope::NT;
738
+ } else {
739
+ THROW_JS_EXCEPTION("Unknown search scope!");
740
+ }
741
+
728
742
  this->_currentModuleSearchWorker = new ModuleSearchWorker(*(this->_moduleHelper),
729
743
  *(this->_moduleSearch),
730
744
  *(this->_moduleStore),
@@ -735,6 +749,7 @@ Napi::Value NodeSwordInterface::getModuleSearchResults(const Napi::CallbackInfo&
735
749
  moduleName,
736
750
  searchTerm,
737
751
  searchType,
752
+ searchScope,
738
753
  isCaseSensitive,
739
754
  useExtendedVerseBoundaries);
740
755
  this->_currentModuleSearchWorker->Queue();
@@ -21,6 +21,7 @@
21
21
 
22
22
  #include <napi.h>
23
23
  #include <iostream>
24
+ #include <map>
24
25
 
25
26
  #include "api_lock.hpp"
26
27
  #include "napi_sword_helper.hpp"
@@ -115,20 +116,29 @@ public:
115
116
  this,
116
117
  std::placeholders::_1);
117
118
 
118
- int ret = this->_repoInterface.refreshRemoteSources(this->_forced, &_progressCallback);
119
+ int ret = this->_repoInterface.refreshRemoteSources(this->_forced, &this->_repoUpdateStatus, &_progressCallback);
119
120
  this->_isSuccessful = (ret == 0);
120
121
  unlockApi();
121
122
  }
122
123
 
123
124
  void OnOK() {
124
125
  Napi::HandleScope scope(this->Env());
125
- Napi::Boolean isSuccessful = Napi::Boolean::New(this->Env(), this->_isSuccessful);
126
- Callback().Call({ isSuccessful });
126
+
127
+ Napi::Object repoUpdateStatusObject = Napi::Object::New(this->Env());
128
+ repoUpdateStatusObject["result"] = this->_isSuccessful;
129
+
130
+ map<string, bool>::iterator it;
131
+ for (it = this->_repoUpdateStatus.begin(); it != this->_repoUpdateStatus.end(); it++) {
132
+ repoUpdateStatusObject[it->first] = it->second;
133
+ }
134
+
135
+ Callback().Call({ repoUpdateStatusObject });
127
136
  }
128
137
 
129
138
  private:
130
139
  bool _isSuccessful;
131
140
  bool _forced;
141
+ map<string, bool> _repoUpdateStatus;
132
142
  };
133
143
 
134
144
  class UninstallModuleWorker : public BaseWorker {
@@ -197,7 +197,7 @@ int main(int argc, char** argv)
197
197
 
198
198
  //get_strongs_entry(textProcessor);
199
199
 
200
- get_module_text(textProcessor);
200
+ //get_module_text(textProcessor);
201
201
 
202
202
  //get_book_intro(textProcessor);
203
203
 
@@ -206,11 +206,11 @@ int main(int argc, char** argv)
206
206
  //string translation = sword_facade.getSwordTranslation(string("/usr/share/sword/locales.d"), string("de"), string("locales"));
207
207
  //cout << translation << endl;
208
208
 
209
- /*vector<Verse> searchResults = moduleSearch.getModuleSearchResults("NASB", "Jesus faith", SearchType::multiWord, false, true);
209
+ vector<Verse> searchResults = moduleSearch.getModuleSearchResults("NASB", "faith", SearchType::multiWord, SearchScope::NT, true);
210
210
  cout << "Got " << searchResults.size() << " results!" << endl;
211
211
  for (unsigned int i=0; i < searchResults.size(); i++) {
212
212
  cout << searchResults[i].reference << endl;
213
- }*/
213
+ }
214
214
 
215
215
  return 0;
216
216
  }
@@ -82,6 +82,13 @@ void FileSystemHelper::createBasicDirectories()
82
82
  #endif
83
83
  #endif
84
84
 
85
+ if (!this->fileExists(this->getUserDir())) {
86
+ ret = this->makeDirectory(this->getUserDir());
87
+ if (ret != 0) {
88
+ cerr << "Failed to create user dir at " << this->getUserDir() << endl;
89
+ }
90
+ }
91
+
85
92
  if (!this->fileExists(this->getUserSwordDir())) {
86
93
  ret = this->makeDirectory(this->getUserSwordDir());
87
94
  if (ret != 0) {
@@ -50,17 +50,52 @@
50
50
  using namespace std;
51
51
  using namespace sword;
52
52
 
53
+ ListKey ModuleSearch::getScopeKey(SearchScope scope)
54
+ {
55
+ ListKey key;
56
+
57
+ switch (scope) {
58
+ case SearchScope::OT:
59
+ {
60
+ const char* otBooks = "Genesis;Exodus;Leviticus;Numbers;Joshua;Judges;"
61
+ "Ruth;I Samuel;II Samuel;I Kings;II Kings;I Chronicles;II Chronicles;"
62
+ "Ezra;Nehemiah;Esther;Job;Psalms;Proverbs;Ecclesiastes;Song of Solomon;"
63
+ "Isaiah;Jeremiah;Lamentations;Ezekiel;Daniel;Hosea;Joel;Amos;Obadiah;"
64
+ "Jonah;Micah;Nahum;Habakkuk;Zephaniah;Haggai;Zechariah;Malachi;";
65
+
66
+ key = VerseKey().parseVerseList(otBooks, "", true);
67
+ break;
68
+ }
69
+
70
+ case SearchScope::NT:
71
+ {
72
+ const char* ntBooks = "Matthew;Mark;Luke;John;Acts;Romans;I Corinthians;II Corinthians;"
73
+ "Galatians;Ephesians;Philippians;Colossians;I Thessalonians;II Thessalonians;"
74
+ "I Timothy;II Timothy;Titus;Philemon;Hebrews;James;I Peter;II Peter;"
75
+ "I John;II John;III John;Jude;Revelation of John;";
76
+
77
+ key = VerseKey().parseVerseList(ntBooks, "", true);
78
+ break;
79
+ }
80
+
81
+ default:
82
+ break;
83
+ }
84
+
85
+ return key;
86
+ }
53
87
 
54
88
  vector<Verse> ModuleSearch::getModuleSearchResults(string moduleName,
55
89
  string searchTerm,
56
90
  SearchType searchType,
91
+ SearchScope searchScope,
57
92
  bool isCaseSensitive,
58
93
  bool useExtendedVerseBoundaries)
59
94
  {
60
95
  this->_currentModuleName = moduleName;
61
96
  SWModule* module = this->_moduleStore.getLocalModule(moduleName);
62
97
  ListKey listKey;
63
- ListKey* scope = 0;
98
+ SWKey* scope = 0;
64
99
  int flags = 0;
65
100
  // This holds the text that we will return
66
101
  vector<Verse> searchResults;
@@ -81,6 +116,13 @@ vector<Verse> ModuleSearch::getModuleSearchResults(string moduleName,
81
116
  } else if (searchTerm == "") {
82
117
  cerr << "ModuleSearch::getModuleSearchResults: cannot work with empty search term!" << endl;
83
118
  } else {
119
+ ListKey scopeKey;
120
+
121
+ if (searchScope != SearchScope::BIBLE) {
122
+ scopeKey = this->getScopeKey(searchScope);
123
+ scope = &scopeKey;
124
+ }
125
+
84
126
  bool hasStrongs = this->_moduleHelper.moduleHasGlobalOption(module, "Strongs");
85
127
 
86
128
  if (searchType == SearchType::strongsNumber) {
@@ -29,6 +29,7 @@ void internalModuleSearchProgressCB(char percent, void* userData);
29
29
 
30
30
  namespace sword {
31
31
  class SWModule;
32
+ class ListKey;
32
33
  };
33
34
 
34
35
  enum class SearchType {
@@ -37,6 +38,12 @@ enum class SearchType {
37
38
  strongsNumber = -3
38
39
  };
39
40
 
41
+ enum class SearchScope {
42
+ BIBLE = 0,
43
+ OT = 1,
44
+ NT = 2
45
+ };
46
+
40
47
  class ModuleStore;
41
48
  class ModuleHelper;
42
49
  class TextProcessor;
@@ -51,12 +58,15 @@ public:
51
58
  std::vector<Verse> getModuleSearchResults(std::string moduleName,
52
59
  std::string searchTerm,
53
60
  SearchType searchType=SearchType::multiWord,
61
+ SearchScope searchScope=SearchScope::BIBLE,
54
62
  bool isCaseSensitive=false,
55
63
  bool useExtendedVerseBoundaries=false);
56
64
 
57
65
  void terminate();
58
66
 
59
67
  private:
68
+ sword::ListKey getScopeKey(SearchScope scope);
69
+
60
70
  ModuleStore& _moduleStore;
61
71
  ModuleHelper& _moduleHelper;
62
72
  TextProcessor& _textProcessor;
@@ -67,6 +67,9 @@ void RepositoryInterface::resetMgr()
67
67
 
68
68
  this->_installMgr = new InstallMgr(this->_fileSystemHelper.getInstallMgrDir().c_str(), &this->_statusReporter);
69
69
  this->_installMgr->setUserDisclaimerConfirmed(true);
70
+
71
+ long timeoutMillis = 20000;
72
+ this->_installMgr->setTimeoutMillis(timeoutMillis);
70
73
  }
71
74
 
72
75
  int RepositoryInterface::refreshRepositoryConfig()
@@ -84,7 +87,7 @@ int RepositoryInterface::refreshRepositoryConfig()
84
87
  return 0;
85
88
  }
86
89
 
87
- int RepositoryInterface::refreshRemoteSources(bool force, std::function<void(unsigned int progress)>* progressCallback)
90
+ int RepositoryInterface::refreshRemoteSources(bool force, map<string, bool>* repoUpdateStatus, std::function<void(unsigned int progress)>* progressCallback)
88
91
  {
89
92
  vector<future<int>> refreshFutures;
90
93
  this->_remoteSourceUpdateCount = 0;
@@ -111,6 +114,10 @@ int RepositoryInterface::refreshRemoteSources(bool force, std::function<void(uns
111
114
  if (ret != 0) {
112
115
  refreshSuccessful = false;
113
116
  }
117
+
118
+ if (repoUpdateStatus != 0) {
119
+ (*repoUpdateStatus)[sourceNames[i]] = (ret == 0);
120
+ }
114
121
  }
115
122
  }
116
123
 
@@ -21,6 +21,7 @@
21
21
 
22
22
  #include <vector>
23
23
  #include <string>
24
+ #include <map>
24
25
  #include <future>
25
26
 
26
27
  #include "common_defs.hpp"
@@ -45,7 +46,7 @@ public:
45
46
  void resetMgr();
46
47
 
47
48
  int refreshRepositoryConfig();
48
- int refreshRemoteSources(bool force=false, std::function<void(unsigned int progress)>* progressCallback=0);
49
+ int refreshRemoteSources(bool force=false, std::map<std::string, bool>* repoUpdateStatus=0, std::function<void(unsigned int progress)>* progressCallback=0);
49
50
 
50
51
  std::vector<std::string> getRepoNames();
51
52
  sword::SWModule* getRepoModule(std::string moduleName, std::string repoName="all");