@e-mc/core 0.12.13 → 0.12.15
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/README.md +11 -9
- package/index.js +167 -138
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
## Interface
|
|
11
11
|
|
|
12
|
-
* [View Source](https://www.unpkg.com/@e-mc/types@0.12.
|
|
12
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.12.15/lib/index.d.ts)
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { DataSource, LogStatus, WorkerAction } from "./squared";
|
|
@@ -74,6 +74,7 @@ interface HostConstructor extends ModuleConstructor {
|
|
|
74
74
|
getThreadCount(full: true): ThreadCountStat;
|
|
75
75
|
getThreadCount(username: string, iv?: BinaryLike): ThreadCountStat;
|
|
76
76
|
getThreadCount(username?: string | boolean, iv?: BinaryLike): number;
|
|
77
|
+
parseIp(value: unknown, kind?: "ipv4" | "ipv6"): string;
|
|
77
78
|
getPermissionFromSettings(freeze?: boolean): IPermission;
|
|
78
79
|
readonly prototype: IHost;
|
|
79
80
|
new(config?: HostInitConfig): IHost;
|
|
@@ -132,9 +133,10 @@ interface ClientDbConstructor extends ClientConstructor<IHost, ClientModule> {
|
|
|
132
133
|
convertTime(value: number | string): number;
|
|
133
134
|
findResult(source: string, credential: unknown, queryString: string, timeout: number, sessionKey?: string | boolean, renewCache?: boolean): QueryResult | undefined;
|
|
134
135
|
storeResult(source: string, credential: unknown, queryString: string, result: QueryResult, options: StoreResultOptions): QueryResult;
|
|
136
|
+
/** @deprecated */
|
|
135
137
|
storeResult(source: string, credential: unknown, queryString: string, result: QueryResult, sessionKey: string, sessionExpires: number): QueryResult;
|
|
136
138
|
storeResult(source: string, credential: unknown, queryString: string, result: QueryResult, cache: DbCacheValue): QueryResult;
|
|
137
|
-
storeResult(source: string, credential: unknown, queryString: string, result: QueryResult, cache: DbCacheValue | undefined, options: StoreResultOptions): QueryResult;
|
|
139
|
+
storeResult(source: string, credential: unknown, queryString: string, result: QueryResult, cache: DbCacheValue | undefined, options: Omit<StoreResultOptions, "cache">): QueryResult;
|
|
138
140
|
purgeResult(prefix?: string): Promise<number>;
|
|
139
141
|
extractUUID(credential: unknown): string;
|
|
140
142
|
setPoolConfig(value: unknown): void;
|
|
@@ -319,13 +321,13 @@ NOTE: **@e-mc/core** is mostly a collection of abstract base classes which canno
|
|
|
319
321
|
|
|
320
322
|
## References
|
|
321
323
|
|
|
322
|
-
- https://www.unpkg.com/@e-mc/types@0.12.
|
|
323
|
-
- https://www.unpkg.com/@e-mc/types@0.12.
|
|
324
|
-
- https://www.unpkg.com/@e-mc/types@0.12.
|
|
325
|
-
- https://www.unpkg.com/@e-mc/types@0.12.
|
|
326
|
-
- https://www.unpkg.com/@e-mc/types@0.12.
|
|
327
|
-
- https://www.unpkg.com/@e-mc/types@0.12.
|
|
328
|
-
- https://www.unpkg.com/@e-mc/types@0.12.
|
|
324
|
+
- https://www.unpkg.com/@e-mc/types@0.12.15/lib/squared.d.ts
|
|
325
|
+
- https://www.unpkg.com/@e-mc/types@0.12.15/lib/core.d.ts
|
|
326
|
+
- https://www.unpkg.com/@e-mc/types@0.12.15/lib/db.d.ts
|
|
327
|
+
- https://www.unpkg.com/@e-mc/types@0.12.15/lib/dom.d.ts
|
|
328
|
+
- https://www.unpkg.com/@e-mc/types@0.12.15/lib/logger.d.ts
|
|
329
|
+
- https://www.unpkg.com/@e-mc/types@0.12.15/lib/node.d.ts
|
|
330
|
+
- https://www.unpkg.com/@e-mc/types@0.12.15/lib/settings.d.ts
|
|
329
331
|
|
|
330
332
|
* https://www.npmjs.com/package/@types/node
|
|
331
333
|
|
package/index.js
CHANGED
|
@@ -72,10 +72,17 @@ function closeHostThread(host) {
|
|
|
72
72
|
resumeHostQueue(item, true);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
const length = HOST.QUEUE.length;
|
|
76
|
+
if (length > 0 && HOST.DONE.size < HOST.THREAD_LIMIT) {
|
|
77
|
+
for (let i = 0; i < length; ++i) {
|
|
78
|
+
const queue = HOST.QUEUE[i];
|
|
79
|
+
if (queue.joined) {
|
|
80
|
+
HOST.DONE.set(queue.instance, HOST.PID++);
|
|
81
|
+
resumeHostQueue(queue);
|
|
82
|
+
HOST.QUEUE.splice(i, 1);
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
79
86
|
HOST.QUEUE.forEach((item, index) => {
|
|
80
87
|
notifyHostQueue(item.instance, index, item.priority, true);
|
|
81
88
|
});
|
|
@@ -145,16 +152,32 @@ function resumeHostQueue(item, aborted) {
|
|
|
145
152
|
}
|
|
146
153
|
}
|
|
147
154
|
}
|
|
148
|
-
HOST.LOG_PROGRESS_QUEUE.delete(instance);
|
|
149
155
|
instance.writeTimeElapsed('JOIN', ['Thread restarting...', HOST.THREAD_LIMIT > 1 ? 'Availability: ' + HOST.DONE.size + ' / ' + HOST.THREAD_LIMIT : ''], startTime, { type: 2, ...module_1.LOG_STYLE_WARN });
|
|
150
156
|
}
|
|
151
|
-
|
|
152
|
-
|
|
157
|
+
HOST.LOG_PROGRESS_QUEUE.delete(instance);
|
|
158
|
+
if (typeof instance.resumeThread === 'function') {
|
|
159
|
+
queueMicrotask(() => {
|
|
153
160
|
instance.resumeThread({ args, startTime, aborted });
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function killHostThread() {
|
|
165
|
+
const items = [];
|
|
166
|
+
const current = Date.now();
|
|
167
|
+
for (const [host, pid] of HOST.DONE) {
|
|
168
|
+
if (host.done) {
|
|
169
|
+
closeHostThread(host);
|
|
154
170
|
}
|
|
155
|
-
|
|
171
|
+
else if (host.startTime + HOST.THREAD_EXPIRES >= current) {
|
|
172
|
+
host.writeFail(["Transaction was cancelled", host.username], (0, types_1.errorValue)("Timeout was exceeded", (0, types_1.formatTime)(HOST.THREAD_EXPIRES)), { fatal: true });
|
|
173
|
+
host.abort();
|
|
174
|
+
closeHostThread(host);
|
|
156
175
|
}
|
|
157
|
-
|
|
176
|
+
else {
|
|
177
|
+
items.push([host, pid]);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return items;
|
|
158
181
|
}
|
|
159
182
|
function encryptText(data, iv) {
|
|
160
183
|
return HOST.CIPHER && (0, types_1.isString)(data) && (0, types_1.encryptUTF8)(HOST.CIPHER.algorithm, HOST.CIPHER.key, iv, data) || '';
|
|
@@ -211,10 +234,6 @@ function incrementSourceCount(source, data, cacheData, queryString) {
|
|
|
211
234
|
}
|
|
212
235
|
}
|
|
213
236
|
}
|
|
214
|
-
function getSettingsValue(options, name, component) {
|
|
215
|
-
const result = options[name];
|
|
216
|
-
return component ? (0, types_1.isObject)(result) ? result[component] : undefined : result;
|
|
217
|
-
}
|
|
218
237
|
function isInvalidRange(result, range) {
|
|
219
238
|
const [lower, upper = 0] = range;
|
|
220
239
|
return Array.isArray(result) && (result.length <= lower || upper > 0 && result.length > upper);
|
|
@@ -226,30 +245,8 @@ function asPosix(value) {
|
|
|
226
245
|
}
|
|
227
246
|
return path.normalize(value);
|
|
228
247
|
}
|
|
229
|
-
function parseIp(value, kind) {
|
|
230
|
-
if (value) {
|
|
231
|
-
try {
|
|
232
|
-
let ip = ipaddr.parse(value);
|
|
233
|
-
if (ip.kind() === 'ipv4') {
|
|
234
|
-
if (kind === 6) {
|
|
235
|
-
ip = ip.toIPv4MappedAddress();
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
else if (kind === 4) {
|
|
239
|
-
if (!ip.isIPv4MappedAddress()) {
|
|
240
|
-
return '';
|
|
241
|
-
}
|
|
242
|
-
ip = ip.toIPv4Address();
|
|
243
|
-
}
|
|
244
|
-
return ip.toNormalizedString();
|
|
245
|
-
}
|
|
246
|
-
catch {
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
return '';
|
|
250
|
-
}
|
|
251
248
|
const readable = (value) => (0, types_1.isString)(value) || (0, types_1.isArray)(value);
|
|
252
|
-
const expireTime = (value) => Date.now() + value * 1000;
|
|
249
|
+
const expireTime = (value) => Date.now() + Math.trunc(value * 1000);
|
|
253
250
|
const convertSeconds = (value) => typeof value === 'string' && Math.ceil((0, types_1.parseTime)(value) / 1000) || 0;
|
|
254
251
|
class Host extends module_1 {
|
|
255
252
|
static [kHost] = true;
|
|
@@ -436,21 +433,7 @@ class Host extends module_1 {
|
|
|
436
433
|
if (HOST.ADMIN_PRIVATE && !username) {
|
|
437
434
|
return full ? { count: -1 } : -1;
|
|
438
435
|
}
|
|
439
|
-
const
|
|
440
|
-
const items = [];
|
|
441
|
-
for (const [host, pid] of HOST.DONE) {
|
|
442
|
-
if (host.done) {
|
|
443
|
-
closeHostThread(host);
|
|
444
|
-
}
|
|
445
|
-
else if (host.startTime + HOST.THREAD_EXPIRES >= current) {
|
|
446
|
-
host.writeFail(["Transaction was cancelled", host.username], (0, types_1.errorValue)("Timeout was exceeded", (0, types_1.formatTime)(HOST.THREAD_EXPIRES)), { fatal: true });
|
|
447
|
-
host.abort();
|
|
448
|
-
closeHostThread(host);
|
|
449
|
-
}
|
|
450
|
-
else {
|
|
451
|
-
items.push([host, pid]);
|
|
452
|
-
}
|
|
453
|
-
}
|
|
436
|
+
const items = killHostThread();
|
|
454
437
|
const count = items.length;
|
|
455
438
|
if (full) {
|
|
456
439
|
const result = { count, pending: HOST.QUEUE.length, opened: HOST.DONE.size, closed: HOST.CLOSED, queued: HOST.QUEUED, rejected: HOST.REJECTED, killed: HOST.KILLED };
|
|
@@ -484,6 +467,32 @@ class Host extends module_1 {
|
|
|
484
467
|
}
|
|
485
468
|
return count;
|
|
486
469
|
}
|
|
470
|
+
static parseIp(value, kind) {
|
|
471
|
+
if ((0, types_1.isString)(value)) {
|
|
472
|
+
try {
|
|
473
|
+
let ip = ipaddr.parse(value);
|
|
474
|
+
if (kind) {
|
|
475
|
+
if (ip.kind() === 'ipv4') {
|
|
476
|
+
if (kind === 'ipv6') {
|
|
477
|
+
ip = ip.toIPv4MappedAddress();
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
else if (kind === 'ipv4') {
|
|
481
|
+
if (ip.isIPv4MappedAddress()) {
|
|
482
|
+
ip = ip.toIPv4Address();
|
|
483
|
+
}
|
|
484
|
+
else {
|
|
485
|
+
return '';
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
return ip.toNormalizedString();
|
|
490
|
+
}
|
|
491
|
+
catch {
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
return '';
|
|
495
|
+
}
|
|
487
496
|
static getLogDelayed() {
|
|
488
497
|
return HOST.LOG_DELAYED;
|
|
489
498
|
}
|
|
@@ -537,10 +546,16 @@ class Host extends module_1 {
|
|
|
537
546
|
this.ignoreLog(typeof log === 'boolean' ? !log : log);
|
|
538
547
|
}
|
|
539
548
|
this.#config = Object.freeze({ ...config });
|
|
549
|
+
if (HOST.DONE.size >= HOST.THREAD_LIMIT) {
|
|
550
|
+
killHostThread();
|
|
551
|
+
}
|
|
540
552
|
if (HOST.DONE.size < HOST.THREAD_LIMIT || this.username && typeof priority === 'number' && priority === HOST.PRIORITY_BYPASS) {
|
|
541
553
|
HOST.DONE.set(this, HOST.PID++);
|
|
542
554
|
if (HOST.LOG_PROGRESS) {
|
|
543
555
|
this.pauseLog('progress');
|
|
556
|
+
if (showProgress) {
|
|
557
|
+
HOST.LOG_PROGRESS_QUEUE.add(this);
|
|
558
|
+
}
|
|
544
559
|
}
|
|
545
560
|
else if (showProgress) {
|
|
546
561
|
HOST.LOG_PROGRESS = this;
|
|
@@ -740,10 +755,10 @@ class Host extends module_1 {
|
|
|
740
755
|
HOST.QUEUE.splice(index, 1);
|
|
741
756
|
return false;
|
|
742
757
|
}
|
|
743
|
-
if (Array.isArray(args)) {
|
|
744
|
-
queue.args = args;
|
|
745
|
-
}
|
|
746
758
|
if (!queue.joined) {
|
|
759
|
+
if (Array.isArray(args)) {
|
|
760
|
+
queue.args = args;
|
|
761
|
+
}
|
|
747
762
|
queue.joined = true;
|
|
748
763
|
++HOST.QUEUED;
|
|
749
764
|
}
|
|
@@ -762,10 +777,10 @@ class Host extends module_1 {
|
|
|
762
777
|
return this.#username;
|
|
763
778
|
}
|
|
764
779
|
get ipV4() {
|
|
765
|
-
return parseIp(this.config.remoteIp,
|
|
780
|
+
return Host.parseIp(this.config.remoteIp, 'ipv4');
|
|
766
781
|
}
|
|
767
782
|
get ipV6() {
|
|
768
|
-
return parseIp(this.config.remoteIp,
|
|
783
|
+
return Host.parseIp(this.config.remoteIp, 'ipv6');
|
|
769
784
|
}
|
|
770
785
|
set done(value) {
|
|
771
786
|
if (value) {
|
|
@@ -891,29 +906,31 @@ class ClientDb extends Client {
|
|
|
891
906
|
const memory = settings.memory;
|
|
892
907
|
if ((0, types_1.isPlainObject)(memory)) {
|
|
893
908
|
for (const name in memory) {
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
const
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
percent
|
|
909
|
+
if (name !== 'settings') {
|
|
910
|
+
const client = memory[name];
|
|
911
|
+
if ((0, types_1.isPlainObject)(client)) {
|
|
912
|
+
for (const source in client) {
|
|
913
|
+
const item = client[source];
|
|
914
|
+
if ((0, types_1.isPlainObject)(item) && 'enabled' in item) {
|
|
915
|
+
const key = name + '_' + source;
|
|
916
|
+
const stored = CACHE_SOURCE[key];
|
|
917
|
+
const { enabled, limit = 0, min = 0, max = 0 } = item;
|
|
918
|
+
if (enabled && +limit > 0) {
|
|
919
|
+
let percent = item.percent || 0;
|
|
920
|
+
if ((0, types_1.isString)(percent)) {
|
|
921
|
+
percent = percent.includes('%') ? parseFloat(percent) / 100 : parseFloat(percent);
|
|
922
|
+
}
|
|
923
|
+
else if ((percent = Math.max(percent, 0)) > 1) {
|
|
924
|
+
percent /= 100;
|
|
925
|
+
}
|
|
926
|
+
if (percent > 0) {
|
|
927
|
+
(stored || (CACHE_SOURCE[key] = { items: [] })).config = { limit: +limit > 0 ? +limit : 0, percent: Math.min(percent, 1), min: min > 0 ? min : 0, max: max > 0 ? max : Infinity };
|
|
928
|
+
}
|
|
909
929
|
}
|
|
910
|
-
if (
|
|
911
|
-
|
|
930
|
+
else if (stored) {
|
|
931
|
+
delete stored.config;
|
|
912
932
|
}
|
|
913
933
|
}
|
|
914
|
-
else if (stored) {
|
|
915
|
-
delete stored.config;
|
|
916
|
-
}
|
|
917
934
|
}
|
|
918
935
|
}
|
|
919
936
|
}
|
|
@@ -925,7 +942,7 @@ class ClientDb extends Client {
|
|
|
925
942
|
return parent ? super.purgeMemory(percent, limit, parent) : 0;
|
|
926
943
|
}
|
|
927
944
|
static getTimeout(value) {
|
|
928
|
-
if (value
|
|
945
|
+
if (value == null) {
|
|
929
946
|
return 0;
|
|
930
947
|
}
|
|
931
948
|
let result = 0;
|
|
@@ -962,11 +979,13 @@ class ClientDb extends Client {
|
|
|
962
979
|
if (!userKey) {
|
|
963
980
|
return;
|
|
964
981
|
}
|
|
965
|
-
|
|
966
|
-
if (timeout > 0) {
|
|
982
|
+
if (timeout > 0 && timeout < Infinity) {
|
|
967
983
|
const userCache = CACHE_USER[source]?.[userKey];
|
|
968
|
-
|
|
969
|
-
|
|
984
|
+
if (!userCache) {
|
|
985
|
+
return;
|
|
986
|
+
}
|
|
987
|
+
const stored = userCache[queryString = (0, types_1.hashKey)(queryString)];
|
|
988
|
+
if (!stored) {
|
|
970
989
|
return;
|
|
971
990
|
}
|
|
972
991
|
const [expires, result] = stored;
|
|
@@ -998,38 +1017,27 @@ class ClientDb extends Client {
|
|
|
998
1017
|
delete userCache[queryString];
|
|
999
1018
|
}
|
|
1000
1019
|
else if (sessionKey) {
|
|
1001
|
-
return CACHE_SESSION[source]?.[userKey + sessionKey]?.[queryString];
|
|
1020
|
+
return CACHE_SESSION[source]?.[userKey + sessionKey]?.[(0, types_1.hashKey)(queryString)];
|
|
1002
1021
|
}
|
|
1003
1022
|
}
|
|
1004
|
-
static storeResult(source, credential, queryString, result,
|
|
1023
|
+
static storeResult(source, credential, queryString, result, cache, sessionKey, sessionExpires) {
|
|
1005
1024
|
if (!credential || !Array.isArray(result)) {
|
|
1006
1025
|
return result;
|
|
1007
1026
|
}
|
|
1008
|
-
let
|
|
1027
|
+
let cacheDir;
|
|
1009
1028
|
if ((0, types_1.isObject)(sessionKey)) {
|
|
1010
1029
|
({ cacheDir, sessionKey, sessionExpires } = sessionKey);
|
|
1011
1030
|
}
|
|
1012
|
-
else if ((0, types_1.isObject)(
|
|
1013
|
-
({ cache, cacheDir, sessionKey, sessionExpires } =
|
|
1031
|
+
else if ((0, types_1.isObject)(cache) && 'cache' in cache) {
|
|
1032
|
+
({ cache, cacheDir, sessionKey, sessionExpires } = cache);
|
|
1014
1033
|
}
|
|
1015
1034
|
let timeout = 0, userKey, whenEmpty, partition = false;
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
timeout = cache;
|
|
1020
|
-
break;
|
|
1021
|
-
case 'string':
|
|
1022
|
-
if (typeof sessionKey === 'number') {
|
|
1023
|
-
sessionExpires = sessionKey;
|
|
1024
|
-
sessionKey = cache;
|
|
1025
|
-
break;
|
|
1026
|
-
}
|
|
1027
|
-
timeout = convertSeconds(cache);
|
|
1028
|
-
break;
|
|
1029
|
-
case 'object': {
|
|
1035
|
+
switch (typeof cache) {
|
|
1036
|
+
case 'object':
|
|
1037
|
+
if (cache) {
|
|
1030
1038
|
let seconds, dir;
|
|
1031
1039
|
({ timeout: seconds, when_empty: whenEmpty, dir } = cache);
|
|
1032
|
-
if (
|
|
1040
|
+
if (dir && (!cacheDir || module_1.isDir(dir))) {
|
|
1033
1041
|
cacheDir = dir;
|
|
1034
1042
|
partition = true;
|
|
1035
1043
|
}
|
|
@@ -1037,15 +1045,25 @@ class ClientDb extends Client {
|
|
|
1037
1045
|
timeout = seconds;
|
|
1038
1046
|
}
|
|
1039
1047
|
else {
|
|
1040
|
-
cache.timeout = seconds ? convertSeconds(seconds) : 0;
|
|
1048
|
+
cache.timeout = seconds ? timeout = convertSeconds(seconds) : 0;
|
|
1041
1049
|
}
|
|
1050
|
+
}
|
|
1051
|
+
break;
|
|
1052
|
+
case 'number':
|
|
1053
|
+
timeout = cache;
|
|
1054
|
+
break;
|
|
1055
|
+
case 'string':
|
|
1056
|
+
if (typeof sessionKey === 'number') {
|
|
1057
|
+
sessionExpires = sessionKey;
|
|
1058
|
+
sessionKey = cache;
|
|
1042
1059
|
break;
|
|
1043
1060
|
}
|
|
1044
|
-
|
|
1061
|
+
timeout = convertSeconds(cache);
|
|
1062
|
+
break;
|
|
1045
1063
|
}
|
|
1046
1064
|
if ((result.length > 0 || whenEmpty) && (userKey = this.extractUUID(credential) || (0, types_1.hashKey)(this.asString(credential)))) {
|
|
1047
|
-
|
|
1048
|
-
|
|
1065
|
+
if (timeout > 0 && timeout < Infinity) {
|
|
1066
|
+
queryString = (0, types_1.hashKey)(queryString);
|
|
1049
1067
|
const item = [expireTime(timeout), result, Date.now(), 0];
|
|
1050
1068
|
((CACHE_USER[source] ||= {})[userKey] ||= {})[queryString] = item;
|
|
1051
1069
|
addSourceResult(source, item);
|
|
@@ -1076,7 +1094,7 @@ class ClientDb extends Client {
|
|
|
1076
1094
|
sourceData[dbKey] = data;
|
|
1077
1095
|
setTimeout(() => delete sourceData[dbKey], sessionExpires * 1000);
|
|
1078
1096
|
}
|
|
1079
|
-
data[queryString] = result;
|
|
1097
|
+
data[(0, types_1.hashKey)(queryString)] = result;
|
|
1080
1098
|
}
|
|
1081
1099
|
}
|
|
1082
1100
|
return result;
|
|
@@ -1154,13 +1172,8 @@ class ClientDb extends Client {
|
|
|
1154
1172
|
this.cacheDir = cache_dir;
|
|
1155
1173
|
}
|
|
1156
1174
|
if (expires !== undefined) {
|
|
1157
|
-
if (typeof expires === 'string') {
|
|
1158
|
-
|
|
1159
|
-
this.settings.session_expires = expires;
|
|
1160
|
-
}
|
|
1161
|
-
else {
|
|
1162
|
-
delete this.settings.cache_session;
|
|
1163
|
-
}
|
|
1175
|
+
if (typeof expires === 'string' && !isNaN(expires = (0, types_1.parseTime)(expires))) {
|
|
1176
|
+
this.settings.session_expires = expires;
|
|
1164
1177
|
}
|
|
1165
1178
|
if (expires >= 0) {
|
|
1166
1179
|
this.cacheExpires = expires;
|
|
@@ -1207,15 +1220,15 @@ class ClientDb extends Client {
|
|
|
1207
1220
|
sessionKey = options;
|
|
1208
1221
|
break;
|
|
1209
1222
|
case 'object':
|
|
1210
|
-
if (options
|
|
1211
|
-
({ value, sessionKey,
|
|
1223
|
+
if (options) {
|
|
1224
|
+
({ value, sessionKey, exclusiveOf, renewCache } = options);
|
|
1212
1225
|
if (Array.isArray(exclusiveOf)) {
|
|
1213
1226
|
const ignoreCache = exclusiveOf[2];
|
|
1214
1227
|
if (ignoreCache === 1) {
|
|
1215
1228
|
return;
|
|
1216
1229
|
}
|
|
1217
1230
|
renewCache ||= ignoreCache === 0;
|
|
1218
|
-
queryString += '_' + exclusiveOf.toString();
|
|
1231
|
+
queryString += '_' + exclusiveOf.slice(0, 2).toString();
|
|
1219
1232
|
}
|
|
1220
1233
|
}
|
|
1221
1234
|
break;
|
|
@@ -1228,7 +1241,7 @@ class ClientDb extends Client {
|
|
|
1228
1241
|
}
|
|
1229
1242
|
}
|
|
1230
1243
|
const result = ClientDb.findResult(this.moduleName + '_' + source, uuidKey || credential, queryString, value === 0 ? 0 : ClientDb.getTimeout(value || this.settingsOf(source, 'cache')), sessionKey, renewCache);
|
|
1231
|
-
if (exclusiveOf &&
|
|
1244
|
+
if (exclusiveOf && isInvalidRange(result, exclusiveOf)) {
|
|
1232
1245
|
return;
|
|
1233
1246
|
}
|
|
1234
1247
|
return result;
|
|
@@ -1241,30 +1254,37 @@ class ClientDb extends Client {
|
|
|
1241
1254
|
return result;
|
|
1242
1255
|
}
|
|
1243
1256
|
const uuidKey = ClientDb.extractUUID(credential);
|
|
1244
|
-
let
|
|
1245
|
-
if (
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1257
|
+
let value, exclusiveOf;
|
|
1258
|
+
if ((0, types_1.isObject)(sessionKey)) {
|
|
1259
|
+
({ value, sessionKey, exclusiveOf } = sessionKey);
|
|
1260
|
+
}
|
|
1261
|
+
if (Array.isArray(exclusiveOf)) {
|
|
1262
|
+
if (isInvalidRange(result, exclusiveOf)) {
|
|
1263
|
+
return result;
|
|
1249
1264
|
}
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1265
|
+
queryString += '_' + exclusiveOf.slice(0, 2).toString();
|
|
1266
|
+
}
|
|
1267
|
+
if (uuidKey) {
|
|
1268
|
+
const cache = this.settingsKey(uuidKey, 'cache');
|
|
1269
|
+
if (cache !== undefined) {
|
|
1270
|
+
value = cache;
|
|
1255
1271
|
}
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1272
|
+
}
|
|
1273
|
+
const cacheDir = this.cacheDir;
|
|
1274
|
+
value ??= this.settingsOf(source, 'cache');
|
|
1275
|
+
let options;
|
|
1276
|
+
if (this.hasPermission('memory')) {
|
|
1277
|
+
if (cacheDir || sessionKey) {
|
|
1278
|
+
options = { cacheDir, sessionKey, sessionExpires: this.cacheExpires / 1000 };
|
|
1261
1279
|
}
|
|
1262
|
-
options = { cache: value === 0 ? 0 : value || this.settingsOf(source, 'cache'), cacheDir: this.cacheDir, sessionKey, sessionExpires: this.cacheExpires / 1000 };
|
|
1263
1280
|
}
|
|
1264
|
-
else {
|
|
1265
|
-
options = { cacheDir
|
|
1281
|
+
else if (cacheDir) {
|
|
1282
|
+
options = { cacheDir };
|
|
1283
|
+
}
|
|
1284
|
+
else if (!(0, types_1.isObject)(value) || !(0, types_1.isString)(value.dir)) {
|
|
1285
|
+
return result;
|
|
1266
1286
|
}
|
|
1267
|
-
return ClientDb.storeResult(this.moduleName + '_' + source, uuidKey || credential, queryString, result, options);
|
|
1287
|
+
return value || options ? ClientDb.storeResult(this.moduleName + '_' + source, uuidKey || credential, queryString, result, value, options) : result;
|
|
1268
1288
|
}
|
|
1269
1289
|
getCacheResult(source, credential, queryString, cacheValue, ignoreCache) {
|
|
1270
1290
|
if (ignoreCache !== 1) {
|
|
@@ -1300,13 +1320,22 @@ class ClientDb extends Client {
|
|
|
1300
1320
|
settingsOf(source, name, component) {
|
|
1301
1321
|
const data = this.settings[source];
|
|
1302
1322
|
if ((0, types_1.isObject)(data)) {
|
|
1303
|
-
return
|
|
1323
|
+
return this.#settingsValue(data, name, component);
|
|
1304
1324
|
}
|
|
1305
1325
|
}
|
|
1306
1326
|
settingsKey(uuidKey, name, component) {
|
|
1307
1327
|
const data = this.settings.user_key?.[uuidKey];
|
|
1308
1328
|
if ((0, types_1.isObject)(data)) {
|
|
1309
|
-
return
|
|
1329
|
+
return this.#settingsValue(data, name, component);
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
#settingsValue(options, name, component) {
|
|
1333
|
+
const result = options[name];
|
|
1334
|
+
if (!component) {
|
|
1335
|
+
return result;
|
|
1336
|
+
}
|
|
1337
|
+
if ((0, types_1.isObject)(result)) {
|
|
1338
|
+
return result[component];
|
|
1310
1339
|
}
|
|
1311
1340
|
}
|
|
1312
1341
|
get pending() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/core",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.15",
|
|
4
4
|
"description": "Core modules for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"license": "BSD-3-Clause",
|
|
20
20
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@e-mc/module": "0.12.
|
|
23
|
-
"@e-mc/types": "0.12.
|
|
22
|
+
"@e-mc/module": "0.12.15",
|
|
23
|
+
"@e-mc/types": "0.12.15",
|
|
24
24
|
"ipaddr.js": "^2.3.0",
|
|
25
25
|
"picomatch": "^4.0.3"
|
|
26
26
|
}
|