@e-mc/types 0.8.1 → 0.8.2

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,5 +1,7 @@
1
1
  ### @e-mc/types
2
2
 
3
+ https://e-mc.readthedocs.io
4
+
3
5
  ### LICENSE
4
6
 
5
7
  BSD 3-Clause
package/constant.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export const enum INTERNAL {
2
- VERSION = '0.8.1',
2
+ VERSION = '0.8.2',
3
3
  TEMP_DIR = 'tmp', // eslint-disable-line @typescript-eslint/no-shadow
4
4
  CJS = '__cjs__'
5
5
  }
@@ -153,6 +153,10 @@ export const enum ERR_IMAGE {
153
153
  METHOD_ARGS = 'Invalid method arguments'
154
154
  }
155
155
 
156
+ export const enum ERR_HTTP {
157
+ HEADERS = 'Unable to process headers'
158
+ }
159
+
156
160
  export const enum DB_TRANSACTION {
157
161
  ACTIVE = 1,
158
162
  PARTIAL = 2,
package/index.js CHANGED
@@ -15,7 +15,8 @@ class AbortError extends Error {
15
15
  }
16
16
  }
17
17
  const REGEXP_UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
18
- const REGEXP_FUNCTION = /^(async\s+)?(function(?:\b|\s+)([\w_$]*)\s*\(([^)]*)\)\s*\{([\S\s]*)\})$/;
18
+ const REGEXP_FUNCTION = /^(async\s+)?(function(?:\b|\s+)[\w_$]*\s*\(([^)]*)\)\s*\{([\S\s]*)\})$/;
19
+ const REGEXP_FUNCTION_ARROW = /^(async\s+)?(\s*\(([^)]*)\)\s*=>\s*(?:\{([\S\s]*)\}|(?!\s|{)((?:(?<!return\s+)(?:"[^"\n]*"|'[^'\n]*'|`[^`]*`|[^\n;"'`]))*;)))$/;
19
20
  const ASYNC_FUNCTION = Object.getPrototypeOf(async () => { }).constructor;
20
21
  let CACHE_COERCED = new WeakSet();
21
22
  let LOG_CURRENT = null;
@@ -805,10 +806,10 @@ function asFunction(value, sync = true) {
805
806
  return value;
806
807
  }
807
808
  let match;
808
- if (isString(value) && (match = REGEXP_FUNCTION.exec(value = value.trim()))) {
809
+ if (isString(value) && (match = REGEXP_FUNCTION.exec(value = value.trim()) || REGEXP_FUNCTION_ARROW.exec(value))) {
809
810
  if (!sync || match[1]) {
810
- const args = match[4].trim().split(/\s*,\s*/);
811
- args.push(match[5]);
811
+ const args = match[3].trim().split(/\s*,\s*/);
812
+ args.push(match[4] || (match[5] && (match[5] = 'return ' + match[5])));
812
813
  return new ASYNC_FUNCTION(...args);
813
814
  }
814
815
  try {
@@ -824,7 +825,22 @@ function asFunction(value, sync = true) {
824
825
  }
825
826
  exports.asFunction = asFunction;
826
827
  function getEncoding(value, fallback = 'utf-8') {
827
- return typeof value === 'string' && Buffer.isEncoding(value = value.trim().toLowerCase()) ? value : fallback;
828
+ if (typeof value === 'string') {
829
+ switch (value = value.trim().toLowerCase()) {
830
+ case 'utf8':
831
+ case 'utf-8':
832
+ case 'utf16le':
833
+ case 'utf-16le':
834
+ return value;
835
+ case 'utf16':
836
+ case 'utf-16':
837
+ return 'utf-16le';
838
+ }
839
+ if (Buffer.isEncoding(value)) {
840
+ return value;
841
+ }
842
+ }
843
+ return fallback;
828
844
  }
829
845
  exports.getEncoding = getEncoding;
830
846
  function encryptUTF8(algorithm, key, iv, data, encoding = 'hex') {
package/lib/http.d.ts CHANGED
@@ -45,6 +45,7 @@ export const enum HTTP_STATUS {
45
45
  UNPROCESSABLE_ENTITY = 422,
46
46
  LOCKED = 423,
47
47
  FAILED_DEPENDENCY = 424,
48
+ TOO_EARLY = 425,
48
49
  UPGRADE_REQUIRED = 426,
49
50
  PRECONDITION_REQUIRED = 428,
50
51
  TOO_MANY_REQUESTS = 429,
@@ -62,6 +63,7 @@ export const enum HTTP_STATUS {
62
63
  VARIANT_ALSO_NEGOTIATES = 506,
63
64
  INSUFFICIENT_STORAGE = 507,
64
65
  LOOP_DETECTED = 508,
66
+ BANDWIDTH_LIMIT_EXCEEDED = 509,
65
67
  NOT_EXTENDED = 510,
66
68
  NETWORK_AUTHENTICATION_REQUIRED = 511,
67
69
  WEB_SERVER_IS_DOWN = 521,
package/lib/index.d.ts CHANGED
@@ -17,7 +17,7 @@ import type { CommandData, CropData, QualityData, ResizeData, RotateData, Transf
17
17
  import type { ExecCommand, LOG_TYPE, LogArguments, LogComponent, LogDate, LogFailOptions, LogMessageOptions, LogOptions, LogProcessOptions, LogTime, LogType, LogValue, STATUS_TYPE, StatusType } from './logger';
18
18
  import type { AsHashOptions, CheckSemVerOptions, CopyDirOptions, CopyDirResult, CopyFileOptions, CreateDirOptions, DeleteFileOptions, GetTempDirOptions, MoveFileOptions, NormalizeFlags, ParseFunctionOptions, PermissionOptions, ProtocolType, ReadBufferOptions, ReadFileCallback, ReadFileOptions, ReadHashOptions, ReadTextOptions, RemoveDirOptions, WriteFileOptions } from './module';
19
19
  import type { RequestData, Settings } from './node';
20
- import type { ApplyOptions, Aria2Options, BufferFormat, DataEncodedResult, DataObjectResult, FormDataPart, HeadersOnCallback, HostConfig, OpenOptions, PostOptions, ProxySettings, ReadExpectType, RequestInit } from './request';
20
+ import type { ApplyOptions, Aria2Options, BufferFormat, DataEncodedResult, DataObjectResult, FormDataPart, HeadersOnCallback, HostConfig, OpenOptions, PostOptions, ProxySettings, ReadExpectType, RequestInit, StatusOnCallback } from './request';
21
21
  import type { ClientModule, CloudModule, CloudServiceOptions, CompressModule, CompressSettings, DbCoerceSettings, DbModule, DbSourceOptions, DnsLookupSettings, DocumentComponent, DocumentComponentOption, DocumentModule, HttpConnectSettings, HttpMemorySettings, ImageModule, RequestModule, RequestSettings, TaskModule, WatchModule } from './settings';
22
22
  import type { Command, SpawnResult } from './task';
23
23
  import type { IFileGroup, ModifiedPostFinalizeListener, SecureOptions, WatchInitResult } from './watch';
@@ -109,6 +109,7 @@ declare namespace functions {
109
109
  clamp(value: unknown, min?: number, max?: number): number;
110
110
  isBinary(mime: unknown): mime is string;
111
111
  toABGR(buffer: Uint8Array | Buffer): Buffer;
112
+ /* @deprecated IImage.using (v0.9) */
112
113
  using?<V extends ExternalAsset>(this: T, instance: IImage<T, U>, data: IFileThread<V>, command: string): Promise<unknown>;
113
114
  readonly prototype: IImage<T, U>;
114
115
  new(module?: U): IImage<T, U>;
@@ -126,6 +127,7 @@ declare namespace functions {
126
127
 
127
128
  interface TaskConstructor<T extends IHost = IHost, U extends TaskModule = TaskModule> extends ModuleConstructor {
128
129
  finalize<V extends ExternalAsset>(this: T, instance: ITask<T, U>, assets: V[]): Promise<unknown>;
130
+ /* @deprecated ITask.using (v0.9) */
129
131
  using?<V extends ExternalAsset>(this: T, instance: ITask<T, U>, assets: V[], preceding?: boolean): Promise<unknown>;
130
132
  readonly prototype: ITask<T, U>;
131
133
  new(module?: U, ...args: unknown[]): ITask<T, U>;
@@ -254,6 +256,7 @@ declare namespace functions {
254
256
  writeSourceMap(uri: string, data: SourceCode, options?: SourceMapOptions): Undef<string>;
255
257
  updateGradle(source: string, namespaces: string[], value: string, options?: UpdateGradleOptions | boolean): string;
256
258
  generateLintTable(messages: LintMessage[], options: GenerateLintTableOptions): LogComponent[];
259
+ /* @deprecated IDocument.using (v0.9) */
257
260
  using?(this: T, instance: IDocument<T, U, V, W, X, Y>, file: U): Promise<unknown>;
258
261
  cleanup?(this: T, instance: IDocument<T, U, V, W, X, Y>): Promise<unknown>;
259
262
  sanitizeAssets?(assets: U[], exclusions?: U[]): U[];
@@ -302,9 +305,12 @@ declare namespace functions {
302
305
  proxy: Null<ProxySettings>;
303
306
  init(config?: RequestInit): this;
304
307
  apply(options: ApplyOptions): this;
305
- addDns(hostname: string, address: string, family?: NumString): void;
308
+ addDns(hostname: string, address: string, timeout: number): void;
309
+ addDns(hostname: string, address: string, family?: NumString, timeout?: number): void;
306
310
  lookupDns(hostname: string): LookupFunction;
307
311
  proxyOf(uri: string, localhost?: boolean): Undef<ProxySettings>;
312
+ statusOn(name: ArrayOf<number>, callback: StatusOnCallback): void;
313
+ statusOn(name: ArrayOf<number>, patternUrl: string, callback: StatusOnCallback): void;
308
314
  headersOn(name: ArrayOf<string>, callback: HeadersOnCallback): void;
309
315
  headersOn(name: ArrayOf<string>, patternUrl: string, callback: HeadersOnCallback): void;
310
316
  headersOf(uri: string): Undef<OutgoingHttpHeaders>;
package/lib/logger.d.ts CHANGED
@@ -40,6 +40,7 @@ export interface LoggerFormat<T = NumString> {
40
40
  bold?: boolean;
41
41
  justify?: TextAlign;
42
42
  unit?: string;
43
+ as?: StringMap;
43
44
  }
44
45
 
45
46
  export interface LoggerStatus<T = boolean> {
package/lib/request.d.ts CHANGED
@@ -128,4 +128,5 @@ export type BufferFormat = "json" | "yaml" | "json5" | "xml" | "toml";
128
128
  export type ReadExpectType = "always" | "string" | "none";
129
129
  export type DataEncodedResult<T extends { encoding?: BufferEncoding }> = T extends { encoding: BufferEncoding } ? string : Null<BufferContent>;
130
130
  export type DataObjectResult<T extends { format?: unknown; encoding?: BufferEncoding }> = T extends { format: string | PlainObject } ? Null<object> : DataEncodedResult<T>;
131
- export type HeadersOnCallback = (value: IncomingHttpHeaders, url?: URL) => Void<boolean>;
131
+ export type StatusOnCallback = (code: number, headers: IncomingHttpHeaders, url?: URL) => Void<boolean>;
132
+ export type HeadersOnCallback = (headers: IncomingHttpHeaders, url?: URL) => Void<boolean>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/types",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "description": "Type definitions for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",