@e-mc/types 0.12.4 → 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.4/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";
@@ -74,7 +74,8 @@ function errorValue(value: string, hint?: string): Error;
74
74
  function errorMessage(title: number | string, value: string, hint?: string): Error;
75
75
  function supported(major: number, minor: number, lts: boolean): boolean;
76
76
  function supported(major: number, minor?: number, patch?: number, lts?: boolean): boolean;
77
- 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>;
78
79
  function purgeMemory(percent?: number): number;
79
80
 
80
81
  interface LOG_TYPE {
@@ -137,6 +138,7 @@ interface ACTION_FLAG {
137
138
 
138
139
  interface ERR_CODE {
139
140
  MODULE_NOT_FOUND: "MODULE_NOT_FOUND";
141
+ ERR_MODULE_NOT_FOUND: "ERR_MODULE_NOT_FOUND";
140
142
  }
141
143
 
142
144
  interface DOWNLOAD_TYPE {
@@ -201,10 +203,10 @@ const IMPORT_MAP: Record<string, string | undefined>;
201
203
 
202
204
  ## References
203
205
 
204
- - https://www.unpkg.com/@e-mc/types@0.12.4/index.d.ts
205
- - https://www.unpkg.com/@e-mc/types@0.12.4/lib/logger.d.ts
206
- - https://www.unpkg.com/@e-mc/types@0.12.4/lib/module.d.ts
207
- - https://www.unpkg.com/@e-mc/types@0.12.4/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
208
210
 
209
211
  * https://developer.mozilla.org/en-US/docs/Web/API/DOMException
210
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.4',
2
+ VERSION = '0.12.5',
3
3
  TEMP_DIR = 'tmp',
4
4
  CJS = '__cjs__'
5
5
  }
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
 
@@ -340,7 +341,8 @@ declare namespace types {
340
341
  function errorMessage(title: number | string, value: string, hint?: string): Error;
341
342
  function supported(major: number, minor: number, lts: boolean): boolean;
342
343
  function supported(major: number, minor?: number, patch?: number, lts?: boolean): boolean;
343
- 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>;
344
346
  function purgeMemory(percent?: number): number;
345
347
  }
346
348
 
package/index.js CHANGED
@@ -100,6 +100,7 @@ const RESERVED_SHELL = [
100
100
  let CACHE_COERCED = new WeakSet();
101
101
  let LOG_CURRENT = null;
102
102
  let SUPPORTED_HASHSINGLE = false;
103
+ let SUPPORTED_IMPORTATTRIBUTES = false;
103
104
  let TEMP_DIR = path.join(process.cwd(), "tmp");
104
105
  let INCREMENT_COUNT = 65536;
105
106
  let INCREMENT_PREFIX = '';
@@ -1188,10 +1189,21 @@ function supported(major, minor = 0, patch = 0, lts = false) {
1188
1189
  return !lts;
1189
1190
  }
1190
1191
  async function importESM(name, isDefault, fromPath) {
1191
- 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)) {
1192
1197
  name = (0, node_url_1.pathToFileURL)(name).toString();
1193
1198
  }
1194
- 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);
1195
1207
  if (isDefault) {
1196
1208
  const out = await result;
1197
1209
  if (isObject(out) && 'default' in out) {
@@ -1201,3 +1213,4 @@ async function importESM(name, isDefault, fromPath) {
1201
1213
  return result;
1202
1214
  }
1203
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/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 {
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.4",
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",