@simplysm/service-common 13.0.29 → 13.0.31

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/README.md +84 -65
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @simplysm/service-common
2
2
 
3
- A package that provides shared communication protocols, message types, and service interface definitions between the service client (`service-client`) and server (`service-server`). It includes binary protocol-based message encoding/decoding, automatic message chunking for large payloads, event system types, and service interfaces for ORM/encryption/auto-update.
3
+ A package that provides shared communication protocols, message types, and service interface definitions between the service client (`service-client`) and server (`service-server`). It includes binary protocol-based message encoding/decoding, automatic message chunking for large payloads, event system types, and service interfaces for ORM and auto-update.
4
4
 
5
5
  ## Installation
6
6
 
@@ -15,46 +15,48 @@ pnpm add @simplysm/service-common
15
15
  ### Module Structure
16
16
 
17
17
  | Module Path | Description |
18
- |-----------|------|
18
+ |-------------|-------------|
19
19
  | `protocol/protocol.types` | Protocol constants, message type definitions |
20
- | `protocol/service-protocol` | Message encoding/decoding class |
21
- | `service-types/orm-service.types` | ORM service interface and DB connection options |
22
- | `service-types/auto-update-service.types` | Auto-update service interface |
23
- | `types` | `ServiceUploadResult` |
24
- | `define-event` | `defineEvent`, `ServiceEventDef` |
20
+ | `protocol/service-protocol` | `ServiceProtocol` interface, `ServiceMessageDecodeResult` type, `createServiceProtocol()` factory |
21
+ | `service-types/orm-service.types` | `OrmService` interface and `DbConnOptions` type |
22
+ | `service-types/auto-update-service.types` | `AutoUpdateService` interface |
23
+ | `types` | `ServiceUploadResult` interface |
24
+ | `define-event` | `defineEvent()` function, `ServiceEventDef` interface |
25
25
 
26
- ## ServiceProtocol
26
+ ## Protocol
27
27
 
28
- The core interface for encoding/decoding messages into binary format. Created via the `createServiceProtocol()` factory function. Messages exceeding 3MB are automatically split into 300KB chunks, and the receiving side automatically assembles the chunks to restore the original message.
28
+ ### ServiceProtocol
29
29
 
30
- ### Binary Header Structure
30
+ The core interface for encoding and decoding messages in binary format. Created via the `createServiceProtocol()` factory function. Messages exceeding 3MB are automatically split into 300KB chunks, and the receiving side automatically assembles the chunks to restore the original message.
31
31
 
32
- Each chunk consists of a 28-byte header and body (Big Endian).
32
+ #### Binary Header Structure
33
+
34
+ Each chunk consists of a 28-byte header followed by a JSON body (Big Endian).
33
35
 
34
36
  | Offset | Size | Field | Description |
35
- |--------|------|------|------|
37
+ |--------|------|-------|-------------|
36
38
  | 0 | 16 bytes | UUID | Message identifier (binary) |
37
39
  | 16 | 8 bytes | TotalSize | Total message size (uint64) |
38
40
  | 24 | 4 bytes | Index | Chunk index (uint32) |
39
41
 
40
- ### API
42
+ #### API
41
43
 
42
44
  | Method | Return Type | Description |
43
- |--------|-----------|------|
44
- | `encode(uuid, message)` | `{ chunks: Bytes[]; totalSize: number }` | Encodes the message and automatically splits if necessary |
45
- | `decode<T>(bytes)` | `ServiceMessageDecodeResult<T>` | Decodes binary chunks and automatically assembles split messages |
45
+ |--------|-------------|-------------|
46
+ | `encode(uuid, message)` | `{ chunks: Bytes[]; totalSize: number }` | Encodes the message and automatically splits into chunks if it exceeds `SPLIT_MESSAGE_SIZE` |
47
+ | `decode<TMessage extends ServiceMessage>(bytes)` | `ServiceMessageDecodeResult<TMessage>` | Decodes binary chunks and automatically assembles split messages |
46
48
  | `dispose()` | `void` | Releases the GC timer of the internal chunk accumulator. Must be called when the instance is no longer used |
