k2hdkc 2.0.2 → 2.0.3

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.
@@ -182,6 +182,11 @@ check_and_download_asset_file()
182
182
  PRNINFO "Not found ${ASSET_TGZ_FILENAME} file."
183
183
  return 1
184
184
  fi
185
+ if ! tar tvfz "${SRCTOP}/${ASSET_TGZ_FILENAME}" >/dev/null 2>&1; then
186
+ PRNINFO "${ASSET_TGZ_FILENAME} file is not tar.gz format."
187
+ rm -f "${SRCTOP}/${ASSET_TGZ_FILENAME}" 2>/dev/null
188
+ return 1
189
+ fi
185
190
  if ! _RESULT_CODE=$("${CURLCMD}" -s -S -L -w '%{http_code}' -o "${SRCTOP}/${ASSET_SHA256_FILENAME}" -X GET "${ASSET_SHA256_DOWNLOAD_URL}" --insecure); then
186
191
  PRNINFO "Failed to get sha256 file(${ASSET_SHA256_FILENAME})."
187
192
  rm -f "${SRCTOP}/${ASSET_SHA256_FILENAME}" 2>/dev/null
@@ -203,10 +208,14 @@ check_and_download_asset_file()
203
208
  SHA256_VALUE=$(awk '{print $1}' "${SRCTOP}/${ASSET_SHA256_FILENAME}" 2>/dev/null | tr -d '\n')
204
209
  if ! DL_TGZ_SHA256_VALUE=$(sha256sum "${SRCTOP}/${ASSET_TGZ_FILENAME}" 2>/dev/null | awk '{print $1}' 2>/dev/null | tr -d '\n'); then
205
210
  PRNINFO "Failed to make sha256 value from download tgz file."
211
+ rm -f "${SRCTOP}/${ASSET_TGZ_FILENAME}" 2>/dev/null
212
+ rm -f "${SRCTOP}/${ASSET_SHA256_FILENAME}" 2>/dev/null
206
213
  return 1
207
214
  fi
208
215
  if [ -z "${SHA256_VALUE}" ] || [ -z "${DL_TGZ_SHA256_VALUE}" ] || [ "${SHA256_VALUE}" != "${DL_TGZ_SHA256_VALUE}" ]; then
209
216
  PRNINFO "The sha256 value of the downloaded tgz file is incorrect."
217
+ rm -f "${SRCTOP}/${ASSET_TGZ_FILENAME}" 2>/dev/null
218
+ rm -f "${SRCTOP}/${ASSET_SHA256_FILENAME}" 2>/dev/null
210
219
  return 1
211
220
  fi
212
221
 
@@ -217,6 +226,8 @@ check_and_download_asset_file()
217
226
  cd "${SRCTOP}" || exit 1
218
227
  if ! tar xvfz "${SRCTOP}/${ASSET_TGZ_FILENAME}" >/dev/null 2>&1; then
219
228
  PRNINFO "Could not extract files from ${ASSET_TGZ_FILENAME} file."
229
+ rm -f "${SRCTOP}/${ASSET_TGZ_FILENAME}" 2>/dev/null
230
+ rm -f "${SRCTOP}/${ASSET_SHA256_FILENAME}" 2>/dev/null
220
231
  cd "${_CUR_DIR}" || exit 1
221
232
  return 1
222
233
  fi
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "k2hdkc",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "K2HDKC addon library for Node.js",
5
5
  "os": "linux",
6
6
  "main": "index.js",
@@ -20,33 +20,35 @@
20
20
  "buildutils/make_node_prebuild_variables.sh",
21
21
  "buildutils/node_prebuild_install.sh",
22
22
  "buildutils/node_prebuild.sh",
23
+ "tsconfig.json",
24
+ "tsconfig.*.json",
23
25
  "README.md",
24
26
  "LICENSE"
25
27
  ],
