@veloxts/storage 0.6.56 → 0.6.57

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/dist/index.d.ts CHANGED
@@ -44,3 +44,25 @@ export { createStorageManager, type StorageManager, storage } from './manager.js
44
44
  export { _resetStandaloneStorage, getStorage, getStorageFromInstance, storagePlugin, } from './plugin.js';
45
45
  export type { CopyOptions, FileMetadata, FileVisibility, GetOptions, ListOptions, ListResult, LocalStorageConfig, PutOptions, S3StorageConfig, SignedUrlOptions, StorageBaseOptions, StorageConfig, StorageDefaultOptions, StorageDriver, StorageLocalOptions, StorageManagerOptions, StoragePluginOptions, StorageS3Options, StorageStore, } from './types.js';
46
46
  export { basename, detectMimeType, dirname, extname, formatBytes, joinPath, normalizePath, uniqueFileName, validatePath, } from './utils.js';
47
+ /**
48
+ * DI tokens and providers for @veloxts/storage
49
+ *
50
+ * Use these to integrate storage services with the @veloxts/core DI container.
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * import { Container } from '@veloxts/core';
55
+ * import { registerStorageProviders, STORAGE_MANAGER } from '@veloxts/storage';
56
+ *
57
+ * const container = new Container();
58
+ * await registerStorageProviders(container, {
59
+ * driver: 'local',
60
+ * config: { root: './uploads' },
61
+ * });
62
+ *
63
+ * const storage = container.resolve(STORAGE_MANAGER);
64
+ * await storage.put('file.txt', Buffer.from('Hello'));
65
+ * ```
66
+ */
67
+ export { registerStorageProviders } from './providers.js';
68
+ export { STORAGE_CONFIG, STORAGE_MANAGER, STORAGE_STORE } from './tokens.js';
package/dist/index.js CHANGED
@@ -48,3 +48,30 @@ export { createStorageManager, storage } from './manager.js';
48
48
  export { _resetStandaloneStorage, getStorage, getStorageFromInstance, storagePlugin, } from './plugin.js';
49
49
  // Utilities
50
50
  export { basename, detectMimeType, dirname, extname, formatBytes, joinPath, normalizePath, uniqueFileName, validatePath, } from './utils.js';
