node-sword-interface 1.0.42 → 1.0.44
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/.github/workflows/build.yml +1 -1
- package/API.md +1 -0
- package/index.js +33 -18
- package/package.json +5 -2
- package/scripts/build_sword.sh +4 -0
- package/scripts/get_sword_build_win32.ps1 +4 -1
- package/src/napi_module/napi_sword_helper.cpp +4 -0
- package/src/sword_backend/module_helper.cpp +39 -0
- package/src/sword_backend/module_helper.hpp +2 -0
package/API.md
CHANGED
|
@@ -692,6 +692,7 @@ An object representation of a SWORD module.
|
|
|
692
692
|
| shortCopyright | <code>String</code> | The short copyright information of the SWORD module |
|
|
693
693
|
| version | <code>String</code> | The version of the SWORD module |
|
|
694
694
|
| lastUpdate | <code>String</code> | The date of the last version update of the SWORD module |
|
|
695
|
+
| history | <code>Array.<String></code> | The history of the SWORD module. A list of strings where each looks like this: <version>=<version-info> |
|
|
695
696
|
| category | <code>String</code> | The category of the SWORD module |
|
|
696
697
|
| repository | <code>String</code> | The repository of the SWORD module |
|
|
697
698
|
| about | <code>String</code> | Extended description of the SWORD module |
|
package/index.js
CHANGED
|
@@ -18,6 +18,10 @@
|
|
|
18
18
|
|
|
19
19
|
const path = require('path');
|
|
20
20
|
const nodeSwordInterfaceModule = require('./build/Release/node_sword_interface.node');
|
|
21
|
+
const { Mutex } = require('async-mutex');
|
|
22
|
+
|
|
23
|
+
// Create a mutex instance
|
|
24
|
+
const searchMutex = new Mutex();
|
|
21
25
|
|
|
22
26
|
/**
|
|
23
27
|
* An object representation of a Bible verse.
|
|
@@ -43,6 +47,7 @@ const nodeSwordInterfaceModule = require('./build/Release/node_sword_interface.n
|
|
|
43
47
|
* @property {String} shortCopyright - The short copyright information of the SWORD module
|
|
44
48
|
* @property {String} version - The version of the SWORD module
|
|
45
49
|
* @property {String} lastUpdate - The date of the last version update of the SWORD module
|
|
50
|
+
* @property {String[]} history - The history of the SWORD module. A list of strings where each looks like this: <version>=<version-info>
|
|
46
51
|
* @property {String} category - The category of the SWORD module
|
|
47
52
|
* @property {String} repository - The repository of the SWORD module
|
|
48
53
|
* @property {String} about - Extended description of the SWORD module
|
|
@@ -112,7 +117,7 @@ class NodeSwordInterface {
|
|
|
112
117
|
* @param {Function} progressCB - Optional callback function that is called on progress events.
|
|
113
118
|
* @return {Promise}
|
|
114
119
|
*/
|
|
115
|
-
updateRepositoryConfig(progressCB=undefined) {
|
|
120
|
+
async updateRepositoryConfig(progressCB=undefined) {
|
|
116
121
|
return new Promise((resolve, reject) => {
|
|
117
122
|
if (progressCB === undefined) {
|
|
118
123
|
progressCB = function(progress) {};
|
|
@@ -241,7 +246,7 @@ class NodeSwordInterface {
|
|
|
241
246
|
* @param {Function} progressCB - Callback function that is called on progress events.
|
|
242
247
|
* @return {Promise}
|
|
243
248
|
*/
|
|
244
|
-
installModule(moduleCode, progressCB=undefined) {
|
|
249
|
+
async installModule(moduleCode, progressCB=undefined) {
|
|
245
250
|
if (progressCB === undefined) {
|
|
246
251
|
progressCB = function(progress) {};
|
|
247
252
|
}
|
|
@@ -272,7 +277,7 @@ class NodeSwordInterface {
|
|
|
272
277
|
* @param {String} moduleCode - The module code of the SWORD module that shall be uninstalled.
|
|
273
278
|
* @return {Promise}
|
|
274
279
|
*/
|
|
275
|
-
uninstallModule(moduleCode) {
|
|
280
|
+
async uninstallModule(moduleCode) {
|
|
276
281
|
return new Promise((resolve, reject) => {
|
|
277
282
|
this.nativeInterface.uninstallModule(moduleCode, function(uninstallSuccessful) {
|
|
278
283
|
if (uninstallSuccessful) {
|
|
@@ -595,21 +600,27 @@ class NodeSwordInterface {
|
|
|
595
600
|
* @param {Boolean} filterOnWordBoundaries - Whether to filter results based on word boundaries.
|
|
596
601
|
* @return {Promise}
|
|
597
602
|
*/
|
|
598
|
-
getModuleSearchResults(moduleCode,
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
603
|
+
async getModuleSearchResults(moduleCode,
|
|
604
|
+
searchTerm,
|
|
605
|
+
progressCB = undefined,
|
|
606
|
+
searchType = "phrase",
|
|
607
|
+
searchScope = "BIBLE",
|
|
608
|
+
isCaseSensitive = false,
|
|
609
|
+
useExtendedVerseBoundaries = false,
|
|
610
|
+
filterOnWordBoundaries = false) {
|
|
606
611
|
|
|
607
612
|
if (progressCB === undefined) {
|
|
608
613
|
progressCB = function(progress) {};
|
|
609
614
|
}
|
|
610
615
|
|
|
611
|
-
|
|
612
|
-
|
|
616
|
+
if (searchMutex.isLocked()) {
|
|
617
|
+
throw new Error("Module search in progress. Wait until it is finished.");
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
const release = await searchMutex.acquire();
|
|
621
|
+
|
|
622
|
+
try {
|
|
623
|
+
return new Promise((resolve, reject) => {
|
|
613
624
|
this.nativeInterface.getModuleSearchResults(moduleCode,
|
|
614
625
|
searchTerm,
|
|
615
626
|
searchType,
|
|
@@ -618,11 +629,15 @@ class NodeSwordInterface {
|
|
|
618
629
|
useExtendedVerseBoundaries,
|
|
619
630
|
filterOnWordBoundaries,
|
|
620
631
|
progressCB,
|
|
621
|
-
function(searchResults) {
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
632
|
+
function(searchResults) {
|
|
633
|
+
release();
|
|
634
|
+
resolve(searchResults);
|
|
635
|
+
});
|
|
636
|
+
});
|
|
637
|
+
} catch (error) {
|
|
638
|
+
release();
|
|
639
|
+
throw error;
|
|
640
|
+
}
|
|
626
641
|
}
|
|
627
642
|
|
|
628
643
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-sword-interface",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.44",
|
|
4
4
|
"description": "Javascript (N-API) interface to SWORD library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"C++",
|
|
@@ -17,11 +17,13 @@
|
|
|
17
17
|
"doc": "jsdoc2md index.js > API.md",
|
|
18
18
|
"pub": "rm -rf build node_modules sword sword_build test && npm publish ./",
|
|
19
19
|
"deploy": "scripts/deploy_local.sh",
|
|
20
|
-
"postinstall": "node scripts/postinstall.js"
|
|
20
|
+
"postinstall": "node scripts/postinstall.js",
|
|
21
|
+
"test": "jest"
|
|
21
22
|
},
|
|
22
23
|
"author": "Tobias Klein",
|
|
23
24
|
"license": "GPL-2.0+",
|
|
24
25
|
"dependencies": {
|
|
26
|
+
"async-mutex": "^0.5.0",
|
|
25
27
|
"glob": "^8.0.3",
|
|
26
28
|
"node-addon-api": "^8.2.2",
|
|
27
29
|
"node-html-parser": "^6.1.13"
|
|
@@ -31,6 +33,7 @@
|
|
|
31
33
|
"url": "git+https://github.com/ezra-bible-app/node-sword-interface.git"
|
|
32
34
|
},
|
|
33
35
|
"devDependencies": {
|
|
36
|
+
"jest": "^30.0.5",
|
|
34
37
|
"jsdoc-to-markdown": "^9.1.1",
|
|
35
38
|
"node-gyp": "^9.1.0"
|
|
36
39
|
}
|
package/scripts/build_sword.sh
CHANGED
|
@@ -47,6 +47,10 @@ mkdir -p sword_build
|
|
|
47
47
|
|
|
48
48
|
SWORD_BUILD_TYPE="Release"
|
|
49
49
|
|
|
50
|
+
# Newer CMake versions have removed compatibility with CMake < 3.5.
|
|
51
|
+
# SWORD is configured with CMake minimum 2.6.0, which leads to a build error with newer CMake versions (e.g. 4.0.3).
|
|
52
|
+
export CMAKE_POLICY_VERSION_MINIMUM=3.5
|
|
53
|
+
|
|
50
54
|
if [ "$1" = "--android" ] ; then
|
|
51
55
|
git clone https://github.com/karlkleinpaste/biblesync.git
|
|
52
56
|
git -C biblesync checkout 2.1.0
|
|
@@ -57,9 +57,12 @@ if (Test-Path sword-build-win32) {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
# --- Download the file to the current location
|
|
60
|
-
$OutputPath =
|
|
60
|
+
$OutputPath = Join-Path -Path (Get-Location).Path -ChildPath $ZipName
|
|
61
61
|
Invoke-RestMethod -Method Get -Uri $ZipUrl -OutFile $OutputPath -Headers $headers
|
|
62
62
|
|
|
63
|
+
Write-Host "OutputPath: $OutputPath"
|
|
64
|
+
Write-Host "ZipUrl: $ZipUrl"
|
|
65
|
+
|
|
63
66
|
# --- Unzip the zip file and remove it afterwards
|
|
64
67
|
unzip $OutputPath $((Get-Location).Path)
|
|
65
68
|
Remove-Item $OutputPath
|
|
@@ -128,6 +128,10 @@ void NapiSwordHelper::swordModuleToNapiObject(const Napi::Env& env, SWModule* sw
|
|
|
128
128
|
|
|
129
129
|
object["hasGreekStrongsKeys"] = Napi::Boolean::New(env, this->_moduleHelper.moduleHasFeature(swModule, "GreekDef"));
|
|
130
130
|
object["hasHebrewStrongsKeys"] = Napi::Boolean::New(env, this->_moduleHelper.moduleHasFeature(swModule, "HebrewDef"));
|
|
131
|
+
|
|
132
|
+
// Add module history entries
|
|
133
|
+
std::vector<std::string> historyEntries = this->_moduleHelper.getModuleHistoryEntries(swModule);
|
|
134
|
+
object["history"] = this->getNapiArrayFromStringVector(env, historyEntries);
|
|
131
135
|
}
|
|
132
136
|
|
|
133
137
|
Napi::String NapiSwordHelper::getConfigEntry(sword::SWModule* swModule, std::string key, const Napi::Env& env)
|
|
@@ -198,6 +198,45 @@ map<string, int> ModuleHelper::getAbsoluteVerseNumberMap(SWModule* module, vecto
|
|
|
198
198
|
return absoluteVerseNumbers;
|
|
199
199
|
}
|
|
200
200
|
|
|
201
|
+
vector<string> ModuleHelper::getModuleConfigEntries(sword::SWModule* module)
|
|
202
|
+
{
|
|
203
|
+
vector<string> configEntries;
|
|
204
|
+
|
|
205
|
+
const ConfigEntMap& config = module->getConfig();
|
|
206
|
+
|
|
207
|
+
for (ConfigEntMap::const_iterator it = config.begin(); it != config.end(); ++it) {
|
|
208
|
+
configEntries.push_back(it->first.c_str());
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return configEntries;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
std::vector<std::string> ModuleHelper::getModuleHistoryEntries(sword::SWModule* module)
|
|
215
|
+
{
|
|
216
|
+
std::vector<std::string> historyEntries;
|
|
217
|
+
|
|
218
|
+
if (module == 0) {
|
|
219
|
+
cerr << "module is 0! Cannot get history entries!" << endl;
|
|
220
|
+
return historyEntries;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Get all config entries
|
|
224
|
+
const ConfigEntMap& config = module->getConfig();
|
|
225
|
+
|
|
226
|
+
// Find all entries that start with "History_"
|
|
227
|
+
for (ConfigEntMap::const_iterator it = config.begin(); it != config.end(); ++it) {
|
|
228
|
+
std::string key = it->first.c_str();
|
|
229
|
+
if (key.find("History_") == 0) {
|
|
230
|
+
std::string value = it->second.c_str();
|
|
231
|
+
std::string version = key.substr(8); // Remove "History_" prefix
|
|
232
|
+
std::string entry = version + "=" + value;
|
|
233
|
+
historyEntries.push_back(entry);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return historyEntries;
|
|
238
|
+
}
|
|
239
|
+
|
|
201
240
|
bool ModuleHelper::isBrokenMarkupModule(std::string moduleName)
|
|
202
241
|
{
|
|
203
242
|
return std::find(this->_brokenMarkupModules.begin(),
|
|
@@ -50,6 +50,8 @@ public:
|
|
|
50
50
|
std::map<std::string, int> getAbsoluteVerseNumberMap(sword::SWModule* module, std::vector<std::string> bookList={});
|
|
51
51
|
bool isBrokenMarkupModule(std::string moduleName);
|
|
52
52
|
bool isInconsistentClosingEndDivModule(std::string moduleName);
|
|
53
|
+
std::vector<std::string> getModuleConfigEntries(sword::SWModule* module);
|
|
54
|
+
std::vector<std::string> getModuleHistoryEntries(sword::SWModule* module);
|
|
53
55
|
|
|
54
56
|
private:
|
|
55
57
|
bool moduleHasKeyValuePair(sword::SWModule* module, std::string key, std::string value);
|