@e-mc/file-manager 0.8.11 → 0.8.13

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.
Files changed (5) hide show
  1. package/LICENSE +6 -6
  2. package/README.md +205 -205
  3. package/index.d.ts +5 -5
  4. package/index.js +30 -39
  5. package/package.json +34 -34
package/LICENSE CHANGED
@@ -1,7 +1,7 @@
1
- Copyright 2024 An Pham
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
-
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
-
1
+ Copyright 2024 An Pham
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
7
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,206 +1,206 @@
1
- # @e-mc/file-manager
2
-
3
- * NodeJS 14
4
- * ES2019
5
-
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.11/lib/index.d.ts
13
-
14
- ```typescript
15
- import type { DataSource, IncrementalMatch, TaskAction } from "./squared";
16
-
17
- import type { DocumentConstructor, HostConstructor, ICloud, ICompress, IDocument, IHost, IImage, IModule, IRequest, ITask, ImageConstructor, TaskConstructor, WatchInstance } from "./index";
18
- import type { ExternalAsset, FileCommand, FileData, IFileThread, OutputFinalize } from "./asset";
19
- import type { IPermission, PermissionReadWrite } from "./core";
20
- import type { AssetContentOptions, ChecksumOptions, DeleteFileAddendum, FileOutput, FinalizeResult, FindAssetOptions, IHttpDiskCache, IHttpMemoryCache, InstallData, PostFinalizeCallback, ReplaceOptions } from "./filemanager";
21
- import type { ExecCommand } from "./logger";
22
- import type { CopyFileOptions, CreateDirOptions, DeleteFileOptions, MoveFileOptions, ReadFileOptions, RemoveDirOptions, WriteFileOptions } from "./module";
23
- import type { RequestData, Settings } from "./node";
24
- import type { Aria2Options, BufferFormat, OpenOptions } from "./request";
25
- import type { CloudModule, CompressModule, DbModule, DocumentModule, HttpConnectSettings, HttpMemorySettings, ImageModule, RequestModule, TaskModule, WatchModule } from "./settings";
26
-
27
- import type { SpawnOptions } from "child_process";
28
- import type { NoParamCallback } from "fs";
29
-
30
- interface IFileManager extends IHost, Set<string> {
31
- finalizeState: number;
32
- processTimeout: number;
33
- cacheToDisk: IHttpDiskCache<ExternalAsset>;
34
- cacheToMemory: IHttpMemoryCache<ExternalAsset>;
35
- Request: IRequest<RequestModule>;
36
- Document: InstallData<IDocument<IFileManager, ExternalAsset>, DocumentConstructor<IFileManager, ExternalAsset>>[];
37
- Task: InstallData<ITask, TaskConstructor>[];
38
- Image: Map<string, InstallData<IImage, ImageConstructor>> | null;
39
- Cloud: ICloud | null;
40
- Watch: WatchInstance<ExternalAsset> | null;
41
- Compress: ICompress<CompressModule> | null;
42
- readonly documentAssets: ExternalAsset[];
43
- readonly taskAssets: (ExternalAsset & Required<TaskAction>)[];
44
- readonly dataSourceItems: DataSource[];
45
- readonly files: Set<string>;
46
- readonly filesQueued: Set<string>;
47
- readonly filesToRemove: Set<string>;
48
- readonly filesToCompare: Map<ExternalAsset, string[]>;
49
- readonly contentToAppend: Map<string, string[]>;
50
- readonly contentToReplace: Map<string, string[]>;
51
- readonly processing: IFileThread[];
52
- readonly fetchedAssets: ExternalAsset[];
53
- readonly copiedAssets: ExternalAsset[];
54
- readonly emptyDir: Set<string>;
55
- install(name: "document", target: DocumentConstructor<IFileManager, ExternalAsset>, module?: DocumentModule): IDocument<IFileManager, ExternalAsset> | undefined;
56
- install(name: "task", target: TaskConstructor, module?: TaskModule): ITask | undefined;
57
- install(name: "cloud", handler: string, module?: CloudModule): ICloud | undefined;
58
- install(name: "cloud", module?: CloudModule): ICloud | undefined;
59
- install(name: "db", module?: DbModule): IDb | undefined;
60
- install(name: "image", targets: Map<string, ImageConstructor>, module?: ImageModule): void;
61
- install(name: "watch", module: WatchModule): WatchInstance<ExternalAsset> | undefined;
62
- install(name: "watch", interval?: number | string, port?: number | string, securePort?: number | string, extensions?: unknown[]): WatchInstance<ExternalAsset> | undefined;
63
- install(name: "compress", module?: CompressModule): ICompress<CompressModule> | undefined;
64
- install(name: string, ...args: unknown[]): IModule | undefined;
65
- using(...items: ExternalAsset[] | [boolean, ...ExternalAsset[]]): this;
66
- contains(item: ExternalAsset, condition?: (...args: [ExternalAsset]) => boolean): boolean;
67
- removeCwd(value: unknown): string;
68
- findAsset(value: string | URL, instance?: IModule | FindAssetOptions<ExternalAsset>): ExternalAsset | undefined;
69
- removeAsset(file: ExternalAsset): boolean;
70
- replace(file: ExternalAsset, replaceWith: string, options: ReplaceOptions): boolean;
71
- replace(file: ExternalAsset, replaceWith: string, mimeType?: string | ReplaceOptions): boolean;
72
- rename(file: ExternalAsset, value: string): boolean;
73
- performAsyncTask(): void;
74
- removeAsyncTask(): void;
75
- completeAsyncTask(err?: unknown, uri?: string, parent?: ExternalAsset, type?: number): void;
76
- performFinalize(override?: boolean): void;
77
- hasDocument(instance: IModule, document: string | string[] | undefined): boolean;
78
- getDocumentAssets(instance: IModule, condition?: (...args: [ExternalAsset]) => boolean): ExternalAsset[];
79
- getDataSourceItems(instance: IModule, condition?: (...args: [DataSource]) => boolean): DataSource[];
80
- setLocalUri(file: ExternalAsset, replace?: boolean): FileOutput;
81
- getLocalUri(data: FileData<ExternalAsset>): string;
82
- getMimeType(data: FileData<ExternalAsset>): string;
83
- openThread(instance: IModule, data: IFileThread, timeout?: number): boolean;
84
- closeThread(instance: IModule | null, data: IFileThread, callback?: (...args: unknown[]) => void): boolean;
85
- addProcessTimeout(instance: IModule, file: ExternalAsset, timeout: number): void;
86
- removeProcessTimeout(instance: IModule, file: ExternalAsset): void;
87
- getProcessTimeout(handler: InstallData): number;
88
- clearProcessTimeout(): void;
89
- addDownload(value: number | Buffer | string, encoding: BufferEncoding): number;
90
- addDownload(value: number | Buffer | string, type?: number, encoding?: BufferEncoding): number;
91
- getDownload(type?: number): [number, number];
92
- transformAsset(data: IFileThread, parent?: ExternalAsset): Promise<void>;
93
- addCopy(data: FileCommand<ExternalAsset>, saveAs?: string, replace?: boolean): string | undefined;
94
- findMime(file: ExternalAsset, rename?: boolean): Promise<string>;
95
- getUTF8String(file: ExternalAsset, uri?: string): string;
96
- getBuffer(file: ExternalAsset, minStreamSize?: number): Promise<Buffer> | Buffer | null;
97
- getCacheDir(url: string | URL, createDir?: boolean): string;
98
- setAssetContent(file: ExternalAsset, content: string, options?: AssetContentOptions): string;
99
- getAssetContent(file: ExternalAsset, content?: string): string | undefined;
100
- writeBuffer(file: ExternalAsset, options?: WriteFileOptions): Buffer | null;
101
- writeImage(document: string | string[], output: OutputFinalize<ExternalAsset>): boolean;
102
- compressFile(file: ExternalAsset, overwrite?: boolean): Promise<unknown>;
103
- fetchObject(uri: string | URL, format: BufferFormat): Promise<object | null>;
104
- fetchObject(uri: string | URL, options?: OpenOptions | BufferFormat): Promise<object | null>;
105
- fetchBuffer(uri: string | URL, options?: OpenOptions): Promise<Buffer | string | null>;
106
- fetchFiles(uri: string | URL, pathname: string): Promise<string[]>;
107
- fetchFiles(uri: string | URL, options?: Aria2Options | string): Promise<string[]>;
108
- start(emptyDir?: boolean): Promise<FinalizeResult>;
109
- processAssets(emptyDir?: boolean, using?: ExternalAsset[]): void;
110
- deleteFile(src: string, promises: boolean): Promise<void>;
111
- deleteFile(src: string, options: DeleteFileOptions & DeleteFileAddendum, promises: boolean): Promise<void>;
112
- deleteFile(src: string, callback?: NoParamCallback): unknown;
113
- deleteFile(src: string, options: DeleteFileOptions & DeleteFileAddendum, callback?: NoParamCallback): unknown;
114
- restart(recursive?: boolean | "abort", emptyDir?: boolean): void;
115
- restart(recursive?: boolean | "abort", exclusions?: string[], emptyDir?: boolean): void;
116
- finalizeCompress(assets: ExternalAsset[]): Promise<unknown>;
117
- finalizeDocument(): Promise<unknown>;
118
- finalizeTask(assets: (ExternalAsset & Required<TaskAction>)[]): Promise<unknown>;
119
- finalizeCloud(): Promise<unknown>;
120
- finalizeCleanup(): Promise<unknown>;
121
- finalize(): Promise<void>;
122
- close(): void;
123
- reset(): boolean;
124
- get baseDirectory(): string;
125
- get config(): RequestData;
126
- get assets(): ExternalAsset[];
127
- get incremental(): IncrementalMatch;
128
- set restarting(value);
129
- get restarting(): boolean;
130
- get delayed(): number;
131
- set cleared(value);
132
- get cleared(): boolean;
133
-
134
- /* Set */
135
- add(value: string, parent?: ExternalAsset, type?: number): this;
136
- delete(value: string, emptyDir?: boolean): boolean;
137
- has(value: unknown): value is string;
138
-
139
- /* EventEmitter */
140
- on(event: "end", listener: PostFinalizeCallback): this;
141
- on(event: "exec", listener: (command: ExecCommand, options?: SpawnOptions) => void): this;
142
- on(event: "error", listener: (err: Error) => void): this;
143
- on(event: "file:read", listener: (src: string, data: Buffer | string, options?: ReadFileOptions) => void): this;
144
- on(event: "file:write", listener: (src: string, options?: WriteFileOptions) => void): this;
145
- on(event: "file:delete", listener: (src: string, options?: DeleteFileOptions) => void): this;
146
- on(event: "file:copy", listener: (dest: string, options?: CopyFileOptions) => void): this;
147
- on(event: "file:move", listener: (dest: string, options?: MoveFileOptions) => void): this;
148
- on(event: "dir:create", listener: (src: string, options?: CreateDirOptions) => void): this;
149
- on(event: "dir:remove", listener: (src: string, options?: RemoveDirOptions) => void): this;
150
- once(event: "end", listener: PostFinalizeCallback): this;
151
- once(event: "exec", listener: (command: ExecCommand, options?: SpawnOptions) => void): this;
152
- once(event: "error", listener: (err: Error) => void): this;
153
- once(event: "file:read", listener: (src: string, data: Buffer | string, options?: ReadFileOptions) => void): this;
154
- once(event: "file:write", listener: (src: string, options?: WriteFileOptions) => void): this;
155
- once(event: "file:delete", listener: (src: string, options?: DeleteFileOptions) => void): this;
156
- once(event: "file:copy", listener: (dest: string, options?: CopyFileOptions) => void): this;
157
- once(event: "file:move", listener: (dest: string, options?: MoveFileOptions) => void): this;
158
- once(event: "dir:create", listener: (src: string, options?: CreateDirOptions) => void): this;
159
- once(event: "dir:remove", listener: (src: string, options?: RemoveDirOptions) => void): this;
160
- emit(event: "end", result: FinalizeResult): boolean;
161
- emit(event: "exec", command: ExecCommand, options?: SpawnOptions): boolean;
162
- emit(event: "error", err: Error): boolean;
163
- emit(event: "file:read", src: string, data: Buffer | string, options?: ReadFileOptions): boolean;
164
- emit(event: "file:write", src: string, options?: WriteFileOptions): boolean;
165
- emit(event: "file:delete", src: string, options?: DeleteFileOptions): boolean;
166
- emit(event: "file:copy", dest: string, options?: CopyFileOptions): boolean;
167
- emit(event: "file:move", dest: string, options?: MoveFileOptions): boolean;
168
- emit(event: "dir:create", src: string, options?: CreateDirOptions): boolean;
169
- emit(event: "dir:remove", src: string, options?: RemoveDirOptions): boolean;
170
- }
171
-
172
- interface FileManagerConstructor extends HostConstructor {
173
- loadSettings(settings: Settings, password?: string): boolean;
174
- loadSettings(settings: Settings, permission?: PermissionReadWrite, password?: string): boolean;
175
- sanitizeAssets(assets: ExternalAsset[], exclusions?: string[]): ExternalAsset[];
176
- writeChecksum(root: string, options?: ChecksumOptions): Promise<string[]>;
177
- writeChecksum(root: string, to: string | undefined, options?: ChecksumOptions): Promise<string[] | null>;
178
- writeChecksum(root: string, to?: string | ChecksumOptions, options?: ChecksumOptions): Promise<string[] | null>;
179
- verifyChecksum(root: string, options?: ChecksumOptions): Promise<[string[], string[]] | null>;
180
- verifyChecksum(root: string, from: string | undefined, options?: ChecksumOptions): Promise<[string[], string[]] | null>;
181
- verifyChecksum(root: string, from?: string | ChecksumOptions, options?: ChecksumOptions): Promise<[string[], string[]] | null>;
182
- createFileThread(host: IFileManager, file: ExternalAsset): IFileThread;
183
- setTimeout(options: Record<string, number | string>): void;
184
- defineHttpCache(options: HttpMemorySettings, disk?: boolean): void;
185
- defineHttpConnect(options: HttpConnectSettings): void;
186
- readonly prototype: IFileManager;
187
- new(baseDirectory: string, config: RequestData, postFinalize?: PostFinalizeCallback): IFileManager;
188
- new(baseDirectory: string, config: RequestData, permission?: IPermission, postFinalize?: PostFinalizeCallback): IFileManager;
189
- }
190
- ```
191
-
192
- ## References
193
-
194
- - https://www.unpkg.com/@e-mc/types@0.8.11/lib/squared.d.ts
195
- - https://www.unpkg.com/@e-mc/types@0.8.11/lib/asset.d.ts
196
- - https://www.unpkg.com/@e-mc/types@0.8.11/lib/core.d.ts
197
- - https://www.unpkg.com/@e-mc/types@0.8.11/lib/filemanager.d.ts
198
- - https://www.unpkg.com/@e-mc/types@0.8.11/lib/logger.d.ts
199
- - https://www.unpkg.com/@e-mc/types@0.8.11/lib/module.d.ts
200
- - https://www.unpkg.com/@e-mc/types@0.8.11/lib/node.d.ts
201
- - https://www.unpkg.com/@e-mc/types@0.8.11/lib/request.d.ts
202
- - https://www.unpkg.com/@e-mc/types@0.8.11/lib/settings.d.ts
203
-
204
- ## LICENSE
205
-
1
+ # @e-mc/file-manager
2
+
3
+ * NodeJS 14
4
+ * ES2019
5
+
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.13/lib/index.d.ts
13
+
14
+ ```typescript
15
+ import type { DataSource, IncrementalMatch, TaskAction } from "./squared";
16
+
17
+ import type { DocumentConstructor, HostConstructor, ICloud, ICompress, IDocument, IHost, IImage, IModule, IRequest, ITask, ImageConstructor, TaskConstructor, WatchInstance } from "./index";
18
+ import type { ExternalAsset, FileCommand, FileData, IFileThread, OutputFinalize } from "./asset";
19
+ import type { IPermission, PermissionReadWrite } from "./core";
20
+ import type { AssetContentOptions, ChecksumOptions, DeleteFileAddendum, FileOutput, FinalizeResult, FindAssetOptions, IHttpDiskCache, IHttpMemoryCache, InstallData, PostFinalizeCallback, ReplaceOptions } from "./filemanager";
21
+ import type { ExecCommand } from "./logger";
22
+ import type { CopyFileOptions, CreateDirOptions, DeleteFileOptions, MoveFileOptions, ReadFileOptions, RemoveDirOptions, WriteFileOptions } from "./module";
23
+ import type { RequestData, Settings } from "./node";
24
+ import type { Aria2Options, BufferFormat, OpenOptions } from "./request";
25
+ import type { CloudModule, CompressModule, DbModule, DocumentModule, HttpConnectSettings, HttpMemorySettings, ImageModule, RequestModule, TaskModule, WatchModule } from "./settings";
26
+
27
+ import type { SpawnOptions } from "child_process";
28
+ import type { NoParamCallback } from "fs";
29
+
30
+ interface IFileManager extends IHost, Set<string> {
31
+ finalizeState: number;
32
+ processTimeout: number;
33
+ cacheToDisk: IHttpDiskCache<ExternalAsset>;
34
+ cacheToMemory: IHttpMemoryCache<ExternalAsset>;
35
+ Request: IRequest<RequestModule>;
36
+ Document: InstallData<IDocument<IFileManager, ExternalAsset>, DocumentConstructor<IFileManager, ExternalAsset>>[];
37
+ Task: InstallData<ITask, TaskConstructor>[];
38
+ Image: Map<string, InstallData<IImage, ImageConstructor>> | null;
39
+ Cloud: ICloud | null;
40
+ Watch: WatchInstance<ExternalAsset> | null;
41
+ Compress: ICompress<CompressModule> | null;
42
+ readonly documentAssets: ExternalAsset[];
43
+ readonly taskAssets: (ExternalAsset & Required<TaskAction>)[];
44
+ readonly dataSourceItems: DataSource[];
45
+ readonly files: Set<string>;
46
+ readonly filesQueued: Set<string>;
47
+ readonly filesToRemove: Set<string>;
48
+ readonly filesToCompare: Map<ExternalAsset, string[]>;
49
+ readonly contentToAppend: Map<string, string[]>;
50
+ readonly contentToReplace: Map<string, string[]>;
51
+ readonly processing: IFileThread[];
52
+ readonly fetchedAssets: ExternalAsset[];
53
+ readonly copiedAssets: ExternalAsset[];
54
+ readonly emptyDir: Set<string>;
55
+ install(name: "document", target: DocumentConstructor<IFileManager, ExternalAsset>, module?: DocumentModule): IDocument<IFileManager, ExternalAsset> | undefined;
56
+ install(name: "task", target: TaskConstructor, module?: TaskModule): ITask | undefined;
57
+ install(name: "cloud", handler: string, module?: CloudModule): ICloud | undefined;
58
+ install(name: "cloud", module?: CloudModule): ICloud | undefined;
59
+ install(name: "db", module?: DbModule): IDb | undefined;
60
+ install(name: "image", targets: Map<string, ImageConstructor>, module?: ImageModule): void;
61
+ install(name: "watch", module: WatchModule): WatchInstance<ExternalAsset> | undefined;
62
+ install(name: "watch", interval?: number | string, port?: number | string, securePort?: number | string, extensions?: unknown[]): WatchInstance<ExternalAsset> | undefined;
63
+ install(name: "compress", module?: CompressModule): ICompress<CompressModule> | undefined;
64
+ install(name: string, ...args: unknown[]): IModule | undefined;
65
+ using(...items: ExternalAsset[] | [boolean, ...ExternalAsset[]]): this;
66
+ contains(item: ExternalAsset, condition?: (...args: [ExternalAsset]) => boolean): boolean;
67
+ removeCwd(value: unknown): string;
68
+ findAsset(value: string | URL, instance?: IModule | FindAssetOptions<ExternalAsset>): ExternalAsset | undefined;
69
+ removeAsset(file: ExternalAsset): boolean;
70
+ replace(file: ExternalAsset, replaceWith: string, options: ReplaceOptions): boolean;
71
+ replace(file: ExternalAsset, replaceWith: string, mimeType?: string | ReplaceOptions): boolean;
72
+ rename(file: ExternalAsset, value: string): boolean;
73
+ performAsyncTask(): void;
74
+ removeAsyncTask(): void;
75
+ completeAsyncTask(err?: unknown, uri?: string, parent?: ExternalAsset, type?: number): void;
76
+ performFinalize(override?: boolean): void;
77
+ hasDocument(instance: IModule, document: string | string[] | undefined): boolean;
78
+ getDocumentAssets(instance: IModule, condition?: (...args: [ExternalAsset]) => boolean): ExternalAsset[];
79
+ getDataSourceItems(instance: IModule, condition?: (...args: [DataSource]) => boolean): DataSource[];
80
+ setLocalUri(file: ExternalAsset, replace?: boolean): FileOutput;
81
+ getLocalUri(data: FileData<ExternalAsset>): string;
82
+ getMimeType(data: FileData<ExternalAsset>): string;
83
+ openThread(instance: IModule, data: IFileThread, timeout?: number): boolean;
84
+ closeThread(instance: IModule | null, data: IFileThread, callback?: (...args: unknown[]) => void): boolean;
85
+ addProcessTimeout(instance: IModule, file: ExternalAsset, timeout: number): void;
86
+ removeProcessTimeout(instance: IModule, file: ExternalAsset): void;
87
+ getProcessTimeout(handler: InstallData): number;
88
+ clearProcessTimeout(): void;
89
+ addDownload(value: number | Buffer | string, encoding: BufferEncoding): number;
90
+ addDownload(value: number | Buffer | string, type?: number, encoding?: BufferEncoding): number;
91
+ getDownload(type?: number): [number, number];
92
+ transformAsset(data: IFileThread, parent?: ExternalAsset): Promise<void>;
93
+ addCopy(data: FileCommand<ExternalAsset>, saveAs?: string, replace?: boolean): string | undefined;
94
+ findMime(file: ExternalAsset, rename?: boolean): Promise<string>;
95
+ getUTF8String(file: ExternalAsset, uri?: string): string;
96
+ getBuffer(file: ExternalAsset, minStreamSize?: number): Promise<Buffer> | Buffer | null;
97
+ getCacheDir(url: string | URL, createDir?: boolean): string;
98
+ setAssetContent(file: ExternalAsset, content: string, options?: AssetContentOptions): string;
99
+ getAssetContent(file: ExternalAsset, content?: string): string | undefined;
100
+ writeBuffer(file: ExternalAsset, options?: WriteFileOptions): Buffer | null;
101
+ writeImage(document: string | string[], output: OutputFinalize<ExternalAsset>): boolean;
102
+ compressFile(file: ExternalAsset, overwrite?: boolean): Promise<unknown>;
103
+ fetchObject(uri: string | URL, format: BufferFormat): Promise<object | null>;
104
+ fetchObject(uri: string | URL, options?: OpenOptions | BufferFormat): Promise<object | null>;
105
+ fetchBuffer(uri: string | URL, options?: OpenOptions): Promise<Buffer | string | null>;
106
+ fetchFiles(uri: string | URL, pathname: string): Promise<string[]>;
107
+ fetchFiles(uri: string | URL, options?: Aria2Options | string): Promise<string[]>;
108
+ start(emptyDir?: boolean): Promise<FinalizeResult>;
109
+ processAssets(emptyDir?: boolean, using?: ExternalAsset[]): void;
110
+ deleteFile(src: string, promises: boolean): Promise<void>;
111
+ deleteFile(src: string, options: DeleteFileOptions & DeleteFileAddendum, promises: boolean): Promise<void>;
112
+ deleteFile(src: string, callback?: NoParamCallback): unknown;
113
+ deleteFile(src: string, options: DeleteFileOptions & DeleteFileAddendum, callback?: NoParamCallback): unknown;
114
+ restart(recursive?: boolean | "abort", emptyDir?: boolean): void;
115
+ restart(recursive?: boolean | "abort", exclusions?: string[], emptyDir?: boolean): void;
116
+ finalizeCompress(assets: ExternalAsset[]): Promise<unknown>;
117
+ finalizeDocument(): Promise<unknown>;
118
+ finalizeTask(assets: (ExternalAsset & Required<TaskAction>)[]): Promise<unknown>;
119
+ finalizeCloud(): Promise<unknown>;
120
+ finalizeCleanup(): Promise<unknown>;
121
+ finalize(): Promise<void>;
122
+ close(): void;
123
+ reset(): boolean;
124
+ get baseDirectory(): string;
125
+ get config(): RequestData;
126
+ get assets(): ExternalAsset[];
127
+ get incremental(): IncrementalMatch;
128
+ set restarting(value);
129
+ get restarting(): boolean;
130
+ get delayed(): number;
131
+ set cleared(value);
132
+ get cleared(): boolean;
133
+
134
+ /* Set */
135
+ add(value: string, parent?: ExternalAsset, type?: number): this;
136
+ delete(value: string, emptyDir?: boolean): boolean;
137
+ has(value: unknown): value is string;
138
+
139
+ /* EventEmitter */
140
+ on(event: "end", listener: PostFinalizeCallback): this;
141
+ on(event: "exec", listener: (command: ExecCommand, options?: SpawnOptions) => void): this;
142
+ on(event: "error", listener: (err: Error) => void): this;
143
+ on(event: "file:read", listener: (src: string, data: Buffer | string, options?: ReadFileOptions) => void): this;
144
+ on(event: "file:write", listener: (src: string, options?: WriteFileOptions) => void): this;
145
+ on(event: "file:delete", listener: (src: string, options?: DeleteFileOptions) => void): this;
146
+ on(event: "file:copy", listener: (dest: string, options?: CopyFileOptions) => void): this;
147
+ on(event: "file:move", listener: (dest: string, options?: MoveFileOptions) => void): this;
148
+ on(event: "dir:create", listener: (src: string, options?: CreateDirOptions) => void): this;
149
+ on(event: "dir:remove", listener: (src: string, options?: RemoveDirOptions) => void): this;
150
+ once(event: "end", listener: PostFinalizeCallback): this;
151
+ once(event: "exec", listener: (command: ExecCommand, options?: SpawnOptions) => void): this;
152
+ once(event: "error", listener: (err: Error) => void): this;
153
+ once(event: "file:read", listener: (src: string, data: Buffer | string, options?: ReadFileOptions) => void): this;
154
+ once(event: "file:write", listener: (src: string, options?: WriteFileOptions) => void): this;
155
+ once(event: "file:delete", listener: (src: string, options?: DeleteFileOptions) => void): this;
156
+ once(event: "file:copy", listener: (dest: string, options?: CopyFileOptions) => void): this;
157
+ once(event: "file:move", listener: (dest: string, options?: MoveFileOptions) => void): this;
158
+ once(event: "dir:create", listener: (src: string, options?: CreateDirOptions) => void): this;
159
+ once(event: "dir:remove", listener: (src: string, options?: RemoveDirOptions) => void): this;
160
+ emit(event: "end", result: FinalizeResult): boolean;
161
+ emit(event: "exec", command: ExecCommand, options?: SpawnOptions): boolean;
162
+ emit(event: "error", err: Error): boolean;
163
+ emit(event: "file:read", src: string, data: Buffer | string, options?: ReadFileOptions): boolean;
164
+ emit(event: "file:write", src: string, options?: WriteFileOptions): boolean;
165
+ emit(event: "file:delete", src: string, options?: DeleteFileOptions): boolean;
166
+ emit(event: "file:copy", dest: string, options?: CopyFileOptions): boolean;
167
+ emit(event: "file:move", dest: string, options?: MoveFileOptions): boolean;
168
+ emit(event: "dir:create", src: string, options?: CreateDirOptions): boolean;
169
+ emit(event: "dir:remove", src: string, options?: RemoveDirOptions): boolean;
170
+ }
171
+
172
+ interface FileManagerConstructor extends HostConstructor {
173
+ loadSettings(settings: Settings, password?: string): boolean;
174
+ loadSettings(settings: Settings, permission?: PermissionReadWrite, password?: string): boolean;
175
+ sanitizeAssets(assets: ExternalAsset[], exclusions?: string[]): ExternalAsset[];
176
+ writeChecksum(root: string, options?: ChecksumOptions): Promise<string[]>;
177
+ writeChecksum(root: string, to: string | undefined, options?: ChecksumOptions): Promise<string[] | null>;
178
+ writeChecksum(root: string, to?: string | ChecksumOptions, options?: ChecksumOptions): Promise<string[] | null>;
179
+ verifyChecksum(root: string, options?: ChecksumOptions): Promise<[string[], string[]] | null>;
180
+ verifyChecksum(root: string, from: string | undefined, options?: ChecksumOptions): Promise<[string[], string[]] | null>;
181
+ verifyChecksum(root: string, from?: string | ChecksumOptions, options?: ChecksumOptions): Promise<[string[], string[]] | null>;
182
+ createFileThread(host: IFileManager, file: ExternalAsset): IFileThread;
183
+ setTimeout(options: Record<string, number | string>): void;
184
+ defineHttpCache(options: HttpMemorySettings, disk?: boolean): void;
185
+ defineHttpConnect(options: HttpConnectSettings): void;
186
+ readonly prototype: IFileManager;
187
+ new(baseDirectory: string, config: RequestData, postFinalize?: PostFinalizeCallback): IFileManager;
188
+ new(baseDirectory: string, config: RequestData, permission?: IPermission, postFinalize?: PostFinalizeCallback): IFileManager;
189
+ }
190
+ ```
191
+
192
+ ## References
193
+
194
+ - https://www.unpkg.com/@e-mc/types@0.8.13/lib/squared.d.ts
195
+ - https://www.unpkg.com/@e-mc/types@0.8.13/lib/asset.d.ts
196
+ - https://www.unpkg.com/@e-mc/types@0.8.13/lib/core.d.ts
197
+ - https://www.unpkg.com/@e-mc/types@0.8.13/lib/filemanager.d.ts
198
+ - https://www.unpkg.com/@e-mc/types@0.8.13/lib/logger.d.ts
199
+ - https://www.unpkg.com/@e-mc/types@0.8.13/lib/module.d.ts
200
+ - https://www.unpkg.com/@e-mc/types@0.8.13/lib/node.d.ts
201
+ - https://www.unpkg.com/@e-mc/types@0.8.13/lib/request.d.ts
202
+ - https://www.unpkg.com/@e-mc/types@0.8.13/lib/settings.d.ts
203
+
204
+ ## LICENSE
205
+
206
206
  MIT
