@e-mc/types 0.8.3 → 0.8.4

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 CHANGED
@@ -1,7 +1,198 @@
1
- ### @e-mc/types
1
+ # @e-mc/types
2
2
 
3
- https://e-mc.readthedocs.io
3
+ * NodeJS 14
4
+ * ES2020
4
5
 
5
- ### LICENSE
6
+ ## General Usage
7
+
8
+ * [Read the Docs](https://e-mc.readthedocs.io)
9
+
10
+ ## Interface
11
+
12
+ - https://www.unpkg.com/@e-mc/types@0.8.4/index.d.ts
13
+
14
+ ```typescript
15
+ import type { LogArguments } from "./lib/logger";
16
+ import type { CloneObjectOptions } from "./lib/module";
17
+
18
+ import type { BinaryLike, CipherGCMTypes, Encoding } from "crypto";
19
+
20
+ import type { BytesOptions } from "bytes";
21
+
22
+ function createAbortError(): Error;
23
+ function hasBit(value: unknown, flags: number): boolean;
24
+ function ignoreFlag(value: unknown): boolean;
25
+ function cloneFlag(value: unknown): boolean;
26
+ function usingFlag(value: unknown): boolean;
27
+ function watchFlag(value: unknown): boolean;
28
+ function modifiedFlag(value: unknown): boolean;
29
+ function processFlag(value: unknown): boolean;
30
+ function mainFlag(value: unknown): boolean;
31
+ function existsFlag(value: unknown): boolean;
32
+ function getLogCurrent(): LogArguments | null;
33
+ function setLogCurrent(value: LogArguments): void;
34
+ function setTempDir(value: string): boolean;
35
+ function getTempDir(): string;
36
+ function isArray(value: unknown): value is unknown[];
37
+ function isObject(value: unknown): value is object;
38
+ function isPlainObject(value: unknown): value is Record<string | number | symbol, unknown>;
39
+ function isString(value: unknown): value is string;
40
+ function isEmpty(value: unknown): boolean;
41
+ function asFunction(value: unknown, sync?: boolean): ((...args: unknown[]) => Promise<unknown> | unknown) | null;
42
+ function parseTime(value: number | string, start?: number): number;
43
+ function parseExpires(value: number | string, start?: number): number;
44
+ function formatTime(value: number, char: string): string;
45
+ function formatTime(value: number, elapsed?: boolean, char?: string): string;
46
+ function convertTime(value: number | string): number;
47
+ function convertTime(value: HighResolutionTime, format: true): string;
48
+ function convertTime(value: HighResolutionTime, format?: boolean): number;
49
+ function hasGlob(value: string): boolean;
50
+ function escapePattern(value: unknown, lookBehind?: boolean): string;
51
+ function renameExt(value: string, ext: string, when?: string): string;
52
+ function formatSize(value: string): number;
53
+ function formatSize(value: number, options?: BytesOptions): string;
54
+ function alignSize(value: unknown, kb?: number, factor?: number): number;
55
+ function cascadeObject(data: object, query: string, fallback?: unknown): unknown;
56
+ function cloneObject(data: unknown, deep: boolean): unknown;
57
+ function cloneObject(data: unknown, deepIgnore: WeakSet<object>): unknown;
58
+ function cloneObject(data: unknown, options?: CloneObjectOptions<unknown>): unknown;
59
+ function coerceObject(data: unknown, cache: boolean): unknown;
60
+ function coerceObject(data: unknown, parseString?: (...args: [string]) => unknown, cache?: boolean): unknown;
61
+ function getEncoding(value: unknown, fallback?: BufferEncoding): BufferEncoding;
62
+ function encryptUTF8(algorithm: CipherGCMTypes, key: BinaryLike, iv: BinaryLike, data: string, encoding?: Encoding): string | undefined;
63
+ function decryptUTF8(algorithm: CipherGCMTypes, key: BinaryLike, iv: BinaryLike, data: string, encoding?: Encoding): string | undefined;
64
+ function generateUUID(): string;
65
+ function incrementUUID(restart?: boolean): string;
66
+ function validateUUID(value: unknown): boolean;
67
+ function randomString(format: string, dictionary?: string): string;
68
+ function errorValue(value: string, hint?: string): Error;
69
+ function errorMessage(title: number | string, value: string, hint?: string): Error;
70
+ function purgeMemory(percent?: number): number;
71
+
72
+ interface LOG_TYPE {
73
+ UNKNOWN: 0;
74
+ SYSTEM: 1;
75
+ NODE: 2;
76
+ PROCESS: 4;
77
+ COMPRESS: 8;
78
+ WATCH: 16;
79
+ FILE: 32;
80
+ CLOUD: 64;
81
+ TIME_ELAPSED: 128;
82
+ TIME_PROCESS: 256;
83
+ FAIL: 512;
84
+ HTTP: 1024;
85
+ IMAGE: 2048;
86
+ EXEC: 4096;
87
+ PERMISSION: 8192;
88
+ TIMEOUT: 16384;
89
+ STDOUT: 32768;
90
+ DB: 65536;
91
+ }
92
+
93
+ interface STATUS_TYPE {
94
+ UNKNOWN: 0;
95
+ FATAL: 1;
96
+ ERROR: 2;
97
+ WARN: 3;
98
+ INFO: 4;
99
+ DEBUG: 5;
100
+ ASSERT: 6;
101
+ TRACE: 7;
102
+ }
103
+
104
+ interface ASSET_FLAG {
105
+ NONE: 0;
106
+ IGNORE: 1;
107
+ CLONE: 2;
108
+ USING: 4;
109
+ WATCH: 8;
110
+ MODIFIED: 16;
111
+ PROCESS: 32;
112
+ MAIN: 64;
113
+ EXISTS: 128;
114
+ }
115
+
116
+ interface FILE_TYPE {
117
+ UNKNOWN: 0;
118
+ ASSET: 1;
119
+ TRANSFORM: 2;
120
+ COMPRESSED: 4;
121
+ SOURCEMAP: 8;
122
+ TORRENT: 16;
123
+ }
124
+
125
+ interface ACTION_FLAG {
126
+ NONE: 0;
127
+ IGNORE: 1;
128
+ }
129
+
130
+ interface ERR_CODE {
131
+ MODULE_NOT_FOUND: "MODULE_NOT_FOUND";
132
+ }
133
+
134
+ interface DOWNLOAD_TYPE {
135
+ HTTP: 0;
136
+ DISK: 1;
137
+ CACHE: 2;
138
+ }
139
+
140
+ interface FETCH_TYPE {
141
+ UNKNOWN: 0;
142
+ HTTP: 1;
143
+ TORRENT: 2;
144
+ FTP: 3;
145
+ UNIX_SOCKET: 4;
146
+ }
147
+
148
+ interface DB_TYPE {
149
+ SQL: 1;
150
+ NOSQL: 2;
151
+ DOCUMENT: 4;
152
+ KEYVALUE: 8;
153
+ }
154
+
155
+ interface DB_TRANSACTION {
156
+ ACTIVE: 1;
157
+ PARTIAL: 2;
158
+ COMMIT: 4;
159
+ TERMINATE: 8;
160
+ ABORT: 16;
161
+ FAIL: 32;
162
+ AUTH: 64;
163
+ CACHE: 128;
164
+ }
165
+
166
+ interface WATCH_EVENT {
167
+ MODIFIED: "modified";
168
+ BROADCAST: "broadcast";
169
+ CLOSE: "close";
170
+ ERROR: "error";
171
+ }
172
+
173
+ interface READDIR_SORT {
174
+ FILE: number;
175
+ DIRECTORY: number;
176
+ DESCENDING: number;
177
+ }
178
+
179
+ interface THRESHOLD {
180
+ FILEMANAGER_INTERVAL: number;
181
+ WATCH_INTERVAL: number;
182
+ WATCH_CHANGE: number;
183
+ }
184
+
185
+ const IMPORT_MAP: Record<string, string | undefined>;
186
+ ```
187
+
188
+ ## References
189
+
190
+ - https://www.unpkg.com/@e-mc/types@0.8.4/lib/logger.d.ts
191
+ - https://www.unpkg.com/@e-mc/types@0.8.4/lib/module.d.ts
192
+
193
+ * https://nodejs.org/api/perf_hooks.html
194
+ * https://www.npmjs.com/package/@types/bytes
195
+
196
+ ## LICENSE
6
197
 
7
198
  BSD 3-Clause
package/constant.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export const enum INTERNAL {
2
- VERSION = '0.8.3',
2
+ VERSION = '0.8.4',
3
3
  TEMP_DIR = 'tmp', // eslint-disable-line @typescript-eslint/no-shadow
4
4
  CJS = '__cjs__'
5
5
  }
package/index.d.ts CHANGED
@@ -276,6 +276,7 @@ declare namespace types {
276
276
  function renameExt(value: string, ext: string, when?: string): string;
277
277
  function formatSize(value: string): number;
278
278
  function formatSize(value: number, options?: BytesOptions): string;
279
+ function alignSize(value: unknown, kb?: number, factor?: number): number;
279
280
  function cascadeObject<T = unknown>(data: object, query: string, fallback?: unknown): T;
280
281
  function cloneObject<T>(data: T, deep: boolean): T;
281
282
  function cloneObject<T>(data: T, deepIgnore: WeakSet<object>): T;
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.errorValue = exports.validateUUID = exports.randomString = exports.decryptUTF8 = exports.encryptUTF8 = exports.getEncoding = exports.asFunction = exports.coerceObject = exports.cloneObject = exports.cascadeObject = exports.formatSize = exports.renameExt = exports.escapePattern = exports.hasGlob = exports.convertTime = exports.formatTime = exports.parseExpires = exports.parseTime = exports.isEmpty = exports.isString = exports.isObject = exports.isPlainObject = exports.isArray = exports.setTempDir = exports.getTempDir = exports.setLogCurrent = exports.getLogCurrent = exports.existsFlag = exports.mainFlag = exports.processFlag = exports.modifiedFlag = exports.watchFlag = exports.usingFlag = exports.cloneFlag = exports.ignoreFlag = exports.hasBit = exports.createAbortError = exports.IMPORT_MAP = exports.THRESHOLD = exports.READDIR_SORT = exports.WATCH_EVENT = exports.DB_TRANSACTION = exports.DB_TYPE = exports.FETCH_TYPE = exports.DOWNLOAD_TYPE = exports.ERR_CODE = exports.ASSET_FLAG = exports.FILE_TYPE = exports.STATUS_TYPE = exports.LOG_TYPE = void 0;
4
- exports.generateUUID = exports.incrementUUID = exports.purgeMemory = exports.errorMessage = void 0;
3
+ exports.validateUUID = exports.randomString = exports.decryptUTF8 = exports.encryptUTF8 = exports.getEncoding = exports.asFunction = exports.coerceObject = exports.cloneObject = exports.cascadeObject = exports.alignSize = exports.formatSize = exports.renameExt = exports.escapePattern = exports.hasGlob = exports.convertTime = exports.formatTime = exports.parseExpires = exports.parseTime = exports.isEmpty = exports.isString = exports.isObject = exports.isPlainObject = exports.isArray = exports.setTempDir = exports.getTempDir = exports.setLogCurrent = exports.getLogCurrent = exports.existsFlag = exports.mainFlag = exports.processFlag = exports.modifiedFlag = exports.watchFlag = exports.usingFlag = exports.cloneFlag = exports.ignoreFlag = exports.hasBit = exports.createAbortError = exports.IMPORT_MAP = exports.THRESHOLD = exports.READDIR_SORT = exports.WATCH_EVENT = exports.DB_TRANSACTION = exports.DB_TYPE = exports.FETCH_TYPE = exports.DOWNLOAD_TYPE = exports.ERR_CODE = exports.ASSET_FLAG = exports.FILE_TYPE = exports.STATUS_TYPE = exports.LOG_TYPE = void 0;
4
+ exports.generateUUID = exports.incrementUUID = exports.purgeMemory = exports.errorMessage = exports.errorValue = void 0;
5
5
  const path = require("path");
6
6
  const fs = require("fs");
7
7
  const crypto = require("crypto");
@@ -571,9 +571,40 @@ function renameExt(value, ext, when) {
571
571
  }
572
572
  exports.renameExt = renameExt;
573
573
  function formatSize(value, options) {
574
- return (typeof value === 'number' ? bytes(value, options) : bytes(value));
574
+ if (typeof value === 'number') {
575
+ return (bytes(value, options) || ('0' + (options?.unitSeparator || '') + 'B'));
576
+ }
577
+ return (bytes(value) || 0);
575
578
  }
576
579
  exports.formatSize = formatSize;
580
+ function alignSize(value, kb = 0, factor = 0) {
581
+ if (value === undefined) {
582
+ return NaN;
583
+ }
584
+ let result = 0;
585
+ switch (typeof value) {
586
+ case 'number':
587
+ if (value < 0) {
588
+ return NaN;
589
+ }
590
+ result = Math.ceil(factor > 0 ? value * Math.pow(1024, factor) : value);
591
+ break;
592
+ case 'string':
593
+ result = formatSize(value);
594
+ if (result < 0) {
595
+ return NaN;
596
+ }
597
+ break;
598
+ default:
599
+ return NaN;
600
+ }
601
+ if (kb > 0) {
602
+ kb = Math.ceil(kb) * 1024;
603
+ return Math.ceil(result / kb) * kb;
604
+ }
605
+ return result;
606
+ }
607
+ exports.alignSize = alignSize;
577
608
  function cascadeObject(data, query, fallback) {
578
609
  if (isObject(data) && isString(query)) {
579
610
  const names = query.trim().split(/(?<!\\)\./).map(item => item.includes('.') ? item.replace(/\\(?=\.)/g, '') : item);
package/lib/index.d.ts CHANGED
@@ -35,7 +35,6 @@ import type * as EventEmitter from 'events';
35
35
 
36
36
  // @ts-ignore
37
37
  import type * as ws from 'ws';
38
- // @ts-ignore
39
38
  import type { FileTypeResult } from 'file-type';
40
39
 
41
40
  type BufferView = BufferContent | NodeJS.ArrayBufferView;
@@ -66,7 +65,7 @@ declare namespace functions {
66
65
  chunkSize?: number;
67
66
  register(format: string, callback: TryFileCompressor): void;
68
67
  getLevel(value: string, fallback?: number): Undef<number>;
69
- getReadable(file: string | Buffer): Readable;
68
+ getReadable(file: string | URL | Buffer): Readable;
70
69
  createGzip(file: string | Buffer, options?: CompressLevel): Gzip;
71
70
  createBrotliCompress(file: string | Buffer, options?: CompressLevel): BrotliCompress;
72
71
  createWriteStreamAsGzip(file: string | Buffer, output: string, options?: CompressLevel): WriteStream;
@@ -109,7 +108,7 @@ declare namespace functions {
109
108
  clamp(value: unknown, min?: number, max?: number): number;
110
109
  isBinary(mime: unknown): mime is string;
111
110
  toABGR(buffer: Uint8Array | Buffer): Buffer;
112
- /* @deprecated IImage.using (v0.9) */
111
+ /* @deprecated - IImage.using */
113
112
  using?<V extends ExternalAsset>(this: T, instance: IImage<T, U>, data: IFileThread<V>, command: string): Promise<unknown>;
114
113
  readonly prototype: IImage<T, U>;
115
114
  new(module?: U): IImage<T, U>;
@@ -127,7 +126,7 @@ declare namespace functions {
127
126
 
128
127
  interface TaskConstructor<T extends IHost = IHost, U extends TaskModule = TaskModule> extends ModuleConstructor {
129
128
  finalize<V extends ExternalAsset>(this: T, instance: ITask<T, U>, assets: V[]): Promise<unknown>;
130
- /* @deprecated ITask.using (v0.9) */
129
+ /* @deprecated - ITask.using */
131
130
  using?<V extends ExternalAsset>(this: T, instance: ITask<T, U>, assets: V[], preceding?: boolean): Promise<unknown>;
132
131
  readonly prototype: ITask<T, U>;
133
132
  new(module?: U, ...args: unknown[]): ITask<T, U>;
@@ -147,9 +146,9 @@ declare namespace functions {
147
146
  handleFail(err: unknown, item: V, options?: HandleFailOptions): boolean;
148
147
  readTLSCert(value: unknown, cache?: boolean): string;
149
148
  readTLSConfig(options: SecureContextOptions, cache?: boolean): void;
150
- settingsOf(source: string, name: "pool" | "cache"): unknown;
149
+ settingsOf(source: string, name: keyof Omit<W, "coerce">): unknown;
151
150
  settingsOf(source: string, name: "coerce", component: keyof X): unknown;
152
- settingsKey(source: string, name: "pool" | "cache"): unknown;
151
+ settingsKey(source: string, name: keyof Omit<W, "coerce">): unknown;
153
152
  settingsKey(source: string, name: "coerce", component: keyof X): unknown;
154
153
  getPoolConfig(source: string, uuidKey?: string): Undef<Required<PoolConfig>>;
155
154
  get sourceType(): DB_TYPE;
@@ -256,7 +255,7 @@ declare namespace functions {
256
255
  writeSourceMap(uri: string, data: SourceCode, options?: SourceMapOptions): Undef<string>;
257
256
  updateGradle(source: string, namespaces: string[], value: string, options?: UpdateGradleOptions | boolean): string;
258
257
  generateLintTable(messages: LintMessage[], options: GenerateLintTableOptions): LogComponent[];
259
- /* @deprecated IDocument.using (v0.9) */
258
+ /* @deprecated - IDocument.using */
260
259
  using?(this: T, instance: IDocument<T, U, V, W, X, Y>, file: U): Promise<unknown>;
261
260
  cleanup?(this: T, instance: IDocument<T, U, V, W, X, Y>): Promise<unknown>;
262
261
  sanitizeAssets?(assets: U[], exclusions?: U[]): U[];
@@ -293,6 +292,7 @@ declare namespace functions {
293
292
  checkTimeout(client: ws): boolean;
294
293
  readonly prototype: IWatch<T, U, V, W>;
295
294
  new(module?: V): IWatch<T, U, V, W>;
295
+ /* @deprecated */
296
296
  new(interval?: number, port?: number, securePort?: number, extensions?: unknown[]): IWatch<T, U, V, W>;
297
297
  }
298
298
 
@@ -311,8 +311,8 @@ declare namespace functions {
311
311
  proxyOf(uri: string, localhost?: boolean): Undef<ProxySettings>;
312
312
  statusOn(name: ArrayOf<number>, callback: StatusOnCallback): void;
313
313
  statusOn(name: ArrayOf<number>, patternUrl: string, callback: StatusOnCallback): void;
314
- headersOn(name: ArrayOf<string>, callback: HeadersOnCallback): void;
315
- headersOn(name: ArrayOf<string>, patternUrl: string, callback: HeadersOnCallback): void;
314
+ headersOn(name: StringOfArray, callback: HeadersOnCallback): void;
315
+ headersOn(name: StringOfArray, patternUrl: string, callback: HeadersOnCallback): void;
316
316
  headersOf(uri: string): Undef<OutgoingHttpHeaders>;
317
317
  aria2c(uri: string | URL, pathname: string): Promise<string[]>;
318
318
  aria2c(uri: string | URL, options?: Aria2Options): Promise<string[]>;
@@ -425,8 +425,10 @@ declare namespace functions {
425
425
  writeBuffer(file: T, options?: WriteFileOptions): Null<Buffer>;
426
426
  writeImage(document: StringOfArray, output: OutputFinalize<T>): boolean;
427
427
  compressFile(file: T, overwrite?: boolean): Promise<unknown>;
428
+ fetchObject(uri: string | URL, format: BufferFormat): Promise<Null<object>>;
428
429
  fetchObject(uri: string | URL, options?: OpenOptions | BufferFormat): Promise<Null<object>>;
429
430
  fetchBuffer<U extends OpenOptions>(uri: string | URL, options?: U): Promise<DataEncodedResult<U>>;
431
+ fetchFiles(uri: string | URL, pathname: string): Promise<string[]>;
430
432
  fetchFiles(uri: string | URL, options?: Aria2Options | string): Promise<string[]>;
431
433
  start(emptyDir?: boolean): Promise<FinalizeResult>;
432
434
  processAssets(emptyDir?: boolean, using?: T[]): void;
@@ -723,8 +725,8 @@ declare namespace functions {
723
725
  copyDir(src: string | URL, dest: string | URL, move?: boolean, recursive?: boolean): Promise<CopyDirResult>;
724
726
  renameFile(src: string | URL, dest: string | URL, throws?: boolean): boolean;
725
727
  streamFile<U extends BufferContent>(src: string, cache: boolean): Promise<U>;
726
- streamFile<U extends BufferContent>(src: string, options: U): Promise<U extends { encoding: string } ? string : Buffer>;
727
- streamFile<U extends BufferContent>(src: string, cache?: boolean | U, options?: U): Promise<U extends { encoding: string } ? string : Buffer>;
728
+ streamFile<U extends ReadBufferOptions>(src: string, options: U): Promise<U extends { encoding: string } ? string : Buffer>;
729
+ streamFile<U extends ReadBufferOptions>(src: string, cache?: boolean | U, options?: U): Promise<U extends { encoding: string } ? string : Buffer>;
728
730
  readText(value: string | URL, cache: boolean): string;
729
731
  readText<U extends ReadTextOptions>(value: string | URL, options: U): U extends { minStreamSize: NumString } ? Promise<string> : string;
730
732
  readText(value: string | URL, encoding?: BufferEncoding | boolean | ReadTextOptions, cache?: boolean): string;
package/lib/logger.d.ts CHANGED
@@ -2,7 +2,6 @@ import type { LogStatus } from './squared';
2
2
 
3
3
  import type { LOG_TYPE, STATUS_TYPE } from '../index.d';
4
4
 
5
- // @ts-ignore
6
5
  import type { BackgroundColor as IBackgroundColor, ForegroundColor as IForegroundColor } from 'chalk';
7
6
 
8
7
  type HexColor = `#${string}`;
package/lib/type.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  type Undef<T> = T | undefined;
4
4
  type Null<T> = T | null;
5
5
  type Void<T> = T | void;
6
- type Optional<T> = Undef<T> | Null<T>;
6
+ type Optional<T> = T | null | undefined;
7
7
  type Nullable<T> = { [P in keyof T]: T[P] | null; };
8
8
  type Writeable<T> = { -readonly [P in keyof T]: T[P] };
9
9
  type KeyOfType<T, U = any, V = any> = { [K in keyof T]: K extends U ? T[K] extends V ? K : never : never }[keyof T];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/types",
3
- "version": "0.8.3",
3
+ "version": "0.8.4",
4
4
  "description": "Type definitions for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",