@e-mc/types 0.12.3 → 0.12.5

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
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- * [View Source](https://www.unpkg.com/@e-mc/types@0.12.2/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.12.5/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { LogArguments } from "./lib/logger";
@@ -32,6 +32,7 @@ function existsFlag(value: unknown): boolean;
32
32
  function getLogCurrent(): LogArguments | null;
33
33
  function setLogCurrent(value: LogArguments): void;
34
34
  function setTempDir(value: string): boolean;
35
+ function getTempDir(create: true, prefix?: string): string;
35
36
  function getTempDir(...values: string[]): string;
36
37
  function isArray(value: unknown): value is unknown[];
37
38
  function isObject(value: unknown): value is object;
@@ -73,7 +74,8 @@ function errorValue(value: string, hint?: string): Error;
73
74
  function errorMessage(title: number | string, value: string, hint?: string): Error;
74
75
  function supported(major: number, minor: number, lts: boolean): boolean;
75
76
  function supported(major: number, minor?: number, patch?: number, lts?: boolean): boolean;
76
- function importESM<T = unknown>(name: string, isDefault?: boolean, fromPath?: boolean): Promise<T>;
77
+ function importESM(name: string | URL, isDefault: boolean, fromPath?: boolean): Promise<unknown>;
78
+ function importESM(name: string | URL, options?: ImportAttributes, fromPath?: boolean): Promise<unknown>;
77
79
  function purgeMemory(percent?: number): number;
78
80
 
79
81
  interface LOG_TYPE {
@@ -136,6 +138,7 @@ interface ACTION_FLAG {
136
138
 
137
139
  interface ERR_CODE {
138
140
  MODULE_NOT_FOUND: "MODULE_NOT_FOUND";
141
+ ERR_MODULE_NOT_FOUND: "ERR_MODULE_NOT_FOUND";
139
142
  }
140
143
 
141
144
  interface DOWNLOAD_TYPE {
@@ -200,10 +203,10 @@ const IMPORT_MAP: Record<string, string | undefined>;
200
203
 
201
204
  ## References
202
205
 
203
- - https://www.unpkg.com/@e-mc/types@0.12.2/index.d.ts
204
- - https://www.unpkg.com/@e-mc/types@0.12.2/lib/logger.d.ts
205
- - https://www.unpkg.com/@e-mc/types@0.12.2/lib/module.d.ts
206
- - https://www.unpkg.com/@e-mc/types@0.12.2/lib/node.d.ts
206
+ - https://www.unpkg.com/@e-mc/types@0.12.5/index.d.ts
207
+ - https://www.unpkg.com/@e-mc/types@0.12.5/lib/logger.d.ts
208
+ - https://www.unpkg.com/@e-mc/types@0.12.5/lib/module.d.ts
209
+ - https://www.unpkg.com/@e-mc/types@0.12.5/lib/node.d.ts
207
210
 
208
211
  * https://developer.mozilla.org/en-US/docs/Web/API/DOMException
209
212
  * https://www.npmjs.com/package/@types/bytes
package/constant.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export const enum INTERNAL {
2
- VERSION = '0.12.3',
2
+ VERSION = '0.12.5',
3
3
  TEMP_DIR = 'tmp',
4
4
  CJS = '__cjs__'
5
5
  }
@@ -301,6 +301,17 @@ export const enum LOG_STATE {
301
301
  STDERR
302
302
  }
303
303
 
304
+ export const enum STATUS_TYPE {
305
+ UNKNOWN,
306
+ FATAL,
307
+ ERROR,
308
+ WARN,
309
+ INFO,
310
+ DEBUG,
311
+ ASSERT,
312
+ TRACE
313
+ }
314
+
304
315
  export const enum READDIR_SORT {
305
316
  FILE,
306
317
  DIRECTORY,
package/index.d.ts CHANGED
@@ -281,6 +281,7 @@ declare namespace types {
281
281
  preserve?: boolean;
282
282
  }
283
283
 
284
+ type ImportAttributes = { with: { type: "json" } };
284
285
  type MergeArrayMethod = "concat" | "concat-pre" | "includes" | "unshift" | "push" | "flat" | "join" | "slice" | "reverse" | ["flat", number] | ["join", string] | ["slice", number, number?];
285
286
  type WatchEventValue = WATCH_EVENT[keyof WATCH_EVENT];
286
287
 
@@ -298,6 +299,7 @@ declare namespace types {
298
299
  function getLogCurrent(): LogArguments | null;
299
300
  function setLogCurrent(value: LogArguments | null): void;
300
301
  function setTempDir(value: string): boolean;
302
+ function getTempDir(create: true, prefix?: string): string;
301
303
  function getTempDir(...values: string[]): string;
302
304
  function isArray<T>(value: unknown): value is T[];
303
305
  function isObject<T extends object>(value: unknown): value is T;
@@ -339,7 +341,8 @@ declare namespace types {
339
341
  function errorMessage(title: number | string, value: string, hint?: string): Error;
340
342
  function supported(major: number, minor: number, lts: boolean): boolean;
341
343
  function supported(major: number, minor?: number, patch?: number, lts?: boolean): boolean;
342
- function importESM<T = unknown>(name: string, isDefault?: boolean, fromPath?: boolean): Promise<T>;
344
+ function importESM<T = unknown>(name: string | URL, isDefault: boolean, fromPath?: boolean): Promise<T>;
345
+ function importESM<T = unknown>(name: string | URL, options?: ImportAttributes, fromPath?: boolean): Promise<T>;
343
346
  function purgeMemory(percent?: number): number;
344
347
  }
345
348
 
package/index.js CHANGED
@@ -51,6 +51,7 @@ const path = require("node:path");
51
51
  const fs = require("node:fs");
52
52
  const crypto = require("node:crypto");
53
53
  const bytes = require("bytes");
54
+ const node_os_1 = require("node:os");
54
55
  const node_url_1 = require("node:url");
55
56
  const PATTERN_CHARS = {
56
57
  '&': '\\x26',
@@ -99,6 +100,7 @@ const RESERVED_SHELL = [
99
100
  let CACHE_COERCED = new WeakSet();
100
101
  let LOG_CURRENT = null;
101
102
  let SUPPORTED_HASHSINGLE = false;
103
+ let SUPPORTED_IMPORTATTRIBUTES = false;
102
104
  let TEMP_DIR = path.join(process.cwd(), "tmp");
103
105
  let INCREMENT_COUNT = 65536;
104
106
  let INCREMENT_PREFIX = '';
@@ -583,7 +585,13 @@ function setLogCurrent(value) {
583
585
  LOG_CURRENT = value;
584
586
  }
585
587
  function getTempDir(...values) {
586
- return values.length > 0 ? path.join(TEMP_DIR, ...values) : TEMP_DIR;
588
+ if (values.length === 0) {
589
+ return TEMP_DIR;
590
+ }
591
+ if (typeof values[0] === 'boolean' && values.shift()) {
592
+ return fs.mkdtempSync(isString(values[0]) ? path.join((0, node_os_1.tmpdir)(), values[0]) : (0, node_os_1.tmpdir)() + path.sep);
593
+ }
594
+ return path.join(TEMP_DIR, ...values);
587
595
  }
588
596
  function setTempDir(value) {
589
597
  try {
@@ -998,7 +1006,6 @@ function getEncoding(value, fallback) {
998
1006
  switch (value = value.trim().toLowerCase()) {
999
1007
  case 'utf8':
1000
1008
  case 'utf-8':
1001
- case 'unicode-1-1-utf-8':
1002
1009
  return 'utf8';
1003
1010
  case 'utf16le':
1004
1011
  case 'utf-16le':
@@ -1182,10 +1189,21 @@ function supported(major, minor = 0, patch = 0, lts = false) {
1182
1189
  return !lts;
1183
1190
  }
1184
1191
  async function importESM(name, isDefault, fromPath) {
1185
- if (fromPath && path.isAbsolute(name)) {
1192
+ let options;
1193
+ if (name instanceof URL) {
1194
+ name = (0, node_url_1.fileURLToPath)(name);
1195
+ }
1196
+ else if (fromPath && path.isAbsolute(name)) {
1186
1197
  name = (0, node_url_1.pathToFileURL)(name).toString();
1187
1198
  }
1188
- const result = import(name);
1199
+ if (isObject(isDefault)) {
1200
+ options = isDefault;
1201
+ if (!SUPPORTED_IMPORTATTRIBUTES && options.with?.type === 'json') {
1202
+ return JSON.parse(fs.readFileSync(name, 'utf8'));
1203
+ }
1204
+ isDefault = true;
1205
+ }
1206
+ const result = import(name, options);
1189
1207
  if (isDefault) {
1190
1208
  const out = await result;
1191
1209
  if (isObject(out) && 'default' in out) {
@@ -1195,3 +1213,4 @@ async function importESM(name, isDefault, fromPath) {
1195
1213
  return result;
1196
1214
  }
1197
1215
  SUPPORTED_HASHSINGLE = supported(20, 12, true) || supported(21, 7);
1216
+ SUPPORTED_IMPORTATTRIBUTES = supported(18, 20, 5, true) || supported(20, 18, 3, true) || supported(22, 12, true) || supported(23, 1);
package/lib/core.d.ts CHANGED
@@ -6,7 +6,7 @@ import type { StatusType } from '@e-mc/types/lib/logger';
6
6
  import type { Settings } from './node';
7
7
  import type { ClientDbSettings, ClientModule, DbCacheValue, DbCoerceSettings, DbSourceOptions } from './settings';
8
8
 
9
- import type { TransferListItem, Worker, WorkerOptions } from 'node:worker_threads';
9
+ import type { Transferable, Worker, WorkerOptions } from 'node:worker_threads';
10
10
 
11
11
  import type * as EventEmitter from 'node:events';
12
12
 
@@ -108,9 +108,9 @@ export interface WorkerGroupConstructor {
108
108
 
109
109
  export interface IWorkerChannel<T = unknown> extends EventEmitter, Iterable<Worker>, WorkerInfo {
110
110
  [Symbol.iterator](): IteratorObject<Worker, BuiltinIteratorReturn>;
111
- sendObject(data: unknown, transferList?: TransferListItem[], callback?: WorkerChannelResponse<T>, ...returnArgs: unknown[]): Worker;
111
+ sendObject(data: unknown, transferList?: Transferable[], callback?: WorkerChannelResponse<T>, ...returnArgs: unknown[]): Worker;
112
112
  sendBuffer(data: Buffer, shared?: boolean, callback?: WorkerChannelResponse<T>, ...returnArgs: unknown[]): Worker | null;
113
- send(data: unknown, transferList?: TransferListItem[]): Promise<T>;
113
+ send(data: unknown, transferList?: Transferable[]): Promise<T>;
114
114
  drop(count?: number): number;
115
115
  join(group: IWorkerGroup, label?: string): void;
116
116
  quit(): void;
@@ -141,13 +141,13 @@ export interface IWorkerChannel<T = unknown> extends EventEmitter, Iterable<Work
141
141
  on(event: "online", listener: () => void): this;
142
142
  on(event: "message", listener: (value: any) => void): this;
143
143
  on(event: "data", listener: (data: T) => void): this;
144
- on(event: "pass", listener: (data: unknown, transferList: TransferListItem[] | undefined) => void): this;
144
+ on(event: "pass", listener: (data: unknown, transferList: Transferable[] | undefined) => void): this;
145
145
  once(event: "error" | "messageerror" | "abort", listener: (err: Error) => void): this;
146
146
  once(event: "exit", listener: (exitCode: number) => void): this;
147
147
  once(event: "online", listener: () => void): this;
148
148
  once(event: "message", listener: (value: any) => void): this;
149
149
  once(event: "data", listener: (data: T) => void): this;
150
- once(event: "pass", listener: (data: unknown, transferList: TransferListItem[] | undefined) => void): this;
150
+ once(event: "pass", listener: (data: unknown, transferList: Transferable[] | undefined) => void): this;
151
151
  }
152
152
 
153
153
  export interface WorkerChannelConstructor<T = unknown> {
package/lib/index.d.ts CHANGED
@@ -28,6 +28,8 @@ import type { Readable, Writable } from 'node:stream';
28
28
  import type { SecureContextOptions } from 'node:tls';
29
29
  import type { BrotliCompress, BrotliOptions, Gzip, ZlibOptions } from 'node:zlib';
30
30
  // @ts-ignore
31
+ import type { Unit } from 'bytes';
32
+ // @ts-ignore
31
33
  import type { FileTypeResult } from 'file-type';
32
34
 
33
35
  import type * as EventEmitter from 'node:events';
@@ -816,8 +818,8 @@ declare namespace functions {
816
818
  initCpuUsage(instance?: IModule): CpuUsage;
817
819
  getCpuUsage(start: CpuUsage, format: true): string;
818
820
  getCpuUsage(start: CpuUsage, format?: boolean): number;
819
- getMemUsage(format: true): string;
820
- getMemUsage(format?: boolean): number;
821
+ getMemUsage(format: true | "%" | Unit, free?: boolean): string;
822
+ getMemUsage(format?: boolean, free?: boolean): number;
821
823
  formatCpuMem(start: CpuUsage, all?: boolean): string;
822
824
  getPackageVersion(name: string | [string, string], options?: PackageVersionOptions): string;
823
825
  /** @deprecated */
package/lib/request.d.ts CHANGED
@@ -143,6 +143,7 @@ export interface OpenOptions extends KeepAliveAction, SilentAction, EncodingActi
143
143
  pipeTo?: string | Writable;
144
144
  postData?: unknown;
145
145
  connected?: ((headers: IncomingHttpHeaders) => boolean | void);
146
+ trailers?: (headers: IncomingHttpHeaders) => void;
146
147
  statusMessage?: string;
147
148
  progressId?: number | string;
148
149
  outFormat?: { out: BufferFormat; parser?: PlainObject };
package/lib/settings.d.ts CHANGED
@@ -272,7 +272,7 @@ export interface DbCoerceSettings<T = boolean> {
272
272
  export interface PurgeBase<T = number | string> extends MinMax {
273
273
  enabled?: boolean;
274
274
  percent?: T;
275
- limit?: number;
275
+ limit?: T;
276
276
  }
277
277
 
278
278
  export interface PurgeComponent extends PurgeBase {
@@ -461,6 +461,7 @@ export interface LoggerProcessSettings extends LoggerColor {
461
461
  cpu_single_core?: boolean;
462
462
  mem?: boolean;
463
463
  mem_format?: "%" | Unit;
464
+ mem_free?: boolean;
464
465
  }
465
466
 
466
467
  export interface LoggerFormatColor {
package/lib/task.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- export interface Command<T = unknown> extends PlainObject {
2
- task: string;
3
- origDir: string;
4
- data: T;
5
- }
6
-
7
- export interface SpawnResult {
8
- added?: string[];
9
- deleted?: string[];
1
+ export interface Command<T = unknown> extends PlainObject {
2
+ task: string;
3
+ origDir: string;
4
+ data: T;
5
+ }
6
+
7
+ export interface SpawnResult {
8
+ added?: string[];
9
+ deleted?: string[];
10
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/types",
3
- "version": "0.12.3",
3
+ "version": "0.12.5",
4
4
  "description": "Type definitions for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -13,8 +13,7 @@
13
13
  "directory": "src/types"
14
14
  },
15
15
  "keywords": [
16
- "squared",
17
- "squared-functions"
16
+ "squared"
18
17
  ],
19
18
  "author": "An Pham <anpham6@gmail.com>",
20
19
  "license": "BSD-3-Clause",