package/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import type { FileManagerConstructor } from '../types/lib';
2
- import type { ExternalAsset } from '../types/lib/asset';
3
-
4
- declare const FileManager: FileManagerConstructor<ExternalAsset>;
5
-
1
+ import type { FileManagerConstructor } from '../types/lib';
2
+ import type { ExternalAsset } from '../types/lib/asset';
3
+
4
+ declare const FileManager: FileManagerConstructor<ExternalAsset>;
5
+
6
6
  export = FileManager;
package/index.js CHANGED
@@ -1114,26 +1114,17 @@ class FileManager extends core_1.Host {
1114
1114
  }
1115
1115
  switch (name) {
1116
1116
  case 'cloud': {
1117
- const instance = new cloud_1.default(args[0]);
1118
- instance.host = this;
1119
- instance.init(this.config);
1120
- observeFile.call(this, instance);
1121
- return this.Cloud = instance;
1122
- }
1123
- case 'watch': {
1124
- const instance = new watch_1.default(...args);
1125
- instance.host = this;
1126
- instance.init(this.config);
1127
- observeFile.call(this, instance);
1128
- return this.Watch = instance;
1129
- }
1130
- case 'compress': {
1131
- const instance = new compress_1.default(args[0]);
1132
- instance.host = this;
1133
- instance.init();
1134
- observeFile.call(this, instance);
1135
- return this.Compress = instance;
1117
+ if ((0, types_1.isArray)(args[1])) {
1118
+ const instance = new cloud_1.default(args[0], args[1]);
1119
+ instance.host = this;
1120
+ instance.init(this.config);
1121
+ observeFile.call(this, instance);
1122
+ return this.Cloud = instance;
1123
+ }
1136
1124
  }
1125
+ case 'watch':
1126
+ case 'compress':
1127
+ return this.install(name, ...args);
1137
1128
  default:
1138
1129
  return null;
1139
1130
  }
