@simplysm/service-common 14.0.22 → 14.0.24

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplysm/service-common",
3
- "version": "14.0.22",
3
+ "version": "14.0.24",
4
4
  "description": "심플리즘 패키지 - 서비스 (common)",
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
  "devDependencies": {
22
21
  "@types/node": "^20.19.39"
23
22
  },
24
23
  "dependencies": {
25
- "@simplysm/orm-common": "14.0.22",
26
- "@simplysm/core-common": "14.0.22"
24
+ "@simplysm/core-common": "14.0.24",
25
+ "@simplysm/orm-common": "14.0.24"
27
26
  }
28
27
  }
package/README.md DELETED
@@ -1,114 +0,0 @@
1
- # @simplysm/service-common
2
-
3
- Shared types and protocol for the Simplysm service framework. Provides the binary protocol V2 encoder/decoder, message type definitions, service interface contracts (ORM, auto-update), and event definition utilities used by both `@simplysm/service-client` and `@simplysm/service-server`.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- npm install @simplysm/service-common
9
- ```
10
-
11
- ## API Overview
12
-
13
- ### Protocol Types
14
- | API | Type | Description |
15
- |-----|------|-------------|
16
- | `PROTOCOL_CONFIG` | `const` | Protocol configuration constants (max size, chunk size, GC interval, expiry) |
17
- | `ServiceMessage` | `type` | Union of all message types |
18
- | `ServiceServerMessage` | `type` | Union of server-to-client message types |
19
- | `ServiceServerRawMessage` | `type` | Union of progress + server message types |
20
- | `ServiceClientMessage` | `type` | Union of client-to-server message types |
21
- | `ServiceProgressMessage` | `interface` | Chunked message progress notification |
22
- | `ServiceErrorMessage` | `interface` | Error notification from server |
23
- | `ServiceAuthMessage` | `interface` | Authentication message from client |
24
- | `ServiceRequestMessage` | `interface` | Service method request from client |
25
- | `ServiceResponseMessage` | `interface` | Service method response from server |
26
- | `ServiceAddEventListenerMessage` | `interface` | Add event listener request |
27
- | `ServiceRemoveEventListenerMessage` | `interface` | Remove event listener request |
28
- | `ServiceGetEventListenerInfosMessage` | `interface` | Get event listener infos request |
29
- | `ServiceEmitEventMessage` | `interface` | Emit event request |
30
- | `ServiceEventMessage` | `interface` | Event notification from server |
31
-
32
- -> See [docs/protocol-types.md](./docs/protocol-types.md) for details.
33
-
34
- ### Service Protocol
35
- | API | Type | Description |
36
- |-----|------|-------------|
37
- | `ServiceProtocol` | `interface` | Binary protocol encoder/decoder interface |
38
- | `ServiceMessageDecodeResult` | `type` | Decode result union (complete or progress) |
39
- | `createServiceProtocol` | `function` | Creates a protocol encoder/decoder instance |
40
-
41
- -> See [docs/service-protocol.md](./docs/service-protocol.md) for details.
42
-
43
- ### ORM Service Types
44
- | API | Type | Description |
45
- |-----|------|-------------|
46
- | `OrmService` | `interface` | ORM service interface for DB operations |
47
- | `DbConnOptions` | `type` | Database connection options |
48
-
49
- -> See [docs/orm-service-types.md](./docs/orm-service-types.md) for details.
50
-
51
- ### Auto-Update Service Types
52
- | API | Type | Description |
53
- |-----|------|-------------|
54
- | `AutoUpdateService` | `interface` | Auto-update service interface |
55
-
56
- -> See [docs/auto-update-service-types.md](./docs/auto-update-service-types.md) for details.
57
-
58
- ### Common Types
59
- | API | Type | Description |
60
- |-----|------|-------------|
61
- | `ServiceUploadResult` | `interface` | File upload result containing path, filename, and size |
62
-
63
- -> See [docs/common-types.md](./docs/common-types.md) for details.
64
-
65
- ### Events
66
- | API | Type | Description |
67
- |-----|------|-------------|
68
- | `ServiceEventDef` | `interface` | Type-safe event definition with info and data markers |
69
- | `defineEvent` | `function` | Creates a typed service event definition |
70
-
71
- -> See [docs/events.md](./docs/events.md) for details.
72
-
73
- ## Usage Examples
74
-
75
- ### Creating a Protocol Instance
76
-
77
- ```typescript
78
- import { createServiceProtocol } from "@simplysm/service-common";
79
-
80
- const protocol = createServiceProtocol();
81
-
82
- // Encode a message
83
- const { chunks, totalSize } = protocol.encode("some-uuid", {
84
- name: "SomeService.someMethod",
85
- body: [arg1, arg2],
86
- });
87
-
88
- // Decode received bytes
89
- const result = protocol.decode(receivedBytes);
90
- if (result.type === "complete") {
91
- console.log(result.message);
92
- } else {
93
- console.log(`Progress: ${result.completedSize}/${result.totalSize}`);
94
- }
95
-
96
- // Dispose when done
97
- protocol.dispose();
98
- ```
99
-
100
- ### Defining a Typed Event
101
-
102
- ```typescript
103
- import { defineEvent } from "@simplysm/service-common";
104
-
105
- const OrderUpdated = defineEvent<{ orderId: number }, { status: string }>("OrderUpdated");
106
-
107
- // Server: emit event
108
- await server.emitEvent(OrderUpdated, (info) => info.orderId === 123, { status: "shipped" });
109
-
110
- // Client: subscribe
111
- await client.addListener(OrderUpdated, { orderId: 123 }, async (data) => {
112
- console.log(data.status);
113
- });
114
- ```
@@ -1,21 +0,0 @@
1
- # Auto-Update Service Types
2
-
3
- ## `AutoUpdateService`
4
-
5
- Auto-update service interface for querying the latest client application version.
6
-
7
- ```typescript
8
- export interface AutoUpdateService {
9
- getLastVersion(platform: string): Promise<
10
- | {
11
- version: string;
12
- downloadPath: string;
13
- }
14
- | undefined
15
- >;
16
- }
17
- ```
18
-
19
- | Method | Parameters | Return | Description |
20
- |--------|-----------|--------|-------------|
21
- | `getLastVersion` | `platform: string` | `Promise<{ version: string; downloadPath: string } \| undefined>` | Returns the latest version info for the given platform (e.g., `"win32"`, `"darwin"`, `"linux"`, `"android"`). Returns `undefined` if no version is available |
@@ -1,19 +0,0 @@
1
- # Common Types
2
-
3
- ## `ServiceUploadResult`
4
-
5
- File upload result containing information about the uploaded file.
6
-
7
- ```typescript
8
- export interface ServiceUploadResult {
9
- path: string;
10
- filename: string;
11
- size: number;
12
- }
13
- ```
14
-
15
- | Field | Type | Description |
16
- |-------|------|-------------|
17
- | `path` | `string` | Server-side storage path (relative) |
18
- | `filename` | `string` | Original filename |
19
- | `size` | `number` | File size in bytes |
package/docs/events.md DELETED
@@ -1,58 +0,0 @@
1
- # Events
2
-
3
- ## `ServiceEventDef`
4
-
5
- Type-safe event definition created by `defineEvent()`. The `$info` and `$data` fields are type-only markers not used at runtime.
6
-
7
- ```typescript
8
- export interface ServiceEventDef<TInfo = unknown, TData = unknown> {
9
- eventName: string;
10
- readonly $info: TInfo;
11
- readonly $data: TData;
12
- }
13
- ```
14
-
15
- | Field | Type | Description |
16
- |-------|------|-------------|
17
- | `eventName` | `string` | Event name identifier |
18
- | `$info` | `TInfo` | Type-only marker for event filter info (not used at runtime) |
19
- | `$data` | `TData` | Type-only marker for event data (not used at runtime) |
20
-
21
- ## `defineEvent`
22
-
23
- Creates a type-safe service event definition with typed info and data.
24
-
25
- ```typescript
26
- export function defineEvent<TInfo = unknown, TData = unknown>(
27
- eventName: string,
28
- ): ServiceEventDef<TInfo, TData>;
29
- ```
30
-
31
- **Parameters:**
32
-
33
- | Parameter | Type | Description |
34
- |-----------|------|-------------|
35
- | `eventName` | `string` | Event name identifier |
36
-
37
- **Type Parameters:**
38
-
39
- | Parameter | Description |
40
- |-----------|-------------|
41
- | `TInfo` | Type of the event filter info |
42
- | `TData` | Type of the event data payload |
43
-
44
- **Returns:** `ServiceEventDef<TInfo, TData>`
45
-
46
- **Example:**
47
-
48
- ```typescript
49
- const OrderUpdated = defineEvent<{ orderId: number }, { status: string }>("OrderUpdated");
50
-
51
- // Server: emit event
52
- ctx.socket?.emitEvent(OrderUpdated, { orderId: 123 }, { status: "shipped" });
53
-
54
- // Client: subscribe
55
- await client.addEventListener(OrderUpdated, { orderId: 123 }, (data) => {
56
- console.log(data.status); // typed as string
57
- });
58
- ```
@@ -1,57 +0,0 @@
1
- # ORM Service Types
2
-
3
- ## `OrmService`
4
-
5
- ORM service interface providing database connection, transaction management, and query execution. Supports MySQL, MSSQL, and PostgreSQL.
6
-
7
- ```typescript
8
- export interface OrmService {
9
- getInfo(opt: DbConnOptions & { configName: string }): Promise<{
10
- dialect: Dialect;
11
- database?: string;
12
- schema?: string;
13
- }>;
14
- connect(opt: DbConnOptions & { configName: string }): Promise<number>;
15
- close(connId: number): Promise<void>;
16
- beginTransaction(connId: number, isolationLevel?: IsolationLevel): Promise<void>;
17
- commitTransaction(connId: number): Promise<void>;
18
- rollbackTransaction(connId: number): Promise<void>;
19
- executeParametrized(connId: number, query: string, params?: unknown[]): Promise<unknown[][]>;
20
- executeDefs(
21
- connId: number,
22
- defs: QueryDef[],
23
- options?: (ResultMeta | undefined)[],
24
- ): Promise<unknown[][]>;
25
- bulkInsert(
26
- connId: number,
27
- tableName: string,
28
- columnDefs: Record<string, ColumnMeta>,
29
- records: Record<string, unknown>[],
30
- ): Promise<void>;
31
- }
32
- ```
33
-
34
- | Method | Parameters | Return | Description |
35
- |--------|-----------|--------|-------------|
36
- | `getInfo` | `opt: DbConnOptions & { configName: string }` | `Promise<{ dialect: Dialect; database?: string; schema?: string }>` | Gets database connection info |
37
- | `connect` | `opt: DbConnOptions & { configName: string }` | `Promise<number>` | Opens a connection, returns connection ID |
38
- | `close` | `connId: number` | `Promise<void>` | Closes a connection |
39
- | `beginTransaction` | `connId: number, isolationLevel?: IsolationLevel` | `Promise<void>` | Begins a transaction |
40
- | `commitTransaction` | `connId: number` | `Promise<void>` | Commits a transaction |
41
- | `rollbackTransaction` | `connId: number` | `Promise<void>` | Rolls back a transaction |
42
- | `executeParametrized` | `connId: number, query: string, params?: unknown[]` | `Promise<unknown[][]>` | Executes a parameterized query |
43
- | `executeDefs` | `connId: number, defs: QueryDef[], options?: (ResultMeta \| undefined)[]` | `Promise<unknown[][]>` | Executes query definitions |
44
- | `bulkInsert` | `connId: number, tableName: string, columnDefs: Record<string, ColumnMeta>, records: Record<string, unknown>[]` | `Promise<void>` | Performs bulk insert |
45
-
46
- ## `DbConnOptions`
47
-
48
- Database connection options.
49
-
50
- ```typescript
51
- export type DbConnOptions = { configName?: string; config?: Record<string, unknown> };
52
- ```
53
-
54
- | Field | Type | Description |
55
- |-------|------|-------------|
56
- | `configName` | `string?` | Configuration name to look up from server config |
57
- | `config` | `Record<string, unknown>?` | Additional configuration overrides |
@@ -1,268 +0,0 @@
1
- # Protocol Types
2
-
3
- ## `PROTOCOL_CONFIG`
4
-
5
- Protocol configuration constants for message size limits and timing.
6
-
7
- ```typescript
8
- export const PROTOCOL_CONFIG: {
9
- readonly MAX_TOTAL_SIZE: 104857600; // 100MB
10
- readonly SPLIT_MESSAGE_SIZE: 3145728; // 3MB
11
- readonly CHUNK_SIZE: 307200; // 300KB
12
- readonly GC_INTERVAL: 10000; // 10s
13
- readonly EXPIRE_TIME: 60000; // 60s
14
- };
15
- ```
16
-
17
- | Field | Value | Description |
18
- |-------|-------|-------------|
19
- | `MAX_TOTAL_SIZE` | `104857600` (100MB) | Maximum total message size |
20
- | `SPLIT_MESSAGE_SIZE` | `3145728` (3MB) | Threshold above which messages are split into chunks |
21
- | `CHUNK_SIZE` | `307200` (300KB) | Size of each chunk when splitting |
22
- | `GC_INTERVAL` | `10000` (10s) | Garbage collection interval for incomplete messages |
23
- | `EXPIRE_TIME` | `60000` (60s) | Expiration time for incomplete messages |
24
-
25
- ## `ServiceMessage`
26
-
27
- Union of all service message types.
28
-
29
- ```typescript
30
- export type ServiceMessage =
31
- | ServiceRequestMessage
32
- | ServiceAuthMessage
33
- | ServiceProgressMessage
34
- | ServiceResponseMessage
35
- | ServiceErrorMessage
36
- | ServiceAddEventListenerMessage
37
- | ServiceRemoveEventListenerMessage
38
- | ServiceGetEventListenerInfosMessage
39
- | ServiceEmitEventMessage
40
- | ServiceEventMessage;
41
- ```
42
-
43
- ## `ServiceServerMessage`
44
-
45
- Union of message types sent from server to client.
46
-
47
- ```typescript
48
- export type ServiceServerMessage =
49
- | ServiceResponseMessage
50
- | ServiceErrorMessage
51
- | ServiceEventMessage;
52
- ```
53
-
54
- ## `ServiceServerRawMessage`
55
-
56
- Union of server raw messages including progress notifications.
57
-
58
- ```typescript
59
- export type ServiceServerRawMessage = ServiceProgressMessage | ServiceServerMessage;
60
- ```
61
-
62
- ## `ServiceClientMessage`
63
-
64
- Union of message types sent from client to server.
65
-
66
- ```typescript
67
- export type ServiceClientMessage =
68
- | ServiceRequestMessage
69
- | ServiceAuthMessage
70
- | ServiceAddEventListenerMessage
71
- | ServiceRemoveEventListenerMessage
72
- | ServiceGetEventListenerInfosMessage
73
- | ServiceEmitEventMessage;
74
- ```
75
-
76
- ## `ServiceProgressMessage`
77
-
78
- Server notification about chunked message reception progress.
79
-
80
- ```typescript
81
- export interface ServiceProgressMessage {
82
- name: "progress";
83
- body: {
84
- totalSize: number;
85
- completedSize: number;
86
- };
87
- }
88
- ```
89
-
90
- | Field | Type | Description |
91
- |-------|------|-------------|
92
- | `name` | `"progress"` | Message type discriminator |
93
- | `body.totalSize` | `number` | Total size in bytes |
94
- | `body.completedSize` | `number` | Completed size in bytes |
95
-
96
- ## `ServiceErrorMessage`
97
-
98
- Server error notification.
99
-
100
- ```typescript
101
- export interface ServiceErrorMessage {
102
- name: "error";
103
- body: {
104
- name: string;
105
- message: string;
106
- code: string;
107
- stack?: string;
108
- detail?: unknown;
109
- cause?: unknown;
110
- };
111
- }
112
- ```
113
-
114
- | Field | Type | Description |
115
- |-------|------|-------------|
116
- | `name` | `"error"` | Message type discriminator |
117
- | `body.name` | `string` | Error name |
118
- | `body.message` | `string` | Error message |
119
- | `body.code` | `string` | Error code (e.g., `"BAD_MESSAGE"`, `"INTERNAL_ERROR"`) |
120
- | `body.stack` | `string?` | Stack trace (dev mode only) |
121
- | `body.detail` | `unknown?` | Additional error detail |
122
- | `body.cause` | `unknown?` | Error cause |
123
-
124
- ## `ServiceAuthMessage`
125
-
126
- Client authentication message.
127
-
128
- ```typescript
129
- export interface ServiceAuthMessage {
130
- name: "auth";
131
- body: string;
132
- }
133
- ```
134
-
135
- | Field | Type | Description |
136
- |-------|------|-------------|
137
- | `name` | `"auth"` | Message type discriminator |
138
- | `body` | `string` | Authentication token |
139
-
140
- ## `ServiceRequestMessage`
141
-
142
- Client service method request.
143
-
144
- ```typescript
145
- export interface ServiceRequestMessage {
146
- name: `${string}.${string}`;
147
- body: unknown[];
148
- }
149
- ```
150
-
151
- | Field | Type | Description |
152
- |-------|------|-------------|
153
- | `name` | `` `${string}.${string}` `` | `${serviceName}.${methodName}` format |
154
- | `body` | `unknown[]` | Method parameters |
155
-
156
- ## `ServiceResponseMessage`
157
-
158
- Server service method response.
159
-
160
- ```typescript
161
- export interface ServiceResponseMessage {
162
- name: "response";
163
- body?: unknown;
164
- }
165
- ```
166
-
167
- | Field | Type | Description |
168
- |-------|------|-------------|
169
- | `name` | `"response"` | Message type discriminator |
170
- | `body` | `unknown?` | Method return value |
171
-
172
- ## `ServiceAddEventListenerMessage`
173
-
174
- Client request to add an event listener.
175
-
176
- ```typescript
177
- export interface ServiceAddEventListenerMessage {
178
- name: "evt:add";
179
- body: {
180
- key: string;
181
- name: string;
182
- info: unknown;
183
- };
184
- }
185
- ```
186
-
187
- | Field | Type | Description |
188
- |-------|------|-------------|
189
- | `name` | `"evt:add"` | Message type discriminator |
190
- | `body.key` | `string` | Listener key (UUID) for removal |
191
- | `body.name` | `string` | Event name |
192
- | `body.info` | `unknown` | Additional listener info for event filtering |
193
-
194
- ## `ServiceRemoveEventListenerMessage`
195
-
196
- Client request to remove an event listener.
197
-
198
- ```typescript
199
- export interface ServiceRemoveEventListenerMessage {
200
- name: "evt:remove";
201
- body: {
202
- key: string;
203
- };
204
- }
205
- ```
206
-
207
- | Field | Type | Description |
208
- |-------|------|-------------|
209
- | `name` | `"evt:remove"` | Message type discriminator |
210
- | `body.key` | `string` | Listener key (UUID) |
211
-
212
- ## `ServiceGetEventListenerInfosMessage`
213
-
214
- Client request to get event listener information.
215
-
216
- ```typescript
217
- export interface ServiceGetEventListenerInfosMessage {
218
- name: "evt:gets";
219
- body: {
220
- name: string;
221
- };
222
- }
223
- ```
224
-
225
- | Field | Type | Description |
226
- |-------|------|-------------|
227
- | `name` | `"evt:gets"` | Message type discriminator |
228
- | `body.name` | `string` | Event name |
229
-
230
- ## `ServiceEmitEventMessage`
231
-
232
- Client request to emit an event to specific listeners.
233
-
234
- ```typescript
235
- export interface ServiceEmitEventMessage {
236
- name: "evt:emit";
237
- body: {
238
- keys: string[];
239
- data: unknown;
240
- };
241
- }
242
- ```
243
-
244
- | Field | Type | Description |
245
- |-------|------|-------------|
246
- | `name` | `"evt:emit"` | Message type discriminator |
247
- | `body.keys` | `string[]` | Target listener keys |
248
- | `body.data` | `unknown` | Event data |
249
-
250
- ## `ServiceEventMessage`
251
-
252
- Server event notification to client.
253
-
254
- ```typescript
255
- export interface ServiceEventMessage {
256
- name: "evt:on";
257
- body: {
258
- keys: string[];
259
- data: unknown;
260
- };
261
- }
262
- ```
263
-
264
- | Field | Type | Description |
265
- |-------|------|-------------|
266
- | `name` | `"evt:on"` | Message type discriminator |
267
- | `body.keys` | `string[]` | Target listener keys |
268
- | `body.data` | `unknown` | Event data |
@@ -1,58 +0,0 @@
1
- # Service Protocol
2
-
3
- ## `ServiceProtocol`
4
-
5
- Binary protocol encoder/decoder interface. Uses a 28-byte header (UUID 16 + TotalSize 8 + Index 4) with JSON body. Automatically chunks messages larger than 3MB into 300KB chunks. Maximum message size is 100MB.
6
-
7
- ```typescript
8
- export interface ServiceProtocol {
9
- encode(uuid: string, message: ServiceMessage): { chunks: Bytes[]; totalSize: number };
10
- decode<T extends ServiceMessage>(bytes: Bytes): ServiceMessageDecodeResult<T>;
11
- dispose(): void;
12
- }
13
- ```
14
-
15
- | Method | Parameters | Return | Description |
16
- |--------|-----------|--------|-------------|
17
- | `encode` | `uuid: string, message: ServiceMessage` | `{ chunks: Bytes[]; totalSize: number }` | Encodes a message, auto-splitting if needed |
18
- | `decode` | `bytes: Bytes` | `ServiceMessageDecodeResult<T>` | Decodes a message, auto-reassembling chunks |
19
- | `dispose` | none | `void` | Releases the internal chunk accumulator GC timer. Must be called when the instance is no longer needed |
20
-
21
- ## `ServiceMessageDecodeResult`
22
-
23
- Decode result union type. Either a complete message or a progress indicator for chunked messages.
24
-
25
- ```typescript
26
- export type ServiceMessageDecodeResult<TMessage extends ServiceMessage> =
27
- | { type: "complete"; uuid: string; message: TMessage }
28
- | { type: "progress"; uuid: string; totalSize: number; completedSize: number };
29
- ```
30
-
31
- When `type` is `"complete"`:
32
-
33
- | Field | Type | Description |
34
- |-------|------|-------------|
35
- | `type` | `"complete"` | All chunks received, message reassembled |
36
- | `uuid` | `string` | Message UUID |
37
- | `message` | `TMessage` | Decoded message |
38
-
39
- When `type` is `"progress"`:
40
-
41
- | Field | Type | Description |
42
- |-------|------|-------------|
43
- | `type` | `"progress"` | Partial chunks received |
44
- | `uuid` | `string` | Message UUID |
45
- | `totalSize` | `number` | Total size in bytes |
46
- | `completedSize` | `number` | Completed size in bytes |
47
-
48
- ## `createServiceProtocol`
49
-
50
- Creates a service protocol encoder/decoder instance.
51
-
52
- ```typescript
53
- export function createServiceProtocol(): ServiceProtocol;
54
- ```
55
-
56
- **Returns:** `ServiceProtocol` -- A new protocol instance with encode/decode/dispose methods.
57
-
58
- The instance maintains an internal `LazyGcMap` accumulator for reassembling chunked messages. The GC timer runs every 10 seconds and expires incomplete messages after 60 seconds.