47
49
 
48
- ### Decode Result Type
50
+ #### ServiceMessageDecodeResult
49
51
 
50
- `ServiceMessageDecodeResult<T>` is a union type with two states.
52
+ `ServiceMessageDecodeResult<TMessage extends ServiceMessage>` is a union type with two states.
51
53
 
52
54
  | `type` | Fields | Description |
53
- |--------|------|------|
54
- | `"complete"` | `uuid`, `message: T` | All chunks received and message assembly complete |
55
- | `"progress"` | `uuid`, `totalSize`, `completedSize` | Split message in progress (only some chunks arrived) |
55
+ |--------|--------|-------------|
56
+ | `"complete"` | `uuid: string`, `message: TMessage` | All chunks received and message assembly complete |
57
+ | `"progress"` | `uuid: string`, `totalSize: number`, `completedSize: number` | Split message in progress (only some chunks have arrived) |
56
58
 
57
- ### Usage Example
59
+ #### Usage Example
58
60
 
59
61
  ```typescript
60
62
  import { createServiceProtocol } from "@simplysm/service-common";
@@ -86,7 +88,7 @@ for (const chunk of chunks) {
86
88
  protocol.dispose();
87
89
  ```
88
90
 
89
- ## Protocol Constants (PROTOCOL_CONFIG)
91
+ ### PROTOCOL_CONFIG
90
92
 
91
93
  A constant object that controls protocol behavior.
92
94
 