@@ -1564,25 +1555,8 @@ class FileManager extends core_1.Host {
1564
1555
  if (state === 0 && (this.cleared && this[kDelayed] <= 0 || override) || (this.aborted || state === 3) && override) {
1565
1556
  this.clearProcessTimeout();
1566
1557
  this[kDelayed] = Infinity;
1567
- const resetState = () => {
1568
- this.finalizeState = 2;
1569
- this._pendingResult = null;
1570
- };
1571
- const aborted = (err) => {
1572
- if (!this.restarting) {
1573
- this.writeFail(["Transaction was not completed", this.baseDirectory], err);
1574
- resetState();
1575
- }
1576
- else {
1577
- this.finalizeState = 4;
1578
- }
1579
- this.emit('end', [], collectErrors.call(this), this.collectLog());
1580
- if (!this.restarting) {
1581
- this.done = true;
1582
- }
1583
- };
1584
1558
  if (this.aborted) {
1585
- aborted((0, types_1.createAbortError)());
1559
+ this.abortFinalize((0, types_1.createAbortError)());
1586
1560
  return;
1587
1561
  }
1588
1562
  this.finalizeState = 1;
@@ -1602,7 +1576,7 @@ class FileManager extends core_1.Host {
1602
1576
  if (LOG_TIMEELAPSED) {
1603
1577
  this.writeTimeElapsed('END', this.baseDirectory, this.startTime, errors.length > 0 ? { failed: true, ...core_1.Host.LOG_STYLE_FAIL } : { ...core_1.Host.LOG_STYLE_SUCCESS });
1604
1578
  }
1605
- resetState();
1579
+ this.resetState();
1606
1580
  const log = this.config.log;
1607
1581
  let useNumeric = false, showSize = true;
1608
1582
  if ((0, types_1.isPlainObject)(log)) {
@@ -1615,7 +1589,7 @@ class FileManager extends core_1.Host {
1615
1589
  this.emit('end', items, errors, this.collectLog());
1616
1590
  this.done = true;
1617
1591
  })
1618
- .catch(err => aborted(err));
1592
+ .catch(err => this.abortFinalize(err));
1619
1593
  }
1620
1594
  }
1621
1595
  hasDocument(instance, document) {
@@ -3588,6 +3562,23 @@ class FileManager extends core_1.Host {
3588
3562
  close() {
3589
3563
  this.Request.close();
3590
3564
  }
3565
+ resetState() {
3566
+ this.finalizeState = 2;
3567
+ this._pendingResult = null;
3568
+ }
3569
+ abortFinalize(err) {
3570
+ if (!this.restarting) {
3571
+ this.writeFail(["Transaction was not completed", this.baseDirectory], err);
3572
+ this.resetState();
3573
+ }
3574
+ else {
3575
+ this.finalizeState = 4;
3576
+ }
3577
+ this.emit('end', [], collectErrors.call(this), this.collectLog());
3578
+ if (!this.restarting) {
3579
+ this.done = true;
3580
+ }
3581
+ }
3591
3582
  set restarting(value) {
3592
3583
  this.finalizeState = (this[kRestarting] = value) ? 3 : 0;
3593
3584
  }
package/package.json CHANGED
@@ -1,34 +1,34 @@
1
- {
2
- "name": "@e-mc/file-manager",
3
- "version": "0.8.11",
4
- "description": "FileManager constructor for E-mc.",
5
- "main": "index.js",
6
- "types": "index.d.ts",
7
- "publishConfig": {
8
- "access": "public"
9
- },
10
- "repository": {
11
- "type": "git",
12
- "url": "git+https://github.com/anpham6/e-mc.git",
13
- "directory": "src/file-manager"
14
- },
15
- "keywords": [
16
- "squared",
17
- "squared-functions"
18
- ],
19
- "author": "An Pham <anpham6@gmail.com>",
20
- "license": "MIT",
21
- "homepage": "https://github.com/anpham6/e-mc#readme",
22
- "dependencies": {
23
- "@e-mc/cloud": "0.8.11",
24
- "@e-mc/compress": "0.8.11",
25
- "@e-mc/core": "0.8.11",
26
- "@e-mc/document": "0.8.11",
27
- "@e-mc/image": "0.8.11",
28
- "@e-mc/request": "0.8.11",
29
- "@e-mc/task": "0.8.11",
30
- "@e-mc/types": "0.8.11",
31
- "@e-mc/watch": "0.8.11",
32
- "picomatch": "^3.0.1"
33
- }
34
- }
1
+ {
2
+ "name": "@e-mc/file-manager",
3
+ "version": "0.8.13",
4
+ "description": "FileManager constructor for E-mc.",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/anpham6/e-mc.git",
13
+ "directory": "src/file-manager"
14
+ },
15
+ "keywords": [
16
+ "squared",
17
+ "squared-functions"
18
+ ],
19
+ "author": "An Pham <anpham6@gmail.com>",
20
+ "license": "MIT",
21
+ "homepage": "https://github.com/anpham6/e-mc#readme",
22
+ "dependencies": {
23
+ "@e-mc/cloud": "0.8.13",
24
+ "@e-mc/compress": "0.8.13",
25
+ "@e-mc/core": "0.8.13",
26
+ "@e-mc/document": "0.8.13",
27
+ "@e-mc/image": "0.8.13",
28
+ "@e-mc/request": "0.8.13",
29
+ "@e-mc/task": "0.8.13",
30
+ "@e-mc/types": "0.8.13",
31
+ "@e-mc/watch": "0.8.13",
32
+ "picomatch": "^3.0.1"
33
+ }
34
+ }