@simplysm/service-common 13.0.0-beta.11

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 (158) hide show
  1. package/README.md +336 -0
  2. package/dist/core-common/src/common.types.d.ts +74 -0
  3. package/dist/core-common/src/common.types.d.ts.map +1 -0
  4. package/dist/core-common/src/env.d.ts +6 -0
  5. package/dist/core-common/src/env.d.ts.map +1 -0
  6. package/dist/core-common/src/errors/argument-error.d.ts +25 -0
  7. package/dist/core-common/src/errors/argument-error.d.ts.map +1 -0
  8. package/dist/core-common/src/errors/not-implemented-error.d.ts +29 -0
  9. package/dist/core-common/src/errors/not-implemented-error.d.ts.map +1 -0
  10. package/dist/core-common/src/errors/sd-error.d.ts +27 -0
  11. package/dist/core-common/src/errors/sd-error.d.ts.map +1 -0
  12. package/dist/core-common/src/errors/timeout-error.d.ts +31 -0
  13. package/dist/core-common/src/errors/timeout-error.d.ts.map +1 -0
  14. package/dist/core-common/src/extensions/arr-ext.d.ts +15 -0
  15. package/dist/core-common/src/extensions/arr-ext.d.ts.map +1 -0
  16. package/dist/core-common/src/extensions/arr-ext.helpers.d.ts +19 -0
  17. package/dist/core-common/src/extensions/arr-ext.helpers.d.ts.map +1 -0
  18. package/dist/core-common/src/extensions/arr-ext.types.d.ts +215 -0
  19. package/dist/core-common/src/extensions/arr-ext.types.d.ts.map +1 -0
  20. package/dist/core-common/src/extensions/map-ext.d.ts +57 -0
  21. package/dist/core-common/src/extensions/map-ext.d.ts.map +1 -0
  22. package/dist/core-common/src/extensions/set-ext.d.ts +36 -0
  23. package/dist/core-common/src/extensions/set-ext.d.ts.map +1 -0
  24. package/dist/core-common/src/features/debounce-queue.d.ts +53 -0
  25. package/dist/core-common/src/features/debounce-queue.d.ts.map +1 -0
  26. package/dist/core-common/src/features/event-emitter.d.ts +66 -0
  27. package/dist/core-common/src/features/event-emitter.d.ts.map +1 -0
  28. package/dist/core-common/src/features/serial-queue.d.ts +47 -0
  29. package/dist/core-common/src/features/serial-queue.d.ts.map +1 -0
  30. package/dist/core-common/src/index.d.ts +32 -0
  31. package/dist/core-common/src/index.d.ts.map +1 -0
  32. package/dist/core-common/src/types/date-only.d.ts +152 -0
  33. package/dist/core-common/src/types/date-only.d.ts.map +1 -0
  34. package/dist/core-common/src/types/date-time.d.ts +96 -0
  35. package/dist/core-common/src/types/date-time.d.ts.map +1 -0
  36. package/dist/core-common/src/types/lazy-gc-map.d.ts +80 -0
  37. package/dist/core-common/src/types/lazy-gc-map.d.ts.map +1 -0
  38. package/dist/core-common/src/types/time.d.ts +68 -0
  39. package/dist/core-common/src/types/time.d.ts.map +1 -0
  40. package/dist/core-common/src/types/uuid.d.ts +35 -0
  41. package/dist/core-common/src/types/uuid.d.ts.map +1 -0
  42. package/dist/core-common/src/utils/bytes.d.ts +51 -0
  43. package/dist/core-common/src/utils/bytes.d.ts.map +1 -0
  44. package/dist/core-common/src/utils/date-format.d.ts +90 -0
  45. package/dist/core-common/src/utils/date-format.d.ts.map +1 -0
  46. package/dist/core-common/src/utils/json.d.ts +34 -0
  47. package/dist/core-common/src/utils/json.d.ts.map +1 -0
  48. package/dist/core-common/src/utils/num.d.ts +60 -0
  49. package/dist/core-common/src/utils/num.d.ts.map +1 -0
  50. package/dist/core-common/src/utils/obj.d.ts +258 -0
  51. package/dist/core-common/src/utils/obj.d.ts.map +1 -0
  52. package/dist/core-common/src/utils/path.d.ts +23 -0
  53. package/dist/core-common/src/utils/path.d.ts.map +1 -0
  54. package/dist/core-common/src/utils/primitive.d.ts +18 -0
  55. package/dist/core-common/src/utils/primitive.d.ts.map +1 -0
  56. package/dist/core-common/src/utils/str.d.ts +103 -0
  57. package/dist/core-common/src/utils/str.d.ts.map +1 -0
  58. package/dist/core-common/src/utils/template-strings.d.ts +84 -0
  59. package/dist/core-common/src/utils/template-strings.d.ts.map +1 -0
  60. package/dist/core-common/src/utils/transferable.d.ts +47 -0
  61. package/dist/core-common/src/utils/transferable.d.ts.map +1 -0
  62. package/dist/core-common/src/utils/wait.d.ts +19 -0
  63. package/dist/core-common/src/utils/wait.d.ts.map +1 -0
  64. package/dist/core-common/src/utils/xml.d.ts +36 -0
  65. package/dist/core-common/src/utils/xml.d.ts.map +1 -0
  66. package/dist/core-common/src/zip/sd-zip.d.ts +80 -0
  67. package/dist/core-common/src/zip/sd-zip.d.ts.map +1 -0
  68. package/dist/index.js +8 -0
  69. package/dist/index.js.map +7 -0
  70. package/dist/orm-common/src/db-context.d.ts +669 -0
  71. package/dist/orm-common/src/db-context.d.ts.map +1 -0
  72. package/dist/orm-common/src/errors/db-transaction-error.d.ts +51 -0
  73. package/dist/orm-common/src/errors/db-transaction-error.d.ts.map +1 -0
  74. package/dist/orm-common/src/exec/executable.d.ts +79 -0
  75. package/dist/orm-common/src/exec/executable.d.ts.map +1 -0
  76. package/dist/orm-common/src/exec/queryable.d.ts +708 -0
  77. package/dist/orm-common/src/exec/queryable.d.ts.map +1 -0
  78. package/dist/orm-common/src/exec/search-parser.d.ts +72 -0
  79. package/dist/orm-common/src/exec/search-parser.d.ts.map +1 -0
  80. package/dist/orm-common/src/expr/expr-unit.d.ts +25 -0
  81. package/dist/orm-common/src/expr/expr-unit.d.ts.map +1 -0
  82. package/dist/orm-common/src/expr/expr.d.ts +1369 -0
  83. package/dist/orm-common/src/expr/expr.d.ts.map +1 -0
  84. package/dist/orm-common/src/index.d.ts +32 -0
  85. package/dist/orm-common/src/index.d.ts.map +1 -0
  86. package/dist/orm-common/src/models/system-migration.d.ts +10 -0
  87. package/dist/orm-common/src/models/system-migration.d.ts.map +1 -0
  88. package/dist/orm-common/src/query-builder/base/expr-renderer-base.d.ts +95 -0
  89. package/dist/orm-common/src/query-builder/base/expr-renderer-base.d.ts.map +1 -0
  90. package/dist/orm-common/src/query-builder/base/query-builder-base.d.ts +66 -0
  91. package/dist/orm-common/src/query-builder/base/query-builder-base.d.ts.map +1 -0
  92. package/dist/orm-common/src/query-builder/mssql/mssql-expr-renderer.d.ts +84 -0
  93. package/dist/orm-common/src/query-builder/mssql/mssql-expr-renderer.d.ts.map +1 -0
  94. package/dist/orm-common/src/query-builder/mssql/mssql-query-builder.d.ts +45 -0
  95. package/dist/orm-common/src/query-builder/mssql/mssql-query-builder.d.ts.map +1 -0
  96. package/dist/orm-common/src/query-builder/mysql/mysql-expr-renderer.d.ts +84 -0
  97. package/dist/orm-common/src/query-builder/mysql/mysql-expr-renderer.d.ts.map +1 -0
  98. package/dist/orm-common/src/query-builder/mysql/mysql-query-builder.d.ts +54 -0
  99. package/dist/orm-common/src/query-builder/mysql/mysql-query-builder.d.ts.map +1 -0
  100. package/dist/orm-common/src/query-builder/postgresql/postgresql-expr-renderer.d.ts +84 -0
  101. package/dist/orm-common/src/query-builder/postgresql/postgresql-expr-renderer.d.ts.map +1 -0
  102. package/dist/orm-common/src/query-builder/postgresql/postgresql-query-builder.d.ts +52 -0
  103. package/dist/orm-common/src/query-builder/postgresql/postgresql-query-builder.d.ts.map +1 -0
  104. package/dist/orm-common/src/query-builder/query-builder.d.ts +7 -0
  105. package/dist/orm-common/src/query-builder/query-builder.d.ts.map +1 -0
  106. package/dist/orm-common/src/schema/factory/column-builder.d.ts +394 -0
  107. package/dist/orm-common/src/schema/factory/column-builder.d.ts.map +1 -0
  108. package/dist/orm-common/src/schema/factory/index-builder.d.ts +151 -0
  109. package/dist/orm-common/src/schema/factory/index-builder.d.ts.map +1 -0
  110. package/dist/orm-common/src/schema/factory/relation-builder.d.ts +337 -0
  111. package/dist/orm-common/src/schema/factory/relation-builder.d.ts.map +1 -0
  112. package/dist/orm-common/src/schema/procedure-builder.d.ts +202 -0
  113. package/dist/orm-common/src/schema/procedure-builder.d.ts.map +1 -0
  114. package/dist/orm-common/src/schema/table-builder.d.ts +259 -0
  115. package/dist/orm-common/src/schema/table-builder.d.ts.map +1 -0
  116. package/dist/orm-common/src/schema/view-builder.d.ts +183 -0
  117. package/dist/orm-common/src/schema/view-builder.d.ts.map +1 -0
  118. package/dist/orm-common/src/types/column.d.ts +172 -0
  119. package/dist/orm-common/src/types/column.d.ts.map +1 -0
  120. package/dist/orm-common/src/types/db.d.ts +175 -0
  121. package/dist/orm-common/src/types/db.d.ts.map +1 -0
  122. package/dist/orm-common/src/types/expr.d.ts +474 -0
  123. package/dist/orm-common/src/types/expr.d.ts.map +1 -0
  124. package/dist/orm-common/src/types/query-def.d.ts +351 -0
  125. package/dist/orm-common/src/types/query-def.d.ts.map +1 -0
  126. package/dist/orm-common/src/utils/result-parser.d.ts +38 -0
  127. package/dist/orm-common/src/utils/result-parser.d.ts.map +1 -0
  128. package/dist/protocol/protocol.types.js +16 -0
  129. package/dist/protocol/protocol.types.js.map +7 -0
  130. package/dist/protocol/service-protocol.js +134 -0
  131. package/dist/protocol/service-protocol.js.map +7 -0
  132. package/dist/service-common/src/index.d.ts +8 -0
  133. package/dist/service-common/src/index.d.ts.map +1 -0
  134. package/dist/service-common/src/protocol/protocol.types.d.ts +100 -0
  135. package/dist/service-common/src/protocol/protocol.types.d.ts.map +1 -0
  136. package/dist/service-common/src/protocol/service-protocol.d.ts +63 -0
  137. package/dist/service-common/src/protocol/service-protocol.d.ts.map +1 -0
  138. package/dist/service-common/src/service-types/auto-update-service.types.d.ts +17 -0
  139. package/dist/service-common/src/service-types/auto-update-service.types.d.ts.map +1 -0
  140. package/dist/service-common/src/service-types/crypto-service.types.d.ts +22 -0
  141. package/dist/service-common/src/service-types/crypto-service.types.d.ts.map +1 -0
  142. package/dist/service-common/src/service-types/orm-service.types.d.ts +30 -0
  143. package/dist/service-common/src/service-types/orm-service.types.d.ts.map +1 -0
  144. package/dist/service-common/src/service-types/smtp-service.types.d.ts +55 -0
  145. package/dist/service-common/src/service-types/smtp-service.types.d.ts.map +1 -0
  146. package/dist/service-common/src/types.d.ts +43 -0
  147. package/dist/service-common/src/types.d.ts.map +1 -0
  148. package/dist/service-types/auto-update-service.types.js +1 -0
  149. package/dist/service-types/auto-update-service.types.js.map +7 -0
  150. package/dist/service-types/crypto-service.types.js +1 -0
  151. package/dist/service-types/crypto-service.types.js.map +7 -0
  152. package/dist/service-types/orm-service.types.js +1 -0
  153. package/dist/service-types/orm-service.types.js.map +7 -0
  154. package/dist/service-types/smtp-service.types.js +1 -0
  155. package/dist/service-types/smtp-service.types.js.map +7 -0
  156. package/dist/types.js +6 -0
  157. package/dist/types.js.map +7 -0
  158. package/package.json +23 -0
