@simplysm/service-common 13.0.96 → 13.0.97

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/README.md +0 -292
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplysm/service-common",
3
- "version": "13.0.96",
3
+ "version": "13.0.97",
4
4
  "description": "Simplysm package - Service module (common)",
5
5
  "author": "simplysm",
6
6
  "license": "Apache-2.0",
@@ -19,7 +19,7 @@
19
19
  ],
20
20
  "sideEffects": false,
21
21
  "dependencies": {
22
- "@simplysm/orm-common": "13.0.96",
23
- "@simplysm/core-common": "13.0.96"
22
+ "@simplysm/core-common": "13.0.97",
23
+ "@simplysm/orm-common": "13.0.97"
24
24
  }
25
25
  }
package/README.md DELETED
@@ -1,292 +0,0 @@
1
- # @simplysm/service-common
2
-
3
- 클라이언트-서버 통신을 위한 공유 프로토콜, 타입, 이벤트 정의.
4
-
5
- ## 설치
6
-
7
- ```bash
8
- npm install @simplysm/service-common
9
- ```
10
-
11
- **의존성:** `@simplysm/core-common`, `@simplysm/orm-common`
12
-
13
- ## 주요 기능
14
-
15
- ### 바이너리 프로토콜
16
-
17
- 28바이트 헤더 + JSON 바디 구조. 3MB 초과 시 300KB 청크로 자동 분할. 최대 메시지 크기 100MB.
18
-
19
- #### 프로토콜 설정값 (`PROTOCOL_CONFIG`)
20
-
21
- ```typescript
22
- import { PROTOCOL_CONFIG } from "@simplysm/service-common";
23
-
24
- PROTOCOL_CONFIG.MAX_TOTAL_SIZE; // 100MB - 최대 메시지 크기
25
- PROTOCOL_CONFIG.SPLIT_MESSAGE_SIZE; // 3MB - 청크 분할 기준
26
- PROTOCOL_CONFIG.CHUNK_SIZE; // 300KB - 청크 크기
27
- PROTOCOL_CONFIG.GC_INTERVAL; // 10초 - 미완성 청크 GC 주기
28
- PROTOCOL_CONFIG.EXPIRE_TIME; // 60초 - 미완성 메시지 만료 시간
29
- ```
30
-
31
- #### 프로토콜 생성 및 사용
32
-
33
- ```typescript
34
- import { createServiceProtocol } from "@simplysm/service-common";
35
- import type { ServiceProtocol, ServiceMessageDecodeResult } from "@simplysm/service-common";
36
-
37
- const protocol: ServiceProtocol = createServiceProtocol();
38
-
39
- // 인코딩: 메시지를 바이너리 청크 배열로 변환
40
- const { chunks, totalSize } = protocol.encode(uuid, message);
41
- // chunks: Bytes[] - 전송할 바이너리 청크 배열
42
- // totalSize: number - 전체 메시지 크기
43
-
44
- // 디코딩: 수신된 바이너리를 메시지로 복원 (청크 자동 재조립)
45
- const result: ServiceMessageDecodeResult<ServiceMessage> = protocol.decode(bytes);
46
-
47
- if (result.type === "complete") {
48
- // 모든 청크 수신 완료
49
- result.uuid; // string - 메시지 UUID
50
- result.message; // ServiceMessage - 복원된 메시지
51
- } else {
52
- // result.type === "progress" - 청크 수신 중
53
- result.uuid; // string
54
- result.totalSize; // number - 전체 크기
55
- result.completedSize; // number - 수신 완료된 크기
56
- }
57
-
58
- // 사용 완료 후 반드시 dispose 호출 (내부 GC 타이머 해제)
59
- protocol.dispose();
60
- ```
61
-
62
- #### 헤더 구조 (28바이트, Big Endian)
63
-
64
- | 오프셋 | 크기 | 필드 |
65
- |--------|------|------|
66
- | 0 | 16 | UUID (binary) |
67
- | 16 | 8 | TotalSize (uint64) |
68
- | 24 | 4 | Index (uint32) |
69
-
70
- ### 이벤트 정의
71
-
72
- 타입 안전한 클라이언트-서버 이벤트 시스템.
73
-
74
- ```typescript
75
- import { defineEvent } from "@simplysm/service-common";
76
- import type { ServiceEventDef } from "@simplysm/service-common";
77
-
78
- // 이벤트 정의 (TInfo: 구독 조건 타입, TData: 이벤트 데이터 타입)
79
- const OrderUpdated = defineEvent<{ orderId: number }, { status: string }>("OrderUpdated");
80
-
81
- // 서버에서 이벤트 발행
82
- ctx.socket?.emitEvent(OrderUpdated, { orderId: 123 }, { status: "shipped" });
83
-
84
- // 클라이언트에서 이벤트 구독
85
- await client.addEventListener(OrderUpdated, { orderId: 123 }, (data) => {
86
- // data.status는 string으로 타입 추론됨
87
- });
88
- ```
89
-
90
- #### `ServiceEventDef<TInfo, TData>`
91
-
92
- ```typescript
93
- interface ServiceEventDef<TInfo = unknown, TData = unknown> {
94
- eventName: string;
95
- readonly $info: TInfo; // 타입 추출 전용 (런타임 미사용)
96
- readonly $data: TData; // 타입 추출 전용 (런타임 미사용)
97
- }
98
- ```
99
-
100
- #### `defineEvent<TInfo, TData>(eventName: string): ServiceEventDef<TInfo, TData>`
101
-
102
- 이벤트 이름과 타입 파라미터로 타입 안전한 이벤트 정의 객체를 생성한다.
103
-
104
- ### 메시지 타입
105
-
106
- 모든 메시지는 `ServiceMessage` 유니온 타입에 포함된다.
107
-
108
- #### 방향별 메시지 그룹
109
-
110
- ```typescript
111
- // 서버 → 클라이언트 메시지
112
- type ServiceServerMessage =
113
- | ServiceReloadMessage
114
- | ServiceResponseMessage
115
- | ServiceErrorMessage
116
- | ServiceEventMessage;
117
-
118
- // 서버 → 클라이언트 (progress 포함)
119
- type ServiceServerRawMessage = ServiceProgressMessage | ServiceServerMessage;
120
-
121
- // 클라이언트 → 서버 메시지
122
- type ServiceClientMessage =
123
- | ServiceRequestMessage
124
- | ServiceAuthMessage
125
- | ServiceAddEventListenerMessage
126
- | ServiceRemoveEventListenerMessage
127
- | ServiceGetEventListenerInfosMessage
128
- | ServiceEmitEventMessage;
129
- ```
130
-
131
- #### 전체 메시지 타입 목록
132
-
133
- | 타입 | name 필드 | 방향 | 설명 |
134
- |------|-----------|------|------|
135
- | `ServiceRequestMessage` | `` `${service}.${method}` `` | C->S | RPC 호출. body: `unknown[]` (파라미터 배열) |
136
- | `ServiceResponseMessage` | `"response"` | S->C | RPC 응답. body?: `unknown` (결과값, 선택) |
137
- | `ServiceErrorMessage` | `"error"` | S->C | 에러. body: `{ name, message, code, stack?, detail?, cause? }` |
138
- | `ServiceAuthMessage` | `"auth"` | C->S | 인증. body: `string` (Bearer 토큰) |
139
- | `ServiceProgressMessage` | `"progress"` | 양방향 | 청크 진행률. body: `{ totalSize, completedSize }` |
140
- | `ServiceReloadMessage` | `"reload"` | S->C | 리로드 알림. body: `{ clientName, changedFileSet }` |
141
- | `ServiceAddEventListenerMessage` | `"evt:add"` | C->S | 이벤트 리스너 등록. body: `{ key, name, info }` |
142
- | `ServiceRemoveEventListenerMessage` | `"evt:remove"` | C->S | 이벤트 리스너 해제. body: `{ key }` |
143
- | `ServiceGetEventListenerInfosMessage` | `"evt:gets"` | C->S | 이벤트 리스너 목록 조회. body: `{ name }` |
144
- | `ServiceEmitEventMessage` | `"evt:emit"` | C->S | 이벤트 발행. body: `{ keys, data }` |
145
- | `ServiceEventMessage` | `"evt:on"` | S->C | 이벤트 브로드캐스트. body: `{ keys, data }` |
146
-
147
- ### 서비스 인터페이스
148
-
149
- #### ORM 서비스 (`OrmService`)
150
-
151
- DB 연결, 트랜잭션, 쿼리 실행을 제공한다. MySQL, MSSQL, PostgreSQL 지원.
152
-
153
- ```typescript
154
- import type { OrmService, DbConnOptions } from "@simplysm/service-common";
155
-
156
- interface OrmService {
157
- getInfo(opt: DbConnOptions & { configName: string }): Promise<{
158
- dialect: Dialect;
159
- database?: string;
160
- schema?: string;
161
- }>;
162
-
163
- connect(opt: Record<string, unknown>): Promise<number>;
164
- close(connId: number): Promise<void>;
165
-
166
- beginTransaction(connId: number, isolationLevel?: IsolationLevel): Promise<void>;
167
- commitTransaction(connId: number): Promise<void>;
168
- rollbackTransaction(connId: number): Promise<void>;
169
-
170
- executeParametrized(connId: number, query: string, params?: unknown[]): Promise<unknown[][]>;
171
- executeDefs(
172
- connId: number,
173
- defs: QueryDef[],
174
- options?: (ResultMeta | undefined)[],
175
- ): Promise<unknown[][]>;
176
-
177
- bulkInsert(
178
- connId: number,
179
- tableName: string,
180
- columnDefs: Record<string, ColumnMeta>,
181
- records: Record<string, unknown>[],
182
- ): Promise<void>;
183
- }
184
- ```
185
-
186
- ##### `DbConnOptions`
187
-
188
- ```typescript
189
- type DbConnOptions = {
190
- configName?: string;
191
- config?: Record<string, unknown>;
192
- };
193
- ```
194
-
195
- #### 자동 업데이트 서비스 (`AutoUpdateService`)
196
-
197
- ```typescript
198
- import type { AutoUpdateService } from "@simplysm/service-common";
199
-
200
- interface AutoUpdateService {
201
- getLastVersion(platform: string): Promise<
202
- | { version: string; downloadPath: string }
203
- | undefined
204
- >;
205
- }
206
- ```
207
-
208
- `platform`: `"win32"`, `"darwin"`, `"linux"` 등.
209
-
210
- #### SMTP 클라이언트 서비스 타입
211
-
212
- ```typescript
213
- import type {
214
- SmtpClientSendOption,
215
- SmtpClientSendByDefaultOption,
216
- SmtpClientSendAttachment,
217
- SmtpClientDefaultOptions,
218
- } from "@simplysm/service-common";
219
-
220
- // 직접 SMTP 설정 포함하여 메일 전송
221
- interface SmtpClientSendOption {
222
- host: string;
223
- port?: number;
224
- secure?: boolean;
225
- user?: string;
226
- pass?: string;
227
- from: string;
228
- to: string;
229
- cc?: string;
230
- bcc?: string;
231
- subject: string;
232
- html: string;
233
- attachments?: SmtpClientSendAttachment[];
234
- }
235
-
236
- // 기본 SMTP 설정 사용 시 (from/host/user/pass 등 생략)
237
- interface SmtpClientSendByDefaultOption {
238
- to: string;
239
- cc?: string;
240
- bcc?: string;
241
- subject: string;
242
- html: string;
243
- attachments?: SmtpClientSendAttachment[];
244
- }
245
-
246
- // 기본 SMTP 서버 설정
247
- interface SmtpClientDefaultOptions {
248
- senderName: string;
249
- senderEmail?: string;
250
- user?: string;
251
- pass?: string;
252
- host: string;
253
- port?: number;
254
- secure?: boolean;
255
- }
256
-
257
- // 첨부파일
258
- interface SmtpClientSendAttachment {
259
- filename: string;
260
- content?: string | Uint8Array;
261
- path?: any;
262
- contentType?: string;
263
- }
264
- ```
265
-
266
- ### 파일 업로드 결과
267
-
268
- ```typescript
269
- import type { ServiceUploadResult } from "@simplysm/service-common";
270
-
271
- interface ServiceUploadResult {
272
- path: string; // 서버 저장 경로
273
- filename: string; // 원본 파일명
274
- size: number; // 파일 크기 (bytes)
275
- }
276
- ```
277
-
278
- ## 디렉토리 구조
279
-
280
- ```
281
- src/
282
- index.ts # 엔트리포인트 (모든 export 재수출)
283
- define-event.ts # defineEvent(), ServiceEventDef
284
- types.ts # ServiceUploadResult
285
- protocol/
286
- protocol.types.ts # PROTOCOL_CONFIG, 메시지 타입 정의
287
- create-service-protocol.ts # createServiceProtocol(), ServiceProtocol
288
- service-types/
289
- orm-service.types.ts # OrmService, DbConnOptions
290
- auto-update-service.types.ts # AutoUpdateService
291
- smtp-client-service.types.ts # SmtpClientSend*, SmtpClientDefault*
292
- ```