nest-multi-storage 1.0.0

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 (54) hide show
  1. package/README.md +236 -0
  2. package/dist/drivers/azure-blob.driver.d.ts +27 -0
  3. package/dist/drivers/azure-blob.driver.d.ts.map +1 -0
  4. package/dist/drivers/azure-blob.driver.js +153 -0
  5. package/dist/drivers/azure-blob.driver.js.map +1 -0
  6. package/dist/drivers/index.d.ts +4 -0
  7. package/dist/drivers/index.d.ts.map +1 -0
  8. package/dist/drivers/index.js +20 -0
  9. package/dist/drivers/index.js.map +1 -0
  10. package/dist/drivers/local.driver.d.ts +23 -0
  11. package/dist/drivers/local.driver.d.ts.map +1 -0
  12. package/dist/drivers/local.driver.js +165 -0
  13. package/dist/drivers/local.driver.js.map +1 -0
  14. package/dist/drivers/s3.driver.d.ts +24 -0
  15. package/dist/drivers/s3.driver.d.ts.map +1 -0
  16. package/dist/drivers/s3.driver.js +178 -0
  17. package/dist/drivers/s3.driver.js.map +1 -0
  18. package/dist/index.d.ts +7 -0
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +23 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/interfaces/index.d.ts +3 -0
  23. package/dist/interfaces/index.d.ts.map +1 -0
  24. package/dist/interfaces/index.js +19 -0
  25. package/dist/interfaces/index.js.map +1 -0
  26. package/dist/interfaces/storage-driver.interface.d.ts +31 -0
  27. package/dist/interfaces/storage-driver.interface.d.ts.map +1 -0
  28. package/dist/interfaces/storage-driver.interface.js +3 -0
  29. package/dist/interfaces/storage-driver.interface.js.map +1 -0
  30. package/dist/interfaces/storage-options.interface.d.ts +42 -0
  31. package/dist/interfaces/storage-options.interface.d.ts.map +1 -0
  32. package/dist/interfaces/storage-options.interface.js +3 -0
  33. package/dist/interfaces/storage-options.interface.js.map +1 -0
  34. package/dist/storage.constants.d.ts +4 -0
  35. package/dist/storage.constants.d.ts.map +1 -0
  36. package/dist/storage.constants.js +7 -0
  37. package/dist/storage.constants.js.map +1 -0
  38. package/dist/storage.module.d.ts +9 -0
  39. package/dist/storage.module.d.ts.map +1 -0
  40. package/dist/storage.module.js +106 -0
  41. package/dist/storage.module.js.map +1 -0
  42. package/dist/storage.service.d.ts +26 -0
  43. package/dist/storage.service.d.ts.map +1 -0
  44. package/dist/storage.service.js +89 -0
  45. package/dist/storage.service.js.map +1 -0
  46. package/dist/utils/index.d.ts +2 -0
  47. package/dist/utils/index.d.ts.map +1 -0
  48. package/dist/utils/index.js +18 -0
  49. package/dist/utils/index.js.map +1 -0
  50. package/dist/utils/path.utils.d.ts +7 -0
  51. package/dist/utils/path.utils.d.ts.map +1 -0
  52. package/dist/utils/path.utils.js +61 -0
  53. package/dist/utils/path.utils.js.map +1 -0
  54. package/package.json +63 -0
