@simplysm/storage 14.0.48 → 14.0.50

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/README.md CHANGED
@@ -12,171 +12,24 @@ npm install @simplysm/storage
12
12
 
13
13
  ### Types
14
14
 
15
- | API | Type | Description |
16
- |-----|------|-------------|
17
- | `StorageProtocol` | type | 지원 프로토콜 유니온 타입 (`"ftp"` \| `"ftps"` \| `"sftp"`) |
18
- | `StorageConnConfig` | interface | 스토리지 연결 설정 |
19
- | `FileInfo` | interface | 파일/디렉토리 정보 |
20
- | `StorageClient` | interface | 스토리지 클라이언트 공통 인터페이스 |
21
-
22
- #### `StorageProtocol`
23
-
24
- ```typescript
25
- type StorageProtocol = "ftp" | "ftps" | "sftp";
26
- ```
27
-
28
- 지원하는 프로토콜을 나타내는 유니온 타입:
29
- - `"ftp"`: 일반 FTP 프로토콜
30
- - `"ftps"`: TLS/SSL 암호화 FTP 프로토콜
31
- - `"sftp"`: SSH 기반 SFTP 프로토콜
32
-
33
- #### `StorageConnConfig`
34
-
35
- ```typescript
36
- interface StorageConnConfig {
37
- host: string;
38
- port?: number;
39
- user?: string;
40
- password?: string;
41
- }
42
- ```
43
-
44
- | Field | Type | Description |
15
+ | Entry | Kind | Description |
45
16
  |-------|------|-------------|
46
- | `host` | `string` | 서버 호스트 주소 |
47
- | `port` | `number \| undefined` | 포트 번호. 생략 시 프로토콜 기본값 사용 (FTP: 21, FTPS: 21, SFTP: 22) |
48
- | `user` | `string \| undefined` | 사용자 이름 |
49
- | `password` | `string \| undefined` | 비밀번호. SFTP에서 생략하면 SSH agent (`SSH_AUTH_SOCK` 환경변수) + `~/.ssh/id_ed25519` 키 파일 인증을 순서대로 시도 |
50
-
51
- #### `FileInfo`
52
-
53
- ```typescript
54
- interface FileInfo {
55
- name: string;
56
- isFile: boolean;
57
- }
58
- ```
59
-
60
- | Field | Type | Description |
61
- |-------|------|-------------|
62
- | `name` | `string` | 파일 또는 디렉토리의 이름 |
63
- | `isFile` | `boolean` | `true`이면 파일, `false`이면 디렉토리 |
64
-
65
- #### `StorageClient`
66
-
67
- 스토리지 클라이언트 공통 인터페이스. `FtpStorageClient`와 `SftpStorageClient`가 구현한다.
68
-
69
- ```typescript
70
- interface StorageClient {
71
- connect(config: StorageConnConfig): Promise<void>;
72
- mkdir(dirPath: string): Promise<void>;
73
- rename(fromPath: string, toPath: string): Promise<void>;
74
- list(dirPath: string): Promise<FileInfo[]>;
75
- readFile(filePath: string): Promise<Bytes>;
76
- exists(filePath: string): Promise<boolean>;
77
- put(localPathOrBuffer: string | Bytes, storageFilePath: string): Promise<void>;
78
- uploadDir(fromPath: string, toPath: string): Promise<void>;
79
- remove(filePath: string): Promise<void>;
80
- close(): Promise<void>;
81
- }
82
- ```
83
-
84
- | Method | Parameters | Return | Description |
85
- |--------|-----------|--------|-------------|
86
- | `connect` | `config: StorageConnConfig` | `Promise<void>` | 스토리지 서버에 연결. 연결 해제 전 한 번만 호출 가능 |
87
- | `mkdir` | `dirPath: string` | `Promise<void>` | 디렉토리 생성. 부모 디렉토리가 없으면 함께 생성 |
88
- | `rename` | `fromPath: string, toPath: string` | `Promise<void>` | 파일/디렉토리 이름 변경 또는 이동 |
89
- | `list` | `dirPath: string` | `Promise<FileInfo[]>` | 디렉토리 내 파일/디렉토리 목록 조회 |
90
- | `readFile` | `filePath: string` | `Promise<Bytes>` | 파일 내용을 `Bytes`(`Uint8Array`)로 읽기 |
91
- | `exists` | `filePath: string` | `Promise<boolean>` | 파일/디렉토리 존재 여부 확인. 모든 예외는 `false` 반환 |
92
- | `put` | `localPathOrBuffer: string \| Bytes, storageFilePath: string` | `Promise<void>` | 로컬 파일 경로 또는 바이트 데이터를 원격 경로에 업로드 |
93
- | `uploadDir` | `fromPath: string, toPath: string` | `Promise<void>` | 로컬 디렉토리 전체를 원격 경로에 업로드 |
94
- | `remove` | `filePath: string` | `Promise<void>` | 파일 삭제 |
95
- | `close` | 없음 | `Promise<void>` | 연결 종료. 이미 종료된 상태에서 호출해도 안전 |
17
+ | [`StorageConnConfig`](./docs/types/storage-conn-config.md) | interface | 스토리지 서버 연결 설정 |
18
+ | [`FileInfo`](./docs/types/file-info.md) | interface | 파일/디렉토리 정보 |
19
+ | [`StorageClient`](./docs/types/storage-client.md) | interface | 스토리지 클라이언트 공통 인터페이스 (포함: `StorageProtocol`) |
96
20
 
