@e-mc/core 0.5.3 → 0.7.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.
- package/index.js +47 -41
- package/package.json +4 -4
package/index.js
CHANGED
|
@@ -272,7 +272,8 @@ class Host extends module_1.default {
|
|
|
272
272
|
}
|
|
273
273
|
if ((0, types_1.isPlainObject)(mini)) {
|
|
274
274
|
try {
|
|
275
|
-
|
|
275
|
+
const pkg = require('minimatch');
|
|
276
|
+
MINIMATCH = 'minimatch' in pkg ? pkg.minimatch : pkg;
|
|
276
277
|
MINIMATCH_OPTIONS = { matchBase: true, nocase: PLATFORM_WIN32, ...mini };
|
|
277
278
|
}
|
|
278
279
|
catch {
|
|
@@ -684,8 +685,8 @@ class Client extends module_1.default {
|
|
|
684
685
|
this.permission = result;
|
|
685
686
|
}
|
|
686
687
|
}
|
|
687
|
-
if ((0, types_1.isArray)(extensions)) {
|
|
688
|
-
this._extensions
|
|
688
|
+
if (!this._extensions && (0, types_1.isArray)(extensions)) {
|
|
689
|
+
this._extensions = extensions.slice(0);
|
|
689
690
|
}
|
|
690
691
|
if (cache_dir) {
|
|
691
692
|
this.cacheDir = cache_dir;
|
|
@@ -797,44 +798,46 @@ class ClientDb extends Client {
|
|
|
797
798
|
}
|
|
798
799
|
static findResult(source, credential, queryString, timeout, sessionKey, renewCache) {
|
|
799
800
|
const userKey = this.extractUUID(credential) || this.asHash(this.asString(credential));
|
|
800
|
-
if (userKey) {
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
801
|
+
if (!userKey) {
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
804
|
+
queryString = this.asHash(queryString);
|
|
805
|
+
if (timeout > 0) {
|
|
806
|
+
const userCache = CACHE_USER[source]?.[userKey];
|
|
807
|
+
let stored;
|
|
808
|
+
if (!(userCache && (stored = userCache[queryString]))) {
|
|
809
|
+
return;
|
|
810
|
+
}
|
|
811
|
+
const [expires, result] = stored;
|
|
812
|
+
if (result) {
|
|
813
|
+
const current = Date.now();
|
|
814
|
+
let valid;
|
|
815
|
+
if (renewCache) {
|
|
816
|
+
stored[0] = expireTime(timeout);
|
|
817
|
+
valid = true;
|
|
818
|
+
}
|
|
819
|
+
else if (current < expires) {
|
|
820
|
+
valid = true;
|
|
821
|
+
}
|
|
822
|
+
if (valid) {
|
|
823
|
+
stored[2] = current;
|
|
824
|
+
incrementSourceCount(source, stored, userCache, queryString);
|
|
825
|
+
if (Array.isArray(result)) {
|
|
826
|
+
return result;
|
|
827
|
+
}
|
|
828
|
+
try {
|
|
829
|
+
return JSON.parse(fs.readFileSync(result, 'utf-8'));
|
|
830
|
+
}
|
|
831
|
+
catch {
|
|
830
832
|
}
|
|
831
|
-
deleteSourceResult(source, stored);
|
|
832
|
-
delete userCache[queryString];
|
|
833
833
|
}
|
|
834
|
+
clearSourceResult(stored);
|
|
834
835
|
}
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
836
|
+
deleteSourceResult(source, stored);
|
|
837
|
+
delete userCache[queryString];
|
|
838
|
+
}
|
|
839
|
+
else if (sessionKey) {
|
|
840
|
+
return CACHE_SESSION[source]?.[userKey + sessionKey]?.[queryString];
|
|
838
841
|
}
|
|
839
842
|
}
|
|
840
843
|
static storeResult(source, credential, queryString, result, options, sessionKey, sessionExpires) {
|
|
@@ -885,7 +888,10 @@ class ClientDb extends Client {
|
|
|
885
888
|
addSourceResult(source, item);
|
|
886
889
|
if (cacheDir) {
|
|
887
890
|
if (partition) {
|
|
888
|
-
|
|
891
|
+
if (STORE_RESULT_COUNT === this.STORE_RESULT_PARTITION_SIZE) {
|
|
892
|
+
STORE_RESULT_COUNT = 0;
|
|
893
|
+
}
|
|
894
|
+
const subDir = path.join(cacheDir, (STORE_RESULT_COUNT++).toString(), queryString.substring(0, this.STORE_RESULT_PARTITION_MULT));
|
|
889
895
|
if (this.createDir(subDir)) {
|
|
890
896
|
cacheDir = subDir;
|
|
891
897
|
}
|
|
@@ -1134,9 +1140,9 @@ class ClientDb extends Client {
|
|
|
1134
1140
|
return this.database.filter(item => (item.transactionState & 32 /* DB_TRANSACTION.FAIL */) === 32 /* DB_TRANSACTION.FAIL */);
|
|
1135
1141
|
}
|
|
1136
1142
|
}
|
|
1137
|
-
ClientDb.STORE_RESULT_PARTITION_SIZE = 16 /* VALUES.DB_PARTITION_SIZE */;
|
|
1138
|
-
ClientDb.STORE_RESULT_PARTITION_MULT = 2 /* VALUES.DB_PARTITION_MULT */;
|
|
1139
1143
|
exports.ClientDb = ClientDb;
|
|
1144
|
+
ClientDb.STORE_RESULT_PARTITION_SIZE = 16 /* CACHE_SIZE.CORE_CLIENTDB_PARTITION_SIZE */;
|
|
1145
|
+
ClientDb.STORE_RESULT_PARTITION_MULT = 2 /* CACHE_SIZE.CORE_CLIENTDB_PARTITION_MULT */;
|
|
1140
1146
|
class AbortComponent {
|
|
1141
1147
|
constructor() {
|
|
1142
1148
|
this[_e] = new AbortController();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Core modules for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"license": "BSD 3-Clause",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/module": "0.
|
|
24
|
-
"@e-mc/types": "0.
|
|
25
|
-
"picomatch": "^
|
|
23
|
+
"@e-mc/module": "0.7.0",
|
|
24
|
+
"@e-mc/types": "0.7.0",
|
|
25
|
+
"picomatch": "^3.0.1"
|
|
26
26
|
}
|
|
27
27
|
}
|