@@ -95,80 +97,80 @@ import { PROTOCOL_CONFIG } from "@simplysm/service-common";
95
97
  ```
96
98
 
97
99
  | Constant | Value | Description |
98
- |------|----|------|
100
+ |----------|-------|-------------|
99
101
  | `MAX_TOTAL_SIZE` | 100MB (104,857,600 bytes) | Maximum size for a single message. `ArgumentError` thrown if exceeded |
100
- | `SPLIT_MESSAGE_SIZE` | 3MB (3,145,728 bytes) | Chunking threshold. Automatically split if this size is exceeded |
102
+ | `SPLIT_MESSAGE_SIZE` | 3MB (3,145,728 bytes) | Chunking threshold. Messages larger than this are automatically split |
101
103
  | `CHUNK_SIZE` | 300KB (307,200 bytes) | Body size of each chunk when split |
102
104
  | `GC_INTERVAL` | 10s (10,000ms) | Garbage collection cycle for incomplete messages |
103
105
  | `EXPIRE_TIME` | 60s (60,000ms) | Expiration time for incomplete messages. Removed from memory if exceeded |
104
106
 
105
- ## Message Types
107
+ ### Message Types
106
108
 
107
109
  Type definitions for messages exchanged between client and server. `ServiceMessage` is a union of all message types.
108
110
 
109
- ### Classification by Message Direction
111
+ #### Classification by Message Direction
110
112
 
111
113
  | Union Type | Direction | Included Messages |
112
- |------------|------|------------|
114
+ |------------|-----------|-------------------|
113
115
  | `ServiceClientMessage` | Client -> Server | Request, Auth, event-related messages |
114
116
  | `ServiceServerMessage` | Server -> Client | Reload, Response, Error, Event |
115
117
  | `ServiceServerRawMessage` | Server -> Client (raw) | Progress + `ServiceServerMessage` |
116
118
  | `ServiceMessage` | Bidirectional (all) | Union of all message types |
117
119
 
118
- ### Individual Message Types
120
+ #### Individual Message Types
119
121
 
120
- #### System Messages
122
+ ##### System Messages
121
123
 
122
124
  | Type | `name` | Direction | `body` Type | Description |
123
- |------|--------|------|-------------|------|
125
+ |------|--------|-----------|-------------|-------------|
124
126
  | `ServiceReloadMessage` | `"reload"` | Server -> Client | `{ clientName: string \| undefined; changedFileSet: Set<string> }` | Client reload command |
125
127
  | `ServiceProgressMessage` | `"progress"` | Server -> Client | `{ totalSize: number; completedSize: number }` | Split message reception progress |
126
- | `ServiceErrorMessage` | `"error"` | Server -> Client | `{ name, message, code, stack?, detail?, cause? }` | Error notification |
128
+ | `ServiceErrorMessage` | `"error"` | Server -> Client | `{ name: string; message: string; code: string; stack?: string; detail?: unknown; cause?: unknown }` | Error notification |
127
129
  | `ServiceAuthMessage` | `"auth"` | Client -> Server | `string` (token) | Authentication token transmission |
128
130
 
129
- #### Service Method Call Messages
131
+ ##### Service Method Call Messages
130
132
 
131
133
  | Type | `name` | Direction | `body` Type | Description |
132
- |------|--------|------|-------------|------|
133
- | `ServiceRequestMessage` | `` `${service}.${method}` `` | Client -> Server | `unknown[]` (parameter array) | RPC method call request |
134
- | `ServiceResponseMessage` | `"response"` | Server -> Client | `unknown` (return value) | Method call response |
134
+ |------|--------|-----------|-------------|-------------|
135
+ | `ServiceRequestMessage` | `` `${string}.${string}` `` | Client -> Server | `unknown[]` (parameter array) | RPC method call request |
136
+ | `ServiceResponseMessage` | `"response"` | Server -> Client | `unknown \| undefined` (optional return value) | Method call response |
135
137
 
136
- #### Event Messages
138
+ ##### Event Messages
137
139
 
138
140
  | Type | `name` | Direction | `body` Type | Description |
139
- |------|--------|------|-------------|------|
140
- | `ServiceAddEventListenerMessage` | `"evt:add"` | Client -> Server | `{ key, name, info }` | Event listener registration |
141
- | `ServiceRemoveEventListenerMessage` | `"evt:remove"` | Client -> Server | `{ key }` | Event listener removal |
142
- | `ServiceGetEventListenerInfosMessage` | `"evt:gets"` | Client -> Server | `{ name }` | Event listener info list query |
143
- | `ServiceEmitEventMessage` | `"evt:emit"` | Client -> Server | `{ keys, data }` | Event emission |
144
- | `ServiceEventMessage` | `"evt:on"` | Server -> Client | `{ keys, data }` | Event notification |
141
+ |------|--------|-----------|-------------|-------------|
142
+ | `ServiceAddEventListenerMessage` | `"evt:add"` | Client -> Server | `{ key: string; name: string; info: unknown }` | Event listener registration |
143
+ | `ServiceRemoveEventListenerMessage` | `"evt:remove"` | Client -> Server | `{ key: string }` | Event listener removal |
144
+ | `ServiceGetEventListenerInfosMessage` | `"evt:gets"` | Client -> Server | `{ name: string }` | Event listener info list query |
145
+ | `ServiceEmitEventMessage` | `"evt:emit"` | Client -> Server | `{ keys: string[]; data: unknown }` | Event emission |
146
+ | `ServiceEventMessage` | `"evt:on"` | Server -> Client | `{ keys: string[]; data: unknown }` | Event notification |
145
147
 
146
148
  ## defineEvent / ServiceEventDef
147
149
 
148
- A function for defining event types. Events are used to publish real-time notifications from server to client.
150
+ A function for defining type-safe service events. Events are used to publish real-time notifications from server to client.
149
151
 
150
152
  ### API
151
153
 
152
154
  ```typescript
153
155
  function defineEvent<TInfo = unknown, TData = unknown>(
154
- eventName: string
156
+ eventName: string,
155
157
  ): ServiceEventDef<TInfo, TData>