97
21
  ### Clients
98
22
 
99
- | API | Type | Description |
100
- |-----|------|-------------|
101
- | `FtpStorageClient` | class | FTP/FTPS 프로토콜 스토리지 클라이언트 (`basic-ftp` 라이브러리 기반) |
102
- | `SftpStorageClient` | class | SFTP 프로토콜 스토리지 클라이언트 (`ssh2-sftp-client` 라이브러리 기반) |
103
-
104
- #### `FtpStorageClient`
105
-
106
- FTP/FTPS 프로토콜을 사용하는 스토리지 클라이언트. `StorageClient` 인터페이스를 구현한다.
107
-
108
- ```typescript
109
- class FtpStorageClient implements StorageClient {
110
- constructor(private readonly _secure: boolean = false);
111
- }
112
- ```
113
-
114
- **생성자**:
115
- - `_secure`: `true`이면 FTPS (TLS/SSL 암호화), `false`이면 FTP (기본값)
116
-
117
- **특징**:
118
- - `connect()`로 연결 후 메서드 호출. 미연결 상태에서 호출하면 `SdError` 발생
119
- - `exists()`는 먼저 `size()` 명령으로 파일을 O(1) 성능으로 확인하고, 실패 시 부모 디렉토리 목록을 조회하여 디렉토리 존재 여부 확인. 모든 예외는 `false` 반환
120
- - 슬래시가 없는 경로(예: `file.txt`)는 루트 디렉토리(`/`)에서 검색
121
- - `close()`는 이미 종료된 상태에서 호출해도 안전 (오류 미발생)
122
-
123
- #### `SftpStorageClient`
124
-
125
- SFTP 프로토콜을 사용하는 스토리지 클라이언트. `StorageClient` 인터페이스를 구현한다.
126
-
127
- ```typescript
128
- class SftpStorageClient implements StorageClient {
129
- constructor();
130
- }
131
- ```
132
-
133
- **인증 메커니즘**:
134
- - `password`가 있으면 패스워드 인증 사용
135
- - `password`가 없으면 다음 순서대로 시도:
136
- 1. SSH agent (`SSH_AUTH_SOCK` 환경변수 설정 시)
137
- 2. `~/.ssh/id_ed25519` 개인키 파일 인증
138
- 3. privateKey 파싱 실패 시 (암호화된 키 등) agent만으로 재시도
139
-
140
- **특징**:
141
- - `connect()`로 연결 후 메서드 호출. 미연결 상태에서 호출하면 `SdError` 발생
142
- - `exists()`는 `ssh2-sftp-client`의 `exists()` 반환값 (`false | 'd' | '-' | 'l'`)을 검사하여 존재 여부 판단. 모든 예외는 `false` 반환
143
- - `close()`는 이미 종료된 상태에서 호출해도 안전 (오류 미발생)
23
+ | Entry | Kind | Description |
24
+ |-------|------|-------------|
25
+ | [`FtpStorageClient`](./docs/clients/ftp-storage-client.md) | class | FTP/FTPS 프로토콜 스토리지 클라이언트 (`basic-ftp` 기반) |
26
+ | [`SftpStorageClient`](./docs/clients/sftp-storage-client.md) | class | SFTP 프로토콜 스토리지 클라이언트 (`ssh2-sftp-client` 기반) |
144
27
 
