@e-mc/file-manager 0.8.4 → 0.8.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.
Files changed (4) hide show
  1. package/LICENSE +4 -8
  2. package/README.md +2 -201
  3. package/index.js +4 -10
  4. package/package.json +11 -11
package/LICENSE CHANGED
@@ -1,11 +1,7 @@
1
- Copyright 2023 An Pham
1
+ Copyright 2024 Mile Square Park
2
2
 
3
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
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
4
 
5
- 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
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
- 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.
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,7 @@
1
1
  # @e-mc/file-manager
2
2
 
3
- * NodeJS 14
4
- * ES2020
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.4/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 { NoParamCallback } from "fs";
28
- import type { SpawnOptions } from "child_process";
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.4/lib/squared.d.ts
195
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/asset.d.ts
196
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/core.d.ts
197
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/filemanager.d.ts
198
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/logger.d.ts
199
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/module.d.ts
200
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/node.d.ts
201
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/request.d.ts
202
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/settings.d.ts
3
+ PEP 402
203
4
 
204
5
  ## LICENSE
205
6
 
206
- BSD 3-Clause
7
+ MIT
package/index.js CHANGED
@@ -1364,7 +1364,7 @@ class FileManager extends core_1.Host {
1364
1364
  }
1365
1365
  const isSame = (a, b) => a === b || decodeURIComponent(a) === decodeURIComponent(b);
1366
1366
  const result = (assets || this.assets).filter(item => {
1367
- let { uri, flags } = item;
1367
+ const { uri, flags } = item;
1368
1368
  if (uri && (!instance || this.hasDocument(instance, item.document)) && (!item.invalid || assets || (0, types_1.mainFlag)(flags) || (0, types_1.usingFlag)(flags) || (0, types_1.cloneFlag)(flags) || (0, types_1.watchFlag)(flags))) {
1369
1369
  if (origin) {
1370
1370
  if (!item.url) {
@@ -1386,13 +1386,7 @@ class FileManager extends core_1.Host {
1386
1386
  const indexA = uri.indexOf('#');
1387
1387
  const indexB = value.indexOf('#');
1388
1388
  if (indexA !== -1 || indexB !== -1) {
1389
- if (indexA !== -1) {
1390
- uri = uri.substring(0, indexA);
1391
- }
1392
- if (indexB !== -1) {
1393
- value = value.substring(0, indexB);
1394
- }
1395
- return isSame(uri, value);
1389
+ return isSame(indexA !== -1 ? uri.substring(0, indexA) : uri, indexB !== -1 ? value.substring(0, indexB) : value);
1396
1390
  }
1397
1391
  }
1398
1392
  return false;
@@ -2220,7 +2214,7 @@ class FileManager extends core_1.Host {
2220
2214
  options = { format: options };
2221
2215
  }
2222
2216
  options.format || (options.format = 'json');
2223
- return this.Request.get(uri, options).then(data => typeof data === 'object' ? data : null).catch(() => null);
2217
+ return this.Request.get(uri, options).then(data => typeof data === 'object' ? data : null);
2224
2218
  }
2225
2219
  async fetchBuffer(uri, options) {
2226
2220
  if (options && 'format' in options) {
@@ -3003,7 +2997,6 @@ class FileManager extends core_1.Host {
3003
2997
  break;
3004
2998
  }
3005
2999
  const { pathname, localUri } = download;
3006
- const uri = item.uri;
3007
3000
  if (item.content) {
3008
3001
  if (!checkQueue(item, localUri, pathname, true)) {
3009
3002
  const content = item.content;
@@ -3033,6 +3026,7 @@ class FileManager extends core_1.Host {
3033
3026
  }
3034
3027
  continue;
3035
3028
  }
3029
+ const uri = item.uri;
3036
3030
  if (!uri) {
3037
3031
  item.invalid = true;
3038
3032
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/file-manager",
3
- "version": "0.8.4",
3
+ "version": "0.8.5",
4
4
  "description": "FileManager constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -17,18 +17,18 @@
17
17
  "squared-functions"
18
18
  ],
19
19
  "author": "An Pham <anpham6@gmail.com>",
20
- "license": "BSD 3-Clause",
20
+ "license": "MIT",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/cloud": "0.8.4",
24
- "@e-mc/compress": "0.8.4",
25
- "@e-mc/core": "0.8.4",
26
- "@e-mc/document": "0.8.4",
27
- "@e-mc/image": "0.8.4",
28
- "@e-mc/request": "0.8.4",
29
- "@e-mc/task": "0.8.4",
30
- "@e-mc/types": "0.8.4",
31
- "@e-mc/watch": "0.8.4",
23
+ "@e-mc/cloud": "0.8.5",
24
+ "@e-mc/compress": "0.8.5",
25
+ "@e-mc/core": "0.8.5",
26
+ "@e-mc/document": "0.8.5",
27
+ "@e-mc/image": "0.8.5",
28
+ "@e-mc/request": "0.8.5",
29
+ "@e-mc/task": "0.8.5",
30
+ "@e-mc/types": "0.8.5",
31
+ "@e-mc/watch": "0.8.5",
32
32
  "picomatch": "^3.0.1"
33
33
  }
34
34
  }