@simplysm/service-common 13.0.100 → 14.0.4
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 +214 -92
- package/dist/define-event.d.ts +7 -7
- package/dist/define-event.d.ts.map +1 -1
- package/dist/define-event.js +21 -10
- package/dist/define-event.js.map +1 -6
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -6
- package/dist/protocol/create-service-protocol.d.ts +20 -20
- package/dist/protocol/create-service-protocol.d.ts.map +1 -1
- package/dist/protocol/create-service-protocol.js +150 -112
- package/dist/protocol/create-service-protocol.js.map +1 -6
- package/dist/protocol/protocol.types.d.ts +18 -26
- package/dist/protocol/protocol.types.d.ts.map +1 -1
- package/dist/protocol/protocol.types.js +16 -15
- package/dist/protocol/protocol.types.js.map +1 -6
- package/dist/service-types/auto-update-service.types.d.ts +5 -5
- package/dist/service-types/auto-update-service.types.js +2 -1
- package/dist/service-types/auto-update-service.types.js.map +1 -6
- package/dist/service-types/orm-service.types.d.ts +7 -5
- package/dist/service-types/orm-service.types.d.ts.map +1 -1
- package/dist/service-types/orm-service.types.js +2 -1
- package/dist/service-types/orm-service.types.js.map +1 -6
- package/dist/types.d.ts +5 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -1
- package/dist/types.js.map +1 -6
- package/package.json +9 -8
- package/src/define-event.ts +7 -7
- package/src/index.ts +4 -6
- package/src/protocol/create-service-protocol.ts +48 -40
- package/src/protocol/protocol.types.ts +35 -46
- package/src/service-types/auto-update-service.types.ts +5 -5
- package/src/service-types/orm-service.types.ts +5 -5
- package/src/types.ts +5 -5
- package/dist/service-types/smtp-client-service.types.d.ts +0 -38
- package/dist/service-types/smtp-client-service.types.d.ts.map +0 -1
- package/dist/service-types/smtp-client-service.types.js +0 -1
- package/dist/service-types/smtp-client-service.types.js.map +0 -6
- package/docs/events.md +0 -51
- package/docs/protocol.md +0 -252
- package/docs/service-types.md +0 -162
- package/src/service-types/smtp-client-service.types.ts +0 -41
- package/tests/define-event.spec.ts +0 -11
- package/tests/protocol/service-protocol.spec.ts +0 -251
package/README.md
CHANGED
|
@@ -1,111 +1,233 @@
|
|
|
1
1
|
# @simplysm/service-common
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Shared service protocol and types -- binary protocol V2 with chunking, message types, service event definitions.
|
|
4
|
+
|
|
5
|
+
This package provides the platform-neutral foundation shared by both `@simplysm/service-client` and `@simplysm/service-server`.
|
|
6
|
+
|
|
7
|
+
## API
|
|
8
|
+
|
|
9
|
+
| Export | Kind | Category | Description |
|
|
10
|
+
|--------|------|----------|-------------|
|
|
11
|
+
| `PROTOCOL_CONFIG` | const | Protocol | Protocol configuration constants (max size, chunk size, GC interval, expiry) |
|
|
12
|
+
| `ServiceMessage` | type | Protocol | Union of all message types (client + server) |
|
|
13
|
+
| `ServiceServerMessage` | type | Protocol | Union of server-to-client message types |
|
|
14
|
+
| `ServiceServerRawMessage` | type | Protocol | Server raw message (includes progress) |
|
|
15
|
+
| `ServiceClientMessage` | type | Protocol | Union of client-to-server message types |
|
|
16
|
+
| `ServiceProgressMessage` | interface | Protocol | Chunk receive progress notification |
|
|
17
|
+
| `ServiceErrorMessage` | interface | Protocol | Error notification from server |
|
|
18
|
+
| `ServiceAuthMessage` | interface | Protocol | Authentication message from client |
|
|
19
|
+
| `ServiceRequestMessage` | interface | Protocol | Service method request from client |
|
|
20
|
+
| `ServiceResponseMessage` | interface | Protocol | Service method response from server |
|
|
21
|
+
| `ServiceAddEventListenerMessage` | interface | Protocol | Add event listener request |
|
|
22
|
+
| `ServiceRemoveEventListenerMessage` | interface | Protocol | Remove event listener request |
|
|
23
|
+
| `ServiceGetEventListenerInfosMessage` | interface | Protocol | Get event listener info list request |
|
|
24
|
+
| `ServiceEmitEventMessage` | interface | Protocol | Emit event request |
|
|
25
|
+
| `ServiceEventMessage` | interface | Protocol | Event notification from server |
|
|
26
|
+
| `ServiceProtocol` | interface | Protocol | Protocol encoder/decoder interface |
|
|
27
|
+
| `ServiceMessageDecodeResult` | type | Protocol | Decode result (complete or progress) |
|
|
28
|
+
| `createServiceProtocol` | function | Protocol | Create a protocol encoder/decoder instance |
|
|
29
|
+
| `OrmService` | interface | Service Types | ORM service interface (connect, transaction, query) |
|
|
30
|
+
| `DbConnOptions` | type | Service Types | Database connection options |
|
|
31
|
+
| `AutoUpdateService` | interface | Service Types | Auto-update service interface |
|
|
32
|
+
| `ServiceUploadResult` | interface | Types | File upload result |
|
|
33
|
+
| `ServiceEventDef` | interface | Definitions | Event definition created by `defineEvent()` |
|
|
34
|
+
| `defineEvent` | function | Definitions | Define a typed service event |
|
|
35
|
+
|
|
36
|
+
## Protocol
|
|
37
|
+
|
|
38
|
+
### PROTOCOL_CONFIG
|
|
39
|
+
|
|
40
|
+
Protocol configuration constants.
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { PROTOCOL_CONFIG } from "@simplysm/service-common";
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
| Field | Type | Default | Description |
|
|
47
|
+
|-------|------|---------|-------------|
|
|
48
|
+
| `MAX_TOTAL_SIZE` | `number` | `104,857,600` (100 MB) | Maximum message size |
|
|
49
|
+
| `SPLIT_MESSAGE_SIZE` | `number` | `3,145,728` (3 MB) | Chunking threshold -- messages larger than this are split |
|
|
50
|
+
| `CHUNK_SIZE` | `number` | `307,200` (300 KB) | Size of each chunk |
|
|
51
|
+
| `GC_INTERVAL` | `number` | `10,000` (10 s) | Garbage collection interval for incomplete messages |
|
|
52
|
+
| `EXPIRE_TIME` | `number` | `60,000` (60 s) | Expiry time for incomplete chunked messages |
|
|
53
|
+
|
|
54
|
+
### Message Types
|
|
55
|
+
|
|
56
|
+
All messages exchanged between client and server are strongly typed.
|
|
57
|
+
|
|
58
|
+
#### Client-to-Server Messages
|
|
59
|
+
|
|
60
|
+
| Interface | `name` Field | Description |
|
|
61
|
+
|-----------|-------------|-------------|
|
|
62
|
+
| `ServiceAuthMessage` | `"auth"` | Authenticate with a token string |
|
|
63
|
+
| `ServiceRequestMessage` | `` `${service}.${method}` `` | Call a service method with parameters |
|
|
64
|
+
| `ServiceAddEventListenerMessage` | `"evt:add"` | Register an event listener with key, event name, and filter info |
|
|
65
|
+
| `ServiceRemoveEventListenerMessage` | `"evt:remove"` | Unregister an event listener by key |
|
|
66
|
+
| `ServiceGetEventListenerInfosMessage` | `"evt:gets"` | Query listener info list for an event name |
|
|
67
|
+
| `ServiceEmitEventMessage` | `"evt:emit"` | Emit an event to specific listener keys |
|
|
4
68
|
|
|
5
|
-
|
|
69
|
+
#### Server-to-Client Messages
|
|
6
70
|
|
|
7
|
-
|
|
71
|
+
| Interface | `name` Field | Description |
|
|
72
|
+
|-----------|-------------|-------------|
|
|
73
|
+
| `ServiceProgressMessage` | `"progress"` | Chunk receive progress (`totalSize`, `completedSize`) |
|
|
74
|
+
| `ServiceResponseMessage` | `"response"` | Service method return value |
|
|
75
|
+
| `ServiceErrorMessage` | `"error"` | Error with name, message, code, optional stack/detail/cause |
|
|
76
|
+
| `ServiceEventMessage` | `"evt:on"` | Event broadcast to listener keys with data |
|
|
8
77
|
|
|
9
|
-
|
|
10
|
-
|
|
78
|
+
### ServiceProtocol
|
|
79
|
+
|
|
80
|
+
Binary protocol V2 interface. Header: 28 bytes (UUID 16 + TotalSize 8 + Index 4), body: JSON. Auto-chunks messages exceeding 3 MB into 300 KB chunks. Maximum message size: 100 MB.
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
interface ServiceProtocol {
|
|
84
|
+
encode(uuid: string, message: ServiceMessage): { chunks: Bytes[]; totalSize: number };
|
|
85
|
+
decode<T extends ServiceMessage>(bytes: Bytes): ServiceMessageDecodeResult<T>;
|
|
86
|
+
dispose(): void;
|
|
87
|
+
}
|
|
11
88
|
```
|
|
12
89
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
|
17
|
-
|
|
18
|
-
| `PROTOCOL_CONFIG` | const | Protocol configuration constants (sizes, timeouts) |
|
|
19
|
-
| `ServiceProtocol` | interface | Binary protocol encoder/decoder interface |
|
|
20
|
-
| `createServiceProtocol` | function | Create a protocol instance |
|
|
21
|
-
| `ServiceMessageDecodeResult` | type | Decode result (complete or progress) |
|
|
22
|
-
| `ServiceMessage` | type | Union of all message types |
|
|
23
|
-
| `ServiceServerMessage` | type | Server-to-client message union |
|
|
24
|
-
| `ServiceServerRawMessage` | type | Server messages including progress |
|
|
25
|
-
| `ServiceClientMessage` | type | Client-to-server message union |
|
|
26
|
-
| `ServiceReloadMessage` | interface | Server reload command |
|
|
27
|
-
| `ServiceProgressMessage` | interface | Chunked message progress notification |
|
|
28
|
-
| `ServiceErrorMessage` | interface | Server error notification |
|
|
29
|
-
| `ServiceAuthMessage` | interface | Client authentication message |
|
|
30
|
-
| `ServiceRequestMessage` | interface | Client service method request |
|
|
31
|
-
| `ServiceResponseMessage` | interface | Server method response |
|
|
32
|
-
| `ServiceAddEventListenerMessage` | interface | Client add event listener |
|
|
33
|
-
| `ServiceRemoveEventListenerMessage` | interface | Client remove event listener |
|
|
34
|
-
| `ServiceGetEventListenerInfosMessage` | interface | Client request event listener infos |
|
|
35
|
-
| `ServiceEmitEventMessage` | interface | Client emit event |
|
|
36
|
-
| `ServiceEventMessage` | interface | Server event notification |
|
|
37
|
-
|
|
38
|
-
-> See [docs/protocol.md](./docs/protocol.md) for details.
|
|
39
|
-
|
|
40
|
-
### Service Types
|
|
41
|
-
| API | Type | Description |
|
|
42
|
-
|-----|------|-------------|
|
|
43
|
-
| `OrmService` | interface | ORM service interface (connect, query, transaction) |
|
|
44
|
-
| `DbConnOptions` | type | Database connection options |
|
|
45
|
-
| `AutoUpdateService` | interface | Auto-update service interface |
|
|
46
|
-
| `SmtpClientSendOption` | interface | Full SMTP send options |
|
|
47
|
-
| `SmtpClientSendByDefaultOption` | interface | SMTP send with server defaults |
|
|
48
|
-
| `SmtpClientSendAttachment` | interface | Email attachment definition |
|
|
49
|
-
| `SmtpClientDefaultOptions` | interface | Default SMTP client config |
|
|
50
|
-
|
|
51
|
-
-> See [docs/service-types.md](./docs/service-types.md) for details.
|
|
52
|
-
|
|
53
|
-
### Types
|
|
54
|
-
| API | Type | Description |
|
|
55
|
-
|-----|------|-------------|
|
|
56
|
-
| `ServiceUploadResult` | interface | File upload result (path, filename, size) |
|
|
57
|
-
|
|
58
|
-
-> See [docs/events.md](./docs/events.md) for details.
|
|
59
|
-
|
|
60
|
-
### Event Definition
|
|
61
|
-
| API | Type | Description |
|
|
62
|
-
|-----|------|-------------|
|
|
63
|
-
| `ServiceEventDef` | interface | Type-safe event definition |
|
|
64
|
-
| `defineEvent` | function | Define a service event with typed info and data |
|
|
65
|
-
|
|
66
|
-
-> See [docs/events.md](./docs/events.md) for details.
|
|
67
|
-
|
|
68
|
-
## Usage Examples
|
|
69
|
-
|
|
70
|
-
### Define and Use Events
|
|
71
|
-
|
|
72
|
-
```typescript
|
|
73
|
-
import { defineEvent } from "@simplysm/service-common";
|
|
90
|
+
| Method | Parameters | Return | Description |
|
|
91
|
+
|--------|-----------|--------|-------------|
|
|
92
|
+
| `encode` | `uuid: string`, `message: ServiceMessage` | `{ chunks: Bytes[]; totalSize: number }` | Encode a message into binary chunks |
|
|
93
|
+
| `decode` | `bytes: Bytes` | `ServiceMessageDecodeResult<T>` | Decode received bytes; returns `"complete"` or `"progress"` |
|
|
94
|
+
| `dispose` | -- | `void` | Clean up internal GC timers |
|
|
74
95
|
|
|
75
|
-
|
|
76
|
-
const OrderUpdated = defineEvent<
|
|
77
|
-
{ orderId: number }, // TInfo: filter info
|
|
78
|
-
{ status: string } // TData: event data
|
|
79
|
-
>("OrderUpdated");
|
|
96
|
+
### ServiceMessageDecodeResult\<TMessage\>
|
|
80
97
|
|
|
81
|
-
|
|
82
|
-
|
|
98
|
+
```ts
|
|
99
|
+
type ServiceMessageDecodeResult<TMessage extends ServiceMessage> =
|
|
100
|
+
| { type: "complete"; uuid: string; message: TMessage }
|
|
101
|
+
| { type: "progress"; uuid: string; totalSize: number; completedSize: number };
|
|
102
|
+
```
|
|
83
103
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
104
|
+
- `"complete"` -- all chunks received; the full message is available.
|
|
105
|
+
- `"progress"` -- chunked message still in progress.
|
|
106
|
+
|
|
107
|
+
### createServiceProtocol
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
function createServiceProtocol(): ServiceProtocol;
|
|
88
111
|
```
|
|
89
112
|
|
|
90
|
-
|
|
113
|
+
Creates a binary protocol V2 encoder/decoder instance.
|
|
91
114
|
|
|
92
|
-
|
|
93
|
-
import { createServiceProtocol } from "@simplysm/service-common";
|
|
115
|
+
## Service Types
|
|
94
116
|
|
|
95
|
-
|
|
117
|
+
### OrmService
|
|
96
118
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
});
|
|
119
|
+
ORM service interface. Supports MySQL, MSSQL, and PostgreSQL.
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
interface OrmService {
|
|
123
|
+
getInfo(opt: DbConnOptions & { configName: string }): Promise<{ dialect: Dialect; database?: string; schema?: string }>;
|
|
124
|
+
connect(opt: DbConnOptions & { configName: string }): Promise<number>;
|
|
125
|
+
close(connId: number): Promise<void>;
|
|
126
|
+
beginTransaction(connId: number, isolationLevel?: IsolationLevel): Promise<void>;
|
|
127
|
+
commitTransaction(connId: number): Promise<void>;
|
|
128
|
+
rollbackTransaction(connId: number): Promise<void>;
|
|
129
|
+
executeParametrized(connId: number, query: string, params?: unknown[]): Promise<unknown[][]>;
|
|
130
|
+
executeDefs(connId: number, defs: QueryDef[], options?: (ResultMeta | undefined)[]): Promise<unknown[][]>;
|
|
131
|
+
bulkInsert(connId: number, tableName: string, columnDefs: Record<string, ColumnMeta>, records: Record<string, unknown>[]): Promise<void>;
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
| Method | Parameters | Return | Description |
|
|
136
|
+
|--------|-----------|--------|-------------|
|
|
137
|
+
| `getInfo` | `opt: DbConnOptions & { configName: string }` | `Promise<{ dialect; database?; schema? }>` | Get database dialect and schema info |
|
|
138
|
+
| `connect` | `opt: DbConnOptions & { configName: string }` | `Promise<number>` | Open a connection; returns connection ID |
|
|
139
|
+
| `close` | `connId: number` | `Promise<void>` | Close a connection |
|
|
140
|
+
| `beginTransaction` | `connId: number`, `isolationLevel?: IsolationLevel` | `Promise<void>` | Begin a transaction |
|
|
141
|
+
| `commitTransaction` | `connId: number` | `Promise<void>` | Commit the current transaction |
|
|
142
|
+
| `rollbackTransaction` | `connId: number` | `Promise<void>` | Rollback the current transaction |
|
|
143
|
+
| `executeParametrized` | `connId: number`, `query: string`, `params?: unknown[]` | `Promise<unknown[][]>` | Execute a parameterized query |
|
|
144
|
+
| `executeDefs` | `connId: number`, `defs: QueryDef[]`, `options?: (ResultMeta \| undefined)[]` | `Promise<unknown[][]>` | Execute query definitions |
|
|
145
|
+
| `bulkInsert` | `connId: number`, `tableName: string`, `columnDefs: Record<string, ColumnMeta>`, `records: Record<string, unknown>[]` | `Promise<void>` | Bulk insert records |
|
|
146
|
+
|
|
147
|
+
### DbConnOptions
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
type DbConnOptions = { configName?: string; config?: Record<string, unknown> };
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
| Field | Type | Description |
|
|
154
|
+
|-------|------|-------------|
|
|
155
|
+
| `configName` | `string?` | Configuration name to look up |
|
|
156
|
+
| `config` | `Record<string, unknown>?` | Inline configuration object |
|
|
157
|
+
|
|
158
|
+
### AutoUpdateService
|
|
159
|
+
|
|
160
|
+
Auto-update service interface. Retrieves the latest version information for client applications.
|
|
161
|
+
|
|
162
|
+
```ts
|
|
163
|
+
interface AutoUpdateService {
|
|
164
|
+
getLastVersion(platform: string): Promise<{ version: string; downloadPath: string } | undefined>;
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
| Method | Parameters | Return | Description |
|
|
169
|
+
|--------|-----------|--------|-------------|
|
|
170
|
+
| `getLastVersion` | `platform: string` | `Promise<{ version: string; downloadPath: string } \| undefined>` | Get latest version info for a platform |
|
|
171
|
+
|
|
172
|
+
## Types
|
|
173
|
+
|
|
174
|
+
### ServiceUploadResult
|
|
175
|
+
|
|
176
|
+
File upload result containing server-side storage information.
|
|
177
|
+
|
|
178
|
+
```ts
|
|
179
|
+
interface ServiceUploadResult {
|
|
180
|
+
path: string;
|
|
181
|
+
filename: string;
|
|
182
|
+
size: number;
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
| Field | Type | Description |
|
|
187
|
+
|-------|------|-------------|
|
|
188
|
+
| `path` | `string` | Server-side storage path |
|
|
189
|
+
| `filename` | `string` | Original file name |
|
|
190
|
+
| `size` | `number` | File size in bytes |
|
|
191
|
+
|
|
192
|
+
## Definitions
|
|
193
|
+
|
|
194
|
+
### ServiceEventDef\<TInfo, TData\>
|
|
102
195
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
196
|
+
Event definition created by `defineEvent()`. The `$info` and `$data` fields are type-only markers (not used at runtime).
|
|
197
|
+
|
|
198
|
+
```ts
|
|
199
|
+
interface ServiceEventDef<TInfo = unknown, TData = unknown> {
|
|
200
|
+
eventName: string;
|
|
201
|
+
readonly $info: TInfo;
|
|
202
|
+
readonly $data: TData;
|
|
107
203
|
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
| Field | Type | Description |
|
|
207
|
+
|-------|------|-------------|
|
|
208
|
+
| `eventName` | `string` | Event name identifier |
|
|
209
|
+
| `$info` | `TInfo` | Type-only marker for listener filter info |
|
|
210
|
+
| `$data` | `TData` | Type-only marker for event payload data |
|
|
211
|
+
|
|
212
|
+
### defineEvent
|
|
213
|
+
|
|
214
|
+
```ts
|
|
215
|
+
function defineEvent<TInfo = unknown, TData = unknown>(eventName: string): ServiceEventDef<TInfo, TData>;
|
|
216
|
+
```
|
|
108
217
|
|
|
109
|
-
|
|
110
|
-
|
|
218
|
+
Define a typed service event for use with the event system.
|
|
219
|
+
|
|
220
|
+
```ts
|
|
221
|
+
import { defineEvent } from "@simplysm/service-common";
|
|
222
|
+
|
|
223
|
+
// Define an event with typed info and data
|
|
224
|
+
const MyEvent = defineEvent<{ userId: number }, { message: string }>("MyEvent");
|
|
225
|
+
|
|
226
|
+
// Server: emit the event
|
|
227
|
+
await server.emitEvent(MyEvent, (info) => info.userId === 123, { message: "hello" });
|
|
228
|
+
|
|
229
|
+
// Client: subscribe to the event
|
|
230
|
+
await client.addListener(MyEvent, { userId: 123 }, async (data) => {
|
|
231
|
+
console.log(data.message);
|
|
232
|
+
});
|
|
111
233
|
```
|
package/dist/define-event.d.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* $info
|
|
2
|
+
* defineEvent()로 생성된 이벤트 정의.
|
|
3
|
+
* $info와 $data는 타입 전용 마커임 (런타임에서는 사용되지 않음).
|
|
4
4
|
*/
|
|
5
5
|
export interface ServiceEventDef<TInfo = unknown, TData = unknown> {
|
|
6
6
|
eventName: string;
|
|
7
|
-
/**
|
|
7
|
+
/** 타입 추출 전용 (런타임에서는 사용되지 않음) */
|
|
8
8
|
readonly $info: TInfo;
|
|
9
|
-
/**
|
|
9
|
+
/** 타입 추출 전용 (런타임에서는 사용되지 않음) */
|
|
10
10
|
readonly $data: TData;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* 타입 안전한 info와 data를 가진 서비스 이벤트를 정의한다.
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
16
16
|
* const OrderUpdated = defineEvent<{ orderId: number }, { status: string }>("OrderUpdated");
|
|
17
17
|
*
|
|
18
|
-
* //
|
|
18
|
+
* // 서버에서 이벤트 발생
|
|
19
19
|
* ctx.socket?.emitEvent(OrderUpdated, { orderId: 123 }, { status: "shipped" });
|
|
20
20
|
*
|
|
21
|
-
* //
|
|
21
|
+
* // 클라이언트에서 구독
|
|
22
22
|
* await client.addEventListener(OrderUpdated, { orderId: 123 }, (data) => {
|
|
23
23
|
* console.log(data.status); // typed
|
|
24
24
|
* });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-event.d.ts","sourceRoot":"","sources":["..\\src\\define-event.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,eAAe,CAAC,KAAK,GAAG,OAAO,EAAE,KAAK,GAAG,OAAO;IAC/D,SAAS,EAAE,MAAM,CAAC;IAClB,
|
|
1
|
+
{"version":3,"file":"define-event.d.ts","sourceRoot":"","sources":["..\\src\\define-event.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,eAAe,CAAC,KAAK,GAAG,OAAO,EAAE,KAAK,GAAG,OAAO;IAC/D,SAAS,EAAE,MAAM,CAAC;IAClB,gCAAgC;IAChC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,gCAAgC;IAChC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;CACvB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,KAAK,GAAG,OAAO,EAAE,KAAK,GAAG,OAAO,EAC1D,SAAS,EAAE,MAAM,GAChB,eAAe,CAAC,KAAK,EAAE,KAAK,CAAC,CAM/B"}
|
package/dist/define-event.js
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
/**
|
|
2
|
+
* 타입 안전한 info와 data를 가진 서비스 이벤트를 정의한다.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* const OrderUpdated = defineEvent<{ orderId: number }, { status: string }>("OrderUpdated");
|
|
6
|
+
*
|
|
7
|
+
* // 서버에서 이벤트 발생
|
|
8
|
+
* ctx.socket?.emitEvent(OrderUpdated, { orderId: 123 }, { status: "shipped" });
|
|
9
|
+
*
|
|
10
|
+
* // 클라이언트에서 구독
|
|
11
|
+
* await client.addEventListener(OrderUpdated, { orderId: 123 }, (data) => {
|
|
12
|
+
* console.log(data.status); // typed
|
|
13
|
+
* });
|
|
14
|
+
*/
|
|
15
|
+
export function defineEvent(eventName) {
|
|
16
|
+
return {
|
|
17
|
+
eventName,
|
|
18
|
+
$info: undefined,
|
|
19
|
+
$data: undefined,
|
|
20
|
+
};
|
|
7
21
|
}
|
|
8
|
-
|
|
9
|
-
defineEvent
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=define-event.js.map
|
|
22
|
+
//# sourceMappingURL=define-event.js.map
|
package/dist/define-event.js.map
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/define-event.ts"],
|
|
4
|
-
"mappings": "AA0BO,SAAS,YACd,WAC+B;AAC/B,SAAO;AAAA,IACL;AAAA,IACA,OAAO;AAAA,IACP,OAAO;AAAA,EACT;AACF;",
|
|
5
|
-
"names": []
|
|
6
|
-
}
|
|
1
|
+
{"version":3,"file":"define-event.js","sourceRoot":"","sources":["..\\src\\define-event.ts"],"names":[],"mappings":"AAYA;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,WAAW,CACzB,SAAiB;IAEjB,OAAO;QACL,SAAS;QACT,KAAK,EAAE,SAA6B;QACpC,KAAK,EAAE,SAA6B;KACrC,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ export * from "./protocol/protocol.types";
|
|
|
2
2
|
export * from "./protocol/create-service-protocol";
|
|
3
3
|
export * from "./service-types/orm-service.types";
|
|
4
4
|
export * from "./service-types/auto-update-service.types";
|
|
5
|
-
export * from "./service-types/smtp-client-service.types";
|
|
6
5
|
export * from "./types";
|
|
7
6
|
export * from "./define-event";
|
|
8
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["..\\src\\index.ts"],"names":[],"mappings":"AACA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oCAAoC,CAAC;AAGnD,cAAc,mCAAmC,CAAC;AAClD,cAAc,2CAA2C,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["..\\src\\index.ts"],"names":[],"mappings":"AACA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oCAAoC,CAAC;AAGnD,cAAc,mCAAmC,CAAC;AAClD,cAAc,2CAA2C,CAAC;AAE1D,cAAc,SAAS,CAAC;AAGxB,cAAc,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
// 프로토콜
|
|
1
2
|
export * from "./protocol/protocol.types.js";
|
|
2
3
|
export * from "./protocol/create-service-protocol.js";
|
|
4
|
+
// 서비스 타입
|
|
3
5
|
export * from "./service-types/orm-service.types.js";
|
|
4
6
|
export * from "./service-types/auto-update-service.types.js";
|
|
5
|
-
|
|
7
|
+
// 타입
|
|
6
8
|
export * from "./types.js";
|
|
9
|
+
// 정의
|
|
7
10
|
export * from "./define-event.js";
|
|
8
|
-
//# sourceMappingURL=index.js.map
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/index.ts"],
|
|
4
|
-
"mappings": "AACA,cAAc;AACd,cAAc;AAGd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,cAAc;AAGd,cAAc;",
|
|
5
|
-
"names": []
|
|
6
|
-
}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["..\\src\\index.ts"],"names":[],"mappings":"AAAA,OAAO;AACP,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oCAAoC,CAAC;AAEnD,SAAS;AACT,cAAc,mCAAmC,CAAC;AAClD,cAAc,2CAA2C,CAAC;AAC1D,KAAK;AACL,cAAc,SAAS,CAAC;AAExB,KAAK;AACL,cAAc,gBAAgB,CAAC"}
|
|
@@ -2,39 +2,39 @@ import type { Bytes } from "@simplysm/core-common";
|
|
|
2
2
|
import "@simplysm/core-common";
|
|
3
3
|
import { type ServiceMessage } from "./protocol.types";
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* 서비스 프로토콜 인터페이스
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
* -
|
|
9
|
-
* -
|
|
10
|
-
* -
|
|
11
|
-
* -
|
|
7
|
+
* 바이너리 프로토콜 V2:
|
|
8
|
+
* - 헤더: 28바이트 (UUID 16 + TotalSize 8 + Index 4)
|
|
9
|
+
* - 본문: JSON
|
|
10
|
+
* - 자동 청킹: 3MB 초과 시 300KB 청크로 분할
|
|
11
|
+
* - 최대 메시지 크기: 100MB
|
|
12
12
|
*/
|
|
13
13
|
export interface ServiceProtocol {
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* 메시지를 인코딩한다 (필요 시 자동 분할)
|
|
16
16
|
*/
|
|
17
17
|
encode(uuid: string, message: ServiceMessage): {
|
|
18
18
|
chunks: Bytes[];
|
|
19
19
|
totalSize: number;
|
|
20
20
|
};
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* 메시지를 디코딩한다 (청크 패킷 자동 재조립)
|
|
23
23
|
*/
|
|
24
24
|
decode<T extends ServiceMessage>(bytes: Bytes): ServiceMessageDecodeResult<T>;
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
26
|
+
* 프로토콜 인스턴스를 해제한다.
|
|
27
27
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
28
|
+
* 내부 청크 누적기의 GC 타이머를 해제하고 메모리를 반환한다.
|
|
29
|
+
* 프로토콜 인스턴스가 더 이상 필요하지 않을 때 반드시 호출해야 한다.
|
|
30
30
|
*/
|
|
31
31
|
dispose(): void;
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
|
-
*
|
|
34
|
+
* 메시지 디코딩 결과 타입 (유니언)
|
|
35
35
|
*
|
|
36
|
-
* - `type: "complete"`:
|
|
37
|
-
* - `type: "progress"`:
|
|
36
|
+
* - `type: "complete"`: 모든 청크를 수신하여 메시지 재조립이 완료됨
|
|
37
|
+
* - `type: "progress"`: 청크 메시지 진행 중 (일부 청크만 도착)
|
|
38
38
|
*/
|
|
39
39
|
export type ServiceMessageDecodeResult<TMessage extends ServiceMessage> = {
|
|
40
40
|
type: "complete";
|
|
@@ -47,13 +47,13 @@ export type ServiceMessageDecodeResult<TMessage extends ServiceMessage> = {
|
|
|
47
47
|
completedSize: number;
|
|
48
48
|
};
|
|
49
49
|
/**
|
|
50
|
-
*
|
|
50
|
+
* 서비스 프로토콜 인코더/디코더를 생성한다
|
|
51
51
|
*
|
|
52
|
-
*
|
|
53
|
-
* -
|
|
54
|
-
* -
|
|
55
|
-
* -
|
|
56
|
-
* -
|
|
52
|
+
* 바이너리 프로토콜 V2:
|
|
53
|
+
* - 헤더: 28바이트 (UUID 16 + TotalSize 8 + Index 4)
|
|
54
|
+
* - 본문: JSON
|
|
55
|
+
* - 자동 청킹: 3MB 초과 시 300KB 청크로 분할
|
|
56
|
+
* - 최대 메시지 크기: 100MB
|
|
57
57
|
*/
|
|
58
58
|
export declare function createServiceProtocol(): ServiceProtocol;
|
|
59
59
|
//# sourceMappingURL=create-service-protocol.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-service-protocol.d.ts","sourceRoot":"","sources":["..\\..\\src\\protocol\\create-service-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,uBAAuB,CAAC;AAQ/B,OAAO,EAAmB,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAExE;;;;;;;;GAQG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG;QAAE,MAAM,EAAE,KAAK,EAAE,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAEtF;;OAEG;IACH,MAAM,CAAC,CAAC,SAAS,cAAc,EAAE,KAAK,EAAE,KAAK,GAAG,0BAA0B,CAAC,CAAC,CAAC,CAAC;IAE9E;;;;;OAKG;IACH,OAAO,IAAI,IAAI,CAAC;CACjB;AAED;;;;;GAKG;AACH,MAAM,MAAM,0BAA0B,CAAC,QAAQ,SAAS,cAAc,IAClE;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,QAAQ,CAAA;CAAE,GACrD;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjF;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,IAAI,eAAe,
|
|
1
|
+
{"version":3,"file":"create-service-protocol.d.ts","sourceRoot":"","sources":["..\\..\\src\\protocol\\create-service-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,uBAAuB,CAAC;AAQ/B,OAAO,EAAmB,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAExE;;;;;;;;GAQG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG;QAAE,MAAM,EAAE,KAAK,EAAE,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAEtF;;OAEG;IACH,MAAM,CAAC,CAAC,SAAS,cAAc,EAAE,KAAK,EAAE,KAAK,GAAG,0BAA0B,CAAC,CAAC,CAAC,CAAC;IAE9E;;;;;OAKG;IACH,OAAO,IAAI,IAAI,CAAC;CACjB;AAED;;;;;GAKG;AACH,MAAM,MAAM,0BAA0B,CAAC,QAAQ,SAAS,cAAc,IAClE;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,QAAQ,CAAA;CAAE,GACrD;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjF;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,IAAI,eAAe,CAqLvD"}
|