145
28
  ### Factory
146
29
 
147
- | API | Type | Description |
148
- |-----|------|-------------|
149
- | `StorageFactory` | class | 프로토콜별 클라이언트 생성 및 연결 생명주기 자동 관리 |
150
-
151
- #### `StorageFactory`
152
-
153
- 스토리지 클라이언트 팩토리. 콜백 패턴으로 연결/종료를 자동 관리한다.
154
-
155
- ```typescript
156
- class StorageFactory {
157
- static async connect<R>(
158
- type: StorageProtocol,
159
- config: StorageConnConfig,
160
- fn: (storage: StorageClient) => R | Promise<R>,
161
- ): Promise<R>;
162
- }
163
- ```
164
-
165
- **메서드**:
166
- - `StorageFactory.connect<R>()` (정적 메서드)
167
-
168
- **파라미터**:
169
-
170
- | Parameter | Type | Description |
171
- |-----------|------|-------------|
172
- | `type` | `StorageProtocol` | 프로토콜 타입 (`"ftp"`, `"ftps"`, `"sftp"`) |
173
- | `config` | `StorageConnConfig` | 연결 설정 |
174
- | `fn` | `(storage: StorageClient) => R \| Promise<R>` | 연결된 클라이언트를 받아 작업을 수행하는 콜백. 반환값은 `Promise<R>` 형태로 래핑되어 반환됨 |
175
-
176
- **동작**:
177
- - `fn` 콜백이 완료되거나 예외를 발생시키면 연결이 자동으로 종료됨
178
- - `fn`에서 발생한 예외는 그대로 전파됨
179
- - 반환값: 콜백의 반환값
30
+ | Entry | Kind | Description |
31
+ |-------|------|-------------|
32
+ | [`StorageFactory`](./docs/factory/storage-factory.md) | class | 프로토콜별 클라이언트 생성 및 연결 생명주기 자동 관리 (포함: `StorageProtocol`) |
180
33
 
181
34
  ## Usage Examples
182
35
 
@@ -210,92 +63,22 @@ const files = await StorageFactory.connect(
210
63
  for (const file of list.filter((f) => f.isFile)) {
211
64
  const content = await storage.readFile(`/data/${file.name}`);
212
65
  // content는 Bytes (Uint8Array)
213
- console.log(`Read ${file.name}: ${content.length} bytes`);
214
66
  }
215
67
  return list;
216
68
  },
217
69
  );
218
70
  ```
219
71
 
220
- ### FTPS로 파일 이름 변경
221
-
222
- ```typescript
223
- import { StorageFactory } from "@simplysm/storage";
224
-
225
- await StorageFactory.connect(
226
- "ftps",
227
- { host: "ftps.example.com", user: "user", password: "pass" },
228
- async (storage) => {
229
- const exists = await storage.exists("/remote/file.txt");
230
- if (exists) {
231
- await storage.rename("/remote/file.txt", "/remote/backup.txt");
232
- }
233
- },
234
- );
235
- ```
236
-
237
- ### 클라이언트 직접 사용 (수동 생명주기 관리)
238
-
239
- 클라이언트를 직접 인스턴스화하여 수동으로 연결 생명주기를 관리할 수 있다. 하지만 연결 누수 위험이 있으므로 `StorageFactory.connect` 사용을 권장한다.
240
-
241
- ```typescript
242
- import { FtpStorageClient } from "@simplysm/storage";
243
-
244
- const client = new FtpStorageClient(true); // FTPS 사용
245
- try {
246
- await client.connect({ host: "ftps.example.com", user: "user", password: "pass" });
247
- const exists = await client.exists("/remote/file.txt");
248
- if (exists) {
249
- await client.rename("/remote/file.txt", "/remote/backup.txt");
250
- }
251
- } finally {
252
- await client.close();
253
- }
254
- ```
255
-
256
72
  ### SSH 키 인증으로 SFTP 연결 (비밀번호 생략)
257
73
 
258
- `password`를 생략하면 SSH agent와 `~/.ssh/id_ed25519` 키 파일을 사용하여 인증한다.
259
-
260
74
  ```typescript