156
158
  ```
157
159
 
158
160
  ### Type Parameters
159
161
 
160
162
  | Parameter | Description |
161
- |---------|------|
163
+ |-----------|-------------|
162
164
  | `TInfo` | Additional information type for listener filtering |
163
165
  | `TData` | Data type passed when the event is emitted |
164
166
 
165
167
  ### ServiceEventDef Properties
166
168
 
167
169
  | Property | Type | Description |
168
- |------|------|------|
170
+ |----------|------|-------------|
169
171
  | `eventName` | `string` | Unique event identifier |
170
- | `$info` | `TInfo` (declare) | For type extraction. Not used at runtime |
171
- | `$data` | `TData` (declare) | For type extraction. Not used at runtime |
172
+ | `$info` | `TInfo` (declare) | For TypeScript type extraction only. Not used at runtime |
173
+ | `$data` | `TData` (declare) | For TypeScript type extraction only. Not used at runtime |
172
174
 
173
175
  ### Usage Example
174
176
 
@@ -195,9 +197,13 @@ await client.addEventListener(
195
197
 
196
198
  An interface representing file upload results.
197
199
 
200
+ ```typescript
201
+ import { ServiceUploadResult } from "@simplysm/service-common";
202
+ ```
203
+
198
204
  | Field | Type | Description |
199
- |------|------|------|
200
- | `path` | `string` | Storage path on server |
205
+ |-------|------|-------------|
206
+ | `path` | `string` | Storage path on the server |
201
207
  | `filename` | `string` | Original filename |
202
208
  | `size` | `number` | File size (bytes) |
203
209
 
@@ -207,24 +213,32 @@ Service interface definitions that are implemented on the server side and called
207
213
 
208
214
  ### OrmService
209
215
 
210
- Defines database connection, transaction management, and query execution capabilities. Supports MySQL, MSSQL, PostgreSQL.
216
+ Defines database connection, transaction management, and query execution capabilities. Supports MySQL, MSSQL, and PostgreSQL.
217
+
218
+ ```typescript
219
+ import type { OrmService } from "@simplysm/service-common";
220
+ ```
211
221
 
212
222
  | Method | Parameters | Return Type | Description |
213
- |--------|---------|-----------|------|
214
- | `getInfo` | `opt: DbConnOptions & { configName: string }` | `Promise<{ dialect, database?, schema? }>` | Query DB connection info |
223
+ |--------|------------|-------------|-------------|
224
+ | `getInfo` | `opt: DbConnOptions & { configName: string }` | `Promise<{ dialect: Dialect; database?: string; schema?: string }>` | Query DB connection info |
215
225
  | `connect` | `opt: Record<string, unknown>` | `Promise<number>` | Create DB connection, return connection ID |
216
226
  | `close` | `connId: number` | `Promise<void>` | Close DB connection |
217
- | `beginTransaction` | `connId, isolationLevel?` | `Promise<void>` | Begin transaction |
227
+ | `beginTransaction` | `connId: number, isolationLevel?: IsolationLevel` | `Promise<void>` | Begin transaction |
218
228
  | `commitTransaction` | `connId: number` | `Promise<void>` | Commit transaction |
219
229
  | `rollbackTransaction` | `connId: number` | `Promise<void>` | Rollback transaction |
220
- | `executeParametrized` | `connId, query, params?` | `Promise<unknown[][]>` | Execute parameterized query |
221
- | `executeDefs` | `connId, defs: QueryDef[], options?: (ResultMeta \| undefined)[]` | `Promise<unknown[][]>` | Execute queries with `QueryDef` array |
222
- | `bulkInsert` | `connId, tableName, columnDefs: Record<string, ColumnMeta>, records` | `Promise<void>` | Bulk data insertion |
230
+ | `executeParametrized` | `connId: number, query: string, params?: unknown[]` | `Promise<unknown[][]>` | Execute a parameterized query |
231
+ | `executeDefs` | `connId: number, defs: QueryDef[], options?: (ResultMeta \| undefined)[]` | `Promise<unknown[][]>` | Execute queries defined as `QueryDef` array |
232
+ | `bulkInsert` | `connId: number, tableName: string, columnDefs: Record<string, ColumnMeta>, records: Record<string, unknown>[]` | `Promise<void>` | Bulk data insertion |
223
233
 
224
234
  #### DbConnOptions
225
235
 
236
+ ```typescript
237
+ import type { DbConnOptions } from "@simplysm/service-common";
238
+ ```
239
+
226
240
  | Field | Type | Description |
227
- |------|------|------|
241
+ |-------|------|-------------|
228
242
  | `configName?` | `string` | Config name to reference in server settings |
229
243
  | `config?` | `Record<string, unknown>` | Directly passed connection config |
230
244
 
@@ -232,18 +246,23 @@ Defines database connection, transaction management, and query execution capabil
232
246
 
233
247
  Defines a service for querying the latest version information of a client application.
234
248
 
249
+ ```typescript
250
+ import type { AutoUpdateService } from "@simplysm/service-common";
251
+ ```
252
+
235
253
  | Method | Parameters | Return Type | Description |
236
- |--------|---------|-----------|------|
237
- | `getLastVersion` | `platform: string` | `Promise<{ version: string; downloadPath: string } \| undefined>` | Query latest version info for the specified platform. Returns `undefined` if none |
254
+ |--------|------------|-------------|-------------|
255
+ | `getLastVersion` | `platform: string` | `Promise<{ version: string; downloadPath: string } \| undefined>` | Query latest version info for the specified platform. Returns `undefined` if none exists |
238
256
 
239
- Pass values like `"win32"`, `"darwin"`, `"linux"` to `platform`.
257
+ Pass values like `"win32"`, `"darwin"`, or `"linux"` to `platform`.
240
258
 
241
259
  ## Caveats
242
260
 
243
- - `ServiceProtocol` instances are created via `createServiceProtocol()` factory function and internally use `LazyGcMap` to manage incomplete split messages. After use, you must call `dispose()` to release the GC timer.
261
+ - `ServiceProtocol` instances are created via the `createServiceProtocol()` factory function and internally use `LazyGcMap` to manage incomplete split messages. After use, you must call `dispose()` to release the GC timer.
244
262
  - Encoding or decoding messages exceeding `PROTOCOL_CONFIG.MAX_TOTAL_SIZE` (100MB) will throw an `ArgumentError`.
245
- - Passing binary data less than 28 bytes during decoding will throw an `ArgumentError`.
246
- - Service interfaces (`OrmService`, `AutoUpdateService`, etc.) only provide type definitions. Actual implementations are handled by the `@simplysm/service-server` package.
263
+ - Passing binary data less than 28 bytes to `decode()` will throw an `ArgumentError`.
264
+ - `ServiceResponseMessage.body` is optional (`body?: unknown`) the server may return `undefined` for void methods.
265
+ - Service interfaces (`OrmService`, `AutoUpdateService`) only provide type definitions. Actual implementations are handled by the `@simplysm/service-server` package.
247
266
  - The `$info` and `$data` properties of `ServiceEventDef` are declared with `declare` and do not exist at runtime; they are only used for TypeScript type extraction.
248
267
 
249
268
  ## License
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplysm/service-common",
3
- "version": "13.0.29",
3
+ "version": "13.0.31",
4
4
  "description": "심플리즘 패키지 - 서비스 모듈 (common)",
5
5
  "author": "김석래",
6
6
  "license": "Apache-2.0",
@@ -18,7 +18,7 @@
18
18
  ],
19
19
  "sideEffects": false,
20
20
  "dependencies": {
21
- "@simplysm/core-common": "13.0.29",
22
- "@simplysm/orm-common": "13.0.29"
21
+ "@simplysm/core-common": "13.0.31",
22
+ "@simplysm/orm-common": "13.0.31"
23
23
  }
24
24
  }