26
28
  "dependencies": {
27
29
  "bindings": "^1.5.0",
28
- "node-addon-api": "^8.5.0",
30
+ "node-addon-api": "^8.6.0",
29
31
  "prebuild-install": "^7.1.3"
30
32
  },
31
33
  "devDependencies": {
32
- "@rollup/plugin-commonjs": "^29.0.0",
34
+ "@rollup/plugin-commonjs": "^29.0.2",
33
35
  "@rollup/plugin-node-resolve": "^16.0.3",
34
36
  "@rollup/plugin-replace": "^6.0.3",
35
- "@rollup/plugin-terser": "^0.4.4",
37
+ "@rollup/plugin-terser": "^1.0.0",
36
38
  "@types/chai": "^5.2.3",
37
39
  "@types/mocha": "^10.0.10",
38
- "@types/node": "^25.2.0",
40
+ "@types/node": "^25.5.0",
39
41
  "chai": "^6.2.2",
40
42
  "mocha": "^11.7.5",
41
43
  "node-gyp": "^12.2.0",
42
44
  "prebuild": "^13.0.1",
43
- "rollup": "^4.57.1",
45
+ "rollup": "^4.59.0",
44
46
  "typescript": "^5.9.3",
45
47
  "ts-node": "^10.9.2"
46
48
  },