261
75
  import { StorageFactory } from "@simplysm/storage";
262
76
 
263
77
  await StorageFactory.connect(
264
78
  "sftp",
265
- { host: "sftp.example.com", user: "user" }, // password 생략
79
+ { host: "sftp.example.com", user: "user" }, // password 생략 → SSH agent/키 파일 인증
266
80
  async (storage) => {
267
81
  const list = await storage.list("/home/user");
268
- console.log(`Files: ${list.map((f) => f.name).join(", ")}`);
269
- },
270
- );
271
- ```
272
-
273
- ### 바이트 데이터로 파일 업로드
274
-
275
- ```typescript
276
- import { StorageFactory } from "@simplysm/storage";
277
-
278
- const data = new Uint8Array([0x48, 0x65, 0x6c, 0x6c, 0x6f]); // "Hello"
279
-
280
- await StorageFactory.connect(
281
- "sftp",
282
- { host: "sftp.example.com", user: "user", password: "pass" },
283
- async (storage) => {
284
- await storage.put(data, "/remote/file.bin");
285
- },
286
- );
287
- ```
288
-
289
- ### 로컬 디렉토리 전체 업로드
290
-
291
- ```typescript
292
- import { StorageFactory } from "@simplysm/storage";
293
-
294
- await StorageFactory.connect(
295
- "ftp",
296
- { host: "ftp.example.com", user: "user", password: "pass" },
297
- async (storage) => {
298
- await storage.uploadDir("/local/folder", "/remote/backup");
299
82
  },
300
83
  );
