@e-mc/types 0.8.0 → 0.8.1

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/LICENSE CHANGED
@@ -1,11 +1,11 @@
1
- Copyright 2023 An Pham
2
-
3
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
-
5
- 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
-
7
- 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
-
9
- 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
-
1
+ Copyright 2023 An Pham
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
+
5
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
+
7
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+
9
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+
11
11
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/constant.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export const enum INTERNAL {
2
- VERSION = '0.8.0',
2
+ VERSION = '0.8.1',
3
3
  TEMP_DIR = 'tmp', // eslint-disable-line @typescript-eslint/no-shadow
4
4
  CJS = '__cjs__'
5
5
  }
@@ -255,6 +255,7 @@ export const enum SETTINGS_KEY_NAME {
255
255
  PERMISSION_HOMEREAD = "permission.home_read",
256
256
  PERMISSION_HOMEWRITE = "permission.home_write",
257
257
  MEMORY_SETTINGS_USERS = "memory.settings.users",
258
+ MEMORY_SETTINGS_CACHE_DISK = "memory.settings.cache_disk",
258
259
  ERROR_OUT = "error.out",
259
260
  ERROR_FATAL = "error.fatal",
260
261
  BROADCAST_OUT = "broadcast.out",
package/lib/asset.d.ts CHANGED
@@ -14,6 +14,10 @@ export interface BinaryAction {
14
14
  binOpts?: string[];
15
15
  }
16
16
 
17
+ export interface StreamAction {
18
+ minStreamSize?: NumString;
19
+ }
20
+
17
21
  export interface FileData<T extends ExternalAsset> extends MimeTypeAction {
18
22
  file: T;
19
23
  }
@@ -50,7 +54,7 @@ export interface InitialValue extends Partial<LocationUri>, MimeTypeAction {
50
54
  cacheable?: boolean;
51
55
  }
52
56
 
53
- export interface ExternalAsset extends FileAsset, BundleAction, BinaryAction {
57
+ export interface ExternalAsset extends FileAsset, BundleAction, BinaryAction, StreamAction {
54
58
  id?: number;
55
59
  url?: URL;
56
60
  socketPath?: string;
package/lib/cloud.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { DbDataSource, LocationUri, StorageAction } from './squared';
2
2
 
3
- import type { ExternalAsset } from './asset';
3
+ import type { ExternalAsset, StreamAction } from './asset';
4
4
 
5
5
  export interface UploadAction {
6
6
  cloudUrl?: string;
@@ -37,7 +37,7 @@ export interface CloudStorageAdmin<T = unknown, U = string, V = unknown, W = unk
37
37
  preservePath?: boolean;
38
38
  }
39
39
 
40
- export interface CloudStorageAction<T = unknown, U = string, V = unknown, W = unknown> extends Partial<LocationUri> {
40
+ export interface CloudStorageAction<T = unknown, U = string, V = unknown, W = unknown> extends Partial<LocationUri>, StreamAction {
41
41
  active?: boolean;
42
42
  overwrite?: boolean;
43
43
  admin?: CloudStorageAdmin<T, U, V, W>;
@@ -49,7 +49,7 @@ export interface CloudStorageUpload<T = unknown, U = string, V = unknown, W = st
49
49
  metadata?: Record<string, string>;
50
50
  tags?: Record<string, string> | false;
51
51
  options?: T;
52
- fileGroup?: [BufferContent, string, string?][];
52
+ fileGroup?: UploadContent[];
53
53
  localStorage?: boolean;
54
54
  endpoint?: string;
55
55
  all?: boolean;
@@ -87,5 +87,6 @@ export interface BucketAction {
87
87
  bucket: string;
88
88
  }
89
89
 
90
+ export type UploadContent = [BufferContent, string, string?];
90
91
  export type CloudFeatures = "storage" | "database";
91
92
  export type CloudFunctions = "upload" | "download";
package/lib/core.d.ts CHANGED
@@ -152,6 +152,7 @@ export interface StoreResultOptions {
152
152
  export interface CacheOptions {
153
153
  value?: DbCacheValue;
154
154
  renewCache?: boolean;
155
+ exclusiveOf?: [number, number?, number?];
155
156
  sessionKey?: string;
156
157
  }
157
158
 
package/lib/index.d.ts CHANGED
@@ -15,7 +15,7 @@ import type { AssetContentOptions, ChecksumOptions, DeleteFileAddendum, FileOutp
15
15
  import type { HttpAgentSettings, HttpProtocolVersion, HttpRequestClient, InternetProtocolVersion } from './http';
16
16
  import type { CommandData, CropData, QualityData, ResizeData, RotateData, TransformOptions } from './image';
17
17
  import type { ExecCommand, LOG_TYPE, LogArguments, LogComponent, LogDate, LogFailOptions, LogMessageOptions, LogOptions, LogProcessOptions, LogTime, LogType, LogValue, STATUS_TYPE, StatusType } from './logger';
18
- import type { AsHashOptions, CheckSemVerOptions, CopyDirOptions, CopyDirResult, CopyFileOptions, CreateDirOptions, DeleteFileOptions, GetTempDirOptions, MoveFileOptions, NormalizeFlags, ParseFunctionOptions, PermissionOptions, ProtocolType, ReadFileCallback, ReadFileOptions, ReadHashOptions, RemoveDirOptions, WriteFileOptions } from './module';
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
20
  import type { ApplyOptions, Aria2Options, BufferFormat, DataEncodedResult, DataObjectResult, FormDataPart, HeadersOnCallback, HostConfig, OpenOptions, PostOptions, ProxySettings, ReadExpectType, RequestInit } 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';
@@ -412,7 +412,7 @@ declare namespace functions {
412
412
  addCopy(data: FileCommand<T>, saveAs?: string, replace?: boolean): Undef<string>;
413
413
  findMime(file: T, rename?: boolean): Promise<string>;
414
414
  getUTF8String(file: T, uri?: string): string;
415
- getBuffer(file: T): Null<Buffer>;
415
+ getBuffer<U>(file: T, minStreamSize?: U): U extends number ? Promise<Buffer> : Null<Buffer>;
416
416
  getCacheDir(url: string | URL, createDir?: boolean): string;
417
417
  setAssetContent(file: T, content: string, options?: AssetContentOptions): string;
418
418
  getAssetContent(file: T, content?: string): Undef<string>;
@@ -562,7 +562,7 @@ declare namespace functions {
562
562
  canRead(uri: string, options?: PermissionOptions): boolean;
563
563
  canWrite(uri: string, options?: PermissionOptions): boolean;
564
564
  readFile(src: string): Undef<Buffer>;
565
- readFile<U extends ReadFileOptions>(src: string, options?: U): Undef<U extends { encoding: string } ? string : BufferContent>;
565
+ readFile<U extends ReadFileOptions>(src: string, options?: U): Undef<U extends { encoding: string } ? U extends { minStreamSize: NumString } ? Promise<string> : string : U extends { minStreamSize: NumString } ? Promise<Buffer> : Buffer>;
566
566
  readFile<U extends Buffer>(src: string, promises: true): Promise<Undef<U>>;
567
567
  readFile<U extends BufferContent>(src: string, options: ReadFileOptions, promises: true): Promise<Undef<U>>;
568
568
  readFile<U extends ReadFileCallback<V>, V extends Buffer>(src: string, callback: U): Undef<U extends ReadFileCallback<infer W> ? W : V>;
@@ -716,8 +716,13 @@ declare namespace functions {
716
716
  copyDir(src: string | URL, dest: string | URL, options: CopyDirOptions): Promise<CopyDirResult>;
717
717
  copyDir(src: string | URL, dest: string | URL, move?: boolean, recursive?: boolean): Promise<CopyDirResult>;
718
718
  renameFile(src: string | URL, dest: string | URL, throws?: boolean): boolean;
719
+ streamFile<U extends BufferContent>(src: string, cache: boolean): Promise<U>;
720
+ streamFile<U extends BufferContent>(src: string, options: U): Promise<U extends { encoding: string } ? string : Buffer>;
721
+ streamFile<U extends BufferContent>(src: string, cache?: boolean | U, options?: U): Promise<U extends { encoding: string } ? string : Buffer>;
719
722
  readText(value: string | URL, cache: boolean): string;
720
- readText(value: string | URL, encoding?: BufferEncoding | boolean, cache?: boolean): string;
723
+ readText<U extends ReadTextOptions>(value: string | URL, options: U): U extends { minStreamSize: NumString } ? Promise<string> : string;
724
+ readText(value: string | URL, encoding?: BufferEncoding | boolean | ReadTextOptions, cache?: boolean): string;
725
+ readBuffer<U extends ReadBufferOptions>(value: string | URL, options: U): U extends { minStreamSize: NumString } ? Promise<Null<Buffer>> : Null<Buffer>;
721
726
  readBuffer(value: string | URL, cache?: boolean): Null<Buffer>;
722
727
  resolveMime(data: string | Buffer | Uint8Array | ArrayBuffer): Promise<Undef<FileTypeResult>>;
723
728
  lookupMime(value: string, extension?: boolean): string;
package/lib/module.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import type { ChecksumBase } from './squared';
2
2
 
3
+ import type { StreamAction } from './asset';
4
+
3
5
  import type { HashOptions } from 'crypto';
4
6
 
5
7
  declare enum NORMALIZE_FLAGS {
@@ -25,7 +27,7 @@ export interface FileSystemOptions extends PermissionOptions {
25
27
  throwsDoesNotExist?: boolean;
26
28
  }
27
29
 
28
- export interface ReadFileOptions extends FileSystemOptions, RequireAction {
30
+ export interface ReadFileOptions extends FileSystemOptions, StreamBase, RequireAction {
29
31
  cache?: boolean;
30
32
  encoding?: BufferEncoding;
31
33
  }
@@ -97,9 +99,17 @@ export interface CopyDirResult {
97
99
  ignored: string[];
98
100
  }
99
101
 
100
- export interface ReadHashOptions extends ChecksumBase {
102
+ export interface StreamBase extends StreamAction {
103
+ signal?: AbortSignal;
104
+ }
105
+
106
+ export interface ReadHashOptions extends ChecksumBase, StreamBase {
101
107
  chunkSize?: number;
102
- minStreamSize?: number;
108
+ }
109
+
110
+ export interface ReadBufferOptions extends StreamBase {
111
+ encoding?: BufferEncoding;
112
+ cache?: boolean;
103
113
  }
104
114
 
105
115
  export interface AsHashOptions extends HashOptions, ChecksumBase {
@@ -116,5 +126,6 @@ export interface GetTempDirOptions {
116
126
  }
117
127
 
118
128
  export type NormalizeFlags = typeof NORMALIZE_FLAGS[keyof typeof NORMALIZE_FLAGS];
129
+ export type ReadTextOptions = ReadBufferOptions;
119
130
  export type ReadFileCallback<T> = (err: Null<NodeJS.ErrnoException>, data?: T) => void;
120
131
  export type ProtocolType = "http" | "https" | "http/s" | "ftp" | "sftp" | "s/ftp" | "torrent" | "unc";
package/lib/settings.d.ts CHANGED
@@ -166,6 +166,14 @@ export interface MemoryModule<T = MemorySettings> extends HandlerSettings<T>, Re
166
166
 
167
167
  export interface MemorySettings extends PlainObject {
168
168
  users?: boolean | string[];
169
+ cache_disk?: MemoryCacheDiskSettings;
170
+ }
171
+
172
+ export interface MemoryCacheDiskSettings<T = NumString> extends IncludeAction<Null<string[]>> {
173
+ enabled?: boolean;
174
+ min_size?: T;
175
+ max_size?: T;
176
+ expires?: T;
169
177
  }
170
178
 
171
179
  export interface DbModule<T = DbSettings> extends ClientModule<T>, DbSourceDataType<ObjectMap<StringMap>>, PlainObject {}
@@ -233,11 +241,9 @@ export interface RequestModule<T = RequestSettings> extends HandlerSettings<T> {
233
241
  http_version?: NumString;
234
242
  accept_encoding?: boolean;
235
243
  };
236
- proxy?: AuthValue & {
244
+ proxy?: AuthValue & IncludeAction & {
237
245
  address?: string;
238
246
  port?: NumString;
239
- include?: string[];
240
- exclude?: string[];
241
247
  keep_alive?: boolean;
242
248
  };
243
249
  headers?: HttpOutgoingHeaders;
@@ -364,12 +370,10 @@ export interface HttpSettings {
364
370
  certs?: ObjectMap<SecureConfig<StringOfArray>>;
365
371
  }
366
372
 
367
- export interface HttpDiskSettings {
373
+ export interface HttpDiskSettings extends IncludeAction {
368
374
  enabled?: boolean;
369
375
  limit?: NumString;
370
376
  expires?: NumString;
371
- include?: string[];
372
- exclude?: string[];
373
377
  }
374
378
 
375
379
  export interface HttpMemorySettings extends HttpDiskSettings {
@@ -392,15 +396,13 @@ export interface DnsLookupSettings {
392
396
  resolve?: ObjectMap<Partial<LookupAddress>>;
393
397
  }
394
398
 
395
- export interface HashConfig {
399
+ export interface HashConfig extends IncludeAction<ObjectMap<string[] | "*">> {
396
400
  enabled?: boolean;
397
401
  algorithm?: HashAlgorithm;
398
402
  etag?: boolean;
399
403
  expires?: NumString;
400
404
  renew?: boolean;
401
405
  limit?: NumString;
402
- exclude?: ObjectMap<string[] | "*">;
403
- include?: ObjectMap<string[] | "*">;
404
406
  }
405
407
 
406
408
  export interface SecureConfig<T = string, U = T> {
@@ -440,6 +442,11 @@ export interface PurgeAction {
440
442
  purge?: PurgeComponent;
441
443
  }
442
444
 
445
+ export interface IncludeAction<T = string[]> {
446
+ include?: T;
447
+ exclude?: T;
448
+ }
449
+
443
450
  export interface CipherConfig {
444
451
  algorithm?: CipherGCMTypes;
445
452
  key?: BinaryLike;
package/lib/squared.d.ts CHANGED
@@ -53,7 +53,7 @@ export interface DataSource<T = unknown> extends DocumentAction {
53
53
  preRender?: string | FunctionType;
54
54
  whenEmpty?: string | FunctionType;
55
55
  removeEmpty?: boolean;
56
- ignoreCache?: boolean | 0 | 1;
56
+ ignoreCache?: boolean | 0 | 1 | [number, number?, number?];
57
57
  transactionState?: number;
58
58
  transactionFail?: boolean;
59
59
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/types",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "Type definitions for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",