@simplysm/service-server 13.0.58 → 13.0.60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/docs/transport.md +64 -1
  2. package/package.json +6 -6
package/docs/transport.md CHANGED
@@ -15,6 +15,23 @@
15
15
 
16
16
  `WebSocketHandler` is created and managed internally by `ServiceServer`. Access its functionality through `ServiceServer` methods (`emitEvent`, `broadcastReload`).
17
17
 
18
+ ### createWebSocketHandler
19
+
20
+ Factory function that creates a `WebSocketHandler` instance.
21
+
22
+ ```typescript
23
+ import { createWebSocketHandler } from "@simplysm/service-server";
24
+
25
+ const handler = createWebSocketHandler(runMethod, jwtSecret);
26
+ ```
27
+
28
+ | Parameter | Type | Description |
29
+ |-----------|------|------|
30
+ | `runMethod` | `(def: { serviceName: string; methodName: string; params: unknown[]; socket?: ServiceSocket }) => Promise<unknown>` | Function to execute service method calls |
31
+ | `jwtSecret` | `string \| undefined` | JWT secret for authentication (`undefined` disables auth) |
32
+
33
+ **Returns:** `WebSocketHandler`
34
+
18
35
  ## ServiceSocket
19
36
 
20
37
  `ServiceSocket` is an interface wrapping a single WebSocket connection. It is available in service methods as `ctx.socket` when the request comes via WebSocket. Create an instance with `createServiceSocket`.
@@ -48,6 +65,25 @@
48
65
  | `close` | `number` | Connection closed (payload is the close code) |
49
66
  | `message` | `{ uuid: string; msg: ServiceClientMessage }` | Decoded message received from client |
50
67
 
68
+ ### createServiceSocket
69
+
70
+ Factory function that creates a `ServiceSocket` instance wrapping a raw WebSocket.
71
+
72
+ ```typescript
73
+ import { createServiceSocket } from "@simplysm/service-server";
74
+
75
+ const serviceSocket = createServiceSocket(socket, clientId, clientName, connReq);
76
+ ```
77
+
78
+ | Parameter | Type | Description |
79
+ |-----------|------|------|
80
+ | `socket` | `WebSocket` | Raw WebSocket connection |
81
+ | `clientId` | `string` | Unique client identifier |
82
+ | `clientName` | `string` | Client app name |
83
+ | `connReq` | `FastifyRequest` | Original Fastify request that initiated the WebSocket upgrade |
84
+
85
+ **Returns:** `ServiceSocket`
86
+
51
87
  ## HTTP API Call
52
88
 
53
89
  Service methods can also be called via HTTP through the `/api/:service/:method` path.
@@ -84,6 +120,13 @@ import { handleHttpRequest } from "@simplysm/service-server";
84
120
  await handleHttpRequest(req, reply, jwtSecret, runMethod);
85
121
  ```
86
122
 
123
+ | Parameter | Type | Description |
124
+ |-----------|------|------|
125
+ | `req` | `FastifyRequest` | Fastify request object |
126
+ | `reply` | `FastifyReply` | Fastify reply object |
127
+ | `jwtSecret` | `string \| undefined` | JWT secret for authentication |
128
+ | `runMethod` | `(def: { serviceName: string; methodName: string; params: unknown[]; http: { clientName: string; authTokenPayload?: AuthTokenPayload } }) => Promise<unknown>` | Function to execute service method calls |
129
+
87
130
  ## File Upload
88
131
 
89
132
  Upload files via multipart request to the `/upload` endpoint. Auth token is required.
@@ -118,6 +161,13 @@ import { handleUpload } from "@simplysm/service-server";
118
161
  await handleUpload(req, reply, rootPath, jwtSecret);
119
162
  ```
120
163
 
164
+ | Parameter | Type | Description |
165
+ |-----------|------|------|
166
+ | `req` | `FastifyRequest` | Fastify request object (must be multipart) |
167
+ | `reply` | `FastifyReply` | Fastify reply object |
168
+ | `rootPath` | `string` | Server root path (files stored under `rootPath/www/uploads/`) |
169
+ | `jwtSecret` | `string \| undefined` | JWT secret for authentication |
170
+
121
171
  ### handleStaticFile
122
172
 
123
173
  The internal handler function for static file serving. Exported for advanced use cases.
@@ -128,6 +178,13 @@ import { handleStaticFile } from "@simplysm/service-server";
128
178
  await handleStaticFile(req, reply, rootPath, urlPath);
129
179
  ```
130
180
 
181
+ | Parameter | Type | Description |
182
+ |-----------|------|------|
183
+ | `req` | `FastifyRequest` | Fastify request object |
184
+ | `reply` | `FastifyReply` | Fastify reply object |
185
+ | `rootPath` | `string` | Server root path (serves files from `rootPath/www/`) |
186
+ | `urlPath` | `string` | URL path relative to the root |
187
+
131
188
  Security behavior:
132
189
  - Blocks path traversal (`..`, outside `rootPath/www/`)
133
190
  - Returns 403 for files starting with `.` (hidden files)
@@ -160,7 +217,13 @@ await server.broadcastReload("my-app", new Set(["main.js"]));
160
217
 
161
218
  ## ProtocolWrapper
162
219
 
163
- `ProtocolWrapper` is an interface for encoding/decoding WebSocket messages. Create an instance with `createProtocolWrapper`. Automatically branches between main thread and worker thread based on message size.
220
+ `ProtocolWrapper` is an interface for encoding/decoding WebSocket messages. Create an instance with `createProtocolWrapper`. Automatically branches between main thread and worker thread based on message size. Uses a shared worker singleton internally.
221
+
222
+ ### createProtocolWrapper
223
+
224
+ Factory function that creates a `ProtocolWrapper` instance.
225
+
226
+ **Returns:** `ProtocolWrapper` (no parameters)
164
227
 
165
228
  ```typescript
166
229
  import { createProtocolWrapper } from "@simplysm/service-server";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplysm/service-server",
3
- "version": "13.0.58",
3
+ "version": "13.0.60",
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.58",
38
- "@simplysm/core-node": "13.0.58",
39
- "@simplysm/orm-node": "13.0.58",
40
- "@simplysm/orm-common": "13.0.58",
41
- "@simplysm/service-common": "13.0.58"
37
+ "@simplysm/core-common": "13.0.60",
38
+ "@simplysm/core-node": "13.0.60",
39
+ "@simplysm/orm-common": "13.0.60",
40
+ "@simplysm/service-common": "13.0.60",
41
+ "@simplysm/orm-node": "13.0.60"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/semver": "^7.7.1",