301
84
  ```
@@ -0,0 +1,47 @@
1
+ # FtpStorageClient
2
+
3
+ FTP/FTPS 프로토콜을 사용하는 스토리지 클라이언트. `basic-ftp` 라이브러리 기반. [`StorageClient`](../types/storage-client.md) 인터페이스를 구현한다.
4
+
5
+ 직접 사용하기보다 [`StorageFactory.connect()`](../factory/storage-factory.md)를 통해 콜백 패턴으로 사용하는 것을 권장한다.
6
+
7
+ ```typescript
8
+ class FtpStorageClient implements StorageClient {
9
+ constructor(private readonly _secure: boolean = false);
10
+ }
11
+ ```
12
+
13
+ ## Constructor
14
+
15
+ | Parameter | Type | Default | Description |
16
+ |-----------|------|---------|-------------|
17
+ | `_secure` | `boolean` | `false` | `true`이면 FTPS (TLS/SSL 암호화), `false`이면 FTP |
18
+
19
+ ## Members
20
+
21
+ [`StorageClient`](../types/storage-client.md) 인터페이스의 모든 메서드를 구현한다. 구현 특이사항:
22
+
23
+ | Member | Kind | Description |
24
+ |--------|------|-------------|
25
+ | `connect` | method | 이미 연결된 상태에서 호출하면 `SdError` 발생. 연결 실패 시 내부 `ftp.Client`를 즉시 닫고 예외를 전파 |
26
+ | `mkdir` | method | `basic-ftp`의 `ensureDir()`을 사용하여 부모 디렉토리 포함 재귀 생성 |
27
+ | `exists` | method | 먼저 `size()` 명령으로 파일을 O(1) 성능으로 확인. 실패 시 부모 디렉토리 `list()`로 디렉토리 존재 여부 확인. 슬래시 없는 경로(예: `file.txt`)는 루트(`/`)에서 검색. 모든 예외는 `false` 반환 |
28
+ | `put` | method | `string`이면 파일 경로로, `Bytes`이면 `Readable` 스트림으로 변환하여 `uploadFrom()` 호출 |
29
+ | `close` | method | 동기적으로 내부 클라이언트를 정리하고 `Promise.resolve()` 반환. 이미 종료된 상태에서 호출해도 안전 |
30
+
31
+ ## Usage
32
+
33
+ ```typescript
34
+ import { FtpStorageClient } from "@simplysm/storage";
35
+
36
+ // FTPS 사용
37
+ const client = new FtpStorageClient(true);
38
+ try {
39
+ await client.connect({ host: "ftps.example.com", user: "user", password: "pass" });
40
+ const exists = await client.exists("/remote/file.txt");
41
+ if (exists) {
42
+ await client.rename("/remote/file.txt", "/remote/backup.txt");
43
+ }
44
+ } finally {
45
+ await client.close();
46
+ }
47
+ ```
@@ -0,0 +1,58 @@
1
+ # SftpStorageClient
2
+
3
+ SFTP 프로토콜을 사용하는 스토리지 클라이언트. `ssh2-sftp-client` 라이브러리 기반. [`StorageClient`](../types/storage-client.md) 인터페이스를 구현한다.
4
+
5
+ 직접 사용하기보다 [`StorageFactory.connect()`](../factory/storage-factory.md)를 통해 콜백 패턴으로 사용하는 것을 권장한다.
6
+
7
+ ```typescript
8
+ class SftpStorageClient implements StorageClient {
9
+ constructor();
10
+ }
11
+ ```
12
+
13
+ ## Members
14
+
15
+ [`StorageClient`](../types/storage-client.md) 인터페이스의 모든 메서드를 구현한다. 구현 특이사항:
16
+
17
+ | Member | Kind | Description |
18
+ |--------|------|-------------|
19
+ | `connect` | method | 이미 연결된 상태에서 호출하면 `SdError` 발생. `password` 유무에 따라 인증 방식이 달라짐 (아래 인증 메커니즘 참조). 연결 실패 시 `client.end()`를 호출하고 예외를 전파 |
20
+ | `mkdir` | method | `ssh2-sftp-client`의 `mkdir(path, true)`를 호출하여 부모 디렉토리 포함 재귀 생성 |
21
+ | `list` | method | `item.type === "-"`이면 파일(`isFile: true`), 아니면 디렉토리(`isFile: false`)로 변환 |
22
+ | `exists` | method | `ssh2-sftp-client`의 `exists()` 반환값(`false \| 'd' \| '-' \| 'l'`)을 검사. 문자열이면 존재. 모든 예외는 `false` 반환 |
23
+ | `readFile` | method | `ssh2-sftp-client`의 `get()` 반환값(`Buffer` 또는 `string`)을 `Bytes`(`Uint8Array`)로 변환 |
24
+ | `put` | method | `string`이면 `fastPut()`으로, `Bytes`이면 `Buffer.from()` 변환 후 `put()`으로 업로드 (`ssh2-sftp-client` 라이브러리 요구사항) |
25
+ | `close` | method | `client.end()`를 호출하여 연결 종료. 이미 종료된 상태에서 호출해도 안전 |
26
+
27
+ ## Authentication
28
+
29
+ `connect()` 호출 시 [`StorageConnConfig`](../types/storage-conn-config.md)의 `password` 유무에 따라 인증 방식이 결정된다:
30
+
31
+ **`password`가 있는 경우**: 패스워드 인증
32
+
33
+ **`password`가 없는 경우**: 다음 순서로 시도
34
+ 1. SSH agent (`SSH_AUTH_SOCK` 환경변수가 설정된 경우 `agent` 옵션 추가)
35
+ 2. `~/.ssh/id_ed25519` 개인키 파일 읽어 `privateKey` 옵션으로 인증 시도
36
+ 3. `privateKey` 파싱 실패 시 (암호화된 키 등) SSH agent만으로 재시도
37
+
38
+ ## Usage
39
+
40
+ ```typescript
41
+ import { SftpStorageClient } from "@simplysm/storage";
42
+
43
+ // 패스워드 인증
44
+ const client = new SftpStorageClient();
45
+ try {
46
+ await client.connect({ host: "sftp.example.com", user: "user", password: "pass" });
47
+ await client.mkdir("/remote/dir");
48
+ await client.put("/local/file.txt", "/remote/dir/file.txt");
49
+ } finally {
50
+ await client.close();
51
+ }
52
+ ```
53
+
54
+ SSH 키 인증 사용 시 `password` 필드를 생략한다:
55
+
56
+ ```typescript
57
+ await client.connect({ host: "sftp.example.com", user: "user" }); // password 생략
58
+ ```
@@ -0,0 +1,82 @@
1
+ # StorageFactory
2
+
3
+ 스토리지 클라이언트 팩토리. 콜백 패턴으로 연결/종료를 자동 관리한다.
4
+
5
+ ```typescript
6
+ class StorageFactory {
7
+ static async connect<R>(
8
+ type: StorageProtocol,
9
+ config: StorageConnConfig,
10
+ fn: (storage: StorageClient) => R | Promise<R>,
11
+ ): Promise<R>;
12
+ }
13
+ ```
14
+
15
+ ## Members
16
+
17
+ | Member | Kind | Type | Description |
18
+ |--------|------|------|-------------|
19
+ | `connect` | static | `<R>(type: StorageProtocol, config: StorageConnConfig, fn: (storage: StorageClient) => R \| Promise<R>) => Promise<R>` | 프로토콜에 맞는 클라이언트를 생성하고, 연결 후 콜백을 실행하며, 완료/예외 시 자동으로 연결을 종료 |
20
+
21
+ ### `connect<R>()` 파라미터
22
+
23
+ | Parameter | Type | Description |
24
+ |-----------|------|-------------|
25
+ | `type` | `StorageProtocol` | 프로토콜 타입 |
26
+ | `config` | [`StorageConnConfig`](../types/storage-conn-config.md) | 연결 설정 |
27
+ | `fn` | `(storage: StorageClient) => R \| Promise<R>` | 연결된 클라이언트로 작업을 수행하는 콜백 |
28
+
29
+ **반환**: `Promise<R>` — 콜백의 반환값
30
+
31
+ **동작**:
32
+ - `type`에 따라 [`FtpStorageClient`](../clients/ftp-storage-client.md) 또는 [`SftpStorageClient`](../clients/sftp-storage-client.md)를 생성
33
+ - `client.connect(config)` 후 `fn(client)` 실행
34
+ - `fn` 완료 또는 예외 발생 여부와 무관하게 `finally`에서 `client.close()` 호출
35
+ - `fn`에서 발생한 예외는 그대로 전파
36
+
37
+ ## Related Types
38
+
39
+ ### `StorageProtocol`
40
+
41
+ `StorageFactory.connect()`의 `type` 파라미터 타입.
42
+
43
+ ```typescript
44
+ type StorageProtocol = "ftp" | "ftps" | "sftp";
45
+ ```
46
+
47
+ | Variant | Description |
48
+ |---------|-------------|
49
+ | `"ftp"` | 일반 FTP. `FtpStorageClient(false)` 생성 |
50
+ | `"ftps"` | TLS/SSL 암호화 FTP. `FtpStorageClient(true)` 생성 |
51
+ | `"sftp"` | SSH 기반 SFTP. `SftpStorageClient()` 생성 |
52
+
53
+ ## Usage
54
+
55
+ ```typescript
56
+ import { StorageFactory } from "@simplysm/storage";
57
+
58
+ // 파일 업로드
59
+ await StorageFactory.connect(
60
+ "sftp",
61
+ { host: "sftp.example.com", user: "user", password: "pass" },
62
+ async (storage) => {
63
+ await storage.mkdir("/remote/dir");
64
+ await storage.put("/local/file.txt", "/remote/dir/file.txt");
65
+ },
66
+ );
67
+
68
+ // 파일 목록 조회 후 반환
69
+ const list = await StorageFactory.connect(
70
+ "ftp",
71
+ { host: "ftp.example.com", port: 21, user: "user", password: "pass" },
72
+ (storage) => storage.list("/data"),
73
+ );
74
+
75
+ // 바이트 데이터로 업로드
76
+ const data = new Uint8Array([0x48, 0x65, 0x6c, 0x6c, 0x6f]);
77
+ await StorageFactory.connect(
78
+ "ftps",
79
+ { host: "ftps.example.com", user: "user", password: "pass" },
80
+ (storage) => storage.put(data, "/remote/file.bin"),
81
+ );
82
+ ```
@@ -0,0 +1,32 @@
1
+ # FileInfo
2
+
3
+ 파일 또는 디렉토리 정보를 담는 인터페이스. [`StorageClient.list()`](./storage-client.md)의 반환 타입이다.
4
+
5
+ ```typescript
6
+ interface FileInfo {
7
+ name: string;
8
+ isFile: boolean;
9
+ }
10
+ ```
11
+
12
+ ## Fields
13
+
14
+ | Field | Type | Description |
15
+ |-------|------|-------------|
16
+ | `name` | `string` | 파일 또는 디렉토리의 이름 (경로 아님, 이름만) |
17
+ | `isFile` | `boolean` | `true`이면 파일, `false`이면 디렉토리 |
18
+
19
+ ## Usage
20
+
21
+ ```typescript
22
+ import { StorageFactory } from "@simplysm/storage";
23
+
24
+ const items = await StorageFactory.connect(
25
+ "sftp",
26
+ { host: "sftp.example.com", user: "user", password: "pass" },
27
+ async (storage) => storage.list("/remote/dir"),
28
+ );
29
+
30
+ const files = items.filter((item) => item.isFile);
31
+ const dirs = items.filter((item) => !item.isFile);
32
+ ```
@@ -0,0 +1,50 @@
1
+ # StorageClient
2
+
3
+ 스토리지 클라이언트 공통 인터페이스. [`FtpStorageClient`](../clients/ftp-storage-client.md)와 [`SftpStorageClient`](../clients/sftp-storage-client.md)가 구현한다.
4
+
5
+ 직접 사용하기보다 [`StorageFactory.connect()`](../factory/storage-factory.md)를 통해 콜백 패턴으로 사용하는 것을 권장한다.
6
+
7
+ ```typescript
8
+ interface StorageClient {
9
+ connect(config: StorageConnConfig): Promise<void>;
10
+ mkdir(dirPath: string): Promise<void>;
11
+ rename(fromPath: string, toPath: string): Promise<void>;
12
+ list(dirPath: string): Promise<FileInfo[]>;
13
+ readFile(filePath: string): Promise<Bytes>;
14
+ exists(filePath: string): Promise<boolean>;
15
+ put(localPathOrBuffer: string | Bytes, storageFilePath: string): Promise<void>;
16
+ uploadDir(fromPath: string, toPath: string): Promise<void>;
17
+ remove(filePath: string): Promise<void>;
18
+ close(): Promise<void>;
19
+ }
20
+ ```
21
+
22
+ ## Members
23
+
24
+ | Member | Kind | Type | Description |
25
+ |--------|------|------|-------------|
26
+ | `connect` | method | `(config: StorageConnConfig) => Promise<void>` | 스토리지 서버에 연결. 이미 연결된 상태에서 호출하면 `SdError` 발생 |
27
+ | `mkdir` | method | `(dirPath: string) => Promise<void>` | 디렉토리 생성. 부모 디렉토리가 없으면 함께 생성 |
28
+ | `rename` | method | `(fromPath: string, toPath: string) => Promise<void>` | 파일/디렉토리 이름 변경 또는 이동 |
29
+ | `list` | method | `(dirPath: string) => Promise<FileInfo[]>` | 디렉토리 내 파일/디렉토리 목록 조회 |
30
+ | `readFile` | method | `(filePath: string) => Promise<Bytes>` | 파일 내용을 `Bytes`(`Uint8Array`)로 읽기 |
31
+ | `exists` | method | `(filePath: string) => Promise<boolean>` | 파일/디렉토리 존재 여부 확인. 모든 예외는 `false` 반환 |
32
+ | `put` | method | `(localPathOrBuffer: string \| Bytes, storageFilePath: string) => Promise<void>` | 로컬 파일 경로 또는 바이트 데이터를 원격 경로에 업로드 |
33
+ | `uploadDir` | method | `(fromPath: string, toPath: string) => Promise<void>` | 로컬 디렉토리 전체를 원격 경로에 업로드 |
34
+ | `remove` | method | `(filePath: string) => Promise<void>` | 파일 삭제 |
35
+ | `close` | method | `() => Promise<void>` | 연결 종료. 이미 종료된 상태에서 호출해도 안전 |
36
+
37
+ ## Usage
38
+
39
+ ```typescript
40
+ import type { StorageClient } from "@simplysm/storage";
41
+ import { StorageFactory } from "@simplysm/storage";
42
+
43
+ // StorageClient 타입을 직접 사용하는 경우 (예: 함수 파라미터 타입)
44
+ async function doWork(storage: StorageClient): Promise<void> {
45
+ await storage.mkdir("/remote/dir");
46
+ await storage.put("/local/file.txt", "/remote/dir/file.txt");
47
+ }
48
+
49
+ await StorageFactory.connect("sftp", { host: "sftp.example.com", user: "user", password: "pass" }, doWork);
50
+ ```
@@ -0,0 +1,34 @@
1
+ # StorageConnConfig
2
+
3
+ 스토리지 서버 연결 설정 인터페이스.
4
+
5
+ ```typescript
6
+ interface StorageConnConfig {
7
+ host: string;
8
+ port?: number;
9
+ user?: string;
10
+ password?: string;
11
+ }
12
+ ```
13
+
14
+ ## Fields
15
+
16
+ | Field | Type | Description |
17
+ |-------|------|-------------|
18
+ | `host` | `string` | 서버 호스트 주소 |
19
+ | `port` | `number \| undefined` | 포트 번호. 생략 시 프로토콜 기본값 사용 (FTP/FTPS: 21, SFTP: 22) |
20
+ | `user` | `string \| undefined` | 사용자 이름 |
21
+ | `password` | `string \| undefined` | 비밀번호. SFTP에서 생략하면 SSH agent + `~/.ssh/id_ed25519` 키 파일 인증을 순서대로 시도 |
22
+
23
+ ## Usage
24
+
25
+ ```typescript
26
+ import type { StorageConnConfig } from "@simplysm/storage";
27
+
28
+ const config: StorageConnConfig = {
29
+ host: "sftp.example.com",
30
+ port: 22,
31
+ user: "user",
32
+ password: "pass",
33
+ };
34
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplysm/storage",
3
- "version": "14.0.48",
3
+ "version": "14.0.50",
4
4
  "description": "심플리즘 패키지 - 저장소 (node)",
5
5
  "author": "심플리즘",
6
6
  "license": "Apache-2.0",
@@ -14,13 +14,14 @@
14
14
  "types": "./dist/index.d.ts",
15
15
  "files": [
16
16
  "dist",
17
- "src"
17
+ "src",
18
+ "docs"
18
19
  ],
19
20
  "sideEffects": false,
20
21
  "dependencies": {
21
22
  "basic-ftp": "^5.3.0",
22
23
  "ssh2-sftp-client": "^12.1.1",
23
- "@simplysm/core-common": "14.0.48"
24
+ "@simplysm/core-common": "14.0.50"
24
25
  },
25
26
  "devDependencies": {
26
27
  "@types/ssh2-sftp-client": "^9.0.6"