@@ -0,0 +1,24 @@
1
+ import { Readable } from 'stream';
2
+ import { StorageDriver, PutOptions, StorageResponse, FileStats } from '../interfaces/storage-driver.interface';
3
+ import { S3DriverOptions } from '../interfaces/storage-options.interface';
4
+ export declare class S3Driver implements StorageDriver {
5
+ private readonly client;
6
+ private readonly bucket;
7
+ private readonly cdnUrl?;
8
+ private readonly signedUrlExpiry;
9
+ constructor(options: S3DriverOptions);
10
+ private normalizeKey;
11
+ put(path: string, content: Buffer | Readable, options?: PutOptions): Promise<StorageResponse>;
12
+ get(path: string): Promise<Buffer>;
13
+ getStream(path: string): Promise<Readable>;
14
+ delete(path: string): Promise<boolean>;
15
+ deleteMany(paths: string[]): Promise<boolean>;
16
+ exists(path: string): Promise<boolean>;
17
+ url(path: string): string;
18
+ signedUrl(path: string, expiresIn?: number): Promise<string>;
19
+ copy(from: string, to: string): Promise<StorageResponse>;
20
+ move(from: string, to: string): Promise<StorageResponse>;
21
+ stat(path: string): Promise<FileStats>;
22
+ list(prefix?: string): Promise<string[]>;
23
+ }
24
+ //# sourceMappingURL=s3.driver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"s3.driver.d.ts","s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CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAMxD,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAkBtC,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAuBjD"}
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.S3Driver = void 0;
4
+ const client_s3_1 = require("@aws-sdk/client-s3");
5
+ const s3_request_presigner_1 = require("@aws-sdk/s3-request-presigner");
6
+ const storage_constants_1 = require("../storage.constants");
7
+ const path_utils_1 = require("../utils/path.utils");
8
+ class S3Driver {
9
+ constructor(options) {
10
+ this.client = new client_s3_1.S3Client({
11
+ region: options.region,
12
+ credentials: options.credentials,
13
+ endpoint: options.endpoint,
14
+ forcePathStyle: options.forcePathStyle,
15
+ });
16
+ this.bucket = options.bucket;
17
+ this.cdnUrl = options.cdnUrl ? (0, path_utils_1.trimTrailingSlash)(options.cdnUrl) : undefined;
18
+ this.signedUrlExpiry = options.signedUrlExpiry ?? storage_constants_1.DEFAULT_SIGNED_URL_EXPIRY;
19
+ }
20
+ normalizeKey(key) {
21
+ return (0, path_utils_1.trimLeadingSlash)(key);
22
+ }
23
+ async put(path, content, options) {
24
+ const key = this.normalizeKey(path);
25
+ const command = new client_s3_1.PutObjectCommand({
26
+ Bucket: this.bucket,
27
+ Key: key,
28
+ Body: content,
29
+ ContentType: options?.contentType,
30
+ Metadata: options?.metadata,
31
+ ACL: options?.visibility === 'public' ? 'public-read' : undefined,
32
+ });
33
+ await this.client.send(command);
34
+ return {
35
+ path: key,
36
+ url: this.url(key),
37
+ };
38
+ }
39
+ async get(path) {
40
+ const key = this.normalizeKey(path);
41
+ const command = new client_s3_1.GetObjectCommand({
42
+ Bucket: this.bucket,
43
+ Key: key,
44
+ });
45
+ const response = await this.client.send(command);
46
+ const stream = response.Body;
47
+ return new Promise((resolve, reject) => {
48
+ const chunks = [];
49
+ stream.on('data', (chunk) => chunks.push(chunk));
50
+ stream.on('end', () => resolve(Buffer.concat(chunks)));
51
+ stream.on('error', reject);
52
+ });
53
+ }
54
+ async getStream(path) {
55
+ const key = this.normalizeKey(path);
56
+ const command = new client_s3_1.GetObjectCommand({
57
+ Bucket: this.bucket,
58
+ Key: key,
59
+ });
60
+ const response = await this.client.send(command);
61
+ return response.Body;
62
+ }
63
+ async delete(path) {
64
+ const key = this.normalizeKey(path);
65
+ const command = new client_s3_1.DeleteObjectCommand({
66
+ Bucket: this.bucket,
67
+ Key: key,
68
+ });
69
+ try {
70
+ await this.client.send(command);
71
+ return true;
72
+ }
73
+ catch {
74
+ return false;
75
+ }
76
+ }
77
+ async deleteMany(paths) {
78
+ if (paths.length === 0)
79
+ return true;
80
+ const command = new client_s3_1.DeleteObjectsCommand({
81
+ Bucket: this.bucket,
82
+ Delete: {
83
+ Objects: paths.map((p) => ({ Key: this.normalizeKey(p) })),
84
+ },
85
+ });
86
+ try {
87
+ await this.client.send(command);
88
+ return true;
89
+ }
90
+ catch {
91
+ return false;
92
+ }
93
+ }
94
+ async exists(path) {
95
+ const key = this.normalizeKey(path);
96
+ const command = new client_s3_1.HeadObjectCommand({
97
+ Bucket: this.bucket,
98
+ Key: key,
99
+ });
100
+ try {
101
+ await this.client.send(command);
102
+ return true;
103
+ }
104
+ catch {
105
+ return false;
106
+ }
107
+ }
108
+ url(path) {
109
+ const key = this.normalizeKey(path);
110
+ if (this.cdnUrl) {
111
+ return `${this.cdnUrl}/${key}`;
112
+ }
113
+ return `https://${this.bucket}.s3.amazonaws.com/${key}`;
114
+ }
115
+ async signedUrl(path, expiresIn) {
116
+ const key = this.normalizeKey(path);
117
+ const command = new client_s3_1.GetObjectCommand({
118
+ Bucket: this.bucket,
119
+ Key: key,
120
+ });
121
+ return (0, s3_request_presigner_1.getSignedUrl)(this.client, command, {
122
+ expiresIn: expiresIn ?? this.signedUrlExpiry,
123
+ });
124
+ }
125
+ async copy(from, to) {
126
+ const fromKey = this.normalizeKey(from);
127
+ const toKey = this.normalizeKey(to);
128
+ const command = new client_s3_1.CopyObjectCommand({
129
+ Bucket: this.bucket,
130
+ CopySource: `${this.bucket}/${fromKey}`,
131
+ Key: toKey,
132
+ });
133
+ await this.client.send(command);
134
+ return {
135
+ path: toKey,
136
+ url: this.url(toKey),
137
+ };
138
+ }
139
+ async move(from, to) {
140
+ const result = await this.copy(from, to);
141
+ await this.delete(from);
142
+ return result;
143
+ }
144
+ async stat(path) {
145
+ const key = this.normalizeKey(path);
146
+ const command = new client_s3_1.HeadObjectCommand({
147
+ Bucket: this.bucket,
148
+ Key: key,
149
+ });
150
+ const response = await this.client.send(command);
151
+ return {
152
+ size: response.ContentLength ?? 0,
153
+ lastModified: response.LastModified ?? new Date(),
154
+ contentType: response.ContentType,
155
+ metadata: response.Metadata,
156
+ };
157
+ }
158
+ async list(prefix) {
159
+ const normalizedPrefix = prefix ? this.normalizeKey(prefix) : undefined;
160
+ const files = [];
161
+ let continuationToken;
162
+ do {
163
+ const command = new client_s3_1.ListObjectsV2Command({
164
+ Bucket: this.bucket,
165
+ Prefix: normalizedPrefix,
166
+ ContinuationToken: continuationToken,
167
+ });
168
+ const response = await this.client.send(command);
169
+ if (response.Contents) {
170
+ files.push(...response.Contents.map((obj) => obj.Key).filter(Boolean));
171
+ }
172
+ continuationToken = response.NextContinuationToken;
173
+ } while (continuationToken);
174
+ return files;
175
+ }
176
+ }
177
+ exports.S3Driver = S3Driver;
178
+ //# sourceMappingURL=s3.driver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"s3.driver.js","sourceRoot":"","sources":["../../src/drivers/s3.driver.ts"],"names":[],"mappings":";;;AACA,kDAS4B;AAC5B,wEAA6D;AAQ7D,4DAAiE;AACjE,oDAA0E;AAK1E,MAAa,QAAQ;IAMjB,YAAY,OAAwB;QAChC,IAAI,CAAC,MAAM,GAAG,IAA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IAAI,QAAQ,CAAC,QAAQ,EAAE,CAAC;gBACpB,KAAK,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,GAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;YAC5E,CAAC;YAED,iBAAiB,GAAG,QAAQ,CAAC,qBAAqB,CAAC;QACvD,CAAC,QAAQ,iBAAiB,EAAE;QAE5B,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ;AA3ND,4BA2NC"}
@@ -0,0 +1,7 @@
1
+ export * from './storage.module';
2
+ export * from './storage.service';
3
+ export * from './storage.constants';
4
+ export * from './interfaces';
5
+ export * from './drivers';
6
+ export * from './utils';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AAGpC,cAAc,cAAc,CAAC;AAG7B,cAAc,WAAW,CAAC;AAG1B,cAAc,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./storage.module"), exports);
18
+ __exportStar(require("./storage.service"), exports);
19
+ __exportStar(require("./storage.constants"), exports);
20
+ __exportStar(require("./interfaces"), exports);
21
+ __exportStar(require("./drivers"), exports);
22
+ __exportStar(require("./utils"), exports);
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AACA,mDAAiC;AACjC,oDAAkC;AAClC,sDAAoC;AAGpC,+CAA6B;AAG7B,4CAA0B;AAG1B,0CAAwB"}
@@ -0,0 +1,3 @@
1
+ export * from './storage-driver.interface';
2
+ export * from './storage-options.interface';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./storage-driver.interface"), exports);
18
+ __exportStar(require("./storage-options.interface"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6DAA2C;AAC3C,8DAA4C"}
@@ -0,0 +1,31 @@
1
+ import { Readable } from 'stream';
2
+ export interface PutOptions {
3
+ contentType?: string;
4
+ metadata?: Record<string, string>;
5
+ visibility?: 'public' | 'private';
6
+ }
7
+ export interface StorageResponse {
8
+ path: string;
9
+ url?: string;
10
+ }
11
+ export interface FileStats {
12
+ size: number;
13
+ lastModified: Date;
14
+ contentType?: string;
15
+ metadata?: Record<string, string>;
16
+ }
17
+ export interface StorageDriver {
18
+ put(path: string, content: Buffer | Readable, options?: PutOptions): Promise<StorageResponse>;
19
+ get(path: string): Promise<Buffer>;
20
+ getStream(path: string): Promise<Readable>;
21
+ delete(path: string): Promise<boolean>;
22
+ deleteMany(paths: string[]): Promise<boolean>;
23
+ exists(path: string): Promise<boolean>;
24
+ url(path: string): string;
25
+ signedUrl(path: string, expiresIn?: number): Promise<string>;
26
+ copy(from: string, to: string): Promise<StorageResponse>;
27
+ move(from: string, to: string): Promise<StorageResponse>;
28
+ stat(path: string): Promise<FileStats>;
29
+ list(prefix?: string): Promise<string[]>;
30
+ }
31
+ //# sourceMappingURL=storage-driver.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage-driver.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/storage-driver.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAKlC,MAAM,WAAW,UAAU;IAIvB,WAAW,CAAC,EAAE,MAAM,CAAC;IAKrB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAKlC,UAAU,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;CACrC;AAKD,MAAM,WAAW,eAAe;IAI5B,IAAI,EAAE,MAAM,CAAC;IAKb,GAAG,CAAC,EAAE,MAA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CAAC,MAAM,EAAE,CAAC,CAAC;CAC5C"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=storage-driver.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage-driver.interface.js","sourceRoot":"","sources":["../../src/interfaces/storage-driver.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,42 @@
1
+ import { ModuleMetadata, Type } from '@nestjs/common';
2
+ export type DriverType = 'local' | 's3' | 'azure';
3
+ export interface LocalDriverOptions {
4
+ driver: 'local';
5
+ basePath: string;
6
+ baseUrl?: string;
7
+ }
8
+ export interface S3DriverOptions {
9
+ driver: 's3';
10
+ region: string;
11
+ bucket: string;
12
+ credentials?: {
13
+ accessKeyId: string;
14
+ secretAccessKey: string;
15
+ };
16
+ endpoint?: string;
17
+ forcePathStyle?: boolean;
18
+ cdnUrl?: string;
19
+ signedUrlExpiry?: number;
20
+ }
21
+ export interface AzureDriverOptions {
22
+ driver: 'azure';
23
+ connectionString: string;
24
+ container: string;
25
+ accountName?: string;
26
+ sasUrlExpiry?: number;
27
+ }
28
+ export type DiskConfig = LocalDriverOptions | S3DriverOptions | AzureDriverOptions;
29
+ export interface StorageModuleOptions {
30
+ default: string;
31
+ disks: Record<string, DiskConfig>;
32
+ }
33
+ export interface StorageModuleOptionsFactory {
34
+ createStorageOptions(): Promise<StorageModuleOptions> | StorageModuleOptions;
35
+ }
36
+ export interface StorageModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
37
+ useExisting?: Type<StorageModuleOptionsFactory>;
38
+ useClass?: Type<StorageModuleOptionsFactory>;
39
+ useFactory?: (...args: any[]) => Promise<StorageModuleOptions> | StorageModuleOptions;
40
+ inject?: any[];
41
+ }
42
+ //# sourceMappingURL=storage-options.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage-options.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/storage-options.interface.ts"],"names":[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AAE,IAAI,CAAC,2BAA2B,CAAC,CAAC;IAKhD,QAAQ,CAAC,EAAE,IAAI,CAAC,2BAA2B,CAAC,CAAC;IAK7C,UAAU,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,oBAAoB,CAAC,GAAG,oBAAoB,CAAC;IAKtF,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC;CAClB"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=storage-options.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage-options.interface.js","sourceRoot":"","sources":["../../src/interfaces/storage-options.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ export declare const STORAGE_MODULE_OPTIONS = "STORAGE_MODULE_OPTIONS";
2
+ export declare const STORAGE_DRIVERS = "STORAGE_DRIVERS";
3
+ export declare const DEFAULT_SIGNED_URL_EXPIRY = 3600;
4
+ //# sourceMappingURL=storage.constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.constants.d.ts","sourceRoot":"","sources":["../src/storage.constants.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,sBAAsB,2BAA2B,CAAC;AAK/D,eAAO,MAAM,eAAe,oBAAoB,CAAC;AAKjD,eAAO,MAAM,yBAAyB,OAAO,CAAC"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_SIGNED_URL_EXPIRY = exports.STORAGE_DRIVERS = exports.STORAGE_MODULE_OPTIONS = void 0;
4
+ exports.STORAGE_MODULE_OPTIONS = 'STORAGE_MODULE_OPTIONS';
5
+ exports.STORAGE_DRIVERS = 'STORAGE_DRIVERS';
6
+ exports.DEFAULT_SIGNED_URL_EXPIRY = 3600;
7
+ //# sourceMappingURL=storage.constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.constants.js","sourceRoot":"","sources":["../src/storage.constants.ts"],"names":[],"mappings":";;;AAGa,QAAA,sBAAsB,GAAG,wBAAwB,CAAC;AAKlD,QAAA,eAAe,GAAG,iBAAiB,CAAC;AAKpC,QAAA,yBAAyB,GAAG,IAAI,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { DynamicModule } from '@nestjs/common';
2
+ import { StorageModuleOptions, StorageModuleAsyncOptions } from './interfaces';
3
+ export declare class StorageModule {
4
+ static forRoot(options: StorageModuleOptions): DynamicModule;
5
+ static forRootAsync(options: StorageModuleAsyncOptions): DynamicModule;
6
+ private static createAsyncProviders;
7
+ private static createAsyncOptionsProvider;
8
+ }
9
+ //# sourceMappingURL=storage.module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.module.d.ts","sourceRoot":"","sources":["../src/storage.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAoB,MAAM,gBAAgB,CAAC;AAGjE,OAAO,EACH,oBAAoB,EACpB,yBAAyB,EAG5B,MAAM,cAAc,CAAC;AAmCtB,qBACa,aAAa;IAKtB,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,oBAAoB,GAAG,aAAa;IAuB5D,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,yBAAyB,GAAG,aAAa;IAqBtE,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAqBnC,OAAO,CAAC,MAAM,CAAC,0BAA0B;CAsB5C"}
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var StorageModule_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.StorageModule = void 0;
11
+ const common_1 = require("@nestjs/common");
12
+ const storage_service_1 = require("./storage.service");
13
+ const storage_constants_1 = require("./storage.constants");
14
+ const local_driver_1 = require("./drivers/local.driver");
15
+ const s3_driver_1 = require("./drivers/s3.driver");
16
+ const azure_blob_driver_1 = require("./drivers/azure-blob.driver");
17
+ function createDriver(config) {
18
+ switch (config.driver) {
19
+ case 'local':
20
+ return new local_driver_1.LocalDriver(config);
21
+ case 's3':
22
+ return new s3_driver_1.S3Driver(config);
23
+ case 'azure':
24
+ return new azure_blob_driver_1.AzureBlobDriver(config);
25
+ default:
26
+ throw new Error(`Unknown storage driver: ${config.driver}`);
27
+ }
28
+ }
29
+ function createDriversMap(options) {
30
+ const drivers = new Map();
31
+ for (const [diskName, config] of Object.entries(options.disks)) {
32
+ drivers.set(diskName, createDriver(config));
33
+ }
34
+ return drivers;
35
+ }
36
+ let StorageModule = StorageModule_1 = class StorageModule {
37
+ static forRoot(options) {
38
+ const driversProvider = {
39
+ provide: storage_constants_1.STORAGE_DRIVERS,
40
+ useValue: createDriversMap(options),
41
+ };
42
+ const optionsProvider = {
43
+ provide: storage_constants_1.STORAGE_MODULE_OPTIONS,
44
+ useValue: options,
45
+ };
46
+ return {
47
+ module: StorageModule_1,
48
+ global: true,
49
+ providers: [optionsProvider, driversProvider, storage_service_1.StorageService],
50
+ exports: [storage_service_1.StorageService],
51
+ };
52
+ }
53
+ static forRootAsync(options) {
54
+ const asyncProviders = this.createAsyncProviders(options);
55
+ const driversProvider = {
56
+ provide: storage_constants_1.STORAGE_DRIVERS,
57
+ useFactory: (moduleOptions) => createDriversMap(moduleOptions),
58
+ inject: [storage_constants_1.STORAGE_MODULE_OPTIONS],
59
+ };
60
+ return {
61
+ module: StorageModule_1,
62
+ global: true,
63
+ imports: options.imports || [],
64
+ providers: [...asyncProviders, driversProvider, storage_service_1.StorageService],
65
+ exports: [storage_service_1.StorageService],
66
+ };
67
+ }
68
+ static createAsyncProviders(options) {
69
+ if (options.useExisting || options.useFactory) {
70
+ return [this.createAsyncOptionsProvider(options)];
71
+ }
72
+ if (options.useClass) {
73
+ return [
74
+ this.createAsyncOptionsProvider(options),
75
+ {
76
+ provide: options.useClass,
77
+ useClass: options.useClass,
78
+ },
79
+ ];
80
+ }
81
+ return [this.createAsyncOptionsProvider(options)];
82
+ }
83
+ static createAsyncOptionsProvider(options) {
84
+ if (options.useFactory) {
85
+ return {
86
+ provide: storage_constants_1.STORAGE_MODULE_OPTIONS,
87
+ useFactory: options.useFactory,
88
+ inject: options.inject || [],
89
+ };
90
+ }
91
+ const inject = options.useExisting || options.useClass;
92
+ if (!inject) {
93
+ throw new Error('Invalid async options: must provide useFactory, useExisting, or useClass');
94
+ }
95
+ return {
96
+ provide: storage_constants_1.STORAGE_MODULE_OPTIONS,
97
+ useFactory: async (optionsFactory) => await optionsFactory.createStorageOptions(),
98
+ inject: [inject],
99
+ };
100
+ }
101
+ };
102
+ exports.StorageModule = StorageModule;
103
+ exports.StorageModule = StorageModule = StorageModule_1 = __decorate([
104
+ (0, common_1.Module)({})
105
+ ], StorageModule);
106
+ //# sourceMappingURL=storage.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.module.js","sourceRoot":"","sources":["../src/storage.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAiE;AACjE,uDAAmD;AACnD,2DAA8E;AAQ9E,yDAAqD;AACrD,mDAA+C;AAC/C,mEAA8D;AAK9D,SAAS,YAAY,CAAC,MAAkB;IACpC,QAAQ,MAAM,CAAC,MAAM,EAAE,CAAC;QACpB,KAAK,OAAO;YACR,OAAO,IAAI,0BAAW,CAAC,MAAM,CAAC,CAAC;QACnC,KAAK,IAAI;YACL,OAAO,IAAI,oBAAQ,CAAC,MAAM,CAAC,CAAC;QAChC,KAAK,OAAO;YACR,OAAO,IAAI,mCAAe,CAAC,MA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MAAM,CAAC;SACnB,CAAC;IACN,CAAC;CACJ,CAAA;AA5FY,sCAAa;wBAAb,aAAa;IADzB,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,aAAa,CA4FzB"}
@@ -0,0 +1,26 @@
1
+ import { Readable } from 'stream';
2
+ import { StorageDriver, PutOptions, StorageResponse, FileStats } from './interfaces';
3
+ import { StorageModuleOptions } from './interfaces';
4
+ export declare class StorageService implements StorageDriver {
5
+ private readonly options;
6
+ private readonly drivers;
7
+ private currentDisk;
8
+ constructor(options: StorageModuleOptions, drivers: Map<string, StorageDriver>);
9
+ disk(diskName: string): StorageService;
10
+ private getDriver;
11
+ getDisks(): string[];
12
+ getDefaultDisk(): string;
13
+ put(path: string, content: Buffer | Readable, options?: PutOptions): Promise<StorageResponse>;
14
+ get(path: string): Promise<Buffer>;
15
+ getStream(path: string): Promise<Readable>;
16
+ delete(path: string): Promise<boolean>;
17
+ deleteMany(paths: string[]): Promise<boolean>;
18
+ exists(path: string): Promise<boolean>;
19
+ url(path: string): string;
20
+ signedUrl(path: string, expiresIn?: number): Promise<string>;
21
+ copy(from: string, to: string): Promise<StorageResponse>;
22
+ move(from: string, to: string): Promise<StorageResponse>;
23
+ stat(path: string): Promise<FileStats>;
24
+ list(prefix?: string): Promise<string[]>;
25
+ }
26
+ //# sourceMappingURL=storage.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.service.d.ts","sourceRoot":"","sources":["../src/storage.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAErF,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAKpD,qBACa,cAAe,YAAW,aAAa;IAK5C,OAAO,CAAC,QAAQ,CAAC,OAAO;IAExB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAN5B,OAAO,CA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