@simplysm/service-client 14.0.51 → 14.0.52
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/package.json +5 -6
- package/README.md +0 -115
- package/docs/features/event-client.md +0 -88
- package/docs/features/file-client.md +0 -58
- package/docs/features/orm-client-connector.md +0 -83
- package/docs/features/orm-client-db-context-executor.md +0 -26
- package/docs/main/service-client.md +0 -147
- package/docs/protocol/client-protocol-wrapper.md +0 -59
- package/docs/transport/service-transport.md +0 -63
- package/docs/transport/socket-provider.md +0 -95
- package/docs/types/blob-input.md +0 -7
- package/docs/types/browser-worker.md +0 -47
- package/docs/types/file-collection.md +0 -21
- package/docs/types/service-connection-options.md +0 -22
- package/docs/types/service-progress.md +0 -39
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simplysm/service-client",
|
|
3
|
-
"version": "14.0.
|
|
3
|
+
"version": "14.0.52",
|
|
4
4
|
"description": "심플리즘 패키지 - 서비스 (client)",
|
|
5
5
|
"author": "심플리즘",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -14,15 +14,14 @@
|
|
|
14
14
|
"types": "./dist/index.d.ts",
|
|
15
15
|
"files": [
|
|
16
16
|
"dist",
|
|
17
|
-
"src"
|
|
18
|
-
"docs"
|
|
17
|
+
"src"
|
|
19
18
|
],
|
|
20
19
|
"sideEffects": false,
|
|
21
20
|
"dependencies": {
|
|
22
21
|
"consola": "^3.4.2",
|
|
23
|
-
"@simplysm/
|
|
24
|
-
"@simplysm/
|
|
25
|
-
"@simplysm/
|
|
22
|
+
"@simplysm/orm-common": "14.0.52",
|
|
23
|
+
"@simplysm/core-common": "14.0.52",
|
|
24
|
+
"@simplysm/service-common": "14.0.52"
|
|
26
25
|
},
|
|
27
26
|
"devDependencies": {
|
|
28
27
|
"@types/ws": "^8.18.1",
|
package/README.md
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
# @simplysm/service-client
|
|
2
|
-
|
|
3
|
-
WebSocket 기반 서비스 서버 클라이언트로, 서비스 호출, 실시간 이벤트 구독/발행, 파일 업로드/다운로드, ORM 원격 실행을 지원한다.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install @simplysm/service-client
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## API Overview
|
|
12
|
-
|
|
13
|
-
### Main
|
|
14
|
-
|
|
15
|
-
| Entry | Kind | Description |
|
|
16
|
-
|-------|------|-------------|
|
|
17
|
-
| [`ServiceClient`](./docs/main/service-client.md) | class | WebSocket 서비스 클라이언트 최상위 파사드 (연결, RPC, 이벤트, 파일, ORM 통합) |
|
|
18
|
-
| [`ServiceProxy<T>`](./docs/main/service-client.md) | type | 서비스 메서드 반환 타입을 Promise로 래핑하는 타입 변환기 |
|
|
19
|
-
| [`createServiceClient()`](./docs/main/service-client.md) | function | ServiceClient 인스턴스 생성 팩토리 함수 |
|
|
20
|
-
|
|
21
|
-
### Transport
|
|
22
|
-
|
|
23
|
-
| Entry | Kind | Description |
|
|
24
|
-
|-------|------|-------------|
|
|
25
|
-
| [`SocketProvider`](./docs/transport/socket-provider.md) | interface | WebSocket 래퍼 (connect, close, send, on, off, 하트비트·재연결 관리) |
|
|
26
|
-
| [`SocketProviderEvents`](./docs/transport/socket-provider.md) | interface | SocketProvider 이벤트 맵 (message, state) |
|
|
27
|
-
| [`createSocketProvider()`](./docs/transport/socket-provider.md) | function | SocketProvider 팩토리 |
|
|
28
|
-
| [`ServiceTransport`](./docs/transport/service-transport.md) | interface | 요청-응답 매핑, progress 중계, 이벤트 디스패치 |
|
|
29
|
-
| [`ServiceTransportEvents`](./docs/transport/service-transport.md) | interface | ServiceTransport 이벤트 맵 (event) |
|
|
30
|
-
| [`createServiceTransport()`](./docs/transport/service-transport.md) | function | ServiceTransport 팩토리 |
|
|
31
|
-
|
|
32
|
-
### Protocol
|
|
33
|
-
|
|
34
|
-
| Entry | Kind | Description |
|
|
35
|
-
|-------|------|-------------|
|
|
36
|
-
| [`ClientProtocolWrapper`](./docs/protocol/client-protocol-wrapper.md) | interface | 메시지 인코딩/디코딩 (30KB 이상 시 Web Worker 오프로드) |
|
|
37
|
-
| [`createClientProtocolWrapper()`](./docs/protocol/client-protocol-wrapper.md) | function | ClientProtocolWrapper 팩토리 |
|
|
38
|
-
|
|
39
|
-
### Features
|
|
40
|
-
|
|
41
|
-
| Entry | Kind | Description |
|
|
42
|
-
|-------|------|-------------|
|
|
43
|
-
| [`EventClient`](./docs/features/event-client.md) | interface | 서버 이벤트 구독/발행 관리 (재연결 시 자동 재구독) |
|
|
44
|
-
| [`ClientEventProxy<T>`](./docs/features/event-client.md) | interface | 특정 이벤트에 대한 프록시 인터페이스 |
|
|
45
|
-
| [`createEventClient()`](./docs/features/event-client.md) | function | EventClient 팩토리 |
|
|
46
|
-
| [`FileClient`](./docs/features/file-client.md) | interface | 파일 업로드(POST)/다운로드(GET) |
|
|
47
|
-
| [`createFileClient()`](./docs/features/file-client.md) | function | FileClient 팩토리 |
|
|
48
|
-
| [`OrmClientConnector`](./docs/features/orm-client-connector.md) | interface | DbContext 원격 트랜잭션 연결 헬퍼 |
|
|
49
|
-
| [`OrmConnectOptions<T>`](./docs/features/orm-client-connector.md) | interface | ORM 연결 설정 (DbClass, connOpt, dbContextOpt) |
|
|
50
|
-
| [`createOrmClientConnector()`](./docs/features/orm-client-connector.md) | function | OrmClientConnector 팩토리 |
|
|
51
|
-
| [`OrmClientDbContextExecutor`](./docs/features/orm-client-db-context-executor.md) | class | DbContextExecutor 구현체 (서버로 원격 호출) |
|
|
52
|
-
|
|
53
|
-
### Types
|
|
54
|
-
|
|
55
|
-
| Entry | Kind | Description |
|
|
56
|
-
|-------|------|-------------|
|
|
57
|
-
| [`ServiceConnectionOptions`](./docs/types/service-connection-options.md) | interface | 서버 연결 옵션 (host, port, ssl, maxReconnectCount) |
|
|
58
|
-
| [`ServiceProgress`](./docs/types/service-progress.md) | interface | progress 콜백 인터페이스 (request, response, server) |
|
|
59
|
-
| [`ServiceProgressState`](./docs/types/service-progress.md) | interface | progress 상태 (uuid, totalSize, completedSize) |
|
|
60
|
-
| [`BlobInput`](./docs/types/blob-input.md) | type | `Blob \| Uint8Array \| ArrayBuffer \| string` (Blob 생성자 허용 타입) |
|
|
61
|
-
| [`FileCollection`](./docs/types/file-collection.md) | interface | FileList 호환 컬렉션 인터페이스 |
|
|
62
|
-
| [`BrowserWorker`](./docs/types/browser-worker.md) | interface | Web Worker 최소 인터페이스 (cross-env 타입 호환용) |
|
|
63
|
-
| [`isBrowserWorkerSupported()`](./docs/types/browser-worker.md) | function | DOM Worker API 지원 여부 확인 |
|
|
64
|
-
| [`isNodeWorkerSupported()`](./docs/types/browser-worker.md) | function | Node.js worker_threads 지원 여부 확인 |
|
|
65
|
-
| [`isWorkerSupported()`](./docs/types/browser-worker.md) | function | Worker 오프로딩 지원 여부 확인 |
|
|
66
|
-
|
|
67
|
-
## Usage Examples
|
|
68
|
-
|
|
69
|
-
### 기본 연결 및 서비스 호출
|
|
70
|
-
|
|
71
|
-
```typescript
|
|
72
|
-
import { ServiceClient } from "@simplysm/service-client";
|
|
73
|
-
|
|
74
|
-
const client = new ServiceClient("my-app", {
|
|
75
|
-
host: "localhost",
|
|
76
|
-
port: 3000,
|
|
77
|
-
ssl: false,
|
|
78
|
-
maxReconnectCount: 10,
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
await client.connect();
|
|
82
|
-
await client.auth("jwt-token");
|
|
83
|
-
|
|
84
|
-
// 타입 안전한 서비스 프록시
|
|
85
|
-
const userSvc = client.getService<UserService>("User");
|
|
86
|
-
const users = await userSvc.getAll();
|
|
87
|
-
|
|
88
|
-
await client.close();
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
### 이벤트 구독
|
|
92
|
-
|
|
93
|
-
```typescript
|
|
94
|
-
// 이벤트 프록시 방식 (권장)
|
|
95
|
-
const chatEvt = client.getEvent<typeof ChatEvent>("Chat");
|
|
96
|
-
const key = await chatEvt.addListener({ roomId: "room-1" }, async (data) => {
|
|
97
|
-
console.log("메시지:", data.message);
|
|
98
|
-
});
|
|
99
|
-
await chatEvt.removeListener(key);
|
|
100
|
-
|
|
101
|
-
// 발행
|
|
102
|
-
await chatEvt.emit((info) => info.roomId === "room-1", { message: "hello" });
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
### ORM 원격 실행
|
|
106
|
-
|
|
107
|
-
```typescript
|
|
108
|
-
import { createOrmClientConnector } from "@simplysm/service-client";
|
|
109
|
-
|
|
110
|
-
const connector = createOrmClientConnector(client);
|
|
111
|
-
const result = await connector.connect(
|
|
112
|
-
{ DbClass: MyDbContext, connOpt: { configName: "main" } },
|
|
113
|
-
async (db) => db.users.select().execute(),
|
|
114
|
-
);
|
|
115
|
-
```
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
# EventClient
|
|
2
|
-
|
|
3
|
-
서버 이벤트 구독/발행 관리 인터페이스. 재연결 시 자동 재구독된다. 팩토리 함수 `createEventClient`로 생성한다.
|
|
4
|
-
|
|
5
|
-
```typescript
|
|
6
|
-
export interface EventClient {
|
|
7
|
-
getEvent<TEventDef extends ServiceEventDef>(
|
|
8
|
-
eventName: string,
|
|
9
|
-
): ClientEventProxy<TEventDef>;
|
|
10
|
-
addListener<TEventDef extends ServiceEventDef>(
|
|
11
|
-
eventName: string,
|
|
12
|
-
info: TEventDef["$info"],
|
|
13
|
-
cb: (data: TEventDef["$data"]) => PromiseLike<void>,
|
|
14
|
-
): Promise<string>;
|
|
15
|
-
removeListener(key: string): Promise<void>;
|
|
16
|
-
emit<TEventDef extends ServiceEventDef>(
|
|
17
|
-
eventName: string,
|
|
18
|
-
infoSelector: (item: TEventDef["$info"]) => boolean,
|
|
19
|
-
data: TEventDef["$data"],
|
|
20
|
-
): Promise<void>;
|
|
21
|
-
resubscribeAll(): Promise<void>;
|
|
22
|
-
}
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## Members
|
|
26
|
-
|
|
27
|
-
| Member | Kind | Type | Description |
|
|
28
|
-
|--------|------|------|-------------|
|
|
29
|
-
| `getEvent(eventName)` | method | `ClientEventProxy<TEventDef>` | 이벤트 이름과 타입을 캡처한 프록시 반환 |
|
|
30
|
-
| `addListener(eventName, info, cb)` | method | `Promise<string>` | 이벤트 리스너 등록. 반환값은 `key` (제거 시 사용) |
|
|
31
|
-
| `removeListener(key)` | method | `Promise<void>` | 등록된 이벤트 리스너 제거 |
|
|
32
|
-
| `emit(eventName, infoSelector, data)` | method | `Promise<void>` | `infoSelector`가 참인 대상에게 데이터 발행 |
|
|
33
|
-
| `resubscribeAll()` | method | `Promise<void>` | 재연결 시 모든 리스너를 서버에 재등록. `ServiceClient`가 자동 호출 |
|
|
34
|
-
|
|
35
|
-
## Related Types
|
|
36
|
-
|
|
37
|
-
### `ClientEventProxy`
|
|
38
|
-
|
|
39
|
-
`getEvent()`가 반환하는 이벤트 프록시 인터페이스. 이벤트 이름과 제네릭 타입이 캡처되어 있어 호출 시 반복 지정이 불필요하다.
|
|
40
|
-
|
|
41
|
-
```typescript
|
|
42
|
-
export interface ClientEventProxy<TEventDef extends ServiceEventDef> {
|
|
43
|
-
addListener(
|
|
44
|
-
info: TEventDef["$info"],
|
|
45
|
-
cb: (data: TEventDef["$data"]) => PromiseLike<void>,
|
|
46
|
-
): Promise<string>;
|
|
47
|
-
removeListener(key: string): Promise<void>;
|
|
48
|
-
emit(
|
|
49
|
-
infoSelector: (item: TEventDef["$info"]) => boolean,
|
|
50
|
-
data: TEventDef["$data"],
|
|
51
|
-
): Promise<void>;
|
|
52
|
-
}
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
| Member | Type | Description |
|
|
56
|
-
|--------|------|-------------|
|
|
57
|
-
| `addListener(info, cb)` | `Promise<string>` | 이벤트 리스너 등록. 반환값은 `key` (제거 시 사용) |
|
|
58
|
-
| `removeListener(key)` | `Promise<void>` | 등록된 이벤트 리스너 제거 |
|
|
59
|
-
| `emit(infoSelector, data)` | `Promise<void>` | `infoSelector`가 참인 대상에게 데이터 발행 |
|
|
60
|
-
|
|
61
|
-
## `createEventClient`
|
|
62
|
-
|
|
63
|
-
`EventClient` 팩토리 함수.
|
|
64
|
-
|
|
65
|
-
```typescript
|
|
66
|
-
export function createEventClient(transport: ServiceTransport): EventClient;
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
| Parameter | Type | Description |
|
|
70
|
-
|-----------|------|-------------|
|
|
71
|
-
| `transport` | [`ServiceTransport`](../transport/service-transport.md) | 서비스 전송 계층 |
|
|
72
|
-
|
|
73
|
-
## Usage
|
|
74
|
-
|
|
75
|
-
```typescript
|
|
76
|
-
// getEvent() 방식 (권장 — 이벤트 이름과 타입이 캡처됨)
|
|
77
|
-
const chatEvt = client.getEvent<typeof ChatEvent>("Chat");
|
|
78
|
-
const key = await chatEvt.addListener({ roomId: "room-1" }, async (data) => {
|
|
79
|
-
console.log("메시지:", data.message);
|
|
80
|
-
});
|
|
81
|
-
await chatEvt.removeListener(key);
|
|
82
|
-
|
|
83
|
-
// 이벤트 발행
|
|
84
|
-
await chatEvt.emit(
|
|
85
|
-
(info) => info.roomId === "room-1",
|
|
86
|
-
{ message: "hello" },
|
|
87
|
-
);
|
|
88
|
-
```
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
# FileClient
|
|
2
|
-
|
|
3
|
-
파일 업로드(POST)/다운로드(GET) 인터페이스. 팩토리 함수 `createFileClient`로 생성한다.
|
|
4
|
-
|
|
5
|
-
```typescript
|
|
6
|
-
export interface FileClient {
|
|
7
|
-
download(relPath: string): Promise<Bytes>;
|
|
8
|
-
upload(
|
|
9
|
-
files: File[] | FileCollection | { name: string; data: BlobInput }[],
|
|
10
|
-
authToken: string,
|
|
11
|
-
): Promise<ServiceUploadResult[]>;
|
|
12
|
-
}
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Members
|
|
16
|
-
|
|
17
|
-
| Member | Kind | Type | Description |
|
|
18
|
-
|--------|------|------|-------------|
|
|
19
|
-
| `download(relPath)` | method | `Promise<Bytes>` | `GET {hostUrl}{relPath}`로 파일 다운로드. `Uint8Array` 반환 |
|
|
20
|
-
| `upload(files, authToken)` | method | `Promise<ServiceUploadResult[]>` | `POST {hostUrl}/upload`로 파일 업로드. `multipart/form-data` 사용 |
|
|
21
|
-
|
|
22
|
-
### `upload` Parameters
|
|
23
|
-
|
|
24
|
-
| Parameter | Type | Description |
|
|
25
|
-
|-----------|------|-------------|
|
|
26
|
-
| `files` | `File[] \| FileCollection \| { name: string; data: BlobInput }[]` | 업로드할 파일 목록 |
|
|
27
|
-
| `authToken` | `string` | 인증 토큰 (`Authorization: Bearer {token}` 헤더로 전송) |
|
|
28
|
-
|
|
29
|
-
## `createFileClient`
|
|
30
|
-
|
|
31
|
-
`FileClient` 팩토리 함수.
|
|
32
|
-
|
|
33
|
-
```typescript
|
|
34
|
-
export function createFileClient(hostUrl: string, clientName: string): FileClient;
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
| Parameter | Type | Description |
|
|
38
|
-
|-----------|------|-------------|
|
|
39
|
-
| `hostUrl` | `string` | 서버 기본 URL (`http://host:port` 형식) |
|
|
40
|
-
| `clientName` | `string` | 클라이언트 식별자 (`x-sd-client-name` 헤더로 전송) |
|
|
41
|
-
|
|
42
|
-
## Usage
|
|
43
|
-
|
|
44
|
-
```typescript
|
|
45
|
-
// 일반적으로 ServiceClient를 통해 간접 사용한다
|
|
46
|
-
// 파일 업로드 (auth() 호출 후 사용)
|
|
47
|
-
const results = await client.uploadFile([
|
|
48
|
-
new File(["content"], "file.txt", { type: "text/plain" }),
|
|
49
|
-
]);
|
|
50
|
-
|
|
51
|
-
// 커스텀 데이터 업로드
|
|
52
|
-
const results2 = await client.uploadFile([
|
|
53
|
-
{ name: "report.csv", data: "col1,col2\nval1,val2" },
|
|
54
|
-
]);
|
|
55
|
-
|
|
56
|
-
// 파일 다운로드
|
|
57
|
-
const bytes = await client.downloadFileBuffer("/uploaded/file.txt");
|
|
58
|
-
```
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
# OrmClientConnector
|
|
2
|
-
|
|
3
|
-
`DbContext` 트랜잭션 연결을 원격 서버에서 실행하는 헬퍼 인터페이스. 팩토리 함수 `createOrmClientConnector`로 생성한다.
|
|
4
|
-
|
|
5
|
-
```typescript
|
|
6
|
-
export interface OrmClientConnector {
|
|
7
|
-
connect<T extends DbContext, R>(
|
|
8
|
-
config: OrmConnectOptions<T>,
|
|
9
|
-
callback: (db: T) => Promise<R> | R,
|
|
10
|
-
): Promise<R>;
|
|
11
|
-
connectWithoutTransaction<T extends DbContext, R>(
|
|
12
|
-
config: OrmConnectOptions<T>,
|
|
13
|
-
callback: (db: T) => Promise<R> | R,
|
|
14
|
-
): Promise<R>;
|
|
15
|
-
}
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## Members
|
|
19
|
-
|
|
20
|
-
| Member | Kind | Type | Description |
|
|
21
|
-
|--------|------|------|-------------|
|
|
22
|
-
| `connect(config, callback)` | method | `Promise<R>` | 트랜잭션 모드로 연결. FK 제약 위반 시 사용자 친화적 에러 메시지로 변환 |
|
|
23
|
-
| `connectWithoutTransaction(config, callback)` | method | `Promise<R>` | 트랜잭션 없이 연결 |
|
|
24
|
-
|
|
25
|
-
## Related Types
|
|
26
|
-
|
|
27
|
-
### `OrmConnectOptions`
|
|
28
|
-
|
|
29
|
-
ORM 원격 연결에 필요한 옵션 인터페이스.
|
|
30
|
-
|
|
31
|
-
```typescript
|
|
32
|
-
export interface OrmConnectOptions<T extends DbContext> {
|
|
33
|
-
DbClass: new (executor: DbContextExecutor, opt: { database: string; schema?: string }) => T;
|
|
34
|
-
connOpt: DbConnOptions & { configName: string };
|
|
35
|
-
dbContextOpt?: {
|
|
36
|
-
database: string;
|
|
37
|
-
schema: string;
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
| Field | Type | Required | Description |
|
|
43
|
-
|-------|------|----------|-------------|
|
|
44
|
-
| `DbClass` | `new (executor: DbContextExecutor, opt: { database: string; schema?: string }) => T` | required | 사용할 `DbContext` 서브클래스 생성자 |
|
|
45
|
-
| `connOpt` | `DbConnOptions & { configName: string }` | required | DB 연결 옵션. `configName`은 서버 설정 키 |
|
|
46
|
-
| `dbContextOpt` | `{ database: string; schema: string }` | optional | DB 컨텍스트 옵션. 생략하면 서버에서 조회한 `info.database`/`info.schema` 사용 |
|
|
47
|
-
|
|
48
|
-
## `createOrmClientConnector`
|
|
49
|
-
|
|
50
|
-
`OrmClientConnector` 팩토리 함수.
|
|
51
|
-
|
|
52
|
-
```typescript
|
|
53
|
-
export function createOrmClientConnector(serviceClient: ServiceClient): OrmClientConnector;
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
| Parameter | Type | Description |
|
|
57
|
-
|-----------|------|-------------|
|
|
58
|
-
| `serviceClient` | [`ServiceClient`](../main/service-client.md) | 이미 연결된 서비스 클라이언트 |
|
|
59
|
-
|
|
60
|
-
## Usage
|
|
61
|
-
|
|
62
|
-
```typescript
|
|
63
|
-
import { createOrmClientConnector } from "@simplysm/service-client";
|
|
64
|
-
|
|
65
|
-
const connector = createOrmClientConnector(client);
|
|
66
|
-
|
|
67
|
-
// 트랜잭션 모드
|
|
68
|
-
const result = await connector.connect(
|
|
69
|
-
{
|
|
70
|
-
DbClass: MyDbContext,
|
|
71
|
-
connOpt: { configName: "main", username: "user", password: "pass" },
|
|
72
|
-
},
|
|
73
|
-
async (db) => {
|
|
74
|
-
return db.myTable.select((item) => ({ id: item.id, name: item.name }));
|
|
75
|
-
},
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
// 트랜잭션 없이
|
|
79
|
-
const result2 = await connector.connectWithoutTransaction(
|
|
80
|
-
{ DbClass: MyDbContext, connOpt: { configName: "main" } },
|
|
81
|
-
async (db) => db.myTable.select(),
|
|
82
|
-
);
|
|
83
|
-
```
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
# OrmClientDbContextExecutor
|
|
2
|
-
|
|
3
|
-
`DbContextExecutor` 인터페이스 구현체. `DbContext`의 쿼리 실행을 서버 `OrmService`에 원격 호출한다. 직접 사용보다 [`createOrmClientConnector`](./orm-client-connector.md)를 통해 사용하는 것을 권장한다.
|
|
4
|
-
|
|
5
|
-
```typescript
|
|
6
|
-
export class OrmClientDbContextExecutor implements DbContextExecutor {
|
|
7
|
-
constructor(
|
|
8
|
-
private readonly _client: ServiceClient,
|
|
9
|
-
private readonly _opt: DbConnOptions & { configName: string },
|
|
10
|
-
);
|
|
11
|
-
}
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
## Members
|
|
15
|
-
|
|
16
|
-
| Member | Kind | Type | Description |
|
|
17
|
-
|--------|------|------|-------------|
|
|
18
|
-
| `getInfo()` | method | `Promise<{ dialect: Dialect; database?: string; schema?: string }>` | 서버에서 DB dialect, database, schema 조회 |
|
|
19
|
-
| `connect()` | method | `Promise<void>` | 서버에서 DB 연결 생성. `_connId` 할당 |
|
|
20
|
-
| `beginTransaction(isolationLevel?)` | method | `Promise<void>` | 트랜잭션 시작 |
|
|
21
|
-
| `commitTransaction()` | method | `Promise<void>` | 트랜잭션 커밋 |
|
|
22
|
-
| `rollbackTransaction()` | method | `Promise<void>` | 트랜잭션 롤백 |
|
|
23
|
-
| `close()` | method | `Promise<void>` | DB 연결 종료 및 `_connId` 해제 |
|
|
24
|
-
| `executeDefs(defs, options?)` | method | `Promise<T[][]>` | QueryDef 배열을 서버에서 실행 |
|
|
25
|
-
| `executeParametrized(query, params?)` | method | `Promise<unknown[][]>` | 파라미터화된 쿼리를 서버에서 실행 |
|
|
26
|
-
| `bulkInsert(tableName, columnDefs, records)` | method | `Promise<void>` | 대량 INSERT를 서버에서 실행 |
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
# ServiceClient
|
|
2
|
-
|
|
3
|
-
WebSocket 기반 서비스 클라이언트의 최상위 파사드 클래스. [`SocketProvider`](../transport/socket-provider.md), [`ClientProtocolWrapper`](../protocol/client-protocol-wrapper.md), [`ServiceTransport`](../transport/service-transport.md), [`EventClient`](../features/event-client.md), [`FileClient`](../features/file-client.md)를 내부적으로 조합한다.
|
|
4
|
-
|
|
5
|
-
```typescript
|
|
6
|
-
export class ServiceClient extends EventEmitter<ServiceClientEvents> {
|
|
7
|
-
constructor(
|
|
8
|
-
public readonly name: string,
|
|
9
|
-
public readonly options: ServiceConnectionOptions,
|
|
10
|
-
);
|
|
11
|
-
get connected(): boolean;
|
|
12
|
-
get hostUrl(): string;
|
|
13
|
-
getService<TService>(serviceName: string): ServiceProxy<TService>;
|
|
14
|
-
getEvent<TEventDef extends ServiceEventDef>(eventName: string): ClientEventProxy<TEventDef>;
|
|
15
|
-
connect(): Promise<void>;
|
|
16
|
-
close(): Promise<void>;
|
|
17
|
-
send(
|
|
18
|
-
serviceName: string,
|
|
19
|
-
methodName: string,
|
|
20
|
-
params: unknown[],
|
|
21
|
-
progress?: ServiceProgress,
|
|
22
|
-
): Promise<unknown>;
|
|
23
|
-
auth(token: string): Promise<void>;
|
|
24
|
-
addListener<TEventDef extends ServiceEventDef>(
|
|
25
|
-
eventName: string,
|
|
26
|
-
info: TEventDef["$info"],
|
|
27
|
-
cb: (data: TEventDef["$data"]) => PromiseLike<void>,
|
|
28
|
-
): Promise<string>;
|
|
29
|
-
removeListener(key: string): Promise<void>;
|
|
30
|
-
emitEvent<TEventDef extends ServiceEventDef>(
|
|
31
|
-
eventName: string,
|
|
32
|
-
infoSelector: (item: TEventDef["$info"]) => boolean,
|
|
33
|
-
data: TEventDef["$data"],
|
|
34
|
-
): Promise<void>;
|
|
35
|
-
uploadFile(
|
|
36
|
-
files: File[] | FileCollection | { name: string; data: BlobInput }[],
|
|
37
|
-
): Promise<ServiceUploadResult[]>;
|
|
38
|
-
downloadFileBuffer(relPath: string): Promise<Bytes>;
|
|
39
|
-
}
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
## Constructor Parameters
|
|
43
|
-
|
|
44
|
-
| Parameter | Type | Description |
|
|
45
|
-
|-----------|------|-------------|
|
|
46
|
-
| `name` | `string` | 클라이언트 식별자 (WebSocket URL 파라미터 및 HTTP 헤더로 전달됨) |
|
|
47
|
-
| `options` | [`ServiceConnectionOptions`](../types/service-connection-options.md) | 연결 옵션 |
|
|
48
|
-
|
|
49
|
-
## Members
|
|
50
|
-
|
|
51
|
-
| Member | Kind | Type | Description |
|
|
52
|
-
|--------|------|------|-------------|
|
|
53
|
-
| `name` | property | `string` | 클라이언트 식별자 (읽기 전용) |
|
|
54
|
-
| `options` | property | `ServiceConnectionOptions` | 연결 옵션 (읽기 전용) |
|
|
55
|
-
| `connected` | getter | `boolean` | 현재 WebSocket 연결 상태 |
|
|
56
|
-
| `hostUrl` | getter | `string` | HTTP 기본 URL (`http(s)://host:port`) |
|
|
57
|
-
| `connect()` | method | `Promise<void>` | WebSocket 연결 시작 |
|
|
58
|
-
| `close()` | method | `Promise<void>` | WebSocket 연결 종료 및 protocol dispose |
|
|
59
|
-
| `auth(token)` | method | `Promise<void>` | 서버에 인증 토큰 전송. 재연결 시 자동 재인증됨 |
|
|
60
|
-
| `getService<TService>(serviceName)` | method | `ServiceProxy<TService>` | 타입 안전한 서비스 프록시 반환 |
|
|
61
|
-
| `getEvent<TEventDef>(eventName)` | method | `ClientEventProxy<TEventDef>` | 타입 안전한 이벤트 프록시 반환 |
|
|
62
|
-
| `send(serviceName, methodName, params, progress?)` | method | `Promise<unknown>` | 서비스 메서드 원격 호출 |
|
|
63
|
-
| `addListener(eventName, info, cb)` | method | `Promise<string>` | 서버 이벤트 구독. 연결 상태여야 함 |
|
|
64
|
-
| `removeListener(key)` | method | `Promise<void>` | 서버 이벤트 구독 해제 |
|
|
65
|
-
| `emitEvent(eventName, infoSelector, data)` | method | `Promise<void>` | 서버 이벤트 발행 |
|
|
66
|
-
| `uploadFile(files)` | method | `Promise<ServiceUploadResult[]>` | 파일 업로드. `auth()` 호출 후 사용해야 함 |
|
|
67
|
-
| `downloadFileBuffer(relPath)` | method | `Promise<Bytes>` | 파일 다운로드 (`Uint8Array` 반환) |
|
|
68
|
-
|
|
69
|
-
## Events (EventEmitter)
|
|
70
|
-
|
|
71
|
-
`ServiceClient`는 `EventEmitter<ServiceClientEvents>`를 상속한다. `.on()`/`.off()`로 이벤트를 구독한다.
|
|
72
|
-
|
|
73
|
-
| Event | Data Type | Description |
|
|
74
|
-
|-------|-----------|-------------|
|
|
75
|
-
| `request-progress` | `ServiceProgressState` | 요청 전송 progress |
|
|
76
|
-
| `response-progress` | `ServiceProgressState` | 응답 수신 progress |
|
|
77
|
-
| `server-progress` | `ServiceProgressState` | 서버 내부 처리 progress |
|
|
78
|
-
| `state` | `"connected" \| "closed" \| "reconnecting"` | 연결 상태 변경 |
|
|
79
|
-
|
|
80
|
-
## Related Types
|
|
81
|
-
|
|
82
|
-
### `ServiceProxy`
|
|
83
|
-
|
|
84
|
-
`TService`의 모든 메서드 반환 타입을 `Promise`로 래핑하는 유틸리티 타입. `getService<TService>()`의 반환 타입으로 사용된다.
|
|
85
|
-
|
|
86
|
-
```typescript
|
|
87
|
-
export type ServiceProxy<TService> = {
|
|
88
|
-
[K in keyof TService]: TService[K] extends (...args: infer P) => infer R
|
|
89
|
-
? (...args: P) => Promise<Awaited<R>>
|
|
90
|
-
: never;
|
|
91
|
-
};
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
함수가 아닌 속성(`never`)은 타입에서 제외된다.
|
|
95
|
-
|
|
96
|
-
## `createServiceClient`
|
|
97
|
-
|
|
98
|
-
`ServiceClient` 팩토리 함수. `new ServiceClient(name, options)`와 동일하다.
|
|
99
|
-
|
|
100
|
-
```typescript
|
|
101
|
-
export function createServiceClient(name: string, options: ServiceConnectionOptions): ServiceClient;
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
| Parameter | Type | Description |
|
|
105
|
-
|-----------|------|-------------|
|
|
106
|
-
| `name` | `string` | 클라이언트 식별자 |
|
|
107
|
-
| `options` | `ServiceConnectionOptions` | 연결 옵션 |
|
|
108
|
-
|
|
109
|
-
## Usage
|
|
110
|
-
|
|
111
|
-
```typescript
|
|
112
|
-
import { ServiceClient } from "@simplysm/service-client";
|
|
113
|
-
|
|
114
|
-
const client = new ServiceClient("my-app", {
|
|
115
|
-
host: "localhost",
|
|
116
|
-
port: 3000,
|
|
117
|
-
ssl: false,
|
|
118
|
-
maxReconnectCount: 10,
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
await client.connect();
|
|
122
|
-
await client.auth("my-auth-token");
|
|
123
|
-
|
|
124
|
-
// 타입 안전한 서비스 호출
|
|
125
|
-
const userSvc = client.getService<UserService>("User");
|
|
126
|
-
const users = await userSvc.getList();
|
|
127
|
-
|
|
128
|
-
// 이벤트 프록시 (권장)
|
|
129
|
-
const chatEvt = client.getEvent<typeof ChatEvent>("Chat");
|
|
130
|
-
const key = await chatEvt.addListener({ roomId: "room-1" }, async (data) => {
|
|
131
|
-
console.log("메시지:", data.message);
|
|
132
|
-
});
|
|
133
|
-
await chatEvt.removeListener(key);
|
|
134
|
-
|
|
135
|
-
// 연결 상태 모니터링
|
|
136
|
-
client.on("state", (state) => {
|
|
137
|
-
console.log("상태:", state); // "connected" | "closed" | "reconnecting"
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
// 파일 업로드
|
|
141
|
-
const results = await client.uploadFile([{ name: "file.txt", data: "hello" }]);
|
|
142
|
-
|
|
143
|
-
// 파일 다운로드
|
|
144
|
-
const bytes = await client.downloadFileBuffer("/files/report.pdf");
|
|
145
|
-
|
|
146
|
-
await client.close();
|
|
147
|
-
```
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
# ClientProtocolWrapper
|
|
2
|
-
|
|
3
|
-
메시지 인코딩/디코딩 인터페이스. 데이터 크기가 30KB 이상이면 Web Worker로 처리를 오프로드한다. 팩토리 함수 `createClientProtocolWrapper`로 생성한다.
|
|
4
|
-
|
|
5
|
-
```typescript
|
|
6
|
-
export interface ClientProtocolWrapper {
|
|
7
|
-
encode(uuid: string, message: ServiceMessage): Promise<{ chunks: Bytes[]; totalSize: number }>;
|
|
8
|
-
decode(bytes: Bytes): Promise<ServiceMessageDecodeResult<ServiceMessage>>;
|
|
9
|
-
dispose(): void;
|
|
10
|
-
}
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Members
|
|
14
|
-
|
|
15
|
-
| Member | Kind | Type | Description |
|
|
16
|
-
|--------|------|------|-------------|
|
|
17
|
-
| `encode(uuid, message)` | method | `Promise<{ chunks: Bytes[]; totalSize: number }>` | 메시지를 바이너리 청크로 인코딩. 큰 데이터는 Worker로 오프로드 |
|
|
18
|
-
| `decode(bytes)` | method | `Promise<ServiceMessageDecodeResult<ServiceMessage>>` | 바이너리를 메시지로 디코딩. 큰 데이터는 Worker로 오프로드 (zero-copy 전송) |
|
|
19
|
-
| `dispose()` | method | `void` | 내부 `ServiceProtocol`과 Worker resolver 맵 정리 |
|
|
20
|
-
|
|
21
|
-
## `createClientProtocolWrapper`
|
|
22
|
-
|
|
23
|
-
`ClientProtocolWrapper` 팩토리 함수.
|
|
24
|
-
|
|
25
|
-
```typescript
|
|
26
|
-
export function createClientProtocolWrapper(protocol: ServiceProtocol): ClientProtocolWrapper;
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
| Parameter | Type | Description |
|
|
30
|
-
|-----------|------|-------------|
|
|
31
|
-
| `protocol` | `ServiceProtocol` | `@simplysm/service-common`의 `createServiceProtocol()`로 생성한 프로토콜 인스턴스 |
|
|
32
|
-
|
|
33
|
-
내부 동작:
|
|
34
|
-
- 임계값: 30KB (`30 * 1024` bytes)
|
|
35
|
-
- Worker가 지원되지 않는 환경에서는 메인 스레드에서 처리
|
|
36
|
-
- Worker는 모듈 스코프 싱글턴으로 공유됨 (`createClientProtocolWrapper` 여러 번 호출해도 Worker는 하나)
|
|
37
|
-
- Worker 작업은 60초 타임아웃 후 자동 reject (메모리 누수 방지)
|
|
38
|
-
- `decode` 시 Worker로 `ArrayBuffer` 소유권 이전 (zero-copy)
|
|
39
|
-
|
|
40
|
-
**Worker 생성 패턴 제약:**
|
|
41
|
-
|
|
42
|
-
Worker 생성 시 반드시 `new Worker(new URL("...", import.meta.url))` 직접 패턴을 사용해야 한다. sd-cli의 esbuild Worker 번들링 플러그인(`sd-worker-bundle`)이 AST에서 이 패턴만 인식하여 Worker 파일을 별도 번들로 분리한다. 래퍼 함수로 감싸면 플러그인이 인식하지 못하고 브라우저에서 404 에러가 발생한다.
|
|
43
|
-
|
|
44
|
-
## Usage
|
|
45
|
-
|
|
46
|
-
```typescript
|
|
47
|
-
import { createClientProtocolWrapper } from "@simplysm/service-client";
|
|
48
|
-
import { createServiceProtocol } from "@simplysm/service-common";
|
|
49
|
-
|
|
50
|
-
const protocol = createServiceProtocol();
|
|
51
|
-
const wrapper = createClientProtocolWrapper(protocol);
|
|
52
|
-
|
|
53
|
-
const { chunks, totalSize } = await wrapper.encode("uuid-1", { name: "User.getList", body: [] });
|
|
54
|
-
// chunks: Bytes[] — 전송할 청크 배열
|
|
55
|
-
// totalSize: number — 전체 크기 (progress 표시용)
|
|
56
|
-
|
|
57
|
-
// 사용 완료 후 반드시 정리
|
|
58
|
-
wrapper.dispose();
|
|
59
|
-
```
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
# ServiceTransport
|
|
2
|
-
|
|
3
|
-
요청-응답 매핑, progress 중계, 서버 이벤트 디스패치를 담당하는 인터페이스. 팩토리 함수 `createServiceTransport`로 생성한다.
|
|
4
|
-
|
|
5
|
-
```typescript
|
|
6
|
-
export interface ServiceTransport {
|
|
7
|
-
on<K extends keyof ServiceTransportEvents & string>(
|
|
8
|
-
type: K,
|
|
9
|
-
listener: (data: ServiceTransportEvents[K]) => void,
|
|
10
|
-
): void;
|
|
11
|
-
off<K extends keyof ServiceTransportEvents & string>(
|
|
12
|
-
type: K,
|
|
13
|
-
listener: (data: ServiceTransportEvents[K]) => void,
|
|
14
|
-
): void;
|
|
15
|
-
send(message: ServiceClientMessage, progress?: ServiceProgress): Promise<unknown>;
|
|
16
|
-
}
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## Members
|
|
20
|
-
|
|
21
|
-
| Member | Kind | Type | Description |
|
|
22
|
-
|--------|------|------|-------------|
|
|
23
|
-
| `on(type, listener)` | method | `void` | 이벤트 리스너 등록 |
|
|
24
|
-
| `off(type, listener)` | method | `void` | 이벤트 리스너 제거 |
|
|
25
|
-
| `send(message, progress?)` | method | `Promise<unknown>` | 서버에 메시지 전송하고 응답 대기 |
|
|
26
|
-
|
|
27
|
-
## Related Types
|
|
28
|
-
|
|
29
|
-
### `ServiceTransportEvents`
|
|
30
|
-
|
|
31
|
-
`ServiceTransport`에서 발생하는 이벤트 타입 맵.
|
|
32
|
-
|
|
33
|
-
```typescript
|
|
34
|
-
export interface ServiceTransportEvents {
|
|
35
|
-
event: { keys: string[]; data: unknown };
|
|
36
|
-
}
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
| Event | Type | Description |
|
|
40
|
-
|-------|------|-------------|
|
|
41
|
-
| `event` | `{ keys: string[]; data: unknown }` | 서버에서 발행된 이벤트 수신 |
|
|
42
|
-
|
|
43
|
-
## `createServiceTransport`
|
|
44
|
-
|
|
45
|
-
`ServiceTransport` 팩토리 함수.
|
|
46
|
-
|
|
47
|
-
```typescript
|
|
48
|
-
export function createServiceTransport(
|
|
49
|
-
socket: SocketProvider,
|
|
50
|
-
protocol: ClientProtocolWrapper,
|
|
51
|
-
): ServiceTransport;
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
| Parameter | Type | Description |
|
|
55
|
-
|-----------|------|-------------|
|
|
56
|
-
| `socket` | [`SocketProvider`](./socket-provider.md) | WebSocket 소켓 제공자 |
|
|
57
|
-
| `protocol` | [`ClientProtocolWrapper`](../protocol/client-protocol-wrapper.md) | 인코딩/디코딩 래퍼 |
|
|
58
|
-
|
|
59
|
-
내부 동작:
|
|
60
|
-
- `uuid` 기반 요청-응답 `Map`으로 비동기 응답을 매핑
|
|
61
|
-
- 소켓 `closed`/`reconnecting` 상태 시 대기 중인 모든 요청을 reject
|
|
62
|
-
- 분할 메시지의 progress 상태를 추적하여 완료 시 100% 이벤트 전송
|
|
63
|
-
- 소켓 `message` 이벤트를 수신하여 `progress`, `response`, `error`, `evt:on` 타입으로 분기 처리
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
# SocketProvider
|
|
2
|
-
|
|
3
|
-
WebSocket 연결, 재연결, 하트비트를 관리하는 인터페이스. 팩토리 함수 `createSocketProvider`로 생성한다.
|
|
4
|
-
|
|
5
|
-
```typescript
|
|
6
|
-
export interface SocketProvider {
|
|
7
|
-
readonly clientName: string;
|
|
8
|
-
readonly connected: boolean;
|
|
9
|
-
on<K extends keyof SocketProviderEvents & string>(
|
|
10
|
-
type: K,
|
|
11
|
-
listener: (data: SocketProviderEvents[K]) => void,
|
|
12
|
-
): void;
|
|
13
|
-
off<K extends keyof SocketProviderEvents & string>(
|
|
14
|
-
type: K,
|
|
15
|
-
listener: (data: SocketProviderEvents[K]) => void,
|
|
16
|
-
): void;
|
|
17
|
-
connect(): Promise<void>;
|
|
18
|
-
close(): Promise<void>;
|
|
19
|
-
send(data: Bytes): Promise<void>;
|
|
20
|
-
}
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## Members
|
|
24
|
-
|
|
25
|
-
| Member | Kind | Type | Description |
|
|
26
|
-
|--------|------|------|-------------|
|
|
27
|
-
| `clientName` | property | `string` | 클라이언트 식별자 (읽기 전용) |
|
|
28
|
-
| `connected` | getter | `boolean` | 현재 연결 상태 |
|
|
29
|
-
| `on(type, listener)` | method | `void` | 이벤트 리스너 등록 |
|
|
30
|
-
| `off(type, listener)` | method | `void` | 이벤트 리스너 제거 |
|
|
31
|
-
| `connect()` | method | `Promise<void>` | WebSocket 연결 시작 |
|
|
32
|
-
| `close()` | method | `Promise<void>` | WebSocket 연결 종료 |
|
|
33
|
-
| `send(data)` | method | `Promise<void>` | 바이너리 데이터 전송. 연결 복구 대기 후 전송 |
|
|
34
|
-
|
|
35
|
-
## Related Types
|
|
36
|
-
|
|
37
|
-
### `SocketProviderEvents`
|
|
38
|
-
|
|
39
|
-
`SocketProvider`에서 발생하는 이벤트 타입 맵.
|
|
40
|
-
|
|
41
|
-
```typescript
|
|
42
|
-
export interface SocketProviderEvents {
|
|
43
|
-
message: Bytes;
|
|
44
|
-
state: "connected" | "closed" | "reconnecting";
|
|
45
|
-
}
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
| Event | Type | Description |
|
|
49
|
-
|-------|------|-------------|
|
|
50
|
-
| `message` | `Bytes` | 서버로부터 바이너리 메시지 수신 |
|
|
51
|
-
| `state` | `"connected" \| "closed" \| "reconnecting"` | 연결 상태 변경 |
|
|
52
|
-
|
|
53
|
-
## `createSocketProvider`
|
|
54
|
-
|
|
55
|
-
`SocketProvider` 팩토리 함수.
|
|
56
|
-
|
|
57
|
-
```typescript
|
|
58
|
-
export function createSocketProvider(
|
|
59
|
-
url: string,
|
|
60
|
-
clientName: string,
|
|
61
|
-
maxReconnectCount: number,
|
|
62
|
-
): SocketProvider;
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
| Parameter | Type | Description |
|
|
66
|
-
|-----------|------|-------------|
|
|
67
|
-
| `url` | `string` | WebSocket 서버 URL (`ws://` 또는 `wss://`) |
|
|
68
|
-
| `clientName` | `string` | 클라이언트 식별자 (URL 파라미터 `clientName`으로 전달됨) |
|
|
69
|
-
| `maxReconnectCount` | `number` | 최대 재연결 횟수. `0`이면 재연결 안 함 |
|
|
70
|
-
|
|
71
|
-
내부 동작:
|
|
72
|
-
- 하트비트: 5초마다 ping 전송, 30초 응답 없으면 재연결 시도
|
|
73
|
-
- 재연결: 연결 끊김 시 3초 간격으로 `maxReconnectCount`회 재시도
|
|
74
|
-
- Node.js 환경에서 `globalThis.WebSocket`이 없으면 `ws` 패키지로 폴리필
|
|
75
|
-
- ping/pong은 1바이트 패킷(ping: `0x01`, pong: `0x02`)으로 처리
|
|
76
|
-
|
|
77
|
-
## Usage
|
|
78
|
-
|
|
79
|
-
```typescript
|
|
80
|
-
import { createSocketProvider } from "@simplysm/service-client";
|
|
81
|
-
|
|
82
|
-
const socket = createSocketProvider("ws://localhost:3000/ws", "my-app", 10);
|
|
83
|
-
|
|
84
|
-
socket.on("state", (state) => {
|
|
85
|
-
console.log("소켓 상태:", state); // "connected" | "closed" | "reconnecting"
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
socket.on("message", (bytes) => {
|
|
89
|
-
console.log("메시지 수신:", bytes.length, "bytes");
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
await socket.connect();
|
|
93
|
-
await socket.send(new Uint8Array([1, 2, 3]));
|
|
94
|
-
await socket.close();
|
|
95
|
-
```
|
package/docs/types/blob-input.md
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
# BrowserWorker
|
|
2
|
-
|
|
3
|
-
Web Worker 최소 인터페이스. DOM lib 없이도 타입체크가 통과하도록 하는 추상 타입이다.
|
|
4
|
-
|
|
5
|
-
```typescript
|
|
6
|
-
export interface BrowserWorker {
|
|
7
|
-
onmessage: ((event: MessageEvent) => void) | null;
|
|
8
|
-
onerror: ((event: Event) => void) | null;
|
|
9
|
-
postMessage(message: unknown, transfer?: unknown[]): void;
|
|
10
|
-
terminate(): void;
|
|
11
|
-
}
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
## Fields
|
|
15
|
-
|
|
16
|
-
| Field | Type | Description |
|
|
17
|
-
|-------|------|-------------|
|
|
18
|
-
| `onmessage` | `((event: MessageEvent) => void) \| null` | 메시지 수신 핸들러 |
|
|
19
|
-
| `onerror` | `((event: Event) => void) \| null` | 에러 핸들러 |
|
|
20
|
-
| `postMessage(message, transfer?)` | `void` | Worker에 메시지 전송 |
|
|
21
|
-
| `terminate()` | `void` | Worker 종료 |
|
|
22
|
-
|
|
23
|
-
## Related Functions
|
|
24
|
-
|
|
25
|
-
### `isBrowserWorkerSupported`
|
|
26
|
-
|
|
27
|
-
DOM Worker API 지원 여부를 확인한다. `"Worker" in globalThis`로 판별한다.
|
|
28
|
-
|
|
29
|
-
```typescript
|
|
30
|
-
export function isBrowserWorkerSupported(): boolean;
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
### `isNodeWorkerSupported`
|
|
34
|
-
|
|
35
|
-
Node.js `worker_threads` 지원 여부를 확인한다. `process.versions.node` 존재 여부로 판별한다.
|
|
36
|
-
|
|
37
|
-
```typescript
|
|
38
|
-
export function isNodeWorkerSupported(): boolean;
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
### `isWorkerSupported`
|
|
42
|
-
|
|
43
|
-
Worker 오프로딩 지원 여부를 확인한다. `isBrowserWorkerSupported() || isNodeWorkerSupported()`를 반환한다.
|
|
44
|
-
|
|
45
|
-
```typescript
|
|
46
|
-
export function isWorkerSupported(): boolean;
|
|
47
|
-
```
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# FileCollection
|
|
2
|
-
|
|
3
|
-
File 컬렉션 인터페이스. DOM `FileList`를 대체하며 브라우저 `FileList`와 구조적으로 호환된다.
|
|
4
|
-
|
|
5
|
-
```typescript
|
|
6
|
-
export interface FileCollection {
|
|
7
|
-
readonly length: number;
|
|
8
|
-
item(index: number): File | null;
|
|
9
|
-
[index: number]: File;
|
|
10
|
-
[Symbol.iterator](): IterableIterator<File>;
|
|
11
|
-
}
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
## Fields
|
|
15
|
-
|
|
16
|
-
| Field | Type | Description |
|
|
17
|
-
|-------|------|-------------|
|
|
18
|
-
| `length` | `number` | 파일 개수 (읽기 전용) |
|
|
19
|
-
| `item(index)` | `File \| null` | 인덱스로 File 반환 |
|
|
20
|
-
| `[index]` | `File` | 인덱스 접근자 |
|
|
21
|
-
| `[Symbol.iterator]()` | `IterableIterator<File>` | for-of 이터레이션 지원 |
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
# ServiceConnectionOptions
|
|
2
|
-
|
|
3
|
-
서비스 서버에 연결할 때 사용하는 옵션 인터페이스.
|
|
4
|
-
|
|
5
|
-
```typescript
|
|
6
|
-
export interface ServiceConnectionOptions {
|
|
7
|
-
port: number;
|
|
8
|
-
host: string;
|
|
9
|
-
ssl?: boolean;
|
|
10
|
-
/** 0으로 설정하면 재연결을 비활성화하고 즉시 연결을 끊음 */
|
|
11
|
-
maxReconnectCount?: number;
|
|
12
|
-
}
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Fields
|
|
16
|
-
|
|
17
|
-
| Field | Type | Required | Description |
|
|
18
|
-
|-------|------|----------|-------------|
|
|
19
|
-
| `port` | `number` | required | 서버 포트 번호 |
|
|
20
|
-
| `host` | `string` | required | 서버 호스트 주소 |
|
|
21
|
-
| `ssl` | `boolean` | optional | HTTPS/WSS 사용 여부. 기본값 `false` |
|
|
22
|
-
| `maxReconnectCount` | `number` | optional | 최대 재연결 횟수. `0`이면 재연결 비활성화. `ServiceClient` 기본값 `10` |
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
# ServiceProgress
|
|
2
|
-
|
|
3
|
-
요청/응답/서버 단계별 progress 콜백을 담는 컨테이너 인터페이스.
|
|
4
|
-
|
|
5
|
-
```typescript
|
|
6
|
-
export interface ServiceProgress {
|
|
7
|
-
request?: (s: ServiceProgressState) => void;
|
|
8
|
-
response?: (s: ServiceProgressState) => void;
|
|
9
|
-
server?: (s: ServiceProgressState) => void;
|
|
10
|
-
}
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Fields
|
|
14
|
-
|
|
15
|
-
| Field | Type | Required | Description |
|
|
16
|
-
|-------|------|----------|-------------|
|
|
17
|
-
| `request` | `(s: ServiceProgressState) => void` | optional | 클라이언트 → 서버 전송 progress |
|
|
18
|
-
| `response` | `(s: ServiceProgressState) => void` | optional | 서버 → 클라이언트 수신 progress |
|
|
19
|
-
| `server` | `(s: ServiceProgressState) => void` | optional | 서버 내부 처리 progress |
|
|
20
|
-
|
|
21
|
-
## Related Types
|
|
22
|
-
|
|
23
|
-
### `ServiceProgressState`
|
|
24
|
-
|
|
25
|
-
progress 콜백에 전달되는 상태 객체.
|
|
26
|
-
|
|
27
|
-
```typescript
|
|
28
|
-
export interface ServiceProgressState {
|
|
29
|
-
uuid: string;
|
|
30
|
-
totalSize: number;
|
|
31
|
-
completedSize: number;
|
|
32
|
-
}
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
| Field | Type | Description |
|
|
36
|
-
|-------|------|-------------|
|
|
37
|
-
| `uuid` | `string` | 요청 식별자 |
|
|
38
|
-
| `totalSize` | `number` | 전체 크기 (bytes) |
|
|
39
|
-
| `completedSize` | `number` | 완료된 크기 (bytes) |
|