@simplysm/service-server 13.0.42 → 13.0.43

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 CHANGED
@@ -18,9 +18,12 @@ pnpm add @simplysm/service-server
18
18
 
19
19
  - [`createServiceServer`](#basic-server-configuration) - Factory function for creating a `ServiceServer` instance
20
20
  - [`ServiceServer`](docs/server.md#serviceserver) - Main server class. Creates a Fastify instance and configures routes/plugins
21
- - [`defineService`](#custom-services) - Defines a service with a factory function pattern
21
+ - [`defineService`](#custom-services) - Defines a service with a name and factory function
22
22
  - [`ServiceContext`](docs/server.md#servicecontext) - Context object passed to service factory functions
23
- - `runServiceMethod` - Internal function that dispatches a service method call (auth checks + execution)
23
+ - [`createServiceContext`](docs/server.md#createservicecontext) - Factory function that creates a `ServiceContext` (exported for advanced use)
24
+ - [`runServiceMethod`](docs/server.md#runservicemethod) - Dispatches a service method call with auth checks and execution
25
+ - [`ServiceDefinition`](docs/server.md#servicedefinition) - Type describing a registered service (name + factory + authPermissions)
26
+ - [`ServiceMethods`](docs/server.md#servicemethods) - Type utility that extracts method signatures from a `ServiceDefinition`
24
27
 
25
28
  ### Authentication
26
29
 
package/docs/server.md CHANGED
@@ -154,6 +154,81 @@ import { createServiceContext } from "@simplysm/service-server";
154
154
  const ctx = createServiceContext(server, socket, httpContext, legacyContext);
155
155
  ```
156
156
 
157
+ | Parameter | Type | Description |
158
+ |-----------|------|------|
159
+ | `server` | `ServiceServer<TAuthInfo>` | The server instance |
160
+ | `socket` | `ServiceSocket \| undefined` | WebSocket connection, or `undefined` for HTTP/legacy |
161
+ | `http` | `{ clientName: string; authTokenPayload?: AuthTokenPayload<TAuthInfo> } \| undefined` | HTTP request context |
162
+ | `legacy` | `{ clientName?: string } \| undefined` | V1 legacy context (auto-update only) |
163
+
164
+ ## ServiceDefinition
165
+
166
+ Type describing a registered service. Created by `defineService()`.
167
+
168
+ ```typescript
169
+ import type { ServiceDefinition } from "@simplysm/service-server";
170
+
171
+ interface ServiceDefinition<TMethods = Record<string, (...args: any[]) => any>> {
172
+ /** Service name (used as RPC route prefix, e.g., "User" → "User.getProfile") */
173
+ name: string;
174
+ /** Factory function that returns the service's method object */
175
+ factory: (ctx: ServiceContext) => TMethods;
176
+ /** Auth permissions required at service level (set by wrapping factory with auth()) */
177
+ authPermissions?: string[];
178
+ }
179
+ ```
180
+
181
+ Pass `ServiceDefinition[]` to `ServiceServerOptions.services` when creating the server.
182
+
183
+ ## ServiceMethods
184
+
185
+ Type utility that extracts method signatures from a `ServiceDefinition`. Use this to share method types with the client without exposing implementation details.
186
+
187
+ ```typescript
188
+ import type { ServiceMethods } from "@simplysm/service-server";
189
+
190
+ export const MyService = defineService("My", (ctx) => ({
191
+ hello: async (name: string): Promise<string> => `Hello, ${name}!`,
192
+ }));
193
+
194
+ // Export type for client-side type sharing
195
+ export type MyServiceType = ServiceMethods<typeof MyService>;
196
+ // Equivalent to: { hello: (name: string) => Promise<string> }
197
+
198
+ // Client usage:
199
+ // const service = client.getService<MyServiceType>("My");
200
+ // const result = await service.hello("World");
201
+ ```
202
+
203
+ ## runServiceMethod
204
+
205
+ Dispatches a single service method call. Performs auth checks and executes the method. Used internally by `ServiceServer` for both WebSocket and HTTP transports, but exported for advanced use cases such as custom transports or testing.
206
+
207
+ ```typescript
208
+ import { runServiceMethod } from "@simplysm/service-server";
209
+
210
+ const result = await runServiceMethod(server, {
211
+ serviceName: "My",
212
+ methodName: "hello",
213
+ params: ["World"],
214
+ socket: serviceSocket, // or undefined for HTTP
215
+ http: undefined, // or { clientName, authTokenPayload } for HTTP
216
+ });
217
+ ```
218
+
219
+ | Parameter | Type | Description |
220
+ |-----------|------|------|
221
+ | `server` | `ServiceServer` | The server instance |
222
+ | `def.serviceName` | `string` | Name of the service to dispatch to |
223
+ | `def.methodName` | `string` | Name of the method to invoke |
224
+ | `def.params` | `unknown[]` | Positional arguments for the method |
225
+ | `def.socket` | `ServiceSocket \| undefined` | WebSocket context (for WebSocket requests) |
226
+ | `def.http` | `{ clientName: string; authTokenPayload?: AuthTokenPayload } \| undefined` | HTTP context (for HTTP requests) |
227
+
228
+ Returns: `Promise<unknown>` — the method's return value.
229
+
230
+ Throws if the service or method is not found, or if the caller lacks required auth permissions.
231
+
157
232
  ## Config File Reference
158
233
 
159
234
  Read sections from `.config.json` files using `ctx.getConfig()`. Root and per-client configs are automatically merged.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplysm/service-server",
3
- "version": "13.0.42",
3
+ "version": "13.0.43",
4
4
  "description": "심플리즘 패키지 - 서비스 모듈 (server)",
5
5
  "author": "김석래",
6
6
  "license": "Apache-2.0",
@@ -34,11 +34,11 @@
34
34
  "semver": "^7.7.4",
35
35
  "utf-8-validate": "^6.0.6",
36
36
  "ws": "^8.19.0",
37
- "@simplysm/core-common": "13.0.42",
38
- "@simplysm/orm-common": "13.0.42",
39
- "@simplysm/core-node": "13.0.42",
40
- "@simplysm/service-common": "13.0.42",
41
- "@simplysm/orm-node": "13.0.42"
37
+ "@simplysm/core-common": "13.0.43",
38
+ "@simplysm/core-node": "13.0.43",
39
+ "@simplysm/orm-node": "13.0.43",
40
+ "@simplysm/orm-common": "13.0.43",
41
+ "@simplysm/service-common": "13.0.43"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/semver": "^7.7.1",