@arikajs/storage 0.0.1
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 +247 -0
- package/dist/Contracts/Filesystem.d.ts +48 -0
- package/dist/Contracts/Filesystem.d.ts.map +1 -0
- package/dist/Contracts/Filesystem.js +3 -0
- package/dist/Contracts/Filesystem.js.map +1 -0
- package/dist/Disk.d.ts +60 -0
- package/dist/Disk.d.ts.map +1 -0
- package/dist/Disk.js +119 -0
- package/dist/Disk.js.map +1 -0
- package/dist/Drivers/LocalDriver.d.ts +65 -0
- package/dist/Drivers/LocalDriver.d.ts.map +1 -0
- package/dist/Drivers/LocalDriver.js +156 -0
- package/dist/Drivers/LocalDriver.js.map +1 -0
- package/dist/Drivers/S3Driver.d.ts +67 -0
- package/dist/Drivers/S3Driver.d.ts.map +1 -0
- package/dist/Drivers/S3Driver.js +218 -0
- package/dist/Drivers/S3Driver.js.map +1 -0
- package/dist/Exceptions/FileNotFoundException.d.ts +4 -0
- package/dist/Exceptions/FileNotFoundException.d.ts.map +1 -0
- package/dist/Exceptions/FileNotFoundException.js +11 -0
- package/dist/Exceptions/FileNotFoundException.js.map +1 -0
- package/dist/StorageManager.d.ts +33 -0
- package/dist/StorageManager.d.ts.map +1 -0
- package/dist/StorageManager.js +87 -0
- package/dist/StorageManager.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/src/Contracts/Filesystem.d.ts +48 -0
- package/dist/src/Contracts/Filesystem.d.ts.map +1 -0
- package/dist/src/Contracts/Filesystem.js +3 -0
- package/dist/src/Contracts/Filesystem.js.map +1 -0
- package/dist/src/Disk.d.ts +60 -0
- package/dist/src/Disk.d.ts.map +1 -0
- package/dist/src/Disk.js +119 -0
- package/dist/src/Disk.js.map +1 -0
- package/dist/src/Drivers/LocalDriver.d.ts +65 -0
- package/dist/src/Drivers/LocalDriver.d.ts.map +1 -0
- package/dist/src/Drivers/LocalDriver.js +156 -0
- package/dist/src/Drivers/LocalDriver.js.map +1 -0
- package/dist/src/Drivers/S3Driver.d.ts +67 -0
- package/dist/src/Drivers/S3Driver.d.ts.map +1 -0
- package/dist/src/Drivers/S3Driver.js +218 -0
- package/dist/src/Drivers/S3Driver.js.map +1 -0
- package/dist/src/Exceptions/FileNotFoundException.d.ts +4 -0
- package/dist/src/Exceptions/FileNotFoundException.d.ts.map +1 -0
- package/dist/src/Exceptions/FileNotFoundException.js +11 -0
- package/dist/src/Exceptions/FileNotFoundException.js.map +1 -0
- package/dist/src/StorageManager.d.ts +33 -0
- package/dist/src/StorageManager.d.ts.map +1 -0
- package/dist/src/StorageManager.js +87 -0
- package/dist/src/StorageManager.js.map +1 -0
- package/dist/src/index.d.ts +9 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +37 -0
- package/dist/src/index.js.map +1 -0
- package/dist/tests/AdvancedStorage.test.d.ts +2 -0
- package/dist/tests/AdvancedStorage.test.d.ts.map +1 -0
- package/dist/tests/AdvancedStorage.test.js +121 -0
- package/dist/tests/AdvancedStorage.test.js.map +1 -0
- package/dist/tests/Storage.test.d.ts +2 -0
- package/dist/tests/Storage.test.d.ts.map +1 -0
- package/dist/tests/Storage.test.js +121 -0
- package/dist/tests/Storage.test.js.map +1 -0
- package/package.json +52 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ArikaJs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
## Arika Storage
|
|
2
|
+
|
|
3
|
+
`@arikajs/storage` is the filesystem abstraction layer for the ArikaJS framework.
|
|
4
|
+
|
|
5
|
+
It provides a clean, unified API to work with local and cloud-based storage systems using interchangeable drivers, inspired by Laravel's Storage but designed for Node.js and TypeScript.
|
|
6
|
+
|
|
7
|
+
This package allows ArikaJS applications to interact with files without caring where or how they are stored.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## ✨ Features
|
|
12
|
+
|
|
13
|
+
- **Multiple storage disks**: Configure different storage locations
|
|
14
|
+
- **Driver-based filesystem architecture**: Pluggable storage backends
|
|
15
|
+
- **Local filesystem driver**: Built-in support for local file storage (v1)
|
|
16
|
+
- **Unified file API**: `put`, `get`, `delete`, `exists`, `url`
|
|
17
|
+
- **Buffer, string, and stream support**: Flexible content handling
|
|
18
|
+
- **Configuration-based disk resolution**: Easy setup via config files
|
|
19
|
+
- **TypeScript-first**: Full type safety with JavaScript compatibility
|
|
20
|
+
- **Designed for cloud drivers**: Ready for S3, GCS, Azure (planned)
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## 📦 Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install @arikajs/storage
|
|
28
|
+
# or
|
|
29
|
+
yarn add @arikajs/storage
|
|
30
|
+
# or
|
|
31
|
+
pnpm add @arikajs/storage
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## 🚀 Quick Start
|
|
37
|
+
|
|
38
|
+
### Basic File Operations
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { Storage } from '@arikajs/storage';
|
|
42
|
+
|
|
43
|
+
// Write a file
|
|
44
|
+
await Storage.put('files/example.txt', 'Hello Arika');
|
|
45
|
+
|
|
46
|
+
// Read a file
|
|
47
|
+
const content = await Storage.get('files/example.txt');
|
|
48
|
+
|
|
49
|
+
// Delete a file
|
|
50
|
+
await Storage.delete('files/example.txt');
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## 💽 Working with Disks
|
|
56
|
+
|
|
57
|
+
Arika Storage supports multiple disks, each backed by a driver.
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
// Use a specific disk
|
|
61
|
+
await Storage.disk('local').put('notes.txt', 'Hello');
|
|
62
|
+
|
|
63
|
+
// Check if file exists on a disk
|
|
64
|
+
const exists = await Storage.disk('public').exists('image.png');
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## ⚙️ Configuration
|
|
70
|
+
|
|
71
|
+
Storage disks are defined in your application configuration:
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
export default {
|
|
75
|
+
default: 'local',
|
|
76
|
+
|
|
77
|
+
disks: {
|
|
78
|
+
local: {
|
|
79
|
+
driver: 'local',
|
|
80
|
+
root: './storage/app'
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
public: {
|
|
84
|
+
driver: 'local',
|
|
85
|
+
root: './storage/public',
|
|
86
|
+
url: '/storage'
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## 📁 Supported Drivers (v1)
|
|
95
|
+
|
|
96
|
+
| Driver | Status |
|
|
97
|
+
| :--- | :--- |
|
|
98
|
+
| Local filesystem | ✅ Supported |
|
|
99
|
+
| Amazon S3 | ✅ Supported |
|
|
100
|
+
| Google Cloud Storage | ⏳ Planned |
|
|
101
|
+
| Azure Blob Storage | ⏳ Planned |
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## 📚 API Reference
|
|
106
|
+
|
|
107
|
+
### `Storage.put(path, contents)`
|
|
108
|
+
|
|
109
|
+
Write contents to a file.
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
await Storage.put('file.txt', 'content');
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### `Storage.get(path)`
|
|
116
|
+
|
|
117
|
+
Read file contents.
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
const content = await Storage.get('file.txt');
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
**Throws** `FileNotFoundException` if the file does not exist.
|
|
124
|
+
|
|
125
|
+
### `Storage.exists(path)`
|
|
126
|
+
|
|
127
|
+
Check if a file exists.
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
const exists = await Storage.exists('file.txt');
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### `Storage.delete(path)`
|
|
134
|
+
|
|
135
|
+
Delete a file.
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
await Storage.delete('file.txt');
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### `Storage.url(path)`
|
|
142
|
+
|
|
143
|
+
Get the public URL for a file.
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
const url = Storage.url('image.png');
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Returns a public URL if supported by the disk.
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## 🧠 Architecture
|
|
154
|
+
|
|
155
|
+
```
|
|
156
|
+
storage/
|
|
157
|
+
├── src/
|
|
158
|
+
│ ├── StorageManager.ts ← Resolves disks and drivers
|
|
159
|
+
│ ├── Disk.ts ← Disk wrapper
|
|
160
|
+
│ ├── Drivers/
|
|
161
|
+
│ │ └── LocalDriver.ts ← Local filesystem implementation
|
|
162
|
+
│ ├── Contracts/
|
|
163
|
+
│ │ └── Filesystem.ts ← Driver interface
|
|
164
|
+
│ ├── Exceptions/
|
|
165
|
+
│ │ └── FileNotFoundException.ts
|
|
166
|
+
│ └── index.ts
|
|
167
|
+
├── tests/
|
|
168
|
+
│ └── Storage.test.ts
|
|
169
|
+
├── package.json
|
|
170
|
+
├── tsconfig.json
|
|
171
|
+
├── README.md
|
|
172
|
+
└── LICENSE
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## 🔌 Extending Storage (Custom Drivers)
|
|
178
|
+
|
|
179
|
+
You can create your own storage driver:
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
import { Filesystem } from '@arikajs/storage';
|
|
183
|
+
|
|
184
|
+
class CustomDriver implements Filesystem {
|
|
185
|
+
async put(path: string, contents: string | Buffer): Promise<void> {
|
|
186
|
+
// Implementation
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
async get(path: string): Promise<Buffer> {
|
|
190
|
+
// Implementation
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
async delete(path: string): Promise<void> {
|
|
194
|
+
// Implementation
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
async exists(path: string): Promise<boolean> {
|
|
198
|
+
// Implementation
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
url(path: string): string {
|
|
202
|
+
// Implementation
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Register it inside `StorageManager`.
|
|
208
|
+
|
|
209
|
+
---
|
|
210
|
+
|
|
211
|
+
## 🔗 Integration with ArikaJS
|
|
212
|
+
|
|
213
|
+
`@arikajs/storage` integrates seamlessly with:
|
|
214
|
+
|
|
215
|
+
- **`@arikajs/auth`** → User uploads
|
|
216
|
+
- **`@arikajs/mail`** → Attachments
|
|
217
|
+
- **`@arikajs/logging`** → File logs
|
|
218
|
+
- **`@arikajs/queue`** → Temporary files
|
|
219
|
+
- **`@arikajs/view`** → Asset handling
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## 🧪 Testing
|
|
224
|
+
|
|
225
|
+
The storage layer is fully testable by mocking drivers or using temporary disks.
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
## 🛣 Roadmap
|
|
230
|
+
|
|
231
|
+
- [x] S3 driver
|
|
232
|
+
- [x] Streaming API
|
|
233
|
+
- [x] Temporary signed URLs
|
|
234
|
+
- [x] Disk-level middleware
|
|
235
|
+
- [x] File metadata support
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## 📄 License
|
|
240
|
+
|
|
241
|
+
`@arikajs/storage` is open-source software licensed under the **MIT License**.
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
## 🧭 Philosophy
|
|
246
|
+
|
|
247
|
+
> "Your application should care about files, not filesystems."
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Readable } from 'stream';
|
|
2
|
+
export interface Filesystem {
|
|
3
|
+
/**
|
|
4
|
+
* Write contents to a file.
|
|
5
|
+
*/
|
|
6
|
+
put(path: string, contents: string | Buffer): Promise<void>;
|
|
7
|
+
/**
|
|
8
|
+
* Write a stream to a file.
|
|
9
|
+
*/
|
|
10
|
+
putStream(path: string, stream: Readable): Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* Read file contents.
|
|
13
|
+
*/
|
|
14
|
+
get(path: string): Promise<Buffer>;
|
|
15
|
+
/**
|
|
16
|
+
* Read file as a stream.
|
|
17
|
+
*/
|
|
18
|
+
readStream(path: string): Readable;
|
|
19
|
+
/**
|
|
20
|
+
* Check if a file exists.
|
|
21
|
+
*/
|
|
22
|
+
exists(path: string): Promise<boolean>;
|
|
23
|
+
/**
|
|
24
|
+
* Delete a file.
|
|
25
|
+
*/
|
|
26
|
+
delete(path: string): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Get the URL for a file.
|
|
29
|
+
*/
|
|
30
|
+
url(path: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* Get a temporary URL for a file.
|
|
33
|
+
*/
|
|
34
|
+
temporaryUrl(path: string, expiresAt: Date): Promise<string>;
|
|
35
|
+
/**
|
|
36
|
+
* Get the file size in bytes.
|
|
37
|
+
*/
|
|
38
|
+
size(path: string): Promise<number>;
|
|
39
|
+
/**
|
|
40
|
+
* Get the last modified time of the file.
|
|
41
|
+
*/
|
|
42
|
+
lastModified(path: string): Promise<number>;
|
|
43
|
+
/**
|
|
44
|
+
* Get the mime type of the file.
|
|
45
|
+
*/
|
|
46
|
+
mimeType(path: string): Promise<string>;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=Filesystem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Filesystem.d.ts","sourceRoot":"","sources":["../../src/Contracts/Filesystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAY,MAAM,QAAQ,CAAC;AAE5C,MAAM,WAAW,UAAU;IACvB;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5D;;OAEG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzD;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEnC;;OAEG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAC;IAEnC;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEvC;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpC;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAE1B;;OAEG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE7D;;OAEG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEpC;;OAEG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE5C;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC3C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Filesystem.js","sourceRoot":"","sources":["../../src/Contracts/Filesystem.ts"],"names":[],"mappings":""}
|
package/dist/Disk.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Readable } from 'stream';
|
|
2
|
+
import { Filesystem } from './Contracts/Filesystem';
|
|
3
|
+
export declare class Disk {
|
|
4
|
+
private driver;
|
|
5
|
+
private middlewares;
|
|
6
|
+
constructor(driver: Filesystem);
|
|
7
|
+
/**
|
|
8
|
+
* Register middleware for this disk.
|
|
9
|
+
*/
|
|
10
|
+
middleware(middleware: any): this;
|
|
11
|
+
/**
|
|
12
|
+
* Create a pipeline for an operation.
|
|
13
|
+
*/
|
|
14
|
+
protected runPipeline(operation: string, params: any, callback: (params: any) => Promise<any>): Promise<any>;
|
|
15
|
+
/**
|
|
16
|
+
* Write contents to a file.
|
|
17
|
+
*/
|
|
18
|
+
put(path: string, contents: string | Buffer): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Write a stream to a file.
|
|
21
|
+
*/
|
|
22
|
+
putStream(path: string, stream: Readable): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Read file contents.
|
|
25
|
+
*/
|
|
26
|
+
get(path: string): Promise<Buffer>;
|
|
27
|
+
/**
|
|
28
|
+
* Read file as a stream.
|
|
29
|
+
*/
|
|
30
|
+
readStream(path: string): Readable;
|
|
31
|
+
/**
|
|
32
|
+
* Check if a file exists.
|
|
33
|
+
*/
|
|
34
|
+
exists(path: string): Promise<boolean>;
|
|
35
|
+
/**
|
|
36
|
+
* Delete a file.
|
|
37
|
+
*/
|
|
38
|
+
delete(path: string): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Get the URL for a file.
|
|
41
|
+
*/
|
|
42
|
+
url(path: string): string;
|
|
43
|
+
/**
|
|
44
|
+
* Get a temporary URL for a file.
|
|
45
|
+
*/
|
|
46
|
+
temporaryUrl(path: string, expiresAt: Date): Promise<string>;
|
|
47
|
+
/**
|
|
48
|
+
* Get the file size in bytes.
|
|
49
|
+
*/
|
|
50
|
+
size(path: string): Promise<number>;
|
|
51
|
+
/**
|
|
52
|
+
* Get the last modified time of the file.
|
|
53
|
+
*/
|
|
54
|
+
lastModified(path: string): Promise<number>;
|
|
55
|
+
/**
|
|
56
|
+
* Get the mime type of the file.
|
|
57
|
+
*/
|
|
58
|
+
mimeType(path: string): Promise<string>;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=Disk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Disk.d.ts","sourceRoot":"","sources":["../src/Disk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAA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,GAAG,OAAO,CAAC,MAAM,CAAC;IAMxD;;OAEG;IACU,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAKvD"}
|
package/dist/Disk.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Disk = void 0;
|
|
4
|
+
const middleware_1 = require("@arikajs/middleware");
|
|
5
|
+
class Disk {
|
|
6
|
+
constructor(driver) {
|
|
7
|
+
this.middlewares = [];
|
|
8
|
+
this.driver = driver;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Register middleware for this disk.
|
|
12
|
+
*/
|
|
13
|
+
middleware(middleware) {
|
|
14
|
+
this.middlewares.push(middleware);
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Create a pipeline for an operation.
|
|
19
|
+
*/
|
|
20
|
+
async runPipeline(operation, params, callback) {
|
|
21
|
+
if (this.middlewares.length === 0) {
|
|
22
|
+
return await callback(params);
|
|
23
|
+
}
|
|
24
|
+
return await new middleware_1.Pipeline()
|
|
25
|
+
.pipe(this.middlewares)
|
|
26
|
+
.handle({ operation, ...params }, async (data) => {
|
|
27
|
+
return await callback(data);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Write contents to a file.
|
|
32
|
+
*/
|
|
33
|
+
async put(path, contents) {
|
|
34
|
+
return await this.runPipeline('put', { path, contents }, async (data) => {
|
|
35
|
+
return await this.driver.put(data.path, data.contents);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Write a stream to a file.
|
|
40
|
+
*/
|
|
41
|
+
async putStream(path, stream) {
|
|
42
|
+
return await this.runPipeline('putStream', { path, stream }, async (data) => {
|
|
43
|
+
return await this.driver.putStream(data.path, data.stream);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Read file contents.
|
|
48
|
+
*/
|
|
49
|
+
async get(path) {
|
|
50
|
+
return await this.runPipeline('get', { path }, async (data) => {
|
|
51
|
+
return await this.driver.get(data.path);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Read file as a stream.
|
|
56
|
+
*/
|
|
57
|
+
readStream(path) {
|
|
58
|
+
// Note: readStream is tricky with async middleware.
|
|
59
|
+
// For now, we return the driver stream directly or
|
|
60
|
+
// we'd need a more complex implementation for streaming middleware.
|
|
61
|
+
return this.driver.readStream(path);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Check if a file exists.
|
|
65
|
+
*/
|
|
66
|
+
async exists(path) {
|
|
67
|
+
return await this.runPipeline('exists', { path }, async (data) => {
|
|
68
|
+
return await this.driver.exists(data.path);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Delete a file.
|
|
73
|
+
*/
|
|
74
|
+
async delete(path) {
|
|
75
|
+
return await this.runPipeline('delete', { path }, async (data) => {
|
|
76
|
+
return await this.driver.delete(data.path);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Get the URL for a file.
|
|
81
|
+
*/
|
|
82
|
+
url(path) {
|
|
83
|
+
return this.driver.url(path);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Get a temporary URL for a file.
|
|
87
|
+
*/
|
|
88
|
+
async temporaryUrl(path, expiresAt) {
|
|
89
|
+
return await this.runPipeline('temporaryUrl', { path, expiresAt }, async (data) => {
|
|
90
|
+
return await this.driver.temporaryUrl(data.path, data.expiresAt);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Get the file size in bytes.
|
|
95
|
+
*/
|
|
96
|
+
async size(path) {
|
|
97
|
+
return await this.runPipeline('size', { path }, async (data) => {
|
|
98
|
+
return await this.driver.size(data.path);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Get the last modified time of the file.
|
|
103
|
+
*/
|
|
104
|
+
async lastModified(path) {
|
|
105
|
+
return await this.runPipeline('lastModified', { path }, async (data) => {
|
|
106
|
+
return await this.driver.lastModified(data.path);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Get the mime type of the file.
|
|
111
|
+
*/
|
|
112
|
+
async mimeType(path) {
|
|
113
|
+
return await this.runPipeline('mimeType', { path }, async (data) => {
|
|
114
|
+
return await this.driver.mimeType(data.path);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.Disk = Disk;
|
|
119
|
+
//# sourceMappingURL=Disk.js.map
|
package/dist/Disk.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Disk.js","sourceRoot":"","sources":["../src/Disk.ts"],"names":[],"mappings":";;;AAEA,oDAA+C;AAE/C,MAAa,IAAI;IAIb,YAAY,MAAkB;QAFtB,gBAAW,GAAU,EAAE,CAAC;QAG5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED;;OAEG;IACI,UAAU,CAAC,UAAe;QAC7B,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAClC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;OAEG;IACO,KAAK,CAAC,WAAW,CAAC,SAAiB,EAAE,MAAW,EAAE,QAAuC;QAC/F,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAChC,OAAO,MAAM,QAAQ,CAAC,MAAM,CAAC,CAAC;QAClC,CAAC;QAED,OAAO,MAAM,IAAI,qBAAQ,EAAE;aACtB,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC;aACtB,MAAM,CAAC,EAAE,SAAS,EAAE,GAAG,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE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AAK,CAAC,YAAY,CAAC,IAAY;QAClC,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,cAAc,EAAE,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;YACnE,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrD,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,QAAQ,CAAC,IAAY;QAC9B,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;YAC/D,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjD,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAhID,oBAgIC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Readable } from 'stream';
|
|
2
|
+
import { Filesystem } from '../Contracts/Filesystem';
|
|
3
|
+
export declare class LocalDriver implements Filesystem {
|
|
4
|
+
private root;
|
|
5
|
+
private urlPrefix;
|
|
6
|
+
constructor(config: {
|
|
7
|
+
root: string;
|
|
8
|
+
url?: string;
|
|
9
|
+
});
|
|
10
|
+
/**
|
|
11
|
+
* Get the full path for a file.
|
|
12
|
+
*/
|
|
13
|
+
private getFullPath;
|
|
14
|
+
/**
|
|
15
|
+
* Ensure directory exists.
|
|
16
|
+
*/
|
|
17
|
+
private ensureDirectory;
|
|
18
|
+
/**
|
|
19
|
+
* Write contents to a file.
|
|
20
|
+
*/
|
|
21
|
+
put(filePath: string, contents: string | Buffer): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Write a stream to a file.
|
|
24
|
+
*/
|
|
25
|
+
putStream(filePath: string, stream: Readable): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Read file contents.
|
|
28
|
+
*/
|
|
29
|
+
get(filePath: string): Promise<Buffer>;
|
|
30
|
+
/**
|
|
31
|
+
* Read file as a stream.
|
|
32
|
+
*/
|
|
33
|
+
readStream(filePath: string): Readable;
|
|
34
|
+
/**
|
|
35
|
+
* Check if a file exists.
|
|
36
|
+
*/
|
|
37
|
+
exists(filePath: string): Promise<boolean>;
|
|
38
|
+
/**
|
|
39
|
+
* Delete a file.
|
|
40
|
+
*/
|
|
41
|
+
delete(filePath: string): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Get the URL for a file.
|
|
44
|
+
*/
|
|
45
|
+
url(filePath: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* Get a temporary URL for a file.
|
|
48
|
+
* Note: For local driver, this just returns the normal URL as local files don't support signing by default
|
|
49
|
+
* without a custom server implementation.
|
|
50
|
+
*/
|
|
51
|
+
temporaryUrl(filePath: string, expiresAt: Date): Promise<string>;
|
|
52
|
+
/**
|
|
53
|
+
* Get the file size in bytes.
|
|
54
|
+
*/
|
|
55
|
+
size(filePath: string): Promise<number>;
|
|
56
|
+
/**
|
|
57
|
+
* Get the last modified time of the file.
|
|
58
|
+
*/
|
|
59
|
+
lastModified(filePath: string): Promise<number>;
|
|
60
|
+
/**
|
|
61
|
+
* Get the mime type of the file.
|
|
62
|
+
*/
|
|
63
|
+
mimeType(filePath: string): Promise<string>;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=LocalDriver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocalDriver.d.ts","sourceRoot":"","sources":["../../src/Drivers/LocalDriver.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAGlC,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAGrD,qBAAa,WAAY,YAAW,UAAU;IAC1C,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,SAAS,CAAS;gBAEd,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QA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