@e-mc/types 0.0.1

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.
@@ -0,0 +1,124 @@
1
+ import type { LogStatus } from './squared';
2
+
3
+ import type { LOG_TYPE, STATUS_TYPE } from '../index.d';
4
+
5
+ // @ts-ignore
6
+ import type { BackgroundColor as IBackgroundColor, ForegroundColor as IForegroundColor } from 'chalk';
7
+
8
+ type HexColor = `#${string}`;
9
+
10
+ export interface LogBaseOptions extends LoggerColor, Pick<LogOptions, "queue" | "timeStamp"> {
11
+ type?: LogType;
12
+ statusType?: StatusType;
13
+ sessionId?: string;
14
+ abortable?: boolean;
15
+ titleJustify?: TextAlign;
16
+ broadcastId?: BroadcastValue;
17
+ newline?: boolean | number;
18
+ }
19
+
20
+ export interface LoggerColor {
21
+ titleColor?: ForegroundColor;
22
+ titleBgColor?: BackgroundColor;
23
+ titleBold?: boolean;
24
+ valueColor?: ForegroundColor;
25
+ valueBgColor?: BackgroundColor;
26
+ valueBold?: boolean;
27
+ hintColor?: ForegroundColor;
28
+ hintBgColor?: BackgroundColor;
29
+ hintBold?: boolean;
30
+ messageColor?: ForegroundColor;
31
+ messageBgColor?: BackgroundColor;
32
+ messageBold?: boolean;
33
+ }
34
+
35
+ export interface LoggerFormat<T = NumString> {
36
+ width?: T;
37
+ color?: ForegroundColor;
38
+ bg_color?: BackgroundColor;
39
+ bg_alt_color?: BackgroundColor;
40
+ bold?: boolean;
41
+ justify?: TextAlign;
42
+ unit?: string;
43
+ }
44
+
45
+ export interface LoggerStatus<T = boolean> {
46
+ fatal?: T;
47
+ error?: T;
48
+ warn?: T;
49
+ info?: T;
50
+ debug?: T;
51
+ trace?: T;
52
+ }
53
+
54
+ export interface LogOptions extends Partial<Pick<LogStatus<StatusType>, "duration" | "from" | "source">> {
55
+ queue?: boolean;
56
+ timeStamp?: LogDate;
57
+ }
58
+
59
+ export interface LogMessageOptions extends LogBaseOptions {
60
+ failed?: boolean;
61
+ useColor?: boolean;
62
+ messageWidth?: number;
63
+ messageUnit?: string;
64
+ messageUnitMinWidth?: number;
65
+ messageUnitIndent?: number | [number, string];
66
+ progressBar?: boolean;
67
+ alwaysVisible?: boolean;
68
+ titleIndent?: boolean | number;
69
+ }
70
+
71
+ export interface LogFailOptions extends LogBaseOptions {
72
+ exec?: ExecCommand;
73
+ code?: string;
74
+ fatal?: boolean;
75
+ passThrough?: boolean;
76
+ startTime?: LogTime;
77
+ }
78
+
79
+ export interface LogProcessOptions extends LogMessageOptions {
80
+ bypassLog?: boolean;
81
+ meterIncrement?: number;
82
+ delayTime?: number | HighResolutionTime;
83
+ }
84
+
85
+ export interface LogTimeElapsedOptions extends LogMessageOptions {
86
+ showCpu?: boolean;
87
+ }
88
+
89
+ export interface LogTypeValue {
90
+ type: LogType;
91
+ value: LogValue;
92
+ timeStamp: number;
93
+ sessionId?: string;
94
+ }
95
+
96
+ export interface LogArguments {
97
+ type?: LogType;
98
+ value?: LogValue;
99
+ title?: string;
100
+ message?: unknown;
101
+ }
102
+
103
+ export interface ExecCommand {
104
+ command: string;
105
+ args?: string[];
106
+ warn?: string[];
107
+ }
108
+
109
+ export type { LOG_TYPE, STATUS_TYPE };
110
+ export type LogType = LOG_TYPE[keyof LOG_TYPE];
111
+ export type StatusType = STATUS_TYPE[keyof STATUS_TYPE];
112
+ export type StatusName = keyof typeof STATUS_TYPE;
113
+ export type LogDate = Date | number;
114
+ export type LogTime = LogDate | HighResolutionTime;
115
+ export type LogValue = string | [string, Null<string>?];
116
+ export type LogComponent = Partial<Pick<LogStatus<StatusType>, "type" | "value" | "timeStamp" | "duration" | "from" | "source">>;
117
+ export type BackgroundColor = typeof IBackgroundColor | HexColor;
118
+ export type ForegroundColor = typeof IForegroundColor | HexColor;
119
+ export type TextAlign = "left" | "center" | "right";
120
+ export type ErrorOutMethod = (err: Error, data: LogTypeValue, require?: NodeRequire) => void;
121
+ export type BroadcastOutMethod = (value: string, options: LogMessageOptions, require?: NodeRequire) => void;
122
+ export type BroadcastValue = StringOfArray | { value: StringOfArray; stripAnsi?: boolean };
123
+ export type ModuleWriteFailMethod = (value: LogValue, message?: unknown, options?: LogFailOptions | LogType) => void;
124
+ export type ModuleFormatMessageMethod = (type: LogType, title: string, value: LogValue, message?: unknown, options?: LogMessageOptions) => void;
@@ -0,0 +1,115 @@
1
+ import type { BinaryToTextEncoding, HashOptions } from 'crypto';
2
+
3
+ declare enum NORMALIZE_FLAGS {
4
+ NONE = 0,
5
+ RESOLVE = 1,
6
+ ENSURE_DIR = 2,
7
+ POSIX = 4
8
+ }
9
+
10
+ export interface RequireAction {
11
+ requireExt?: StringOfArray | boolean;
12
+ }
13
+
14
+ export interface PermissionOptions {
15
+ ownPermissionOnly?: boolean;
16
+ hostPermissionOnly?: boolean;
17
+ }
18
+
19
+ export interface FileSystemOptions extends PermissionOptions {
20
+ absolutePath?: boolean;
21
+ ignorePermission?: boolean;
22
+ throwsPermission?: boolean;
23
+ throwsDoesNotExist?: boolean;
24
+ }
25
+
26
+ export interface ReadFileOptions extends FileSystemOptions, RequireAction {
27
+ cache?: boolean;
28
+ encoding?: BufferEncoding;
29
+ }
30
+
31
+ export interface WriteFileOptions extends FileSystemOptions {
32
+ overwrite?: boolean;
33
+ encoding?: BufferEncoding;
34
+ }
35
+
36
+ export interface DeleteFileOptions extends FileSystemOptions {
37
+ emptyDir?: boolean;
38
+ }
39
+
40
+ export interface CopyFileOptions extends FileSystemOptions {
41
+ overwrite?: boolean;
42
+ createDir?: boolean;
43
+ outSrc?: string;
44
+ }
45
+
46
+ export interface RemoveDirOptions extends FileSystemOptions {
47
+ emptyDir?: boolean;
48
+ recursive?: boolean;
49
+ }
50
+
51
+ export type MoveFileOptions = CopyFileOptions;
52
+ export type CreateDirOptions = FileSystemOptions;
53
+
54
+ export interface GetFunctionsOptions extends ParseFunctionOptions {
55
+ outFailed?: string[];
56
+ }
57
+
58
+ export interface ParseFunctionOptions extends RequireAction {
59
+ absolute?: boolean;
60
+ sync?: boolean;
61
+ external?: boolean;
62
+ context?: unknown;
63
+ }
64
+
65
+ export interface CloneObjectOptions<T = unknown> {
66
+ target?: T;
67
+ deep?: boolean;
68
+ deepIgnore?: WeakSet<object>;
69
+ typedArray?: boolean;
70
+ symbol?: boolean;
71
+ inherited?: boolean;
72
+ nonenumerable?: boolean;
73
+ preserve?: boolean;
74
+ }
75
+
76
+ export interface CheckSemVerOptions extends MinMax {
77
+ startDir?: string;
78
+ unstable: boolean;
79
+ }
80
+
81
+ export interface CopyDirOptions {
82
+ move?: boolean;
83
+ recursive?: boolean | number;
84
+ symFile?: boolean;
85
+ symDir?: boolean;
86
+ ignoreFile?: RegExp;
87
+ ignoreDir?: RegExp;
88
+ silent?: boolean;
89
+ overwrite?: boolean;
90
+ }
91
+
92
+ export interface CopyDirResult {
93
+ success: string[];
94
+ failed: string[];
95
+ ignored: string[];
96
+ }
97
+
98
+ export interface AsHashOptions extends HashOptions {
99
+ algorithm?: string;
100
+ digest?: BinaryToTextEncoding;
101
+ minLength?: number;
102
+ }
103
+
104
+ export interface GetTempDirOptions {
105
+ pathname?: string;
106
+ filename?: string;
107
+ moduleDir?: boolean;
108
+ uuidDir?: boolean;
109
+ createDir?: boolean;
110
+ increment?: number;
111
+ }
112
+
113
+ export type NormalizeFlags = typeof NORMALIZE_FLAGS[keyof typeof NORMALIZE_FLAGS];
114
+ export type ReadFileCallback<T> = (err: Null<NodeJS.ErrnoException>, data?: T) => void;
115
+ export type ProtocolType = "http" | "https" | "http/s" | "ftp" | "sftp" | "s/ftp" | "torrent" | "unc";
package/lib/node.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ import type { RequestData as IRequestData } from './squared';
2
+
3
+ import type { ExternalAsset } from './asset';
4
+ import type { HostInitConfig } from './core';
5
+ import type { DownloadModule, ErrorModule, LoggerModule, MemoryModule, NodeModule, PermissionModule, ProcessModule, RequestModule, TempModule } from './settings';
6
+
7
+ type BoolString = boolean | string;
8
+
9
+ export interface RequestData<T extends ExternalAsset = ExternalAsset> extends Readonly<Omit<IRequestData, "log">>, Readonly<HostInitConfig> {
10
+ readonly assets?: T[];
11
+ }
12
+
13
+ export interface Settings {
14
+ temp_dir?: string;
15
+ temp?: TempModule;
16
+ node?: NodeModule;
17
+ process?: ProcessModule;
18
+ permission?: PermissionModule;
19
+ memory?: MemoryModule;
20
+ download?: DownloadModule;
21
+ request?: RequestModule;
22
+ error?: ErrorModule;
23
+ logger?: LoggerModule;
24
+ }
@@ -0,0 +1,30 @@
1
+ interface Point {
2
+ x: number;
3
+ y: number;
4
+ }
5
+
6
+ interface Dimension {
7
+ width: number;
8
+ height: number;
9
+ }
10
+
11
+ interface KeyValue<T, U> {
12
+ key: T;
13
+ value: U;
14
+ }
15
+
16
+ interface ErrorCode extends Error {
17
+ code?: unknown;
18
+ }
19
+
20
+ interface AuthValue {
21
+ username?: string;
22
+ password?: string;
23
+ }
24
+
25
+ interface MinMax<T = number> {
26
+ min?: T;
27
+ max?: T;
28
+ }
29
+
30
+ type HighResolutionTime = TupleOf<number>;
@@ -0,0 +1,130 @@
1
+ import type { BinaryAction } from './asset';
2
+ import type { HttpProtocolVersion, InternetProtocolVersion } from './http';
3
+
4
+ import type { Readable, Writable } from 'stream';
5
+ import type { IncomingHttpHeaders, OutgoingHttpHeaders } from 'http';
6
+
7
+ interface KeepAliveAction {
8
+ keepAlive?: boolean;
9
+ agentTimeout?: number;
10
+ }
11
+
12
+ interface SilentAction {
13
+ silent?: boolean;
14
+ }
15
+
16
+ interface ProtocolAction {
17
+ httpVersion?: HttpProtocolVersion;
18
+ ipVersion?: InternetProtocolVersion;
19
+ }
20
+
21
+ export interface IHttpHost {
22
+ localhost: boolean;
23
+ hasProtocol(version: HttpProtocolVersion): Promise<number>;
24
+ upgrade(version: HttpProtocolVersion, altSvc: Undef<string>): void;
25
+ success(version: HttpProtocolVersion, status?: boolean): number;
26
+ failed(version: HttpProtocolVersion, status?: boolean): number;
27
+ error(version: HttpProtocolVersion, status?: boolean): number;
28
+ didAltSvc(version: HttpProtocolVersion): boolean;
29
+ nextAltSvc(): boolean;
30
+ closeAltSvc(error?: boolean): boolean;
31
+ clearAltSvc(version?: HttpProtocolVersion): void;
32
+ flagAltSvc(version: HttpProtocolVersion, value: number): void;
33
+ reset(): void;
34
+ v2(): boolean;
35
+ set version(value);
36
+ get version(): HttpProtocolVersion;
37
+ get protocol(): string;
38
+ get secure(): boolean;
39
+ get hostname(): string;
40
+ get port(): string;
41
+ get origin(): string;
42
+ }
43
+
44
+ export interface HttpHostConstructor {
45
+ normalizeOrigin(value: string): string;
46
+ formatBasicAuth(url: URL): string;
47
+ getBasicAuth(url: URL): Undef<OutgoingHttpHeaders>;
48
+ defineLocalHost(value: string[]): void;
49
+ defineProtocolNegotiation(value: ObjectMap<string[]>): void;
50
+ readonly prototype: IHttpHost;
51
+ new(url: URL, httpVersion?: HttpProtocolVersion): IHttpHost;
52
+ }
53
+
54
+ export interface OpenOptions extends KeepAliveAction, SilentAction {
55
+ host?: IHttpHost;
56
+ url?: URL;
57
+ socketPath?: string;
58
+ httpVersion?: HttpProtocolVersion;
59
+ method?: "GET" | "POST" | "HEAD";
60
+ encoding?: BufferEncoding;
61
+ format?: BufferFormat | { out?: BufferFormat; parser?: PlainObject };
62
+ headers?: OutgoingHttpHeaders;
63
+ timeout?: number;
64
+ pipeTo?: string | Writable;
65
+ postData?: unknown;
66
+ connected?: (headers: IncomingHttpHeaders) => Void<boolean>;
67
+ statusMessage?: string;
68
+ silent?: boolean;
69
+ outFormat?: { out: BufferFormat; parser?: PlainObject };
70
+ outFilename?: Null<string>;
71
+ outHeaders?: Null<IncomingHttpHeaders>;
72
+ outStream?: Writable;
73
+ outAbort?: AbortController;
74
+ }
75
+
76
+ export interface PostOptions extends OpenOptions {
77
+ contentType?: string;
78
+ formData?: ArrayOf<FormDataPart>;
79
+ dataEncoding?: BufferEncoding;
80
+ }
81
+
82
+ export interface FormDataPart {
83
+ name?: string;
84
+ data?: Buffer | Readable | string;
85
+ value?: unknown;
86
+ contentType?: string;
87
+ filename?: string;
88
+ }
89
+
90
+ export interface Aria2Options extends BinaryAction, SilentAction {
91
+ pathname?: string;
92
+ headers?: OutgoingHttpHeaders;
93
+ }
94
+
95
+ export interface HostConfig extends OpenOptions {
96
+ host: IHttpHost;
97
+ url: URL;
98
+ }
99
+
100
+ export interface ProxySettings extends KeepAliveAction {
101
+ host: URL;
102
+ exclude?: string[];
103
+ include?: string[];
104
+ }
105
+
106
+ export interface RequestInit extends ProtocolAction {
107
+ headers?: unknown;
108
+ requestTimeout?: number;
109
+ }
110
+
111
+ export interface ClientConfig {
112
+ timeout?: number;
113
+ connectTimeout?: number;
114
+ redirectLimit?: number;
115
+ retryWait?: number;
116
+ retryAfter?: number;
117
+ retryLimit?: number;
118
+ }
119
+
120
+ export interface ApplyOptions extends ProtocolAction, PlainObject {
121
+ client?: ClientConfig;
122
+ readExpect?: ReadExpectType;
123
+ acceptEncoding?: boolean;
124
+ keepAlive?: boolean;
125
+ }
126
+
127
+ export type BufferFormat = "json" | "yaml" | "json5" | "xml" | "toml";
128
+ export type ReadExpectType = "always" | "string" | "none";
129
+ export type DataEncodedResult<T extends { encoding?: BufferEncoding }> = T extends { encoding: BufferEncoding } ? string : Null<BufferContent>;
130
+ export type DataObjectResult<T extends { format?: unknown; encoding?: BufferEncoding }> = T extends { format: string | PlainObject } ? Null<object> : DataEncodedResult<T>;