51
+ // ============================================================================
52
+ // Dependency Injection
53
+ // ============================================================================
54
+ /**
55
+ * DI tokens and providers for @veloxts/storage
56
+ *
57
+ * Use these to integrate storage services with the @veloxts/core DI container.
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * import { Container } from '@veloxts/core';
62
+ * import { registerStorageProviders, STORAGE_MANAGER } from '@veloxts/storage';
63
+ *
64
+ * const container = new Container();
65
+ * await registerStorageProviders(container, {
66
+ * driver: 'local',
67
+ * config: { root: './uploads' },
68
+ * });
69
+ *
70
+ * const storage = container.resolve(STORAGE_MANAGER);
71
+ * await storage.put('file.txt', Buffer.from('Hello'));
72
+ * ```
73
+ */
74
+ // Provider exports - factory functions for registering services
75
+ export { registerStorageProviders } from './providers.js';
76
+ // Token exports - unique identifiers for DI resolution
77
+ export { STORAGE_CONFIG, STORAGE_MANAGER, STORAGE_STORE } from './tokens.js';
@@ -0,0 +1,65 @@
1
+ /**
2
+ * DI Providers for @veloxts/storage
3
+ *
4
+ * Factory provider functions for registering storage services with the DI container.
5
+ * These providers allow services to be managed by the container for testability and flexibility.
6
+ *
7
+ * @module storage/providers
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { Container } from '@veloxts/core';
12
+ * import { registerStorageProviders, STORAGE_MANAGER } from '@veloxts/storage';
13
+ *
14
+ * const container = new Container();
15
+ * await registerStorageProviders(container, {
16
+ * driver: 'local',
17
+ * config: { root: './uploads' },
18
+ * });
19
+ *
20
+ * const storage = container.resolve(STORAGE_MANAGER);
21
+ * await storage.put('file.txt', Buffer.from('Hello'));
22
+ * ```
23
+ */
24
+ import type { Container } from '@veloxts/core';
25
+ import type { StoragePluginOptions } from './types.js';
26
+ /**
27
+ * Registers storage providers with a container
28
+ *
29
+ * This handles async initialization of the storage manager and registers
30
+ * the resolved instance directly for synchronous resolution.
31
+ *
32
+ * @param container - The DI container to register providers with
33
+ * @param config - Storage plugin options (driver, config, etc.)
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * import { Container } from '@veloxts/core';
38
+ * import { registerStorageProviders, STORAGE_MANAGER } from '@veloxts/storage';
39
+ *
40
+ * const container = new Container();
41
+ *
42
+ * // Local filesystem driver
43
+ * await registerStorageProviders(container, {
44
+ * driver: 'local',
45
+ * config: { root: './uploads', baseUrl: '/files' },
46
+ * });
47
+ *
48
+ * // S3-compatible driver (AWS S3, Cloudflare R2, MinIO)
49
+ * await registerStorageProviders(container, {
50
+ * driver: 's3',
51
+ * config: {
52
+ * bucket: 'my-bucket',
53
+ * region: 'us-east-1',
54
+ * credentials: {
55
+ * accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
56
+ * secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
57
+ * },
58
+ * },
59
+ * });
60
+ *
61
+ * const storage = container.resolve(STORAGE_MANAGER);
62
+ * await storage.put('avatars/user-123.jpg', imageBuffer);
63
+ * ```
64
+ */
65
+ export declare function registerStorageProviders(container: Container, config?: StoragePluginOptions): Promise<void>;
@@ -0,0 +1,82 @@
1
+ /**
2
+ * DI Providers for @veloxts/storage
3
+ *
4
+ * Factory provider functions for registering storage services with the DI container.
5
+ * These providers allow services to be managed by the container for testability and flexibility.
6
+ *
7
+ * @module storage/providers
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { Container } from '@veloxts/core';
12
+ * import { registerStorageProviders, STORAGE_MANAGER } from '@veloxts/storage';
13
+ *
14
+ * const container = new Container();
15
+ * await registerStorageProviders(container, {
16
+ * driver: 'local',
17
+ * config: { root: './uploads' },
18
+ * });
19
+ *
20
+ * const storage = container.resolve(STORAGE_MANAGER);
21
+ * await storage.put('file.txt', Buffer.from('Hello'));
22
+ * ```
23
+ */
24
+ import { createStorageManager } from './manager.js';
25
+ import { STORAGE_CONFIG, STORAGE_MANAGER } from './tokens.js';
26
+ // ============================================================================
27
+ // Bulk Registration Helpers
28
+ // ============================================================================
29
+ /**
30
+ * Registers storage providers with a container
31
+ *
32
+ * This handles async initialization of the storage manager and registers
33
+ * the resolved instance directly for synchronous resolution.
34
+ *
35
+ * @param container - The DI container to register providers with
36
+ * @param config - Storage plugin options (driver, config, etc.)
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * import { Container } from '@veloxts/core';
41
+ * import { registerStorageProviders, STORAGE_MANAGER } from '@veloxts/storage';
42
+ *
43
+ * const container = new Container();
44
+ *
45
+ * // Local filesystem driver
46
+ * await registerStorageProviders(container, {
47
+ * driver: 'local',
48
+ * config: { root: './uploads', baseUrl: '/files' },
49
+ * });
50
+ *
51
+ * // S3-compatible driver (AWS S3, Cloudflare R2, MinIO)
52
+ * await registerStorageProviders(container, {
53
+ * driver: 's3',
54
+ * config: {
55
+ * bucket: 'my-bucket',
56
+ * region: 'us-east-1',
57
+ * credentials: {
58
+ * accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
59
+ * secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
60
+ * },
61
+ * },
62
+ * });
63
+ *
64
+ * const storage = container.resolve(STORAGE_MANAGER);
65
+ * await storage.put('avatars/user-123.jpg', imageBuffer);
66
+ * ```
67
+ */
68
+ export async function registerStorageProviders(container, config = {}) {
69
+ // Register config
70
+ container.register({
71
+ provide: STORAGE_CONFIG,
72
+ useValue: config,
73
+ });
74
+ // Create storage manager (async operation)
75
+ const storageManager = await createStorageManager(config);
76
+ // Register the resolved storage manager instance directly
77
+ // This allows synchronous resolution from the container
78
+ container.register({
79
+ provide: STORAGE_MANAGER,
80
+ useValue: storageManager,
81
+ });
82
+ }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * DI Tokens for @veloxts/storage
3
+ *
4
+ * Symbol-based tokens for type-safe dependency injection.
5
+ * These tokens allow storage services to be registered, resolved, and mocked via the DI container.
6
+ *
7
+ * @module storage/tokens
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { Container } from '@veloxts/core';
12
+ * import { STORAGE_MANAGER, registerStorageProviders } from '@veloxts/storage';
13
+ *
14
+ * const container = new Container();
15
+ * await registerStorageProviders(container, { driver: 'local', config: { root: './uploads' } });
16
+ *
17
+ * const storage = container.resolve(STORAGE_MANAGER);
18
+ * await storage.put('file.txt', Buffer.from('Hello'));
19
+ * ```
20
+ */
21
+ import type { StorageManager } from './manager.js';
22
+ import type { StoragePluginOptions, StorageStore } from './types.js';
23
+ /**
24
+ * Storage manager token
25
+ *
26
+ * The main storage manager instance for file operations.
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * const storage = container.resolve(STORAGE_MANAGER);
31
+ * await storage.put('avatars/user-123.jpg', imageBuffer);
32
+ * const url = await storage.url('avatars/user-123.jpg');
33
+ * ```
34
+ */
35
+ export declare const STORAGE_MANAGER: import("@veloxts/core").SymbolToken<StorageManager>;
36
+ /**
37
+ * Storage store token
38
+ *
39
+ * The underlying storage driver (local filesystem or S3-compatible).
40
+ * Use STORAGE_MANAGER for high-level operations; use this for direct driver access.
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * const store = container.resolve(STORAGE_STORE);
45
+ * await store.put('file.txt', Buffer.from('content'), { visibility: 'public' });
46
+ * ```
47
+ */
48
+ export declare const STORAGE_STORE: import("@veloxts/core").SymbolToken<StorageStore>;
49
+ /**
50
+ * Storage configuration token
51
+ *
52
+ * Contains storage plugin options including driver and driver-specific config.
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * const config = container.resolve(STORAGE_CONFIG);
57
+ * console.log(config.driver); // 'local' or 's3'
58
+ * ```
59
+ */
60
+ export declare const STORAGE_CONFIG: import("@veloxts/core").SymbolToken<StoragePluginOptions>;
package/dist/tokens.js ADDED
@@ -0,0 +1,65 @@
1
+ /**
2
+ * DI Tokens for @veloxts/storage
3
+ *
4
+ * Symbol-based tokens for type-safe dependency injection.
5
+ * These tokens allow storage services to be registered, resolved, and mocked via the DI container.
6
+ *
7
+ * @module storage/tokens
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { Container } from '@veloxts/core';
12
+ * import { STORAGE_MANAGER, registerStorageProviders } from '@veloxts/storage';
13
+ *
14
+ * const container = new Container();
15
+ * await registerStorageProviders(container, { driver: 'local', config: { root: './uploads' } });
16
+ *
17
+ * const storage = container.resolve(STORAGE_MANAGER);
18
+ * await storage.put('file.txt', Buffer.from('Hello'));
19
+ * ```
20
+ */
21
+ import { token } from '@veloxts/core';
22
+ // ============================================================================
23
+ // Core Storage Tokens
24
+ // ============================================================================
25
+ /**
26
+ * Storage manager token
27
+ *
28
+ * The main storage manager instance for file operations.
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * const storage = container.resolve(STORAGE_MANAGER);
33
+ * await storage.put('avatars/user-123.jpg', imageBuffer);
34
+ * const url = await storage.url('avatars/user-123.jpg');
35
+ * ```
36
+ */
37
+ export const STORAGE_MANAGER = token.symbol('STORAGE_MANAGER');
38
+ /**
39
+ * Storage store token
40
+ *
41
+ * The underlying storage driver (local filesystem or S3-compatible).
42
+ * Use STORAGE_MANAGER for high-level operations; use this for direct driver access.
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * const store = container.resolve(STORAGE_STORE);
47
+ * await store.put('file.txt', Buffer.from('content'), { visibility: 'public' });
48
+ * ```
49
+ */
50
+ export const STORAGE_STORE = token.symbol('STORAGE_STORE');
51
+ // ============================================================================
52
+ // Configuration Tokens
53
+ // ============================================================================
54
+ /**
55
+ * Storage configuration token
56
+ *
57
+ * Contains storage plugin options including driver and driver-specific config.
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * const config = container.resolve(STORAGE_CONFIG);
62
+ * console.log(config.driver); // 'local' or 's3'
63
+ * ```
64
+ */
65
+ export const STORAGE_CONFIG = token.symbol('STORAGE_CONFIG');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veloxts/storage",
3
- "version": "0.6.56",
3
+ "version": "0.6.57",
4
4
  "description": "Multi-driver file storage abstraction for VeloxTS framework",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -28,7 +28,7 @@
28
28
  "dependencies": {
29
29
  "fastify-plugin": "5.1.0",
30
30
  "mime-types": "2.1.35",
31
- "@veloxts/core": "0.6.56"
31
+ "@veloxts/core": "0.6.57"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "@aws-sdk/client-s3": ">=3.0.0",
@@ -57,7 +57,7 @@
57
57
  "fastify": "5.6.2",
58
58
  "typescript": "5.8.3",
59
59
  "vitest": "4.0.16",
60
- "@veloxts/testing": "0.6.56"
60
+ "@veloxts/testing": "0.6.57"
61
61
  },
62
62
  "publishConfig": {
63
63
  "access": "public"