47
49
  "scripts": {
48
50
  "help": "echo 'command list:\n npm run install\n npm run install:onlypackages\n npm run build\n npm run build:ts\n npm run build:ts:cjs\n npm run build:ts:esm\n npm run build:ts:tests:cjs\n npm run build:types\n npm run build:checktypes\n npm run build:configure\n npm run build:rebuild\n npm run build:prebuild\n npm run build:prebuild:pure\n npm run build:bundle:esm\n npm run prepublishOnly\n npm run lint\n npm run test\n npm run test:ci\n npm run test:all\n npm run test:smoke\n npm run test:smoke:cjs\n npm run test:smoke:esm\n npm run test:smoke:ts\n npm run test:k2hdkc\n'",
49
- "install": "export NPM_CONFIG_LOGLEVEL=silent && echo '[START] Install' && ./buildutils/node_prebuild_install.sh || (echo '[INFO] No binaries found, so building from source\n' && if [ -d build/cjs ] && [ -d build/esm ]; then npm run build:rebuild; else npm run build; fi) && echo '-> [DONE] Install\n'",
51
+ "install": "export NPM_CONFIG_LOGLEVEL=silent && echo '[START] Install' && ./buildutils/node_prebuild_install.sh || (echo '[INFO] No binaries found, so building from source\n' && if [ -d build/cjs ] && [ -d build/esm ]; then mv build/cjs ./cjs.backup; mv build/esm ./esm.backup; npm run build:rebuild; rm -rf build/cjs.backup build/esm; mv ./cjs.backup build/cjs; mv ./esm.backup build/esm; else npm run build; fi) && echo '-> [DONE] Install\n'",
50
52
  "install:onlypackages": "export NPM_CONFIG_LOGLEVEL=silent && echo '[START] Install:onlypackages' && npm install --ignore-scripts && echo '-> [DONE] Install:onlypackages\n'",
51
53
  "build": "export NPM_CONFIG_LOGLEVEL=silent && echo '[START] Build' && npm run build:checktypes && npm run build:configure && npm run build:rebuild && npm run build:ts && echo '-> [DONE] Build\n'",
52
54
  "build:ts": "export NPM_CONFIG_LOGLEVEL=silent && echo '[START] Build:ts' && npm run build:ts:cjs && npm run build:ts:esm && echo '-> [DONE] Build:ts\n'",
@@ -1583,9 +1583,10 @@ Napi::Value K2hdkcNode::GetSubkeys(const Napi::CallbackInfo& info)
1583
1583
  uint32_t pos = 0;
1584
1584
  for(const auto& str: strarr){
1585
1585
  std::string strtmp(str);
1586
+ // Removes any non-printble characters(except spaces and tabs) at the end of the string.
1586
1587
  while(!strtmp.empty()){
1587
1588
  unsigned char tmpch = static_cast<unsigned char>(strtmp.back());
1588
- if('\0' != tmpch && !std::isspace(tmpch)){
1589
+ if(('\0' != tmpch && !std::isspace(tmpch)) || ' ' == tmpch || '\t' == tmpch){
1589
1590
  break;
1590
1591
  }
1591
1592
  strtmp.pop_back();
@@ -1856,7 +1857,10 @@ Napi::Value K2hdkcNode::SetValue(const Napi::CallbackInfo& info)
1856
1857
  std::string strval;
1857
1858
  std::string strsubkey;
1858
1859
  std::string strpass;
1859
- time_t expire = 0;
1860
+ time_t expire = 0;
1861
+ bool is_val_set = false;
1862
+ bool is_subkey_set = false;
1863
+ bool is_pass_set = false;
1860
1864
 
1861
1865
  // target key arguments(for both ontime and permanent connection)
1862
1866
  if(info.Length() <= (argpos + 1)){
@@ -1871,9 +1875,11 @@ Napi::Value K2hdkcNode::SetValue(const Napi::CallbackInfo& info)
1871
1875
 
1872
1876
  // target value arguments(for both ontime and permanent connection)
1873
1877
  if(info[argpos].IsString()){
1874
- strval = info[argpos++].As<Napi::String>().Utf8Value();
1878
+ strval = info[argpos++].As<Napi::String>().Utf8Value();
1879
+ is_val_set = true;
1875
1880
  }else{
1876
1881
  argpos++;
1882
+ is_val_set = false;
1877
1883
  }
1878
1884
 
1879
1885
  // other arguments for target
@@ -1881,16 +1887,20 @@ Napi::Value K2hdkcNode::SetValue(const Napi::CallbackInfo& info)
1881
1887
  // target 2'nd parameter is subkey(string or null)
1882
1888
  if(info[argpos].IsNull()){
1883
1889
  argpos++;
1890
+ is_subkey_set = false;
1884
1891
  }else{
1885
- strsubkey = info[argpos++].As<Napi::String>().Utf8Value();
1892
+ strsubkey = info[argpos++].As<Napi::String>().Utf8Value();
1893
+ is_subkey_set = true;
1886
1894
  }
1887
1895
 
1888
1896
  if(argpos < info.Length() && (info[argpos].IsString() || info[argpos].IsNull())){
1889
1897
  // target 3'rd parameter is pass
1890
1898
  if(info[argpos].IsNull()){
1891
1899
  argpos++;
1900
+ is_pass_set = false;
1892
1901
  }else{
1893
- strpass = info[argpos++].As<Napi::String>().Utf8Value();
1902
+ strpass = info[argpos++].As<Napi::String>().Utf8Value();
1903
+ is_pass_set = true;
1894
1904
  }
1895
1905
 
1896
1906
  if(argpos < info.Length() && info[argpos].IsNumber()){
@@ -1947,13 +1957,13 @@ Napi::Value K2hdkcNode::SetValue(const Napi::CallbackInfo& info)
1947
1957
 
1948
1958
  // work
1949
1959
  if(hasCallback){
1950
- SetValueWorker* worker = new SetValueWorker(maybeCallback, obj->_k2hdkcslave, conf, ctlport, cuk, auto_rejoin, no_giveup_rejoin, strkey, strval, strsubkey, strpass, expire);
1960
+ SetValueWorker* worker = new SetValueWorker(maybeCallback, obj->_k2hdkcslave, conf, ctlport, cuk, auto_rejoin, no_giveup_rejoin, strkey, (is_val_set ? &strval : NULL), (is_subkey_set ? &strsubkey : NULL), (is_pass_set ? &strpass : NULL), expire);
1951
1961
  worker->Queue();
1952
1962
  return Napi::Boolean::New(env, true);
1953
1963
  }else{
1954
1964
  dkcres_type_t rescode = DKC_NORESTYPE;
1955
1965
  bool result = false;
1956
- if(!strsubkey.empty()){
1966
+ if(is_subkey_set){
1957
1967
  // subkey is specified, set value into subkey
1958
1968
  K2hdkcComAddSubkey* pComObj;
1959
1969
  if(!obj->IsInitialize()){
@@ -1965,7 +1975,7 @@ Napi::Value K2hdkcNode::SetValue(const Napi::CallbackInfo& info)
1965
1975
  Napi::TypeError::New(env, "Internal error: Could not create command object.").ThrowAsJavaScriptException();
1966
1976
  return env.Undefined();
1967
1977
  }
1968
- result = pComObj->CommandSend(reinterpret_cast<const unsigned char*>(strkey.c_str()), strkey.length() + 1, reinterpret_cast<const unsigned char*>(strsubkey.c_str()), strsubkey.length() + 1, (strval.empty() ? NULL : reinterpret_cast<const unsigned char*>(strval.c_str())), (strval.empty() ? 0 : strval.length() + 1), true, (strpass.empty() ? NULL : strpass.c_str()), (expire > 0 ? &expire : NULL), &rescode);
1978
+ result = pComObj->CommandSend(reinterpret_cast<const unsigned char*>(strkey.c_str()), strkey.length() + 1, reinterpret_cast<const unsigned char*>(strsubkey.c_str()), strsubkey.length() + 1, (is_val_set ? reinterpret_cast<const unsigned char*>(strval.c_str()) : NULL), (is_val_set ? strval.length() + 1 : 0), true, (is_pass_set ? strpass.c_str() : NULL), (expire > 0 ? &expire : NULL), &rescode);
1969
1979
  DKC_DELETE(pComObj);
1970
1980
  }else{
1971
1981
  // set value to key
@@ -1979,7 +1989,7 @@ Napi::Value K2hdkcNode::SetValue(const Napi::CallbackInfo& info)
1979
1989
  Napi::TypeError::New(env, "Internal error: Could not create command object.").ThrowAsJavaScriptException();
1980
1990
  return env.Undefined();
1981
1991
  }
1982
- result = pComObj->CommandSend(reinterpret_cast<const unsigned char*>(strkey.c_str()), strkey.length() + 1, (strval.empty() ? NULL : reinterpret_cast<const unsigned char*>(strval.c_str())), (strval.empty() ? 0 : strval.length() + 1), false, (strpass.empty() ? NULL : strpass.c_str()), (expire > 0 ? &expire : NULL), &rescode);
1992
+ result = pComObj->CommandSend(reinterpret_cast<const unsigned char*>(strkey.c_str()), strkey.length() + 1, (is_val_set ? reinterpret_cast<const unsigned char*>(strval.c_str()) : NULL), (is_val_set ? strval.length() + 1 : 0), false, (is_pass_set ? strpass.c_str() : NULL), (expire > 0 ? &expire : NULL), &rescode);
1983
1993
  DKC_DELETE(pComObj);
1984
1994
  }
1985
1995
  return Napi::Boolean::New(env, result);
@@ -515,16 +515,16 @@ class GetAttrsWorker : public Napi::AsyncWorker
515
515
  //---------------------------------------------------------
516
516
  // SetValueWorker class
517
517
  //
518
- // Constructor: constructor(const Napi::Function& callback, K2hdkcSlave& slaveobj, const std::string& configuration, int control_port, const std::string& inputcuk, bool is_auto_rejoin, bool is_nogiveup_rejoin, const std::string& key, const std::string& val, const std::string& subkey, const std::string& pass, const time_t input_expire)
518
+ // Constructor: constructor(const Napi::Function& callback, K2hdkcSlave& slaveobj, const std::string& configuration, int control_port, const std::string& inputcuk, bool is_auto_rejoin, bool is_nogiveup_rejoin, const std::string& key, const std::string* pval, const std::string* psubkey, const std::string* ppass, const time_t input_expire)
519
519
  // Callback function: function(string error)
520
520
  //
521
521
  //---------------------------------------------------------
522
522
  class SetValueWorker : public Napi::AsyncWorker
523
523
  {
524
524
  public:
525
- SetValueWorker(const Napi::Function& callback, K2hdkcSlave& slaveobj, const std::string& configuration, int control_port, const std::string& inputcuk, bool is_auto_rejoin, bool is_nogiveup_rejoin, const std::string& key, const std::string& val, const std::string& subkey, const std::string& pass, const time_t input_expire) :
525
+ SetValueWorker(const Napi::Function& callback, K2hdkcSlave& slaveobj, const std::string& configuration, int control_port, const std::string& inputcuk, bool is_auto_rejoin, bool is_nogiveup_rejoin, const std::string& key, const std::string* pval, const std::string* psubkey, const std::string* ppass, const time_t input_expire) :
526
526
  Napi::AsyncWorker(callback), _callbackRef(Napi::Persistent(callback)),
527
- _slaveobj(slaveobj), _conf(configuration), _ctlport(control_port), _cuk(inputcuk), _auto_rejoin(is_auto_rejoin), _no_giveup_rejoin(is_nogiveup_rejoin), _strkey(key), _strval(val), _strsubkey(subkey), _strpass(pass), _expire(input_expire)
527
+ _slaveobj(slaveobj), _conf(configuration), _ctlport(control_port), _cuk(inputcuk), _auto_rejoin(is_auto_rejoin), _no_giveup_rejoin(is_nogiveup_rejoin), _strkey(key), _is_val_set(NULL != pval), _strval(pval ? *pval : ""), _is_subkey_set(NULL != psubkey), _strsubkey(psubkey ? *psubkey : ""), _is_pass_set(NULL != ppass), _strpass(ppass ? *ppass : ""), _expire(input_expire)
528
528
  {
529
529
  _callbackRef.Ref();
530
530
  }
@@ -552,7 +552,7 @@ class SetValueWorker : public Napi::AsyncWorker
552
552
 
553
553
  // work
554
554
  dkcres_type_t rescode = DKC_NORESTYPE;
555
- if(!_strsubkey.empty()){
555
+ if(_is_subkey_set){
556
556
  // subkey is specified, set value into subkey
557
557
  K2hdkcComAddSubkey* pComObj;
558
558
  if(!_slaveobj.GetChmCntrlObject()){
@@ -564,7 +564,7 @@ class SetValueWorker : public Napi::AsyncWorker
564
564
  SetError("Internal error: Could not create command object.");
565
565
  return;
566
566
  }
567
- if(!pComObj->CommandSend(reinterpret_cast<const unsigned char*>(_strkey.c_str()), _strkey.length() + 1, reinterpret_cast<const unsigned char*>(_strsubkey.c_str()), _strsubkey.length() + 1, (_strval.empty() ? NULL : reinterpret_cast<const unsigned char*>(_strval.c_str())), (_strval.empty() ? 0 : _strval.length() + 1), true, (_strpass.empty() ? NULL : _strpass.c_str()), (_expire > 0 ? &_expire : NULL), &rescode)){
567
+ if(!pComObj->CommandSend(reinterpret_cast<const unsigned char*>(_strkey.c_str()), _strkey.length() + 1, reinterpret_cast<const unsigned char*>(_strsubkey.c_str()), _strsubkey.length() + 1, (_is_val_set ? reinterpret_cast<const unsigned char*>(_strval.c_str()) : NULL), (_is_val_set ? _strval.length() + 1 : 0), true, (_is_pass_set ? _strpass.c_str() : NULL), (_expire > 0 ? &_expire : NULL), &rescode)){
568
568
  SetError("Failed to set value into subkey/key.");
569
569
  }
570
570
  DKC_DELETE(pComObj);
@@ -580,7 +580,7 @@ class SetValueWorker : public Napi::AsyncWorker
580
580
  SetError("Internal error: Could not create command object.");
581
581
  return;
582
582
  }
583
- if(!pComObj->CommandSend(reinterpret_cast<const unsigned char*>(_strkey.c_str()), _strkey.length() + 1, (_strval.empty() ? NULL : reinterpret_cast<const unsigned char*>(_strval.c_str())), (_strval.empty() ? 0 : _strval.length() + 1), false, (_strpass.empty() ? NULL : _strpass.c_str()), (_expire > 0 ? &_expire : NULL), &rescode)){
583
+ if(!pComObj->CommandSend(reinterpret_cast<const unsigned char*>(_strkey.c_str()), _strkey.length() + 1, (_is_val_set ? reinterpret_cast<const unsigned char*>(_strval.c_str()) : NULL), (_is_val_set ? _strval.length() + 1 : 0), false, (_is_pass_set ? _strpass.c_str() : NULL), (_expire > 0 ? &_expire : NULL), &rescode)){
584
584
  SetError("Failed to set value into key.");
585
585
  }
586
586
  DKC_DELETE(pComObj);
@@ -625,8 +625,11 @@ class SetValueWorker : public Napi::AsyncWorker
625
625
  bool _no_giveup_rejoin;
626
626
 
627
627
  std::string _strkey;
628
+ bool _is_val_set;
628
629
  std::string _strval;
630
+ bool _is_subkey_set;
629
631
  std::string _strsubkey;
632
+ bool _is_pass_set;
630
633
  std::string _strpass;
631
634
  time_t _expire;
632
635
  };
@@ -0,0 +1,14 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "target": "ES2019",
5
+ "module": "CommonJS",
6
+ "declaration": false,
7
+ "emitDeclarationOnly": false,
8
+ "outDir": "build/cjs",
9
+ "esModuleInterop": true
10
+ },
11
+ "include": [
12
+ "src/**/*"
13
+ ]
14
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "target": "ES2019",
5
+ "module": "ESNext",
6
+ "declaration": false,
7
+ "emitDeclarationOnly": false,
8
+ "outDir": "build/esm",
9
+ "esModuleInterop": true
10
+ },
11
+ "include": [
12
+ "src/**/*"
13
+ ]
14
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2019",
4
+ "module": "CommonJS",
5
+ "declaration": false,
6
+ "declarationMap": false,
7
+ "emitDeclarationOnly": false,
8
+ "outDir": "build",
9
+ "rootDir": "src",
10
+ "strict": true,
11
+ "esModuleInterop": true,
12
+ "skipLibCheck": true,
13
+ "moduleResolution": "node",
14
+ "allowJs": false,
15
+ "checkJs": false,
16
+ "resolveJsonModule": true,
17
+ "types": ["node"]
18
+ },
19
+ "include": [
20
+ "src/**/*.ts"
21
+ ],
22
+ "exclude": [
23
+ "node_modules",
24
+ "build",
25
+ "dist",
26
+ "types"
27
+ ]
28
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "extends": "./tsconfig.cjs.json",
3
+ "compilerOptions": {
4
+ "outDir": "tests_cjs",
5
+ "rootDir": "tests",
6
+ "sourceMap": false,
7
+ "types": ["node", "mocha"],
8
+ "baseUrl": ".",
9
+ "paths": {
10
+ "k2hdkc": ["types/index.d.ts"],
11
+ "k2hdkc/*": ["types/*"]
12
+ }
13
+ },
14
+ "include": [
15
+ "tests/**/*"
16
+ ]
17
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "declaration": true,
5
+ "emitDeclarationOnly": true,
6
+ "outDir": "types-generated",
7
+ "rootDir": "src",
8
+ "skipLibCheck": true
9
+ },
10
+ "include": [
11
+ "src/**/*"
12
+ ]
13
+ }