@e-mc/core 0.9.8 → 0.9.10
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/LICENSE +10 -10
- package/README.md +241 -241
- package/index.js +8 -11
- package/package.json +27 -27
package/LICENSE
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
Copyright 2024 An Pham
|
|
2
|
-
|
|
3
|
-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
-
|
|
5
|
-
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
-
|
|
7
|
-
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
8
|
-
|
|
9
|
-
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
10
|
-
|
|
1
|
+
Copyright 2024 An Pham
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
+
|
|
5
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
+
|
|
7
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
8
|
+
|
|
9
|
+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
10
|
+
|
|
11
11
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
CHANGED
|
@@ -1,242 +1,242 @@
|
|
|
1
|
-
# @e-mc/core
|
|
2
|
-
|
|
3
|
-
* NodeJS 16
|
|
4
|
-
* ES2020
|
|
5
|
-
|
|
6
|
-
## General Usage
|
|
7
|
-
|
|
8
|
-
* [Read the Docs](https://e-mc.readthedocs.io)
|
|
9
|
-
|
|
10
|
-
## Interface
|
|
11
|
-
|
|
12
|
-
* [View Source](https://www.unpkg.com/@e-mc/types@0.9.
|
|
13
|
-
|
|
14
|
-
```typescript
|
|
15
|
-
import type { DataSource, LogStatus } from "./squared";
|
|
16
|
-
|
|
17
|
-
import type { IHost, IModule, ModuleConstructor } from "./index";
|
|
18
|
-
import type { CacheOptions, HostInitConfig, JoinQueueOptions, PermissionReadWrite, ResumeThreadOptions, StoreResultOptions, ThreadCountStat } from "./core";
|
|
19
|
-
import type { QueryResult, TimeoutAction } from "./db";
|
|
20
|
-
import type { AddEventListenerOptions } from "./dom";
|
|
21
|
-
import type { LogState, StatusType } from "./logger";
|
|
22
|
-
import type { Settings } from "./node";
|
|
23
|
-
import type { ClientDbSettings, ClientModule, ClientSettings, DbCacheValue, DbCoerceSettings, DbCoerceValue, DbSourceOptions } from "./settings";
|
|
24
|
-
|
|
25
|
-
interface IHost extends IModule {
|
|
26
|
-
restartable: boolean;
|
|
27
|
-
readonly modules: Set<IModule>;
|
|
28
|
-
readonly subProcesses: Set<IModule>;
|
|
29
|
-
readonly startTime: number;
|
|
30
|
-
using(...items: unknown[] | [boolean, ...unknown[]]): this;
|
|
31
|
-
contains(item: unknown, condition?: (...args: any[]) => boolean): boolean;
|
|
32
|
-
find(name: string): IModule | undefined;
|
|
33
|
-
findAll(name: string): IModule[];
|
|
34
|
-
willLog(name: string): boolean;
|
|
35
|
-
ignoreLog(values: boolean | string | string[]): void;
|
|
36
|
-
collectLog(level?: boolean): LogStatus<StatusType>[];
|
|
37
|
-
pauseLog(): void;
|
|
38
|
-
resumeLog(): void;
|
|
39
|
-
hasLog(type: string): boolean;
|
|
40
|
-
delayMessage(...args: unknown[]): void;
|
|
41
|
-
willAbort(value: string | IModule): boolean;
|
|
42
|
-
loadModule(name: string, ...args: any[]): IModule | null;
|
|
43
|
-
retain(process: IModule): void;
|
|
44
|
-
release(process: IModule, log?: boolean): boolean;
|
|
45
|
-
restart(...args: unknown[]): void;
|
|
46
|
-
joinQueue(options?: JoinQueueOptions): boolean;
|
|
47
|
-
updateProgress(name: string, ...args: unknown[]): void;
|
|
48
|
-
resumeThread?(options: ResumeThreadOptions): void;
|
|
49
|
-
set host(value);
|
|
50
|
-
get host(): null;
|
|
51
|
-
get config(): Readonly<HostInitConfig>;
|
|
52
|
-
get username(): string;
|
|
53
|
-
set done(value);
|
|
54
|
-
get done(): boolean;
|
|
55
|
-
get queued(): boolean;
|
|
56
|
-
get logState(): LogState;
|
|
57
|
-
get errorCount(): number;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
interface HostConstructor extends ModuleConstructor {
|
|
61
|
-
loadSettings(settings: Settings, password?: string): boolean;
|
|
62
|
-
loadSettings(settings: Settings, permission?: PermissionReadWrite, password?: string): boolean;
|
|
63
|
-
isPermission(value: unknown): value is IPermission;
|
|
64
|
-
createPermission(all?: boolean, freeze?: boolean): IPermission;
|
|
65
|
-
kill(username: string, iv: BinaryLike, all: true): number;
|
|
66
|
-
kill(username: string, iv: BinaryLike, pid: number | number[]): number;
|
|
67
|
-
getThreadCount(full: true): ThreadCountStat;
|
|
68
|
-
getThreadCount(username: string, iv?: BinaryLike): ThreadCountStat;
|
|
69
|
-
getThreadCount(username?: string | boolean, iv?: BinaryLike): number;
|
|
70
|
-
getPermissionFromSettings(): IPermission;
|
|
71
|
-
readonly prototype: IHost;
|
|
72
|
-
new(config?: HostInitConfig): IHost;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
interface IClient extends IModule<IHost> {
|
|
76
|
-
module: ClientModule;
|
|
77
|
-
init(...args: unknown[]): this;
|
|
78
|
-
getUserSettings(): unknown;
|
|
79
|
-
get settings(): ClientSettings;
|
|
80
|
-
set cacheDir(value: string);
|
|
81
|
-
get cacheDir(): string;
|
|
82
|
-
set extensions(values: unknown[]);
|
|
83
|
-
get extensions(): ((...args: unknown[]) => unknown)[];
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
interface ClientConstructor extends ModuleConstructor {
|
|
87
|
-
readonly prototype: IClient;
|
|
88
|
-
new(module?: ClientModule): IClient;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
interface IClientDb extends IClient<IHost, ClientModule<ClientDbSettings>> {
|
|
92
|
-
database: DataSource[];
|
|
93
|
-
cacheExpires: number;
|
|
94
|
-
add(item: DataSource, state?: number): void;
|
|
95
|
-
hasCache(source: string, sessionKey?: string): boolean;
|
|
96
|
-
hasCoerce(source: string, component: keyof DbCoerceSettings, uuidKey: Undef<string>): boolean;
|
|
97
|
-
hasCoerce(source: string, component: keyof DbCoerceSettings, credential?: unknown): boolean;
|
|
98
|
-
getQueryResult(source: string, credential: unknown, queryString: string, renewCache: boolean): QueryResult | undefined;
|
|
99
|
-
getQueryResult(source: string, credential: unknown, queryString: string, sessionKey?: string, renewCache?: boolean): QueryResult | undefined;
|
|
100
|
-
getQueryResult(source: string, credential: unknown, queryString: string, options?: CacheOptions, renewCache?: boolean): QueryResult | undefined;
|
|
101
|
-
setQueryResult(source: string, credential: unknown, queryString: string, result: unknown, sessionKey?: string): QueryResult;
|
|
102
|
-
setQueryResult(source: string, credential: unknown, queryString: string, result: unknown, options?: CacheOptions): QueryResult;
|
|
103
|
-
applyState(items: DataSource | DataSource[], value: number, as?: boolean): void;
|
|
104
|
-
commit(items?: DataSource[]): Promise<boolean>;
|
|
105
|
-
valueOfKey(credential: unknown, name: keyof DbSourceOptions, component?: keyof DbCoerceSettings): unknown;
|
|
106
|
-
settingsOf(source: string, name: keyof DbSourceOptions, component?: keyof DbCoerceSettings): unknown;
|
|
107
|
-
settingsKey(uuidKey: string, name: keyof DbSourceOptions, component?: keyof DbCoerceSettings): unknown;
|
|
108
|
-
get pending(): DataSource[];
|
|
109
|
-
get committed(): DataSource[];
|
|
110
|
-
get failed(): DataSource[];
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
interface ClientDbConstructor extends ClientConstructor<IHost, ClientModule> {
|
|
114
|
-
STORE_RESULT_PARTITION_SIZE: number;
|
|
115
|
-
STORE_RESULT_PARTITION_MULT: number;
|
|
116
|
-
readonly TRANSACTION_ACTIVE: number;
|
|
117
|
-
readonly TRANSACTION_PARTIAL: number;
|
|
118
|
-
readonly TRANSACTION_COMMIT: number;
|
|
119
|
-
readonly TRANSACTION_TERMINATE: number;
|
|
120
|
-
readonly TRANSACTION_ABORT: number;
|
|
121
|
-
readonly TRANSACTION_FAIL: number;
|
|
122
|
-
loadSettings(settings: Pick<Settings, "process" | "memory">, password?: string): boolean;
|
|
123
|
-
getTimeout(value: number | string | TimeoutAction | undefined): number;
|
|
124
|
-
convertTime(value: number | string): number;
|
|
125
|
-
findResult(source: string, credential: unknown, queryString: string, timeout: number, sessionKey?: string | boolean, renewCache?: boolean): QueryResult | undefined;
|
|
126
|
-
storeResult(source: string, credential: unknown, queryString: string, result: QueryResult, options: StoreResultOptions): QueryResult;
|
|
127
|
-
storeResult(source: string, credential: unknown, queryString: string, result: QueryResult, sessionKey: string, sessionExpires: number): QueryResult;
|
|
128
|
-
storeResult(source: string, credential: unknown, queryString: string, result: QueryResult, cache: DbCacheValue): QueryResult;
|
|
129
|
-
storeResult(source: string, credential: unknown, queryString: string, result: QueryResult, cache: DbCacheValue | undefined, options: StoreResultOptions): QueryResult;
|
|
130
|
-
purgeResult(prefix?: string): Promise<number>;
|
|
131
|
-
extractUUID(credential: unknown): string;
|
|
132
|
-
setPoolConfig(value: unknown): void;
|
|
133
|
-
getPoolConfig(source: string): unknown;
|
|
134
|
-
keyOfResult(source: string, credential: unknown, uuidOnly?: boolean): string;
|
|
135
|
-
readonly prototype: IClientDb;
|
|
136
|
-
new(module?: ClientModule, database?: DataSource[]): IClientDb;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
interface IAbortComponent extends AbortController {
|
|
140
|
-
reset(): void;
|
|
141
|
-
get aborted(): boolean;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
interface AbortComponentConstructor {
|
|
145
|
-
attach(instance: IAbortComponent, signal: AbortSignal, options?: AddEventListenerOptions): void;
|
|
146
|
-
detach(instance: IAbortComponent, signal: AbortSignal): void;
|
|
147
|
-
readonly prototype: IAbortComponent;
|
|
148
|
-
new(): IAbortComponent;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
interface IPermission {
|
|
152
|
-
setDiskRead(pathname?: string | string[], enabled?: boolean): void;
|
|
153
|
-
setDiskWrite(pathname?: string | string[], enabled?: boolean): void;
|
|
154
|
-
setUNCRead(pathname?: string | string[], enabled?: boolean): void;
|
|
155
|
-
setUNCWrite(pathname?: string | string[], enabled?: boolean): void;
|
|
156
|
-
getDiskRead(): string | string[];
|
|
157
|
-
getDiskWrite(): string | string[];
|
|
158
|
-
getUNCRead(): string | string[];
|
|
159
|
-
getUNCWrite(): string | string[];
|
|
160
|
-
hasDiskRead(pathname: string): boolean;
|
|
161
|
-
hasDiskWrite(pathname: string): boolean;
|
|
162
|
-
hasUNCRead(pathname: string): boolean;
|
|
163
|
-
hasUNCWrite(pathname: string): boolean;
|
|
164
|
-
get diskRead(): boolean;
|
|
165
|
-
get diskWrite(): boolean;
|
|
166
|
-
get uncRead(): boolean;
|
|
167
|
-
get uncWrite(): boolean;
|
|
168
|
-
}
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
## Settings
|
|
172
|
-
|
|
173
|
-
```typescript
|
|
174
|
-
import type { ExecOptions } from "./settings";
|
|
175
|
-
|
|
176
|
-
import type { MinimatchOptions } from "minimatch";
|
|
177
|
-
import type { PicomatchOptions } from "picomatch";
|
|
178
|
-
|
|
179
|
-
interface ProcessModule {
|
|
180
|
-
thread?: {
|
|
181
|
-
admin: {
|
|
182
|
-
users?: string[];
|
|
183
|
-
private?: boolean;
|
|
184
|
-
};
|
|
185
|
-
queue?: {
|
|
186
|
-
limit?: number;
|
|
187
|
-
expires?: number | string;
|
|
188
|
-
priority: {
|
|
189
|
-
bypass?: number;
|
|
190
|
-
min?: number;
|
|
191
|
-
max?: number;
|
|
192
|
-
};
|
|
193
|
-
};
|
|
194
|
-
limit?: number;
|
|
195
|
-
expires?: number | string;
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
interface PermissionModule {
|
|
200
|
-
disk_read?: string | string[];
|
|
201
|
-
disk_write?: string | string[];
|
|
202
|
-
unc_read?: string | string[];
|
|
203
|
-
unc_write?: string | string[];
|
|
204
|
-
settings?: {
|
|
205
|
-
broadcast_id?: string | string[];
|
|
206
|
-
picomatch?: PicomatchOptions | null;
|
|
207
|
-
minimatch?: MinimatchOptions | null;
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
### Example usage
|
|
213
|
-
|
|
214
|
-
```javascript
|
|
215
|
-
const { Host } = require("@e-mc/core");
|
|
216
|
-
|
|
217
|
-
Host.loadSettings({ // Global
|
|
218
|
-
process: {
|
|
219
|
-
thread: { limit: 8 }
|
|
220
|
-
},
|
|
221
|
-
permission: {
|
|
222
|
-
disk_read: ["**/*"],
|
|
223
|
-
disk_write: ["/tmp/**"]
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
```
|
|
227
|
-
|
|
228
|
-
NOTE: **@e-mc/core** is mostly a collection of abstract base classes which cannot be instantiated. **Host** is more commonly called through [@e-mc/file-manager](https://www.npmjs.com/package/@e-mc/file-manager).
|
|
229
|
-
|
|
230
|
-
## References
|
|
231
|
-
|
|
232
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
233
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
234
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
235
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
236
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
237
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
238
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
239
|
-
|
|
240
|
-
## LICENSE
|
|
241
|
-
|
|
1
|
+
# @e-mc/core
|
|
2
|
+
|
|
3
|
+
* NodeJS 16
|
|
4
|
+
* ES2020
|
|
5
|
+
|
|
6
|
+
## General Usage
|
|
7
|
+
|
|
8
|
+
* [Read the Docs](https://e-mc.readthedocs.io)
|
|
9
|
+
|
|
10
|
+
## Interface
|
|
11
|
+
|
|
12
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.9.10/lib/index.d.ts)
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
import type { DataSource, LogStatus } from "./squared";
|
|
16
|
+
|
|
17
|
+
import type { IHost, IModule, ModuleConstructor } from "./index";
|
|
18
|
+
import type { CacheOptions, HostInitConfig, JoinQueueOptions, PermissionReadWrite, ResumeThreadOptions, StoreResultOptions, ThreadCountStat } from "./core";
|
|
19
|
+
import type { QueryResult, TimeoutAction } from "./db";
|
|
20
|
+
import type { AddEventListenerOptions } from "./dom";
|
|
21
|
+
import type { LogState, StatusType } from "./logger";
|
|
22
|
+
import type { Settings } from "./node";
|
|
23
|
+
import type { ClientDbSettings, ClientModule, ClientSettings, DbCacheValue, DbCoerceSettings, DbCoerceValue, DbSourceOptions } from "./settings";
|
|
24
|
+
|
|
25
|
+
interface IHost extends IModule {
|
|
26
|
+
restartable: boolean;
|
|
27
|
+
readonly modules: Set<IModule>;
|
|
28
|
+
readonly subProcesses: Set<IModule>;
|
|
29
|
+
readonly startTime: number;
|
|
30
|
+
using(...items: unknown[] | [boolean, ...unknown[]]): this;
|
|
31
|
+
contains(item: unknown, condition?: (...args: any[]) => boolean): boolean;
|
|
32
|
+
find(name: string): IModule | undefined;
|
|
33
|
+
findAll(name: string): IModule[];
|
|
34
|
+
willLog(name: string): boolean;
|
|
35
|
+
ignoreLog(values: boolean | string | string[]): void;
|
|
36
|
+
collectLog(level?: boolean): LogStatus<StatusType>[];
|
|
37
|
+
pauseLog(): void;
|
|
38
|
+
resumeLog(): void;
|
|
39
|
+
hasLog(type: string): boolean;
|
|
40
|
+
delayMessage(...args: unknown[]): void;
|
|
41
|
+
willAbort(value: string | IModule): boolean;
|
|
42
|
+
loadModule(name: string, ...args: any[]): IModule | null;
|
|
43
|
+
retain(process: IModule): void;
|
|
44
|
+
release(process: IModule, log?: boolean): boolean;
|
|
45
|
+
restart(...args: unknown[]): void;
|
|
46
|
+
joinQueue(options?: JoinQueueOptions): boolean;
|
|
47
|
+
updateProgress(name: string, ...args: unknown[]): void;
|
|
48
|
+
resumeThread?(options: ResumeThreadOptions): void;
|
|
49
|
+
set host(value);
|
|
50
|
+
get host(): null;
|
|
51
|
+
get config(): Readonly<HostInitConfig>;
|
|
52
|
+
get username(): string;
|
|
53
|
+
set done(value);
|
|
54
|
+
get done(): boolean;
|
|
55
|
+
get queued(): boolean;
|
|
56
|
+
get logState(): LogState;
|
|
57
|
+
get errorCount(): number;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface HostConstructor extends ModuleConstructor {
|
|
61
|
+
loadSettings(settings: Settings, password?: string): boolean;
|
|
62
|
+
loadSettings(settings: Settings, permission?: PermissionReadWrite, password?: string): boolean;
|
|
63
|
+
isPermission(value: unknown): value is IPermission;
|
|
64
|
+
createPermission(all?: boolean, freeze?: boolean): IPermission;
|
|
65
|
+
kill(username: string, iv: BinaryLike, all: true): number;
|
|
66
|
+
kill(username: string, iv: BinaryLike, pid: number | number[]): number;
|
|
67
|
+
getThreadCount(full: true): ThreadCountStat;
|
|
68
|
+
getThreadCount(username: string, iv?: BinaryLike): ThreadCountStat;
|
|
69
|
+
getThreadCount(username?: string | boolean, iv?: BinaryLike): number;
|
|
70
|
+
getPermissionFromSettings(): IPermission;
|
|
71
|
+
readonly prototype: IHost;
|
|
72
|
+
new(config?: HostInitConfig): IHost;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
interface IClient extends IModule<IHost> {
|
|
76
|
+
module: ClientModule;
|
|
77
|
+
init(...args: unknown[]): this;
|
|
78
|
+
getUserSettings(): unknown;
|
|
79
|
+
get settings(): ClientSettings;
|
|
80
|
+
set cacheDir(value: string);
|
|
81
|
+
get cacheDir(): string;
|
|
82
|
+
set extensions(values: unknown[]);
|
|
83
|
+
get extensions(): ((...args: unknown[]) => unknown)[];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
interface ClientConstructor extends ModuleConstructor {
|
|
87
|
+
readonly prototype: IClient;
|
|
88
|
+
new(module?: ClientModule): IClient;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
interface IClientDb extends IClient<IHost, ClientModule<ClientDbSettings>> {
|
|
92
|
+
database: DataSource[];
|
|
93
|
+
cacheExpires: number;
|
|
94
|
+
add(item: DataSource, state?: number): void;
|
|
95
|
+
hasCache(source: string, sessionKey?: string): boolean;
|
|
96
|
+
hasCoerce(source: string, component: keyof DbCoerceSettings, uuidKey: Undef<string>): boolean;
|
|
97
|
+
hasCoerce(source: string, component: keyof DbCoerceSettings, credential?: unknown): boolean;
|
|
98
|
+
getQueryResult(source: string, credential: unknown, queryString: string, renewCache: boolean): QueryResult | undefined;
|
|
99
|
+
getQueryResult(source: string, credential: unknown, queryString: string, sessionKey?: string, renewCache?: boolean): QueryResult | undefined;
|
|
100
|
+
getQueryResult(source: string, credential: unknown, queryString: string, options?: CacheOptions, renewCache?: boolean): QueryResult | undefined;
|
|
101
|
+
setQueryResult(source: string, credential: unknown, queryString: string, result: unknown, sessionKey?: string): QueryResult;
|
|
102
|
+
setQueryResult(source: string, credential: unknown, queryString: string, result: unknown, options?: CacheOptions): QueryResult;
|
|
103
|
+
applyState(items: DataSource | DataSource[], value: number, as?: boolean): void;
|
|
104
|
+
commit(items?: DataSource[]): Promise<boolean>;
|
|
105
|
+
valueOfKey(credential: unknown, name: keyof DbSourceOptions, component?: keyof DbCoerceSettings): unknown;
|
|
106
|
+
settingsOf(source: string, name: keyof DbSourceOptions, component?: keyof DbCoerceSettings): unknown;
|
|
107
|
+
settingsKey(uuidKey: string, name: keyof DbSourceOptions, component?: keyof DbCoerceSettings): unknown;
|
|
108
|
+
get pending(): DataSource[];
|
|
109
|
+
get committed(): DataSource[];
|
|
110
|
+
get failed(): DataSource[];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
interface ClientDbConstructor extends ClientConstructor<IHost, ClientModule> {
|
|
114
|
+
STORE_RESULT_PARTITION_SIZE: number;
|
|
115
|
+
STORE_RESULT_PARTITION_MULT: number;
|
|
116
|
+
readonly TRANSACTION_ACTIVE: number;
|
|
117
|
+
readonly TRANSACTION_PARTIAL: number;
|
|
118
|
+
readonly TRANSACTION_COMMIT: number;
|
|
119
|
+
readonly TRANSACTION_TERMINATE: number;
|
|
120
|
+
readonly TRANSACTION_ABORT: number;
|
|
121
|
+
readonly TRANSACTION_FAIL: number;
|
|
122
|
+
loadSettings(settings: Pick<Settings, "process" | "memory">, password?: string): boolean;
|
|
123
|
+
getTimeout(value: number | string | TimeoutAction | undefined): number;
|
|
124
|
+
convertTime(value: number | string): number;
|
|
125
|
+
findResult(source: string, credential: unknown, queryString: string, timeout: number, sessionKey?: string | boolean, renewCache?: boolean): QueryResult | undefined;
|
|
126
|
+
storeResult(source: string, credential: unknown, queryString: string, result: QueryResult, options: StoreResultOptions): QueryResult;
|
|
127
|
+
storeResult(source: string, credential: unknown, queryString: string, result: QueryResult, sessionKey: string, sessionExpires: number): QueryResult;
|
|
128
|
+
storeResult(source: string, credential: unknown, queryString: string, result: QueryResult, cache: DbCacheValue): QueryResult;
|
|
129
|
+
storeResult(source: string, credential: unknown, queryString: string, result: QueryResult, cache: DbCacheValue | undefined, options: StoreResultOptions): QueryResult;
|
|
130
|
+
purgeResult(prefix?: string): Promise<number>;
|
|
131
|
+
extractUUID(credential: unknown): string;
|
|
132
|
+
setPoolConfig(value: unknown): void;
|
|
133
|
+
getPoolConfig(source: string): unknown;
|
|
134
|
+
keyOfResult(source: string, credential: unknown, uuidOnly?: boolean): string;
|
|
135
|
+
readonly prototype: IClientDb;
|
|
136
|
+
new(module?: ClientModule, database?: DataSource[]): IClientDb;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
interface IAbortComponent extends AbortController {
|
|
140
|
+
reset(): void;
|
|
141
|
+
get aborted(): boolean;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
interface AbortComponentConstructor {
|
|
145
|
+
attach(instance: IAbortComponent, signal: AbortSignal, options?: AddEventListenerOptions): void;
|
|
146
|
+
detach(instance: IAbortComponent, signal: AbortSignal): void;
|
|
147
|
+
readonly prototype: IAbortComponent;
|
|
148
|
+
new(): IAbortComponent;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
interface IPermission {
|
|
152
|
+
setDiskRead(pathname?: string | string[], enabled?: boolean): void;
|
|
153
|
+
setDiskWrite(pathname?: string | string[], enabled?: boolean): void;
|
|
154
|
+
setUNCRead(pathname?: string | string[], enabled?: boolean): void;
|
|
155
|
+
setUNCWrite(pathname?: string | string[], enabled?: boolean): void;
|
|
156
|
+
getDiskRead(): string | string[];
|
|
157
|
+
getDiskWrite(): string | string[];
|
|
158
|
+
getUNCRead(): string | string[];
|
|
159
|
+
getUNCWrite(): string | string[];
|
|
160
|
+
hasDiskRead(pathname: string): boolean;
|
|
161
|
+
hasDiskWrite(pathname: string): boolean;
|
|
162
|
+
hasUNCRead(pathname: string): boolean;
|
|
163
|
+
hasUNCWrite(pathname: string): boolean;
|
|
164
|
+
get diskRead(): boolean;
|
|
165
|
+
get diskWrite(): boolean;
|
|
166
|
+
get uncRead(): boolean;
|
|
167
|
+
get uncWrite(): boolean;
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Settings
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
import type { ExecOptions } from "./settings";
|
|
175
|
+
|
|
176
|
+
import type { MinimatchOptions } from "minimatch";
|
|
177
|
+
import type { PicomatchOptions } from "picomatch";
|
|
178
|
+
|
|
179
|
+
interface ProcessModule {
|
|
180
|
+
thread?: {
|
|
181
|
+
admin: {
|
|
182
|
+
users?: string[];
|
|
183
|
+
private?: boolean;
|
|
184
|
+
};
|
|
185
|
+
queue?: {
|
|
186
|
+
limit?: number;
|
|
187
|
+
expires?: number | string;
|
|
188
|
+
priority: {
|
|
189
|
+
bypass?: number;
|
|
190
|
+
min?: number;
|
|
191
|
+
max?: number;
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
limit?: number;
|
|
195
|
+
expires?: number | string;
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
interface PermissionModule {
|
|
200
|
+
disk_read?: string | string[];
|
|
201
|
+
disk_write?: string | string[];
|
|
202
|
+
unc_read?: string | string[];
|
|
203
|
+
unc_write?: string | string[];
|
|
204
|
+
settings?: {
|
|
205
|
+
broadcast_id?: string | string[];
|
|
206
|
+
picomatch?: PicomatchOptions | null;
|
|
207
|
+
minimatch?: MinimatchOptions | null;
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### Example usage
|
|
213
|
+
|
|
214
|
+
```javascript
|
|
215
|
+
const { Host } = require("@e-mc/core");
|
|
216
|
+
|
|
217
|
+
Host.loadSettings({ // Global
|
|
218
|
+
process: {
|
|
219
|
+
thread: { limit: 8 }
|
|
220
|
+
},
|
|
221
|
+
permission: {
|
|
222
|
+
disk_read: ["**/*"],
|
|
223
|
+
disk_write: ["/tmp/**"]
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
NOTE: **@e-mc/core** is mostly a collection of abstract base classes which cannot be instantiated. **Host** is more commonly called through [@e-mc/file-manager](https://www.npmjs.com/package/@e-mc/file-manager).
|
|
229
|
+
|
|
230
|
+
## References
|
|
231
|
+
|
|
232
|
+
- https://www.unpkg.com/@e-mc/types@0.9.10/lib/squared.d.ts
|
|
233
|
+
- https://www.unpkg.com/@e-mc/types@0.9.10/lib/core.d.ts
|
|
234
|
+
- https://www.unpkg.com/@e-mc/types@0.9.10/lib/db.d.ts
|
|
235
|
+
- https://www.unpkg.com/@e-mc/types@0.9.10/lib/dom.d.ts
|
|
236
|
+
- https://www.unpkg.com/@e-mc/types@0.9.10/lib/logger.d.ts
|
|
237
|
+
- https://www.unpkg.com/@e-mc/types@0.9.10/lib/node.d.ts
|
|
238
|
+
- https://www.unpkg.com/@e-mc/types@0.9.10/lib/settings.d.ts
|
|
239
|
+
|
|
240
|
+
## LICENSE
|
|
241
|
+
|
|
242
242
|
BSD 3-Clause
|
package/index.js
CHANGED
|
@@ -145,7 +145,7 @@ function clearSourceResult(target) {
|
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
function addSourceResult(source, target) {
|
|
148
|
-
const { items, config } = CACHE_SOURCE[source]
|
|
148
|
+
const { items, config } = CACHE_SOURCE[source] ||= { items: [] };
|
|
149
149
|
if (config && items.length >= config.limit) {
|
|
150
150
|
const { percent, min } = config;
|
|
151
151
|
if (percent === 1) {
|
|
@@ -592,13 +592,12 @@ class Host extends module_1 {
|
|
|
592
592
|
}
|
|
593
593
|
}
|
|
594
594
|
resumeLog() {
|
|
595
|
-
var _k;
|
|
596
595
|
const delayed = this._logDelayed;
|
|
597
596
|
if (delayed) {
|
|
598
597
|
this[kLogState] = 1;
|
|
599
598
|
const trailing = {};
|
|
600
599
|
for (const args of delayed) {
|
|
601
|
-
|
|
600
|
+
args[4].statusType &&= 0;
|
|
602
601
|
if (typeof args[4].progressBar !== 'boolean') {
|
|
603
602
|
this.formatMessage(...args);
|
|
604
603
|
}
|
|
@@ -739,8 +738,7 @@ class Client extends module_1 {
|
|
|
739
738
|
return this[kCacheDir];
|
|
740
739
|
}
|
|
741
740
|
get settings() {
|
|
742
|
-
|
|
743
|
-
return ((_k = this.module).settings || (_k.settings = {}));
|
|
741
|
+
return (this.module.settings ||= {});
|
|
744
742
|
}
|
|
745
743
|
set extensions(values) {
|
|
746
744
|
if (Array.isArray(values)) {
|
|
@@ -878,7 +876,6 @@ class ClientDb extends Client {
|
|
|
878
876
|
}
|
|
879
877
|
}
|
|
880
878
|
static storeResult(source, credential, queryString, result, options, sessionKey, sessionExpires) {
|
|
881
|
-
var _k, _l;
|
|
882
879
|
let cache, cacheDir;
|
|
883
880
|
if ((0, types_1.isObject)(sessionKey)) {
|
|
884
881
|
({ cacheDir, sessionKey, sessionExpires } = sessionKey);
|
|
@@ -921,7 +918,7 @@ class ClientDb extends Client {
|
|
|
921
918
|
queryString = this.asHash(queryString);
|
|
922
919
|
if (timeout > 0) {
|
|
923
920
|
const item = [expireTime(timeout), result, Date.now(), 0];
|
|
924
|
-
((
|
|
921
|
+
((CACHE_USER[source] ||= {})[userKey] ||= {})[queryString] = item;
|
|
925
922
|
addSourceResult(source, item);
|
|
926
923
|
if (cacheDir) {
|
|
927
924
|
if (partition) {
|
|
@@ -943,7 +940,7 @@ class ClientDb extends Client {
|
|
|
943
940
|
}
|
|
944
941
|
else if (typeof sessionKey === 'string' && sessionExpires && sessionExpires > 0) {
|
|
945
942
|
const dbKey = userKey + sessionKey;
|
|
946
|
-
((
|
|
943
|
+
((CACHE_SESSION[source] ||= {})[dbKey] ||= {})[queryString] = result;
|
|
947
944
|
setTimeout(() => delete CACHE_SESSION[dbKey], sessionExpires * 1000);
|
|
948
945
|
}
|
|
949
946
|
}
|
|
@@ -1079,7 +1076,7 @@ class ClientDb extends Client {
|
|
|
1079
1076
|
if (ignoreCache === 1) {
|
|
1080
1077
|
return;
|
|
1081
1078
|
}
|
|
1082
|
-
renewCache
|
|
1079
|
+
renewCache ||= ignoreCache === 0;
|
|
1083
1080
|
queryString += '_' + exclusiveOf.toString();
|
|
1084
1081
|
}
|
|
1085
1082
|
}
|
|
@@ -1133,13 +1130,13 @@ class ClientDb extends Client {
|
|
|
1133
1130
|
applyState(items, value, as) {
|
|
1134
1131
|
for (const item of Array.isArray(items) ? items : [items]) {
|
|
1135
1132
|
if ((0, types_1.hasBit)(value, 8)) {
|
|
1136
|
-
const state = item.transactionState
|
|
1133
|
+
const state = item.transactionState ||= 0;
|
|
1137
1134
|
if ((0, types_1.hasBit)(state, 4) || (0, types_1.hasBit)(state, 32)) {
|
|
1138
1135
|
item.transactionState |= value;
|
|
1139
1136
|
}
|
|
1140
1137
|
}
|
|
1141
1138
|
else if ((0, types_1.hasBit)(value, 16)) {
|
|
1142
|
-
item.transactionState
|
|
1139
|
+
item.transactionState ||= value;
|
|
1143
1140
|
}
|
|
1144
1141
|
else if (as) {
|
|
1145
1142
|
item.transactionState = value;
|
package/package.json
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@e-mc/core",
|
|
3
|
-
"version": "0.9.
|
|
4
|
-
"description": "Core modules for E-mc.",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"types": "index.d.ts",
|
|
7
|
-
"publishConfig": {
|
|
8
|
-
"access": "public"
|
|
9
|
-
},
|
|
10
|
-
"repository": {
|
|
11
|
-
"type": "git",
|
|
12
|
-
"url": "git+https://github.com/anpham6/e-mc.git",
|
|
13
|
-
"directory": "src/core"
|
|
14
|
-
},
|
|
15
|
-
"keywords": [
|
|
16
|
-
"squared",
|
|
17
|
-
"squared-functions"
|
|
18
|
-
],
|
|
19
|
-
"author": "An Pham <anpham6@gmail.com>",
|
|
20
|
-
"license": "BSD 3-Clause",
|
|
21
|
-
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
|
-
"dependencies": {
|
|
23
|
-
"@e-mc/module": "0.9.
|
|
24
|
-
"@e-mc/types": "0.9.
|
|
25
|
-
"picomatch": "^4.0.2"
|
|
26
|
-
}
|
|
27
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@e-mc/core",
|
|
3
|
+
"version": "0.9.10",
|
|
4
|
+
"description": "Core modules for E-mc.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/anpham6/e-mc.git",
|
|
13
|
+
"directory": "src/core"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"squared",
|
|
17
|
+
"squared-functions"
|
|
18
|
+
],
|
|
19
|
+
"author": "An Pham <anpham6@gmail.com>",
|
|
20
|
+
"license": "BSD 3-Clause",
|
|
21
|
+
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@e-mc/module": "0.9.10",
|
|
24
|
+
"@e-mc/types": "0.9.10",
|
|
25
|
+
"picomatch": "^4.0.2"
|
|
26
|
+
}
|
|
27
|
+
}
|