@e-mc/types 0.10.5 → 0.11.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/lib/logger.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import type { LogStatus } from './squared';
2
2
 
3
+ import type { HighResolutionTime } from './node';
4
+
3
5
  import type { LOG_STATE, LOG_TYPE, STATUS_TYPE } from '../index.d';
4
6
 
5
7
  import type { BackgroundColor as IBackgroundColor, ForegroundColor as IForegroundColor } from 'chalk';
@@ -12,6 +14,7 @@ export interface LogBaseOptions extends LoggerColor, Pick<LogOptions, "queue" |
12
14
  sessionId?: string;
13
15
  abortable?: boolean;
14
16
  titleJustify?: TextAlign;
17
+ rawOutput?: boolean;
15
18
  broadcastId?: BroadcastValue;
16
19
  newline?: boolean | number;
17
20
  }
@@ -52,6 +55,7 @@ export interface LogMessageOptions extends LogBaseOptions {
52
55
  messageUnit?: string;
53
56
  messageUnitMinWidth?: number;
54
57
  messageUnitIndent?: number | [number, string];
58
+ messageTextWrap?: boolean | TextWrapStyle;
55
59
  progressBar?: boolean;
56
60
  alwaysVisible?: boolean;
57
61
  titleIndent?: boolean | number;
@@ -101,11 +105,12 @@ export type LogState = LOG_STATE[keyof LOG_STATE];
101
105
  export type StatusName = keyof typeof STATUS_TYPE;
102
106
  export type LogDate = Date | number;
103
107
  export type LogTime = LogDate | HighResolutionTime;
104
- export type LogValue = string | [string, Null<string>?];
108
+ export type LogValue = string | [string, (string | null)?];
105
109
  export type LogComponent = Partial<Pick<LogStatus<StatusType>, "type" | "value" | "timeStamp" | "duration" | "from" | "source">>;
106
110
  export type BackgroundColor = typeof IBackgroundColor | HexColor;
107
111
  export type ForegroundColor = typeof IForegroundColor | HexColor;
108
112
  export type TextAlign = "left" | "center" | "right";
113
+ export type TextWrapStyle = "ellipsis" | "nowrap" | "ellipsis-end" | "nowrap-end" | "none";
109
114
  export type ErrorOutMethod = (err: Error, data: LogTypeValue, require?: NodeRequire) => void;
110
115
  export type BroadcastOutMethod = (value: string, options: LogMessageOptions, require?: NodeRequire) => void;
111
- export type BroadcastValue = ArrayOf<string> | { value: ArrayOf<string>; stripAnsi?: boolean };
116
+ export type BroadcastValue = string | string[] | { value: string | string[]; stripAnsi?: boolean };
package/lib/module.d.ts CHANGED
@@ -2,9 +2,10 @@ import type { ChecksumBase } from './squared';
2
2
 
3
3
  import type { StreamAction } from './asset';
4
4
 
5
- import type { HashOptions } from 'crypto';
5
+ import type { HashOptions } from 'node:crypto';
6
+ import type { Readable } from 'node:stream';
6
7
 
7
- declare enum NORMALIZE_FLAGS {
8
+ export const enum NORMALIZE_FLAGS {
8
9
  NONE = 0,
9
10
  RESOLVE = 1,
10
11
  ENSURE_DIR = 2,
@@ -12,7 +13,22 @@ declare enum NORMALIZE_FLAGS {
12
13
  }
13
14
 
14
15
  export interface RequireAction {
15
- requireExt?: ArrayOf<string> | boolean;
16
+ requireExt?: string | string[] | boolean;
17
+ }
18
+
19
+ export interface ThrowsAction {
20
+ throwsPermission?: boolean;
21
+ throwsDoesNotExist?: boolean;
22
+ }
23
+
24
+ export interface ExecAction {
25
+ uid?: number | string;
26
+ gid?: number | string;
27
+ }
28
+
29
+ export interface IncludeAction<T = string[]> {
30
+ include?: T;
31
+ exclude?: T;
16
32
  }
17
33
 
18
34
  export interface PermissionOptions {
@@ -20,11 +36,9 @@ export interface PermissionOptions {
20
36
  hostPermissionOnly?: boolean;
21
37
  }
22
38
 
23
- export interface FileSystemOptions extends PermissionOptions {
39
+ export interface FileSystemOptions extends PermissionOptions, ThrowsAction {
24
40
  absolutePath?: boolean;
25
41
  ignorePermission?: boolean;
26
- throwsPermission?: boolean;
27
- throwsDoesNotExist?: boolean;
28
42
  }
29
43
 
30
44
  export interface ReadFileOptions extends FileSystemOptions, StreamBase, RequireAction {
@@ -55,10 +69,6 @@ export interface RemoveDirOptions extends FileSystemOptions {
55
69
  export type MoveFileOptions = CopyFileOptions;
56
70
  export type CreateDirOptions = FileSystemOptions;
57
71
 
58
- export interface GetFunctionsOptions extends ParseFunctionOptions {
59
- outFailed?: string[];
60
- }
61
-
62
72
  export interface ParseFunctionOptions extends RequireAction {
63
73
  absolute?: boolean;
64
74
  sync?: boolean;
@@ -66,22 +76,13 @@ export interface ParseFunctionOptions extends RequireAction {
66
76
  context?: unknown;
67
77
  }
68
78
 
69
- export interface CloneObjectOptions<T = unknown> {
70
- target?: T;
71
- deep?: boolean;
72
- deepIgnore?: WeakSet<object>;
73
- typedArray?: boolean;
74
- mergeArray?: MergeArrayMethod;
75
- mergeDepth?: number;
76
- symbol?: boolean;
77
- inherited?: boolean;
78
- nonenumerable?: boolean;
79
- preserve?: boolean;
80
- }
81
-
82
- export interface CheckSemVerOptions extends MinMax {
79
+ export interface CheckSemVerOptions {
80
+ min?: number;
81
+ max?: number;
82
+ equals?: string;
83
+ includes?: boolean;
83
84
  startDir?: string;
84
- unstable?: boolean;
85
+ unstable: boolean;
85
86
  }
86
87
 
87
88
  export interface CopyDirOptions {
@@ -102,7 +103,7 @@ export interface CopyDirResult {
102
103
  }
103
104
 
104
105
  export interface GlobDirOptions {
105
- exclude?: ArrayOf<string>;
106
+ exclude?: string | string[];
106
107
  recursive?: boolean | number;
107
108
  matchBase?: boolean;
108
109
  dot?: boolean;
@@ -122,12 +123,9 @@ export interface ReadBufferOptions extends StreamBase {
122
123
  cache?: boolean;
123
124
  }
124
125
 
125
- export interface AsHashOptions extends HashOptions, ChecksumBase {
126
- /** @deprecated */
127
- minLength?: number;
128
- }
126
+ export interface AsHashOptions extends HashOptions, ChecksumBase {}
129
127
 
130
- export interface GetTempDirOptions {
128
+ export interface TempDirOptions {
131
129
  pathname?: string;
132
130
  filename?: string;
133
131
  moduleDir?: boolean;
@@ -136,18 +134,7 @@ export interface GetTempDirOptions {
136
134
  increment?: number;
137
135
  }
138
136
 
139
- export interface ExecAction {
140
- uid?: NumString;
141
- gid?: NumString;
142
- }
143
-
144
- export interface IncludeAction<T = string[]> {
145
- include?: T;
146
- exclude?: T;
147
- }
148
-
149
- export type NormalizeFlags = typeof NORMALIZE_FLAGS[keyof typeof NORMALIZE_FLAGS];
150
137
  export type ReadTextOptions = ReadBufferOptions;
151
- export type ReadFileCallback<T extends Bufferable = Bufferable> = (err: Null<NodeJS.ErrnoException>, data?: T) => void;
138
+ export type ReadFileCallback<T extends Bufferable = Bufferable> = (err: NodeJS.ErrnoException | null, data?: T) => void;
152
139
  export type ProtocolType = "http" | "https" | "http/s" | "ftp" | "sftp" | "s/ftp" | "torrent" | "unc" | "file";
153
- export type MergeArrayMethod = "concat" | "concat-pre" | "includes" | "unshift" | "push" | "flat" | "join" | "slice" | "reverse" | ["flat", number] | ["join", string] | ["slice", number, number?];
140
+ export type FileTypeFormat = Bufferable | Uint8Array | ArrayBuffer | Readable;
package/lib/node.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import type { RequestData as IRequestData } from './squared';
2
2
 
3
3
  import type { ExternalAsset } from './asset';
4
- import type { HostInitConfig } from './core';
4
+ import type { HostInitConfig, HostInitLog } from './core';
5
5
  import type { DownloadModule, ErrorModule, LoggerModule, MemoryModule, NodeModule, PermissionModule, ProcessModule, RequestModule, TempModule } from './settings';
6
6
 
7
- export interface RequestData<T extends ExternalAsset = ExternalAsset> extends Readonly<Omit<IRequestData, "log">>, Readonly<HostInitConfig> {
7
+ export interface RequestData<T extends ExternalAsset = ExternalAsset, U extends HostInitLog = HostInitLog> extends Readonly<Omit<IRequestData, "log">>, Readonly<HostInitConfig<U>> {
8
8
  readonly assets?: T[];
9
9
  }
10
10
 
@@ -19,4 +19,10 @@ export interface Settings {
19
19
  request?: RequestModule;
20
20
  error?: ErrorModule;
21
21
  logger?: LoggerModule;
22
- }
22
+ }
23
+
24
+ export interface ErrorCode extends Error {
25
+ code?: unknown;
26
+ }
27
+
28
+ export type HighResolutionTime = bigint | [number, number];
package/lib/object.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- /* eslint @typescript-eslint/no-redeclare: "off" */
2
-
3
1
  interface Point {
4
2
  x: number;
5
3
  y: number;
@@ -29,4 +27,4 @@ interface MinMax<T = number> {
29
27
  max?: T;
30
28
  }
31
29
 
32
- type HighResolutionTime = TupleOf<number>;
30
+ type HighResolutionTime = bigint | [number, number];
package/lib/request.d.ts CHANGED
@@ -1,8 +1,11 @@
1
+ import type { IRequest } from './index';
1
2
  import type { BinaryAction } from './asset';
2
- import type { HttpProtocolVersion, InternetProtocolVersion } from './http';
3
+ import type { HttpProtocolVersion, HttpRequestClient, InternetProtocolVersion } from './http';
4
+ import type { IncludeAction } from './module';
5
+ import type { HttpHostSettings, RequestModule } from './settings';
3
6
 
4
- import type { IncomingHttpHeaders, OutgoingHttpHeaders } from 'http';
5
- import type { Readable, Writable } from 'stream';
7
+ import type { IncomingHttpHeaders, OutgoingHttpHeaders } from 'node:http';
8
+ import type { Readable, Writable } from 'node:stream';
6
9
 
7
10
  interface KeepAliveAction {
8
11
  keepAlive?: boolean;
@@ -21,7 +24,7 @@ interface ProtocolAction {
21
24
  export interface IHttpHost {
22
25
  localhost: boolean;
23
26
  hasProtocol(version: HttpProtocolVersion): Promise<number>;
24
- upgrade(version: HttpProtocolVersion, altSvc: Undef<string>): void;
27
+ upgrade(version: HttpProtocolVersion, altSvc: string | undefined): void;
25
28
  success(version: HttpProtocolVersion, status?: boolean): number;
26
29
  failed(version: HttpProtocolVersion, status?: boolean): number;
27
30
  error(version: HttpProtocolVersion, status?: boolean): number;
@@ -39,44 +42,108 @@ export interface IHttpHost {
39
42
  get hostname(): string;
40
43
  get port(): string;
41
44
  get origin(): string;
45
+ get streamSize(): number;
42
46
  }
43
47
 
44
48
  export interface HttpHostConstructor {
45
49
  normalizeOrigin(value: string): string;
46
50
  formatBasicAuth(url: URL): string;
47
- getBasicAuth(url: URL): Undef<OutgoingHttpHeaders>;
48
- defineLocalHost(value: string[]): void;
49
- defineProtocolNegotiation(value: ObjectMap<string[]>): void;
51
+ getBasicAuth(url: URL): OutgoingHttpHeaders | undefined;
52
+ defineLocalHost(values: string[]): void;
53
+ defineProtocolNegotiation(data: ObjectMap<string[]>): void;
54
+ defineHostConfig(settings: HttpHostSettings): void;
50
55
  readonly prototype: IHttpHost;
51
56
  new(url: URL, httpVersion?: HttpProtocolVersion): IHttpHost;
52
57
  }
53
58
 
59
+ export interface IHttpAdapter<T extends OpenOptions = OpenOptions> {
60
+ instance: IRequest;
61
+ state: ControllerState;
62
+ uri: string | URL;
63
+ contentLength: number;
64
+ retries: number;
65
+ redirects: number;
66
+ closed: boolean;
67
+ aborted: boolean;
68
+ timeout: NodeJS.Timeout | null;
69
+ dataTime: bigint | null;
70
+ delayTime: number | bigint | undefined;
71
+ opts: HostConfig & T;
72
+ client: HttpRequestClient;
73
+ resolve: (value: unknown) => void;
74
+ reject: (reason?: any) => void;
75
+ readonly startTime: bigint;
76
+ start(): Promise<object | Bufferable | null>;
77
+ init(): void;
78
+ setOpts(uri?: string | URL): void;
79
+ setWriteStream(): void;
80
+ retryDownload(downgrade: boolean, message: string): void;
81
+ acceptResponse(headers: IncomingHttpHeaders): void;
82
+ updateProgress(dataLength: number, contentLength: number): void;
83
+ redirectResponse(statusCode: number, location?: string): void;
84
+ endResponse(result: unknown, dataLength: number, logging?: boolean): void;
85
+ abortResponse(): void;
86
+ errorResponse(err: unknown): void;
87
+ retryResponse(statusCode: number, retryAfter?: string): void;
88
+ isRetry(value: number): boolean;
89
+ retryTimeout(): void;
90
+ terminate(err: unknown): void;
91
+ sendWarning(message: string): void;
92
+ formatStatus(value: number | string, hint?: string): string;
93
+ close(retry?: boolean): void;
94
+ cleanup(): void;
95
+ set abortController(value);
96
+ get abortController(): AbortController | null;
97
+ set outStream(value);
98
+ get outStream(): Writable | null;
99
+ get destroyed(): boolean;
100
+ get host(): IHttpHost;
101
+ get httpVersion(): HttpProtocolVersion;
102
+ get pipeTo(): string | Writable | undefined;
103
+ get silent(): boolean;
104
+ get retryLimit(): number;
105
+ get retryWait(): number;
106
+ get retryAfter(): number;
107
+ get redirectLimit(): number;
108
+ }
109
+
110
+ export interface HttpAdapterConstructor<T extends OpenOptions = OpenOptions> {
111
+ isUnsupported(value: number): boolean;
112
+ isDowngrade(err: unknown): boolean;
113
+ wasAborted(err: unknown): boolean;
114
+ isConnectionError(err: unknown): boolean;
115
+ defineHostConfig(settings: RequestModule): void;
116
+ readonly prototype: IHttpAdapter<T>;
117
+ new(instance: IRequest, state: ControllerState, uri: string | URL, options: T): IHttpAdapter<T>;
118
+ }
119
+
54
120
  export interface OpenOptions extends KeepAliveAction, SilentAction {
55
121
  host?: IHttpHost;
56
122
  url?: URL;
123
+ base?: boolean;
57
124
  socketPath?: string;
58
125
  httpVersion?: HttpProtocolVersion;
59
126
  method?: HttpMethod | Lowercase<HttpMethod>;
60
127
  search?: StringMap;
61
- /** @deprecated followRedirect */
62
- follow_redirect?: boolean;
63
128
  followRedirect?: boolean;
129
+ expectContinue?: boolean;
130
+ expectTimeout?: number;
64
131
  encoding?: BufferEncoding;
65
- maxBufferSize?: NumString;
132
+ maxBufferSize?: number | string;
66
133
  format?: BufferFormat | { out?: BufferFormat; parser?: PlainObject };
67
134
  headers?: OutgoingHttpHeaders | Headers;
68
135
  signal?: AbortSignal;
69
136
  timeout?: number;
70
137
  pipeTo?: string | Writable;
71
138
  postData?: unknown;
72
- connected?: (headers: IncomingHttpHeaders) => Void<boolean>;
139
+ connected?: ((headers: IncomingHttpHeaders) => boolean | void);
73
140
  statusMessage?: string;
74
- progressId?: NumString;
141
+ progressId?: number | string;
75
142
  outFormat?: { out: BufferFormat; parser?: PlainObject };
76
- outFilename?: Null<string>;
77
- outHeaders?: Null<IncomingHttpHeaders>;
78
- outStream?: Writable;
79
- outAbort?: AbortController;
143
+ outFilename?: string | null;
144
+ outHeaders?: IncomingHttpHeaders | null;
145
+ outStream?: Writable | null;
146
+ outAbort?: AbortController | null;
80
147
  }
81
148
 
82
149
  export interface PutOptions extends OpenOptions {
@@ -85,7 +152,7 @@ export interface PutOptions extends OpenOptions {
85
152
  }
86
153
 
87
154
  export interface PostOptions extends PutOptions {
88
- formData?: ArrayOf<FormDataPart>;
155
+ formData?: FormDataPart | FormDataPart[];
89
156
  }
90
157
 
91
158
  export interface FormDataPart {
@@ -107,10 +174,8 @@ export interface HostConfig extends OpenOptions {
107
174
  url: URL;
108
175
  }
109
176
 
110
- export interface ProxySettings extends KeepAliveAction {
177
+ export interface ProxySettings extends KeepAliveAction, IncludeAction {
111
178
  host: URL;
112
- exclude?: string[];
113
- include?: string[];
114
179
  }
115
180
 
116
181
  export interface RequestInit extends ProtocolAction {
@@ -134,10 +199,17 @@ export interface ApplyOptions extends ProtocolAction, PlainObject {
134
199
  keepAlive?: boolean;
135
200
  }
136
201
 
202
+ export interface ControllerState {
203
+ readonly verbose: boolean;
204
+ readonly log: boolean;
205
+ readonly singleton: boolean;
206
+ readonly config: Required<ClientConfig>;
207
+ }
208
+
137
209
  export type HttpMethod = "GET" | "POST" | "PUT" | "HEAD" | "DELETE";
138
210
  export type BufferFormat = "json" | "yaml" | "json5" | "xml" | "toml";
139
211
  export type ReadExpectType = "always" | "string" | "none";
140
- export type DataEncodedResult<T extends { encoding?: BufferEncoding }> = T extends { encoding: BufferEncoding } ? string : Null<Bufferable>;
141
- export type DataObjectResult<T extends { format?: unknown; encoding?: BufferEncoding }> = T extends { format: string | PlainObject } ? Null<object> : DataEncodedResult<T>;
142
- export type StatusOnCallback = (code: number, headers: IncomingHttpHeaders, url?: URL) => Void<boolean>;
143
- export type HeadersOnCallback = (headers: IncomingHttpHeaders, url?: URL) => Void<boolean>;
212
+ export type DataEncodedResult<T extends { encoding?: BufferEncoding }> = T extends { encoding: BufferEncoding } ? string : Bufferable | null;
213
+ export type DataObjectResult<T extends { format?: unknown; encoding?: BufferEncoding }> = T extends { format: string | PlainObject } ? object | null : DataEncodedResult<T>;
214
+ export type StatusOnCallback = (code: number, headers: IncomingHttpHeaders, url?: URL) => boolean | void;
215
+ export type HeadersOnCallback = (headers: IncomingHttpHeaders, url?: URL) => boolean | void;