@tacxou/nestjs_module_factorydrive 1.1.6
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 +21 -0
- package/README.md +245 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/LICENSE +21 -0
- package/dist/README.md +245 -0
- package/dist/exceptions/authorization-required.exception.d.ts +5 -0
- package/dist/exceptions/driver-not-supported.exception.d.ts +5 -0
- package/dist/exceptions/file-not-found.exception.d.ts +5 -0
- package/dist/exceptions/index.d.ts +9 -0
- package/dist/exceptions/invalid-config.exception.d.ts +7 -0
- package/dist/exceptions/method-not-supported.exception.d.ts +4 -0
- package/dist/exceptions/no-such-bucket.exception.d.ts +5 -0
- package/dist/exceptions/permission-missing.exception.d.ts +5 -0
- package/dist/exceptions/unknown.exception.d.ts +5 -0
- package/dist/exceptions/wrong-key-path.exception.d.ts +5 -0
- package/dist/factorydrive/abstract.storage.d.ts +20 -0
- package/dist/factorydrive/index.d.ts +5 -0
- package/dist/factorydrive/local-file-system.storage.d.ts +25 -0
- package/dist/factorydrive/storage.manager.d.ts +20 -0
- package/dist/factorydrive/types.d.ts +42 -0
- package/dist/factorydrive/utils.d.ts +3 -0
- package/dist/factorydrive.constants.d.ts +1 -0
- package/dist/factorydrive.core-module.d.ts +10 -0
- package/dist/factorydrive.interfaces.d.ts +11 -0
- package/dist/factorydrive.module.d.ts +7 -0
- package/dist/factorydrive.service.d.ts +10 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +549 -0
- package/dist/package.json +88 -0
- package/package.json +88 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,549 @@
|
|
|
1
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
4
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else
|
|
6
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
7
|
+
if (d = decorators[i])
|
|
8
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var __legacyDecorateParamTS = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
12
|
+
var __legacyMetadataTS = (k, v) => {
|
|
13
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
14
|
+
return Reflect.metadata(k, v);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// src/exceptions/authorization-required.exception.ts
|
|
18
|
+
import { RuntimeException } from "node-exceptions";
|
|
19
|
+
|
|
20
|
+
class AuthorizationRequiredException extends RuntimeException {
|
|
21
|
+
raw;
|
|
22
|
+
constructor(err, path) {
|
|
23
|
+
super(`Unauthorized to access file ${path}
|
|
24
|
+
${err.message}`, 500, "E_AUTHORIZATION_REQUIRED");
|
|
25
|
+
this.raw = err;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
// src/exceptions/driver-not-supported.exception.ts
|
|
29
|
+
import { RuntimeException as RuntimeException2 } from "node-exceptions";
|
|
30
|
+
|
|
31
|
+
class DriverNotSupportedException extends RuntimeException2 {
|
|
32
|
+
driver;
|
|
33
|
+
static driver(name) {
|
|
34
|
+
const exception = new this(`Driver ${name} is not supported`, 400);
|
|
35
|
+
exception.driver = name;
|
|
36
|
+
return exception;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// src/exceptions/file-not-found.exception.ts
|
|
40
|
+
import { RuntimeException as RuntimeException3 } from "node-exceptions";
|
|
41
|
+
|
|
42
|
+
class FileNotFoundException extends RuntimeException3 {
|
|
43
|
+
raw;
|
|
44
|
+
constructor(err, path) {
|
|
45
|
+
super(`The file ${path} doesn't exist
|
|
46
|
+
${err.message}`, 500, "E_FILE_NOT_FOUND");
|
|
47
|
+
this.raw = err;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// src/exceptions/invalid-config.exception.ts
|
|
51
|
+
import { RuntimeException as RuntimeException4 } from "node-exceptions";
|
|
52
|
+
|
|
53
|
+
class InvalidConfigException extends RuntimeException4 {
|
|
54
|
+
static missingDiskName() {
|
|
55
|
+
return new this("Make sure to define a default disk name inside config file", 500, "E_INVALID_CONFIG");
|
|
56
|
+
}
|
|
57
|
+
static missingDiskConfig(name) {
|
|
58
|
+
return new this(`Make sure to define config for ${name} disk`, 500, "E_INVALID_CONFIG");
|
|
59
|
+
}
|
|
60
|
+
static missingDiskDriver(name) {
|
|
61
|
+
return new this(`Make sure to define driver for ${name} disk`, 500, "E_INVALID_CONFIG");
|
|
62
|
+
}
|
|
63
|
+
static duplicateDiskName(name) {
|
|
64
|
+
return new this(`A disk named ${name} is already defined`, 500, "E_INVALID_CONFIG");
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// src/exceptions/method-not-supported.exception.ts
|
|
68
|
+
import { RuntimeException as RuntimeException5 } from "node-exceptions";
|
|
69
|
+
|
|
70
|
+
class MethodNotSupportedException extends RuntimeException5 {
|
|
71
|
+
constructor(name, driver) {
|
|
72
|
+
super(`Method ${name} is not supported for the driver ${driver}`, 500, "E_METHOD_NOT_SUPPORTED");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// src/exceptions/no-such-bucket.exception.ts
|
|
76
|
+
import { RuntimeException as RuntimeException6 } from "node-exceptions";
|
|
77
|
+
|
|
78
|
+
class NoSuchBucketException extends RuntimeException6 {
|
|
79
|
+
raw;
|
|
80
|
+
constructor(err, bucket) {
|
|
81
|
+
super(`The bucket ${bucket} doesn't exist
|
|
82
|
+
${err.message}`, 500, "E_NO_SUCH_BUCKET");
|
|
83
|
+
this.raw = err;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// src/exceptions/permission-missing.exception.ts
|
|
87
|
+
import { RuntimeException as RuntimeException7 } from "node-exceptions";
|
|
88
|
+
|
|
89
|
+
class PermissionMissingException extends RuntimeException7 {
|
|
90
|
+
raw;
|
|
91
|
+
constructor(err, path) {
|
|
92
|
+
super(`Missing permission for file ${path}
|
|
93
|
+
${err.message}`, 500, "E_PERMISSION_MISSING");
|
|
94
|
+
this.raw = err;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// src/exceptions/unknown.exception.ts
|
|
98
|
+
import { RuntimeException as RuntimeException8 } from "node-exceptions";
|
|
99
|
+
|
|
100
|
+
class UnknownException extends RuntimeException8 {
|
|
101
|
+
raw;
|
|
102
|
+
constructor(err, errorCode, path) {
|
|
103
|
+
super(`An unknown error happened with the file ${path}.
|
|
104
|
+
Error code: ${errorCode}
|
|
105
|
+
Original stack:
|
|
106
|
+
${err.stack}`, 500, "E_UNKNOWN");
|
|
107
|
+
this.raw = err;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// src/exceptions/wrong-key-path.exception.ts
|
|
111
|
+
import { RuntimeException as RuntimeException9 } from "node-exceptions";
|
|
112
|
+
|
|
113
|
+
class WrongKeyPathException extends RuntimeException9 {
|
|
114
|
+
raw;
|
|
115
|
+
constructor(err, path) {
|
|
116
|
+
super(`The key path does not exist: ${path}
|
|
117
|
+
${err.message}`, 500, "E_WRONG_KEY_PATH");
|
|
118
|
+
this.raw = err;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// src/factorydrive/abstract.storage.ts
|
|
122
|
+
class AbstractStorage {
|
|
123
|
+
constructor() {
|
|
124
|
+
if (this.constructor === AbstractStorage) {
|
|
125
|
+
throw new TypeError('Abstract class "AbstractStorage" cannot be instantiated directly.');
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
onStorageInit() {
|
|
129
|
+
console.log("onStorageInita");
|
|
130
|
+
return Promise.resolve();
|
|
131
|
+
}
|
|
132
|
+
append(_location, _content) {
|
|
133
|
+
throw new MethodNotSupportedException("append", this.constructor.name);
|
|
134
|
+
}
|
|
135
|
+
copy(_src, _dest) {
|
|
136
|
+
throw new MethodNotSupportedException("copy", this.constructor.name);
|
|
137
|
+
}
|
|
138
|
+
delete(_location) {
|
|
139
|
+
throw new MethodNotSupportedException("delete", this.constructor.name);
|
|
140
|
+
}
|
|
141
|
+
driver() {
|
|
142
|
+
throw new MethodNotSupportedException("driver", this.constructor.name);
|
|
143
|
+
}
|
|
144
|
+
exists(_location) {
|
|
145
|
+
throw new MethodNotSupportedException("exists", this.constructor.name);
|
|
146
|
+
}
|
|
147
|
+
get(_location, _encoding) {
|
|
148
|
+
throw new MethodNotSupportedException("get", this.constructor.name);
|
|
149
|
+
}
|
|
150
|
+
getBuffer(_location) {
|
|
151
|
+
throw new MethodNotSupportedException("getBuffer", this.constructor.name);
|
|
152
|
+
}
|
|
153
|
+
getSignedUrl(_location, _options) {
|
|
154
|
+
throw new MethodNotSupportedException("getSignedUrl", this.constructor.name);
|
|
155
|
+
}
|
|
156
|
+
getStat(_location) {
|
|
157
|
+
throw new MethodNotSupportedException("getStat", this.constructor.name);
|
|
158
|
+
}
|
|
159
|
+
getStream(_location) {
|
|
160
|
+
throw new MethodNotSupportedException("getStream", this.constructor.name);
|
|
161
|
+
}
|
|
162
|
+
getUrl(_location) {
|
|
163
|
+
throw new MethodNotSupportedException("getUrl", this.constructor.name);
|
|
164
|
+
}
|
|
165
|
+
move(_src, _dest) {
|
|
166
|
+
throw new MethodNotSupportedException("move", this.constructor.name);
|
|
167
|
+
}
|
|
168
|
+
put(_location, _content) {
|
|
169
|
+
throw new MethodNotSupportedException("put", this.constructor.name);
|
|
170
|
+
}
|
|
171
|
+
prepend(_location, _content) {
|
|
172
|
+
throw new MethodNotSupportedException("prepend", this.constructor.name);
|
|
173
|
+
}
|
|
174
|
+
flatList(_prefix) {
|
|
175
|
+
throw new MethodNotSupportedException("flatList", this.constructor.name);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
// src/factorydrive/local-file-system.storage.ts
|
|
179
|
+
import * as fse from "fs-extra";
|
|
180
|
+
import { promises as fs } from "fs";
|
|
181
|
+
import { dirname, join, relative, resolve, sep } from "path";
|
|
182
|
+
|
|
183
|
+
// src/factorydrive/utils.ts
|
|
184
|
+
import { promisify } from "util";
|
|
185
|
+
import { pipeline as nodePipeline } from "stream";
|
|
186
|
+
function isReadableStream(stream) {
|
|
187
|
+
return stream !== null && typeof stream === "object" && typeof stream.pipe === "function" && typeof stream._read === "function" && typeof stream._readableState === "object" && stream.readable !== false;
|
|
188
|
+
}
|
|
189
|
+
var pipeline = promisify(nodePipeline);
|
|
190
|
+
|
|
191
|
+
// src/factorydrive/local-file-system.storage.ts
|
|
192
|
+
function handleError(err, location) {
|
|
193
|
+
switch (err.code) {
|
|
194
|
+
case "ENOENT": {
|
|
195
|
+
return new FileNotFoundException(err, location);
|
|
196
|
+
}
|
|
197
|
+
case "EPERM": {
|
|
198
|
+
return new PermissionMissingException(err, location);
|
|
199
|
+
}
|
|
200
|
+
default: {
|
|
201
|
+
return new UnknownException(err, err.code, location);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
class LocalFileSystemStorage extends AbstractStorage {
|
|
207
|
+
$root;
|
|
208
|
+
constructor(config) {
|
|
209
|
+
super();
|
|
210
|
+
this.$root = resolve(config.root);
|
|
211
|
+
}
|
|
212
|
+
_fullPath(relativePath) {
|
|
213
|
+
return join(this.$root, join(sep, relativePath));
|
|
214
|
+
}
|
|
215
|
+
async append(location, content) {
|
|
216
|
+
try {
|
|
217
|
+
const result = await fse.appendFile(this._fullPath(location), content);
|
|
218
|
+
return { raw: result };
|
|
219
|
+
} catch (e) {
|
|
220
|
+
throw handleError(e, location);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
async copy(src, dest) {
|
|
224
|
+
try {
|
|
225
|
+
const result = await fse.copy(this._fullPath(src), this._fullPath(dest));
|
|
226
|
+
return { raw: result };
|
|
227
|
+
} catch (e) {
|
|
228
|
+
throw handleError(e, `${src} -> ${dest}`);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
async delete(location) {
|
|
232
|
+
try {
|
|
233
|
+
const result = await fse.unlink(this._fullPath(location));
|
|
234
|
+
return { raw: result, wasDeleted: true };
|
|
235
|
+
} catch (e) {
|
|
236
|
+
e = handleError(e, location);
|
|
237
|
+
if (e instanceof FileNotFoundException) {
|
|
238
|
+
return { raw: undefined, wasDeleted: false };
|
|
239
|
+
}
|
|
240
|
+
throw e;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
driver() {
|
|
244
|
+
return fse;
|
|
245
|
+
}
|
|
246
|
+
async exists(location) {
|
|
247
|
+
try {
|
|
248
|
+
const result = await fse.pathExists(this._fullPath(location));
|
|
249
|
+
return { exists: result, raw: result };
|
|
250
|
+
} catch (e) {
|
|
251
|
+
throw handleError(e, location);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
async get(location, encoding = "utf-8") {
|
|
255
|
+
try {
|
|
256
|
+
const result = await fse.readFile(this._fullPath(location), { encoding });
|
|
257
|
+
return { content: result.toString(), raw: result };
|
|
258
|
+
} catch (e) {
|
|
259
|
+
throw handleError(e, location);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
async getBuffer(location) {
|
|
263
|
+
try {
|
|
264
|
+
const result = await fse.readFile(this._fullPath(location));
|
|
265
|
+
return { content: result, raw: result };
|
|
266
|
+
} catch (e) {
|
|
267
|
+
throw handleError(e, location);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
async getStat(location) {
|
|
271
|
+
try {
|
|
272
|
+
const stat2 = await fse.stat(this._fullPath(location));
|
|
273
|
+
return {
|
|
274
|
+
size: stat2.size,
|
|
275
|
+
modified: stat2.mtime,
|
|
276
|
+
raw: stat2
|
|
277
|
+
};
|
|
278
|
+
} catch (e) {
|
|
279
|
+
throw handleError(e, location);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
getStream(location) {
|
|
283
|
+
return new Promise((resolve2) => {
|
|
284
|
+
resolve2(fse.createReadStream(this._fullPath(location)));
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
async move(src, dest) {
|
|
288
|
+
try {
|
|
289
|
+
const result = await fse.move(this._fullPath(src), this._fullPath(dest));
|
|
290
|
+
return { raw: result };
|
|
291
|
+
} catch (e) {
|
|
292
|
+
throw handleError(e, `${src} -> ${dest}`);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
async prepend(location, content) {
|
|
296
|
+
try {
|
|
297
|
+
const { content: actualContent } = await this.get(location, "utf-8");
|
|
298
|
+
return this.put(location, `${content}${actualContent}`);
|
|
299
|
+
} catch (e) {
|
|
300
|
+
if (e instanceof FileNotFoundException) {
|
|
301
|
+
return this.put(location, content);
|
|
302
|
+
}
|
|
303
|
+
throw e;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
async put(location, content) {
|
|
307
|
+
const fullPath = this._fullPath(location);
|
|
308
|
+
try {
|
|
309
|
+
if (isReadableStream(content)) {
|
|
310
|
+
const dir = dirname(fullPath);
|
|
311
|
+
await fse.ensureDir(dir);
|
|
312
|
+
const ws = fse.createWriteStream(fullPath);
|
|
313
|
+
await pipeline(content, ws);
|
|
314
|
+
return { raw: undefined };
|
|
315
|
+
}
|
|
316
|
+
const result = await fse.outputFile(fullPath, content);
|
|
317
|
+
return { raw: result };
|
|
318
|
+
} catch (e) {
|
|
319
|
+
throw handleError(e, location);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
flatList(prefix = "") {
|
|
323
|
+
const fullPrefix = this._fullPath(prefix);
|
|
324
|
+
return this._flatDirIterator(fullPrefix, prefix);
|
|
325
|
+
}
|
|
326
|
+
async* _flatDirIterator(prefix, originalPrefix) {
|
|
327
|
+
const prefixDirectory = prefix[prefix.length - 1] === sep ? prefix : dirname(prefix);
|
|
328
|
+
try {
|
|
329
|
+
const dir = await fs.opendir(prefixDirectory);
|
|
330
|
+
for await (const file of dir) {
|
|
331
|
+
const fileName = join(prefixDirectory, file.name);
|
|
332
|
+
if (fileName.startsWith(prefix)) {
|
|
333
|
+
if (file.isDirectory()) {
|
|
334
|
+
yield* this._flatDirIterator(join(fileName, sep), originalPrefix);
|
|
335
|
+
} else if (file.isFile()) {
|
|
336
|
+
const path = relative(this.$root, fileName);
|
|
337
|
+
yield {
|
|
338
|
+
raw: null,
|
|
339
|
+
path
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
} catch (e) {
|
|
345
|
+
if (e.code !== "ENOENT") {
|
|
346
|
+
throw handleError(e, originalPrefix);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// src/factorydrive/storage.manager.ts
|
|
353
|
+
import { Logger } from "@nestjs/common";
|
|
354
|
+
|
|
355
|
+
class StorageManager {
|
|
356
|
+
logger = new Logger(StorageManager.name);
|
|
357
|
+
defaultDisk;
|
|
358
|
+
disksConfig;
|
|
359
|
+
_disks = new Map;
|
|
360
|
+
_drivers = new Map;
|
|
361
|
+
constructor(config) {
|
|
362
|
+
this.defaultDisk = config.default;
|
|
363
|
+
this.disksConfig = config.disks || {};
|
|
364
|
+
if (config.registerLocalDriver !== false) {
|
|
365
|
+
this.registerDriver("local", LocalFileSystemStorage);
|
|
366
|
+
}
|
|
367
|
+
this.logger.log("StorageManager initialized \uD83D\uDFE2");
|
|
368
|
+
}
|
|
369
|
+
getDisks() {
|
|
370
|
+
return this._disks;
|
|
371
|
+
}
|
|
372
|
+
getDrivers() {
|
|
373
|
+
return this._drivers;
|
|
374
|
+
}
|
|
375
|
+
async initDisks() {
|
|
376
|
+
for (const diskName of Object.keys(this.disksConfig)) {
|
|
377
|
+
const disk = this.disk(diskName);
|
|
378
|
+
this.logger.debug(`Initializing disk <${diskName}> \uD83D\uDCC0`);
|
|
379
|
+
if (typeof disk.onStorageInit === "function") {
|
|
380
|
+
await this.disk(diskName).onStorageInit();
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
this.logger.log("All disks initialized \uD83D\uDFE2");
|
|
384
|
+
}
|
|
385
|
+
disk(name) {
|
|
386
|
+
name = name || this.defaultDisk;
|
|
387
|
+
if (!name) {
|
|
388
|
+
throw InvalidConfigException.missingDiskName();
|
|
389
|
+
}
|
|
390
|
+
if (this._disks.has(name)) {
|
|
391
|
+
return this._disks.get(name);
|
|
392
|
+
}
|
|
393
|
+
const diskConfig = this.disksConfig[name];
|
|
394
|
+
if (!diskConfig) {
|
|
395
|
+
throw InvalidConfigException.missingDiskConfig(name);
|
|
396
|
+
}
|
|
397
|
+
if (!diskConfig.driver) {
|
|
398
|
+
throw InvalidConfigException.missingDiskDriver(name);
|
|
399
|
+
}
|
|
400
|
+
const Driver = this._drivers.get(diskConfig.driver);
|
|
401
|
+
if (!Driver) {
|
|
402
|
+
throw DriverNotSupportedException.driver(diskConfig.driver);
|
|
403
|
+
}
|
|
404
|
+
const disk = new Driver(diskConfig.config);
|
|
405
|
+
this._disks.set(name, disk);
|
|
406
|
+
return disk;
|
|
407
|
+
}
|
|
408
|
+
addDisk(name, config) {
|
|
409
|
+
if (this.disksConfig[name]) {
|
|
410
|
+
throw InvalidConfigException.duplicateDiskName(name);
|
|
411
|
+
}
|
|
412
|
+
this.disksConfig[name] = config;
|
|
413
|
+
}
|
|
414
|
+
registerDriver(name, driver) {
|
|
415
|
+
this._drivers.set(name, driver);
|
|
416
|
+
this.logger.debug(`Registered <${name}> driver \uD83D\uDE97`);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
// src/factorydrive.module.ts
|
|
420
|
+
import { Module as Module2 } from "@nestjs/common";
|
|
421
|
+
|
|
422
|
+
// src/factorydrive.core-module.ts
|
|
423
|
+
import { Global, Module } from "@nestjs/common";
|
|
424
|
+
|
|
425
|
+
// src/factorydrive.service.ts
|
|
426
|
+
import { Inject, Injectable } from "@nestjs/common";
|
|
427
|
+
|
|
428
|
+
// src/factorydrive.constants.ts
|
|
429
|
+
var FACTORYDRIVE_MODULE_OPTIONS_TOKEN = "FactorydriveModuleOptionsToken";
|
|
430
|
+
|
|
431
|
+
// src/factorydrive.service.ts
|
|
432
|
+
class FactorydriveService {
|
|
433
|
+
options;
|
|
434
|
+
storageManager;
|
|
435
|
+
constructor(options) {
|
|
436
|
+
this.options = options;
|
|
437
|
+
this.storageManager = new StorageManager(options);
|
|
438
|
+
}
|
|
439
|
+
async onModuleInit() {
|
|
440
|
+
await this.storageManager.initDisks();
|
|
441
|
+
}
|
|
442
|
+
getDisk(name) {
|
|
443
|
+
return this.storageManager.disk(name);
|
|
444
|
+
}
|
|
445
|
+
registerDriver(name, driver) {
|
|
446
|
+
this.storageManager.registerDriver(name, driver);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
FactorydriveService = __legacyDecorateClassTS([
|
|
450
|
+
Injectable(),
|
|
451
|
+
__legacyDecorateParamTS(0, Inject(FACTORYDRIVE_MODULE_OPTIONS_TOKEN)),
|
|
452
|
+
__legacyMetadataTS("design:paramtypes", [
|
|
453
|
+
typeof StorageManagerConfig === "undefined" ? Object : StorageManagerConfig
|
|
454
|
+
])
|
|
455
|
+
], FactorydriveService);
|
|
456
|
+
|
|
457
|
+
// src/factorydrive.core-module.ts
|
|
458
|
+
class FactorydriveCoreModule {
|
|
459
|
+
constructor() {}
|
|
460
|
+
static forRoot(options) {
|
|
461
|
+
const storageModuleOptions = {
|
|
462
|
+
provide: FACTORYDRIVE_MODULE_OPTIONS_TOKEN,
|
|
463
|
+
useValue: options
|
|
464
|
+
};
|
|
465
|
+
return {
|
|
466
|
+
module: FactorydriveCoreModule,
|
|
467
|
+
providers: [storageModuleOptions, FactorydriveService],
|
|
468
|
+
exports: [FactorydriveService]
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
static forRootAsync(options) {
|
|
472
|
+
const asyncProviders = this.createAsyncProviders(options);
|
|
473
|
+
return {
|
|
474
|
+
module: FactorydriveCoreModule,
|
|
475
|
+
imports: options.imports,
|
|
476
|
+
providers: [...asyncProviders, FactorydriveService],
|
|
477
|
+
exports: [FactorydriveService]
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
static createAsyncProviders(options) {
|
|
481
|
+
if (options.useFactory)
|
|
482
|
+
return [this.createAsyncOptionsProvider(options)];
|
|
483
|
+
const useClass = options.useClass;
|
|
484
|
+
return [
|
|
485
|
+
this.createAsyncOptionsProvider(options),
|
|
486
|
+
{
|
|
487
|
+
provide: useClass,
|
|
488
|
+
useClass
|
|
489
|
+
}
|
|
490
|
+
];
|
|
491
|
+
}
|
|
492
|
+
static createAsyncOptionsProvider(options) {
|
|
493
|
+
if (options.useFactory) {
|
|
494
|
+
return {
|
|
495
|
+
provide: FACTORYDRIVE_MODULE_OPTIONS_TOKEN,
|
|
496
|
+
useFactory: options.useFactory,
|
|
497
|
+
inject: options.inject || []
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
const inject = [options.useClass];
|
|
501
|
+
return {
|
|
502
|
+
provide: FACTORYDRIVE_MODULE_OPTIONS_TOKEN,
|
|
503
|
+
useFactory: async (optionsFactory) => optionsFactory.createFactorydriveModuleOptions(),
|
|
504
|
+
inject
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
FactorydriveCoreModule = __legacyDecorateClassTS([
|
|
509
|
+
Global(),
|
|
510
|
+
Module({}),
|
|
511
|
+
__legacyMetadataTS("design:paramtypes", [])
|
|
512
|
+
], FactorydriveCoreModule);
|
|
513
|
+
|
|
514
|
+
// src/factorydrive.module.ts
|
|
515
|
+
class FactorydriveModule {
|
|
516
|
+
static forRoot(options) {
|
|
517
|
+
return {
|
|
518
|
+
module: FactorydriveModule,
|
|
519
|
+
imports: [FactorydriveCoreModule.forRoot(options)]
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
static forRootAsync(options) {
|
|
523
|
+
return {
|
|
524
|
+
module: FactorydriveModule,
|
|
525
|
+
imports: [FactorydriveCoreModule.forRootAsync(options)]
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
FactorydriveModule = __legacyDecorateClassTS([
|
|
530
|
+
Module2({})
|
|
531
|
+
], FactorydriveModule);
|
|
532
|
+
export {
|
|
533
|
+
pipeline,
|
|
534
|
+
isReadableStream,
|
|
535
|
+
WrongKeyPathException,
|
|
536
|
+
UnknownException,
|
|
537
|
+
StorageManager,
|
|
538
|
+
PermissionMissingException,
|
|
539
|
+
NoSuchBucketException,
|
|
540
|
+
MethodNotSupportedException,
|
|
541
|
+
LocalFileSystemStorage,
|
|
542
|
+
InvalidConfigException,
|
|
543
|
+
FileNotFoundException,
|
|
544
|
+
FactorydriveService,
|
|
545
|
+
FactorydriveModule,
|
|
546
|
+
DriverNotSupportedException,
|
|
547
|
+
AuthorizationRequiredException,
|
|
548
|
+
AbstractStorage
|
|
549
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tacxou/nestjs_module_factorydrive",
|
|
3
|
+
"version": "1.1.6",
|
|
4
|
+
"description": "Factory drive module for NestJS framework",
|
|
5
|
+
"repository": "https://github.com/tacxou/nestjs_module_factorydrive.git",
|
|
6
|
+
"author": "tacxou <12997062+tacxou@users.noreply.github.com> (https://github.com/tacxou)",
|
|
7
|
+
"contributors": [
|
|
8
|
+
{
|
|
9
|
+
"name": " tacxou",
|
|
10
|
+
"email": "12997062+tacxou@users.noreply.github.com",
|
|
11
|
+
"url": "https://github.com/tacxou"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"name": "Contributors",
|
|
15
|
+
"url": "https://github.com/tacxou/nestjs_module_factorydrive/graphs/contributors"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"main": "dist/index.js",
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"files": [
|
|
22
|
+
"dist/**/*",
|
|
23
|
+
"README.md",
|
|
24
|
+
"LICENSE"
|
|
25
|
+
],
|
|
26
|
+
"keywords": [
|
|
27
|
+
"factory",
|
|
28
|
+
"node",
|
|
29
|
+
"nodejs",
|
|
30
|
+
"disk",
|
|
31
|
+
"driver",
|
|
32
|
+
"local",
|
|
33
|
+
"drive",
|
|
34
|
+
"abstract",
|
|
35
|
+
"abstraction",
|
|
36
|
+
"nestjs",
|
|
37
|
+
"storage",
|
|
38
|
+
"filesystem",
|
|
39
|
+
"file",
|
|
40
|
+
"promise",
|
|
41
|
+
"async",
|
|
42
|
+
"spaces",
|
|
43
|
+
"factorydrive"
|
|
44
|
+
],
|
|
45
|
+
"scripts": {
|
|
46
|
+
"prebuild": "rimraf dist",
|
|
47
|
+
"build": "bun build ./src/index.ts --outdir ./dist --target node --splitting --packages external",
|
|
48
|
+
"build:type": "tsc --emitDeclarationOnly",
|
|
49
|
+
"build:cpr": "cpr README.md dist/README.md && cpr LICENSE dist/LICENSE && cpr package.json dist/package.json",
|
|
50
|
+
"postbuild": "bun build:type && bun build:cpr",
|
|
51
|
+
"test": "bun test",
|
|
52
|
+
"test:watch": "bun test --watch",
|
|
53
|
+
"test:coverage": "bun test --coverage --coverage-reporter lcov"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"fs-extra": "^11.3.4",
|
|
57
|
+
"node-exceptions": "^4.0.1"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@typescript-eslint/eslint-plugin": "^8.56.1",
|
|
61
|
+
"@typescript-eslint/parser": "^8.56.1",
|
|
62
|
+
"@nestjs/common": "^11.1.16",
|
|
63
|
+
"@nestjs/core": "^11.1.16",
|
|
64
|
+
"@types/fs-extra": "^11.0.4",
|
|
65
|
+
"@types/node": "latest",
|
|
66
|
+
"@types/bun": "latest",
|
|
67
|
+
"cpr": "^3.0.1",
|
|
68
|
+
"eslint": "^10.0.2",
|
|
69
|
+
"prettier": "^3.8.1",
|
|
70
|
+
"reflect-metadata": "^0.2.2",
|
|
71
|
+
"rimraf": "^6.1.3",
|
|
72
|
+
"rxjs": "^7.8.2",
|
|
73
|
+
"ts-node": "^10.9.2"
|
|
74
|
+
},
|
|
75
|
+
"peerDependencies": {
|
|
76
|
+
"@nestjs/common": "^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0",
|
|
77
|
+
"@nestjs/core": "^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0",
|
|
78
|
+
"typescript": "^5.0.0"
|
|
79
|
+
},
|
|
80
|
+
"publishConfig": {
|
|
81
|
+
"access": "public"
|
|
82
|
+
},
|
|
83
|
+
"engines": {
|
|
84
|
+
"node": ">=22.0.0",
|
|
85
|
+
"bun": ">=1.0.0"
|
|
86
|
+
},
|
|
87
|
+
"packageManager": "bun@1.3.10"
|
|
88
|
+
}
|