package/README.md ADDED
@@ -0,0 +1,336 @@
1
+ # @simplysm/service-common
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/SMTP/auto-update.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @simplysm/service-common
9
+ ```
10
+
11
+ ### Dependencies
12
+
13
+ | Package | Description |
14
+ |--------|------|
15
+ | `@simplysm/core-common` | Common utilities (`Uuid`, `LazyGcMap`, `jsonStringify`, `jsonParse`, etc.) |
16
+ | `@simplysm/orm-common` | ORM types (`Dialect`, `IsolationLevel`, `QueryDef`, etc.) |
17
+
18
+ ## Main Modules
19
+
20
+ ### Module Structure
21
+
22
+ | Module Path | Description |
23
+ |-----------|------|
24
+ | `protocol/protocol.types` | Protocol constants, message type definitions |
25
+ | `protocol/service-protocol` | Message encoding/decoding class |
26
+ | `service-types/orm-service.types` | ORM service interface and DB connection options |
27
+ | `service-types/crypto-service.types` | Crypto service interface and config |
28
+ | `service-types/smtp-service.types` | SMTP service interface and email options |
29
+ | `service-types/auto-update-service.types` | Auto-update service interface |
30
+ | `types` | `ServiceEventListener`, `ServiceUploadResult` |
31
+
32
+ ---
33
+
34
+ ## ServiceProtocol
35
+
36
+ The core class for encoding/decoding messages into binary format. Messages exceeding 3MB are automatically split into 300KB chunks, and the receiving side automatically assembles the chunks to restore the original message.
37
+
38
+ ### Binary Header Structure
39
+
40
+ Each chunk consists of a 28-byte header and body (Big Endian).
41
+
42
+ | Offset | Size | Field | Description |
43
+ |--------|------|------|------|
44
+ | 0 | 16 bytes | UUID | Message identifier (binary) |
45
+ | 16 | 8 bytes | TotalSize | Total message size (uint64) |
46
+ | 24 | 4 bytes | Index | Chunk index (uint32) |
47
+
48
+ ### API
49
+
50
+ | Method | Return Type | Description |
51
+ |--------|-----------|------|
52
+ | `encode(uuid, message)` | `{ chunks: Bytes[]; totalSize: number }` | Encodes the message and automatically splits if necessary |
53
+ | `decode<T>(bytes)` | `ServiceMessageDecodeResult<T>` | Decodes binary chunks and automatically assembles split messages |
54
+ | `dispose()` | `void` | Releases the GC timer of the internal chunk accumulator. Must be called when the instance is no longer used |
55
+
56
+ ### Decode Result Type
57
+
58
+ `ServiceMessageDecodeResult<T>` is a union type with two states.
59
+
60
+ | `type` | Fields | Description |
61
+ |--------|------|------|
62
+ | `"complete"` | `uuid`, `message: T` | All chunks received and message assembly complete |
63
+ | `"progress"` | `uuid`, `totalSize`, `completedSize` | Split message in progress (only some chunks arrived) |
64
+
65
+ ### Usage Example
66
+
67
+ ```typescript
68
+ import { ServiceProtocol } from "@simplysm/service-common";
69
+ import { Uuid } from "@simplysm/core-common";
70
+
71
+ const protocol = new ServiceProtocol();
72
+
73
+ // Encoding: Convert message to binary chunks
74
+ const uuid = Uuid.new().toString();
75
+ const { chunks, totalSize } = protocol.encode(uuid, {
76
+ name: "TestService.echo",
77
+ body: ["Hello, world!"],
78
+ });
79
+
80
+ // Decoding: Process received chunks one by one
81
+ for (const chunk of chunks) {
82
+ const result = protocol.decode(chunk);
83
+ if (result.type === "complete") {
84
+ console.log(result.message);
85
+ // { name: "TestService.echo", body: ["Hello, world!"] }
86
+ } else {
87
+ // Split message in progress
88
+ const progress = (result.completedSize / result.totalSize) * 100;
89
+ console.log(`Reception progress: ${progress.toFixed(1)}%`);
90
+ }
91
+ }
92
+
93
+ // Clean up instance (release GC timer)
94
+ protocol.dispose();
95
+ ```
96
+
97
+ ---
98
+
99
+ ## Protocol Constants (PROTOCOL_CONFIG)
100
+
101
+ A constant object that controls protocol behavior.
102
+
103
+ ```typescript
104
+ import { PROTOCOL_CONFIG } from "@simplysm/service-common";
105
+ ```
106
+
107
+ | Constant | Value | Description |
108
+ |------|----|------|
109
+ | `MAX_TOTAL_SIZE` | 100MB (104,857,600 bytes) | Maximum size for a single message. `ArgumentError` thrown if exceeded |
110
+ | `SPLIT_MESSAGE_SIZE` | 3MB (3,145,728 bytes) | Chunking threshold. Automatically split if this size is exceeded |
111
+ | `CHUNK_SIZE` | 300KB (307,200 bytes) | Body size of each chunk when split |
112
+ | `GC_INTERVAL` | 10s (10,000ms) | Garbage collection cycle for incomplete messages |
113
+ | `EXPIRE_TIME` | 60s (60,000ms) | Expiration time for incomplete messages. Removed from memory if exceeded |
114
+
115
+ ---
116
+
117
+ ## Message Types
118
+
119
+ Type definitions for messages exchanged between client and server. `ServiceMessage` is a union of all message types.
120
+
121
+ ### Classification by Message Direction
122
+
123
+ | Union Type | Direction | Included Messages |
124
+ |------------|------|------------|
125
+ | `ServiceClientMessage` | Client -> Server | Request, Auth, event-related messages |
126
+ | `ServiceServerMessage` | Server -> Client | Reload, Response, Error, Event |
127
+ | `ServiceServerRawMessage` | Server -> Client (raw) | Progress + `ServiceServerMessage` |
128
+ | `ServiceMessage` | Bidirectional (all) | Union of all message types |
129
+
130
+ ### Individual Message Types
131
+
132
+ #### System Messages
133
+
134
+ | Type | `name` | Direction | `body` Type | Description |
135
+ |------|--------|------|-------------|------|
136
+ | `ServiceReloadMessage` | `"reload"` | Server -> Client | `{ clientName: string \| undefined; changedFileSet: Set<string> }` | Client reload command |
137
+ | `ServiceProgressMessage` | `"progress"` | Server -> Client | `{ totalSize: number; completedSize: number }` | Split message reception progress |
138
+ | `ServiceErrorMessage` | `"error"` | Server -> Client | `{ name, message, code, stack?, detail?, cause? }` | Error notification |
139
+ | `ServiceAuthMessage` | `"auth"` | Client -> Server | `string` (token) | Authentication token transmission |
140
+
141
+ #### Service Method Call Messages
142
+
143
+ | Type | `name` | Direction | `body` Type | Description |
144
+ |------|--------|------|-------------|------|
145
+ | `ServiceRequestMessage` | `` `${service}.${method}` `` | Client -> Server | `unknown[]` (parameter array) | RPC method call request |
146
+ | `ServiceResponseMessage` | `"response"` | Server -> Client | `unknown` (return value) | Method call response |
147
+
148
+ #### Event Messages
149
+
150
+ | Type | `name` | Direction | `body` Type | Description |
151
+ |------|--------|------|-------------|------|
152
+ | `ServiceAddEventListenerMessage` | `"evt:add"` | Client -> Server | `{ key, name, info }` | Event listener registration |
153
+ | `ServiceRemoveEventListenerMessage` | `"evt:remove"` | Client -> Server | `{ key }` | Event listener removal |
154
+ | `ServiceGetEventListenerInfosMessage` | `"evt:gets"` | Client -> Server | `{ name }` | Event listener info list query |
155
+ | `ServiceEmitEventMessage` | `"evt:emit"` | Client -> Server | `{ keys, data }` | Event emission |
156
+ | `ServiceEventMessage` | `"evt:on"` | Server -> Client | `{ keys, data }` | Event notification |
157
+
158
+ ---
159
+
160
+ ## ServiceEventListener
161
+
162
+ An abstract class for defining event listener types. Used by inheriting when defining custom events.
163
+
164
+ ### Type Parameters
165
+
166
+ | Parameter | Description |
167
+ |---------|------|
168
+ | `TInfo` | Additional information type for listener filtering |
169
+ | `TData` | Data type passed when the event is emitted |
170
+
171
+ ### Properties
172
+
173
+ | Property | Type | Description |
174
+ |------|------|------|
175
+ | `eventName` | `string` (abstract) | Mangle-safe event identifier. Must be implemented when inheriting |
176
+ | `$info` | `TInfo` (declare) | For type extraction. Not used at runtime |
177
+ | `$data` | `TData` (declare) | For type extraction. Not used at runtime |
178
+
179
+ ### Usage Example
180
+
181
+ ```typescript
182
+ import { ServiceEventListener } from "@simplysm/service-common";
183
+
184
+ // Custom event definition
185
+ export class DataChangeEvent extends ServiceEventListener<
186
+ { tableName: string; filter: unknown },
187
+ (string | number)[] | undefined
188
+ > {
189
+ readonly eventName = "DataChangeEvent";
190
+ }
191
+
192
+ // Register listener on client (using service-client)
193
+ await client.addEventListener(
194
+ DataChangeEvent,
195
+ { tableName: "User", filter: null },
196
+ (data) => {
197
+ console.log("Changed records:", data);
198
+ },
199
+ );
200
+ ```
201
+
202
+ ---
203
+
204
+ ## ServiceUploadResult
205
+
206
+ An interface representing file upload results.
207
+
208
+ | Field | Type | Description |
209
+ |------|------|------|
210
+ | `path` | `string` | Storage path on server |
211
+ | `filename` | `string` | Original filename |
212
+ | `size` | `number` | File size (bytes) |
213
+
214
+ ---
215
+
216
+ ## Service Interfaces
217
+
218
+ Service interface definitions that are implemented on the server side and called by the client via RPC.
219
+
220
+ ### OrmService
221
+
222
+ Defines database connection, transaction management, and query execution capabilities. Supports MySQL, MSSQL, PostgreSQL.
223
+
224
+ | Method | Parameters | Return Type | Description |
225
+ |--------|---------|-----------|------|
226
+ | `getInfo` | `opt: DbConnOptions & { configName: string }` | `Promise<{ dialect, database?, schema? }>` | Query DB connection info |
227
+ | `connect` | `opt: Record<string, unknown>` | `Promise<number>` | Create DB connection, return connection ID |
228
+ | `close` | `connId: number` | `Promise<void>` | Close DB connection |
229
+ | `beginTransaction` | `connId, isolationLevel?` | `Promise<void>` | Begin transaction |
230
+ | `commitTransaction` | `connId: number` | `Promise<void>` | Commit transaction |
231
+ | `rollbackTransaction` | `connId: number` | `Promise<void>` | Rollback transaction |
232
+ | `executeParametrized` | `connId, query, params?` | `Promise<unknown[][]>` | Execute parameterized query |
233
+ | `executeDefs` | `connId, defs, options?` | `Promise<unknown[][]>` | Execute queries with `QueryDef` array |
234
+ | `bulkInsert` | `connId, tableName, columnDefs, records` | `Promise<void>` | Bulk data insertion |
235
+
236
+ #### DbConnOptions
237
+
238
+ | Field | Type | Description |
239
+ |------|------|------|
240
+ | `configName?` | `string` | Config name to reference in server settings |
241
+ | `config?` | `Record<string, unknown>` | Directly passed connection config |
242
+
243
+ ### CryptoService
244
+
245
+ Defines SHA256 hash generation and AES symmetric key encryption/decryption capabilities.
246
+
247
+ | Method | Parameters | Return Type | Description |
248
+ |--------|---------|-----------|------|
249
+ | `encrypt` | `data: string \| Bytes` | `Promise<string>` | Generate SHA256 hash |
250
+ | `encryptAes` | `data: Bytes` | `Promise<string>` | AES encryption |
251
+ | `decryptAes` | `encText: string` | `Promise<Bytes>` | AES decryption |
252
+
253
+ #### CryptoConfig
254
+
255
+ | Field | Type | Description |
256
+ |------|------|------|
257
+ | `key` | `string` | AES encryption key |
258
+
259
+ ### SmtpService
260
+
261
+ Defines email sending capabilities. Can send by directly passing SMTP settings or by referencing server config.
262
+
263
+ | Method | Parameters | Return Type | Description |
264
+ |--------|---------|-----------|------|
265
+ | `send` | `options: SmtpSendOption` | `Promise<string>` | Send email with direct SMTP settings |
266
+ | `sendByConfig` | `configName, options: SmtpSendByConfigOption` | `Promise<string>` | Send email by referencing server config |
267
+
268
+ #### SmtpSendOption
269
+
270
+ A type combining `SmtpConnectionOptions` and `SmtpEmailContentOptions`, with an additional `from` field.
271
+
272
+ | Field | Type | Required | Description |
273
+ |------|------|------|------|
274
+ | `host` | `string` | Y | SMTP host |
275
+ | `port` | `number` | N | SMTP port |
276
+ | `secure` | `boolean` | N | TLS usage |
277
+ | `user` | `string` | N | SMTP auth user |
278
+ | `pass` | `string` | N | SMTP auth password |
279
+ | `from` | `string` | Y | Sender address |
280
+ | `to` | `string` | Y | Recipient address |
281
+ | `cc` | `string` | N | CC |
282
+ | `bcc` | `string` | N | BCC |
283
+ | `subject` | `string` | Y | Subject |
284
+ | `html` | `string` | Y | Body (HTML) |
285
+ | `attachments` | `SmtpSendAttachment[]` | N | Attachment list |
286
+
287
+ #### SmtpSendByConfigOption
288
+
289
+ Same as `SmtpEmailContentOptions`. SMTP connection info is referenced from server config (`configName`).
290
+
291
+ #### SmtpSendAttachment
292
+
293
+ | Field | Type | Required | Description |
294
+ |------|------|------|------|
295
+ | `filename` | `string` | Y | Attachment filename |
296
+ | `content` | `Bytes` | N | File content (binary). Specify one of `path` or `content` |
297
+ | `path` | `string` | N | File path on server. Specify one of `path` or `content` |
298
+ | `contentType` | `string` | N | MIME type (e.g., `"application/pdf"`) |
299
+
300
+ #### SmtpConfig
301
+
302
+ Server-side SMTP configuration type.
303
+
304
+ | Field | Type | Required | Description |
305
+ |------|------|------|------|
306
+ | `host` | `string` | Y | SMTP host |
307
+ | `port` | `number` | N | SMTP port |
308
+ | `secure` | `boolean` | N | TLS usage |
309
+ | `user` | `string` | N | SMTP auth user |
310
+ | `pass` | `string` | N | SMTP auth password |
311
+ | `senderName` | `string` | Y | Sender display name |
312
+ | `senderEmail` | `string` | N | Sender email address |
313
+
314
+ ### AutoUpdateService
315
+
316
+ Defines a service for querying the latest version information of a client application.
317
+
318
+ | Method | Parameters | Return Type | Description |
319
+ |--------|---------|-----------|------|
320
+ | `getLastVersion` | `platform: string` | `Promise<{ version: string; downloadPath: string } \| undefined>` | Query latest version info for the specified platform. Returns `undefined` if none |
321
+
322
+ Pass values like `"win32"`, `"darwin"`, `"linux"` to `platform`.
323
+
324
+ ---
325
+
326
+ ## Caveats
327
+
328
+ - `ServiceProtocol` instances internally use `LazyGcMap` to manage incomplete split messages. After use, you must call `dispose()` to release the GC timer.
329
+ - Encoding or decoding messages exceeding `PROTOCOL_CONFIG.MAX_TOTAL_SIZE` (100MB) will throw an `ArgumentError`.
330
+ - Passing binary data less than 28 bytes during decoding will throw an `ArgumentError`.
331
+ - Service interfaces (`OrmService`, `CryptoService`, etc.) only provide type definitions. Actual implementations are handled by the `@simplysm/service-server` package.
332
+ - The `$info` and `$data` properties of `ServiceEventListener` are declared with `declare` and do not exist at runtime; they are only used for TypeScript type extraction.
333
+
334
+ ## License
335
+
336
+ Apache-2.0
@@ -0,0 +1,74 @@
1
+ import { DateTime } from "./types/date-time";
2
+ import { DateOnly } from "./types/date-only";
3
+ import { Time } from "./types/time";
4
+ import { Uuid } from "./types/uuid";
5
+ /**
6
+ * Buffer 대신 사용하는 바이너리 타입
7
+ */
8
+ export type Bytes = Uint8Array;
9
+ /**
10
+ * Primitive 타입 매핑
11
+ * orm-common과 공유
12
+ */
13
+ export type PrimitiveTypeMap = {
14
+ string: string;
15
+ number: number;
16
+ boolean: boolean;
17
+ DateTime: DateTime;
18
+ DateOnly: DateOnly;
19
+ Time: Time;
20
+ Uuid: Uuid;
21
+ Bytes: Bytes;
22
+ };
23
+ /**
24
+ * Primitive 타입 문자열 키
25
+ */
26
+ export type PrimitiveTypeStr = keyof PrimitiveTypeMap;
27
+ /**
28
+ * Primitive 타입 유니온
29
+ */
30
+ export type PrimitiveType = PrimitiveTypeMap[PrimitiveTypeStr] | undefined;
31
+ /**
32
+ * 깊은 Partial 타입
33
+ *
34
+ * 객체의 모든 속성을 재귀적으로 선택적(optional)으로 만듭니다.
35
+ * Primitive 타입(string, number, boolean 등)은 그대로 유지하고,
36
+ * 객체/배열 타입만 재귀적으로 Partial을 적용합니다.
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * interface User {
41
+ * name: string;
42
+ * profile: {
43
+ * age: number;
44
+ * address: { city: string };
45
+ * };
46
+ * }
47
+ *
48
+ * // 모든 깊이의 속성이 선택적이 됨
49
+ * const partial: DeepPartial<User> = {
50
+ * profile: { address: {} }
51
+ * };
52
+ * ```
53
+ */
54
+ export type DeepPartial<T> = Partial<{
55
+ [K in keyof T]: T[K] extends PrimitiveType ? T[K] : DeepPartial<T[K]>;
56
+ }>;
57
+ /**
58
+ * 생성자 타입
59
+ *
60
+ * 클래스 생성자를 타입으로 표현할 때 사용합니다.
61
+ * 주로 의존성 주입, 팩토리 패턴, instanceof 체크 등에서 활용됩니다.
62
+ *
63
+ * @example
64
+ * function create<T>(ctor: Type<T>): T {
65
+ * return new ctor();
66
+ * }
67
+ *
68
+ * class MyClass { name = "test"; }
69
+ * const instance = create(MyClass); // MyClass 인스턴스
70
+ */
71
+ export interface Type<T> extends Function {
72
+ new (...args: unknown[]): T;
73
+ }
74
+ //# sourceMappingURL=common.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.types.d.ts","sourceRoot":"","sources":["../../../../core-common/src/common.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAIpC;;GAEG;AACH,MAAM,MAAM,KAAK,GAAG,UAAU,CAAC;AAM/B;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,EAAE,IAAI,CAAC;IACX,KAAK,EAAE,KAAK,CAAC;CACd,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,gBAAgB,CAAC;AAEtD;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,gBAAgB,CAAC,gBAAgB,CAAC,GAAG,SAAS,CAAC;AAM3E;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,OAAO,CAAC;KAClC,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,aAAa,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACtE,CAAC,CAAC;AAEH;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,IAAI,CAAC,CAAC,CAAE,SAAQ,QAAQ;IACvC,KAAK,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;CAC7B"}
@@ -0,0 +1,6 @@
1
+ export declare const env: {
2
+ DEV: boolean;
3
+ VER?: string;
4
+ [key: string]: unknown;
5
+ };
6
+ //# sourceMappingURL=env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../../../core-common/src/env.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,GAAG,EAAE;IAChB,GAAG,EAAE,OAAO,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CAKxB,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { SdError } from "./sd-error";
2
+ /**
3
+ * 인수 오류
4
+ *
5
+ * 잘못된 인수를 받았을 때 발생시키는 에러이다.
6
+ * 인수 객체를 YAML 형식으로 메시지에 포함하여 디버깅을 용이하게 한다.
7
+ *
8
+ * @example
9
+ * // 인수 객체만 전달
10
+ * throw new ArgumentError({ userId: 123, name: null });
11
+ * // 결과 메시지: "인수가 잘못되었습니다.\n\nuserId: 123\nname: null"
12
+ *
13
+ * @example
14
+ * // 커스텀 메시지와 인수 객체 전달
15
+ * throw new ArgumentError("유효하지 않은 사용자", { userId: 123 });
16
+ * // 결과 메시지: "유효하지 않은 사용자\n\nuserId: 123"
17
+ */
18
+ export declare class ArgumentError extends SdError {
19
+ /** 기본 메시지("인수가 잘못되었습니다.")와 함께 인수 객체를 YAML 형식으로 출력 */
20
+ constructor(argObj: Record<string, unknown>);
21
+ /** 커스텀 메시지와 함께 인수 객체를 YAML 형식으로 출력 */
22
+ constructor(message: string, argObj: Record<string, unknown>);
23
+ constructor(arg1: Record<string, unknown> | string, arg2?: Record<string, unknown>);
24
+ }
25
+ //# sourceMappingURL=argument-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"argument-error.d.ts","sourceRoot":"","sources":["../../../../../core-common/src/errors/argument-error.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,aAAc,SAAQ,OAAO;IACxC,qDAAqD;gBACzC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC3C,sCAAsC;gBAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;gBAChD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAYnF"}
@@ -0,0 +1,29 @@
1
+ import { SdError } from "./sd-error";
2
+ /**
3
+ * 미구현 오류
4
+ *
5
+ * 아직 구현되지 않은 기능을 호출했을 때 발생시키는 에러이다.
6
+ * 추상 메서드 스텁, 향후 구현 예정인 분기 등에 사용한다.
7
+ *
8
+ * @example
9
+ * // 추상 메서드 구현 전
10
+ * class BaseService {
11
+ * process(): void {
12
+ * throw new NotImplementedError("서브클래스에서 구현 필요");
13
+ * }
14
+ * }
15
+ *
16
+ * @example
17
+ * // 향후 구현 예정 분기
18
+ * switch (type) {
19
+ * case "A": return handleA();
20
+ * case "B": throw new NotImplementedError(`타입 ${type} 처리`);
21
+ * }
22
+ */
23
+ export declare class NotImplementedError extends SdError {
24
+ /**
25
+ * @param message 추가 설명 메시지
26
+ */
27
+ constructor(message?: string);
28
+ }
29
+ //# sourceMappingURL=not-implemented-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"not-implemented-error.d.ts","sourceRoot":"","sources":["../../../../../core-common/src/errors/not-implemented-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,mBAAoB,SAAQ,OAAO;IAC9C;;OAEG;gBACS,OAAO,CAAC,EAAE,MAAM;CAI7B"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * 오류의 Tree 구조 구성이 가능한 오류 클래스
3
+ * ES2024 cause 속성 활용
4
+ *
5
+ * @example
6
+ * // 원인 에러를 감싸서 생성
7
+ * try {
8
+ * await fetch(url);
9
+ * } catch (err) {
10
+ * throw new SdError(err, "API 호출 실패", "사용자 로드 실패");
11
+ * }
12
+ * // 결과 메시지: "사용자 로드 실패 => API 호출 실패 => 원본 에러 메시지"
13
+ *
14
+ * @example
15
+ * // 메시지만으로 생성
16
+ * throw new SdError("잘못된 상태", "처리 불가");
17
+ * // 결과 메시지: "처리 불가 => 잘못된 상태"
18
+ */
19
+ export declare class SdError extends Error {
20
+ cause?: Error;
21
+ /** 원인 에러를 감싸서 생성. 메시지는 역순으로 연결됨 (상위 메시지 => 하위 메시지 => 원인 메시지) */
22
+ constructor(cause: Error, ...messages: string[]);
23
+ /** 메시지만으로 생성. 메시지는 역순으로 연결됨 (상위 메시지 => 하위 메시지) */
24
+ constructor(...messages: string[]);
25
+ constructor(arg1?: unknown, ...messages: string[]);
26
+ }
27
+ //# sourceMappingURL=sd-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sd-error.d.ts","sourceRoot":"","sources":["../../../../../core-common/src/errors/sd-error.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,OAAQ,SAAQ,KAAK;IACvB,KAAK,CAAC,EAAE,KAAK,CAAC;IAEvB,gEAAgE;gBACpD,KAAK,EAAE,KAAK,EAAE,GAAG,QAAQ,EAAE,MAAM,EAAE;IAC/C,kDAAkD;gBACtC,GAAG,QAAQ,EAAE,MAAM,EAAE;gBACrB,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG,QAAQ,EAAE,MAAM,EAAE;CA2BlD"}
@@ -0,0 +1,31 @@
1
+ import { SdError } from "./sd-error";
2
+ /**
3
+ * 타임아웃 오류
4
+ *
5
+ * 대기 시간이 초과되었을 때 발생하는 에러이다.
6
+ * Wait.until() 등의 비동기 대기 함수에서 최대 시도 횟수를 초과하면 자동으로 발생한다.
7
+ *
8
+ * @example
9
+ * // Wait.until에서 자동 발생
10
+ * try {
11
+ * await Wait.until(() => isReady, 100, 50); // 100ms 간격, 최대 50회
12
+ * } catch (err) {
13
+ * if (err instanceof TimeoutError) {
14
+ * console.log("시간 초과");
15
+ * }
16
+ * }
17
+ *
18
+ * @example
19
+ * // 직접 발생
20
+ * if (elapsed > maxTime) {
21
+ * throw new TimeoutError(undefined, "API 응답 대기 초과");
22
+ * }
23
+ */
24
+ export declare class TimeoutError extends SdError {
25
+ /**
26
+ * @param count 시도 횟수
27
+ * @param message 추가 메시지
28
+ */
29
+ constructor(count?: number, message?: string);
30
+ }
31
+ //# sourceMappingURL=timeout-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timeout-error.d.ts","sourceRoot":"","sources":["../../../../../core-common/src/errors/timeout-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,YAAa,SAAQ,OAAO;IACvC;;;OAGG;gBACS,KAAK,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;CAM7C"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Array 확장 메서드
3
+ *
4
+ * @remarks 각 메서드의 TSDoc은 타입 정의 파일(arr-ext.types.ts) 참조
5
+ */
6
+ import "./map-ext";
7
+ import type { ReadonlyArrayExt, MutableArrayExt } from "./arr-ext.types";
8
+ declare global {
9
+ interface ReadonlyArray<T> extends ReadonlyArrayExt<T> {
10
+ }
11
+ interface Array<T> extends ReadonlyArrayExt<T>, MutableArrayExt<T> {
12
+ }
13
+ }
14
+ export type { ArrayDiffsResult, ArrayDiffs2Result, TreeArray, ComparableType } from "./arr-ext.types";
15
+ //# sourceMappingURL=arr-ext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arr-ext.d.ts","sourceRoot":"","sources":["../../../../../core-common/src/extensions/arr-ext.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,WAAW,CAAC;AAUnB,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EAIhB,MAAM,iBAAiB,CAAC;AA2uBzB,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,aAAa,CAAC,CAAC,CAAE,SAAQ,gBAAgB,CAAC,CAAC,CAAC;KAAG;IACzD,UAAU,KAAK,CAAC,CAAC,CAAE,SAAQ,gBAAgB,CAAC,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC;KAAG;CACtE;AAID,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Array 확장 헬퍼 함수
3
+ */
4
+ import type { ComparableType } from "./arr-ext.types";
5
+ /**
6
+ * DateTime, DateOnly, Time을 비교 가능한 primitive 값으로 변환
7
+ */
8
+ export declare function toComparable(value: ComparableType): string | number | boolean | undefined;
9
+ /**
10
+ * 정렬을 위한 비교 함수
11
+ *
12
+ * @param pp 비교 대상 1
13
+ * @param pn 비교 대상 2
14
+ * @param desc true: 내림차순, false: 오름차순
15
+ * @returns 음수: pp가 앞, 0: 같음, 양수: pn이 앞
16
+ * @note null/undefined 값은 오름차순 시 앞으로, 내림차순 시 뒤로 정렬됨
17
+ */
18
+ export declare function compareForOrder(pp: ComparableType, pn: ComparableType, desc: boolean): number;
19
+ //# sourceMappingURL=arr-ext.helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arr-ext.helpers.d.ts","sourceRoot":"","sources":["../../../../../core-common/src/extensions/arr-ext.helpers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEtD;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAKzF;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,cAAc,EAAE,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE,OAAO,GAAG,MAAM,CAuB7F"}