@simplysm/service-server 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.
Files changed (88) hide show
  1. package/README.md +79 -133
  2. package/dist/auth/auth-token-payload.js +2 -1
  3. package/dist/auth/auth-token-payload.js.map +1 -6
  4. package/dist/auth/jwt-manager.js +21 -21
  5. package/dist/auth/jwt-manager.js.map +1 -6
  6. package/dist/core/define-service.d.ts +12 -12
  7. package/dist/core/define-service.d.ts.map +1 -1
  8. package/dist/core/define-service.js +77 -63
  9. package/dist/core/define-service.js.map +1 -6
  10. package/dist/core/service-executor.d.ts.map +1 -1
  11. package/dist/core/service-executor.js +42 -32
  12. package/dist/core/service-executor.js.map +1 -6
  13. package/dist/index.d.ts +0 -1
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +11 -2
  16. package/dist/index.js.map +1 -6
  17. package/dist/legacy/v1-auto-update-handler.d.ts +2 -2
  18. package/dist/legacy/v1-auto-update-handler.js +42 -35
  19. package/dist/legacy/v1-auto-update-handler.js.map +1 -6
  20. package/dist/protocol/protocol-wrapper.d.ts +9 -9
  21. package/dist/protocol/protocol-wrapper.js +64 -46
  22. package/dist/protocol/protocol-wrapper.js.map +1 -6
  23. package/dist/service-server.d.ts +2 -1
  24. package/dist/service-server.d.ts.map +1 -1
  25. package/dist/service-server.js +183 -165
  26. package/dist/service-server.js.map +1 -6
  27. package/dist/services/auto-update-service.js +35 -34
  28. package/dist/services/auto-update-service.js.map +1 -6
  29. package/dist/services/orm-service.js +114 -120
  30. package/dist/services/orm-service.js.map +1 -6
  31. package/dist/transport/http/http-request-handler.d.ts.map +1 -1
  32. package/dist/transport/http/http-request-handler.js +58 -46
  33. package/dist/transport/http/http-request-handler.js.map +1 -6
  34. package/dist/transport/http/static-file-handler.js +42 -39
  35. package/dist/transport/http/static-file-handler.js.map +1 -6
  36. package/dist/transport/http/upload-handler.d.ts.map +1 -1
  37. package/dist/transport/http/upload-handler.js +60 -55
  38. package/dist/transport/http/upload-handler.js.map +1 -6
  39. package/dist/transport/socket/service-socket.d.ts +13 -13
  40. package/dist/transport/socket/service-socket.js +132 -108
  41. package/dist/transport/socket/service-socket.js.map +1 -6
  42. package/dist/transport/socket/websocket-handler.d.ts +9 -13
  43. package/dist/transport/socket/websocket-handler.d.ts.map +1 -1
  44. package/dist/transport/socket/websocket-handler.js +148 -139
  45. package/dist/transport/socket/websocket-handler.js.map +1 -6
  46. package/dist/types/server-options.d.ts +1 -1
  47. package/dist/types/server-options.d.ts.map +1 -1
  48. package/dist/types/server-options.js +2 -1
  49. package/dist/types/server-options.js.map +1 -6
  50. package/dist/utils/config-manager.js +48 -46
  51. package/dist/utils/config-manager.js.map +1 -6
  52. package/dist/workers/service-protocol.worker.js +8 -11
  53. package/dist/workers/service-protocol.worker.js.map +1 -6
  54. package/docs/auth.md +28 -16
  55. package/docs/core.md +113 -54
  56. package/docs/legacy.md +21 -0
  57. package/docs/main.md +81 -0
  58. package/docs/protocol.md +31 -0
  59. package/docs/services.md +49 -44
  60. package/docs/transport.md +81 -76
  61. package/docs/types.md +31 -0
  62. package/docs/utilities.md +27 -0
  63. package/package.json +12 -13
  64. package/src/auth/jwt-manager.ts +2 -2
  65. package/src/core/define-service.ts +19 -19
  66. package/src/core/service-executor.ts +23 -17
  67. package/src/index.ts +10 -12
  68. package/src/legacy/v1-auto-update-handler.ts +10 -10
  69. package/src/protocol/protocol-wrapper.ts +16 -16
  70. package/src/service-server.ts +51 -43
  71. package/src/services/auto-update-service.ts +1 -1
  72. package/src/services/orm-service.ts +7 -7
  73. package/src/transport/http/http-request-handler.ts +16 -10
  74. package/src/transport/http/static-file-handler.ts +8 -8
  75. package/src/transport/http/upload-handler.ts +16 -9
  76. package/src/transport/socket/service-socket.ts +22 -22
  77. package/src/transport/socket/websocket-handler.ts +50 -70
  78. package/src/types/server-options.ts +1 -1
  79. package/src/utils/config-manager.ts +11 -11
  80. package/dist/services/smtp-client-service.d.ts +0 -8
  81. package/dist/services/smtp-client-service.d.ts.map +0 -1
  82. package/dist/services/smtp-client-service.js +0 -46
  83. package/dist/services/smtp-client-service.js.map +0 -6
  84. package/docs/server.md +0 -126
  85. package/src/services/smtp-client-service.ts +0 -59
  86. package/tests/define-service.spec.ts +0 -66
  87. package/tests/orm-service.spec.ts +0 -83
  88. package/tests/service-executor.spec.ts +0 -114
package/docs/core.md CHANGED
@@ -1,10 +1,12 @@
1
1
  # Core
2
2
 
3
- ## `ServiceContext`
3
+ Service definition, context, authentication wrapper, and method execution.
4
4
 
5
- Context object passed to service factory functions. Provides access to server, socket, auth info, and configuration.
5
+ ## ServiceContext\<TAuthInfo\>
6
6
 
7
- ```typescript
7
+ Context object passed to service factory functions. Provides access to the server, socket, HTTP info, and authentication state.
8
+
9
+ ```ts
8
10
  interface ServiceContext<TAuthInfo = unknown> {
9
11
  server: ServiceServer<TAuthInfo>;
10
12
  socket?: ServiceSocket;
@@ -15,7 +17,6 @@ interface ServiceContext<TAuthInfo = unknown> {
15
17
  legacy?: {
16
18
  clientName?: string;
17
19
  };
18
-
19
20
  get authInfo(): TAuthInfo | undefined;
20
21
  get clientName(): string | undefined;
21
22
  get clientPath(): string | undefined;
@@ -23,22 +24,24 @@ interface ServiceContext<TAuthInfo = unknown> {
23
24
  }
24
25
  ```
25
26
 
26
- | Property | Type | Description |
27
- |----------|------|-------------|
28
- | `server` | `ServiceServer<TAuthInfo>` | Server instance |
29
- | `socket` | `ServiceSocket` | WebSocket connection (if via WebSocket) |
30
- | `http` | `object` | HTTP request info (if via HTTP) |
31
- | `legacy` | `object` | V1 legacy context (auto-update only) |
32
- | `authInfo` | `TAuthInfo \| undefined` | Authenticated user data |
33
- | `clientName` | `string \| undefined` | Client name |
34
- | `clientPath` | `string \| undefined` | Resolved client path on disk |
35
- | `getConfig()` | `<T>(section) => Promise<T>` | Read config from `.config.json` files |
27
+ | Member | Kind | Type | Description |
28
+ |--------|------|------|-------------|
29
+ | `server` | property | `ServiceServer<TAuthInfo>` | Reference to the server instance |
30
+ | `socket` | property | `ServiceSocket?` | WebSocket connection (present for WS calls) |
31
+ | `http` | property | `{ clientName; authTokenPayload? }?` | HTTP request info (present for HTTP calls) |
32
+ | `http.clientName` | field | `string` | Client identifier from HTTP header |
33
+ | `http.authTokenPayload` | field | `AuthTokenPayload<TAuthInfo>?` | Decoded auth token from HTTP request |
34
+ | `legacy` | property | `{ clientName? }?` | Legacy V1 connection info |
35
+ | `authInfo` | getter | `TAuthInfo \| undefined` | Authenticated user data (from socket or HTTP token) |
36
+ | `clientName` | getter | `string \| undefined` | Client name (from socket, HTTP, or legacy) |
37
+ | `clientPath` | getter | `string \| undefined` | Client path identifier |
38
+ | `getConfig` | method | `<T>(section: string) => Promise<T>` | Read a configuration section |
36
39
 
37
- ## `createServiceContext`
40
+ ## createServiceContext
38
41
 
39
- Create a service context instance.
42
+ Create a `ServiceContext` instance.
40
43
 
41
- ```typescript
44
+ ```ts
42
45
  function createServiceContext<TAuthInfo = unknown>(
43
46
  server: ServiceServer<TAuthInfo>,
44
47
  socket?: ServiceSocket,
@@ -47,11 +50,59 @@ function createServiceContext<TAuthInfo = unknown>(
47
50
  ): ServiceContext<TAuthInfo>;
48
51
  ```
49
52
 
50
- ## `ServiceDefinition`
53
+ | Parameter | Type | Description |
54
+ |-----------|------|-------------|
55
+ | `server` | `ServiceServer<TAuthInfo>` | Server instance |
56
+ | `socket` | `ServiceSocket?` | WebSocket connection |
57
+ | `http` | `{ clientName; authTokenPayload? }?` | HTTP request context |
58
+ | `legacy` | `{ clientName? }?` | Legacy V1 context |
59
+
60
+ ## auth
51
61
 
52
- Service definition object. Contains name, factory function, and optional auth permissions.
62
+ Authentication wrapper for service factories and methods. Marks a function as requiring authentication. Optionally restricts access to specific roles.
53
63
 
54
- ```typescript
64
+ ```ts
65
+ // No role restriction -- just requires authentication
66
+ function auth<TFunction extends (...args: any[]) => any>(fn: TFunction): TFunction;
67
+
68
+ // With role restriction
69
+ function auth<TFunction extends (...args: any[]) => any>(permissions: string[], fn: TFunction): TFunction;
70
+ ```
71
+
72
+ Can be applied at the service level (wrapping the factory) or at individual method level.
73
+
74
+ ```ts
75
+ const MyService = defineService("My", (ctx) => ({
76
+ // Public method -- no auth required
77
+ publicMethod() { return "open"; },
78
+
79
+ // Requires authentication (any role)
80
+ protectedMethod: auth(() => "protected"),
81
+
82
+ // Requires "admin" role
83
+ adminMethod: auth(["admin"], () => "admin only"),
84
+ }));
85
+ ```
86
+
87
+ ## getServiceAuthPermissions
88
+
89
+ Read the authentication permissions from a function wrapped with `auth()`. Returns `undefined` if the function is not wrapped.
90
+
91
+ ```ts
92
+ function getServiceAuthPermissions(fn: Function): string[] | undefined;
93
+ ```
94
+
95
+ | Parameter | Type | Description |
96
+ |-----------|------|-------------|
97
+ | `fn` | `Function` | A potentially auth-wrapped function |
98
+
99
+ Returns `string[]` (role list, possibly empty for auth-only) or `undefined` (not wrapped).
100
+
101
+ ## ServiceDefinition\<TMethods\>
102
+
103
+ A named service with a factory function and optional auth permissions.
104
+
105
+ ```ts
55
106
  interface ServiceDefinition<TMethods = Record<string, (...args: any[]) => any>> {
56
107
  name: string;
57
108
  factory: (ctx: ServiceContext) => TMethods;
@@ -61,15 +112,15 @@ interface ServiceDefinition<TMethods = Record<string, (...args: any[]) => any>>
61
112
 
62
113
  | Field | Type | Description |
63
114
  |-------|------|-------------|
64
- | `name` | `string` | Service name |
65
- | `factory` | `(ctx: ServiceContext) => TMethods` | Factory function that creates method object |
66
- | `authPermissions` | `string[]` | Required permissions (from `auth()` wrapper) |
115
+ | `name` | `string` | Service name used for RPC routing |
116
+ | `factory` | `(ctx: ServiceContext) => TMethods` | Factory function that creates service methods |
117
+ | `authPermissions` | `string[]?` | Service-level auth permissions (from `auth()` wrapper) |
67
118
 
68
- ## `defineService`
119
+ ## defineService
69
120
 
70
- Define a service with a name and factory function.
121
+ Define a named service from a factory function.
71
122
 
72
- ```typescript
123
+ ```ts
73
124
  function defineService<TMethods extends Record<string, (...args: any[]) => any>>(
74
125
  name: string,
75
126
  factory: (ctx: ServiceContext) => TMethods,
@@ -79,47 +130,44 @@ function defineService<TMethods extends Record<string, (...args: any[]) => any>>
79
130
  | Parameter | Type | Description |
80
131
  |-----------|------|-------------|
81
132
  | `name` | `string` | Service name |
82
- | `factory` | `(ctx: ServiceContext) => TMethods` | Factory function |
133
+ | `factory` | `(ctx: ServiceContext) => TMethods` | Factory that receives context and returns methods |
83
134
 
84
- ## `auth`
85
-
86
- Auth wrapper for service factories and methods. Can be applied at service-level or method-level with optional role requirements.
87
-
88
- ```typescript
89
- function auth<TFunction extends (...args: any[]) => any>(fn: TFunction): TFunction;
90
- function auth<TFunction extends (...args: any[]) => any>(
91
- permissions: string[],
92
- fn: TFunction,
93
- ): TFunction;
135
+ ```ts
136
+ const UserService = defineService("User", (ctx) => ({
137
+ async getUser(id: number) {
138
+ // ctx.authInfo, ctx.server, ctx.getConfig, etc.
139
+ return { id, name: "Alice" };
140
+ },
141
+ }));
94
142
  ```
95
143
 
96
- | Overload | Description |
97
- |----------|-------------|
98
- | `auth(fn)` | Require login (any authenticated user) |
99
- | `auth(["admin"], fn)` | Require specific roles |
100
-
101
- ## `getServiceAuthPermissions`
144
+ ## ServiceMethods\<TDefinition\>
102
145
 
103
- Read auth permissions from an `auth()`-wrapped function. Returns `undefined` if not wrapped.
146
+ Utility type that extracts method signatures from a `ServiceDefinition`. Useful for sharing types with the client.
104
147
 
105
- ```typescript
106
- function getServiceAuthPermissions(fn: Function): string[] | undefined;
148
+ ```ts
149
+ type ServiceMethods<TDefinition> = TDefinition extends ServiceDefinition<infer M> ? M : never;
107
150
  ```
108
151
 
109
- ## `ServiceMethods`
152
+ ```ts
153
+ // Server
154
+ const UserService = defineService("User", (ctx) => ({
155
+ getUser(id: number) { return { id, name: "Alice" }; },
156
+ }));
110
157
 
111
- Extract method signatures from a `ServiceDefinition` for client-side type sharing.
158
+ // Shared type for client
159
+ type UserServiceType = ServiceMethods<typeof UserService>;
112
160
 
113
- ```typescript
114
- type ServiceMethods<TDefinition> =
115
- TDefinition extends ServiceDefinition<infer M> ? M : never;
161
+ // Client
162
+ const userSvc = client.getService<UserServiceType>("User");
163
+ const user = await userSvc.getUser(1); // typed as { id: number; name: string }
116
164
  ```
117
165
 
118
- ## `executeServiceMethod`
166
+ ## executeServiceMethod
119
167
 
120
- Execute a service method with authentication and authorization checks.
168
+ Execute a service method by name. Used internally by the transport layer; can also be called directly for testing or custom routing.
121
169
 
122
- ```typescript
170
+ ```ts
123
171
  async function executeServiceMethod(
124
172
  server: ServiceServer,
125
173
  def: {
@@ -131,3 +179,14 @@ async function executeServiceMethod(
131
179
  },
132
180
  ): Promise<unknown>;
133
181
  ```
182
+
183
+ | Parameter | Type | Description |
184
+ |-----------|------|-------------|
185
+ | `server` | `ServiceServer` | Server instance containing registered services |
186
+ | `def.serviceName` | `string` | Name of the service to invoke |
187
+ | `def.methodName` | `string` | Method name within the service |
188
+ | `def.params` | `unknown[]` | Method arguments |
189
+ | `def.socket` | `ServiceSocket?` | WebSocket context (for WS calls) |
190
+ | `def.http` | `{ clientName; authTokenPayload? }?` | HTTP context (for HTTP calls) |
191
+
192
+ Returns the method return value.
package/docs/legacy.md ADDED
@@ -0,0 +1,21 @@
1
+ # Legacy
2
+
3
+ ## handleV1Connection
4
+
5
+ V1 legacy client handler. Only supports auto-update requests; all other requests receive an upgrade-required error.
6
+
7
+ ```ts
8
+ function handleV1Connection(
9
+ socket: WebSocket,
10
+ autoUpdateMethods: { getLastVersion: (platform: string) => Promise<any> },
11
+ clientNameSetter?: (clientName: string | undefined) => void,
12
+ ): void;
13
+ ```
14
+
15
+ | Parameter | Type | Description |
16
+ |-----------|------|-------------|
17
+ | `socket` | `WebSocket` | Raw WebSocket connection from the V1 client |
18
+ | `autoUpdateMethods` | `{ getLastVersion: (platform: string) => Promise<any> }` | Auto-update method implementation |
19
+ | `clientNameSetter` | `((clientName: string \| undefined) => void)?` | Optional callback invoked with the client name when connected (or `undefined` on disconnect) |
20
+
21
+ This handler is provided for backward compatibility with V1 protocol clients. New clients should use the V2 binary protocol.
package/docs/main.md ADDED
@@ -0,0 +1,81 @@
1
+ # Main
2
+
3
+ ## ServiceServer\<TAuthInfo\>
4
+
5
+ Main server class. Extends `EventEmitter` with `ready` and `close` events. Manages Fastify, WebSocket connections, service routing, and event broadcasting.
6
+
7
+ ```ts
8
+ class ServiceServer<TAuthInfo = unknown> extends EventEmitter<{
9
+ ready: void;
10
+ close: void;
11
+ }> {
12
+ constructor(options: ServiceServerOptions);
13
+ }
14
+ ```
15
+
16
+ ### Events
17
+
18
+ | Event | Data Type | Description |
19
+ |-------|-----------|-------------|
20
+ | `ready` | `void` | Emitted when the server is listening and ready |
21
+ | `close` | `void` | Emitted when the server has shut down |
22
+
23
+ ### Properties
24
+
25
+ | Property | Type | Description |
26
+ |----------|------|-------------|
27
+ | `isOpen` | `boolean` | Whether the server is currently listening |
28
+ | `fastify` | `FastifyInstance` | Underlying Fastify instance for advanced configuration |
29
+ | `options` | `ServiceServerOptions` | Server configuration options |
30
+
31
+ ### Methods
32
+
33
+ | Method | Parameters | Return | Description |
34
+ |--------|-----------|--------|-------------|
35
+ | `listen` | -- | `Promise<void>` | Start the server and begin accepting connections |
36
+ | `close` | -- | `Promise<void>` | Gracefully shut down the server |
37
+ | `emitEvent` | `eventDef: ServiceEventDef<TInfo, TData>`, `infoSelector: (item: TInfo) => boolean`, `data: TData` | `Promise<void>` | Broadcast an event to matching listeners across all connected sockets |
38
+ | `signAuthToken` | `payload: AuthTokenPayload<TAuthInfo>` | `Promise<string>` | Sign a JWT token using the server's configured secret |
39
+ | `verifyAuthToken` | `token: string` | `Promise<AuthTokenPayload<TAuthInfo>>` | Verify and decode a JWT token |
40
+
41
+ ### Usage
42
+
43
+ ```ts
44
+ import { createServiceServer, defineService } from "@simplysm/service-server";
45
+
46
+ const server = createServiceServer({
47
+ rootPath: process.cwd(),
48
+ port: 3000,
49
+ auth: { jwtSecret: "secret" },
50
+ services: [
51
+ defineService("Hello", () => ({
52
+ greet(name: string) { return `Hello, ${name}!`; },
53
+ })),
54
+ ],
55
+ });
56
+
57
+ server.on("ready", () => {
58
+ // server is listening
59
+ });
60
+
61
+ await server.listen();
62
+
63
+ // Later: shut down
64
+ await server.close();
65
+ ```
66
+
67
+ ## createServiceServer
68
+
69
+ Factory function to create a `ServiceServer` instance.
70
+
71
+ ```ts
72
+ function createServiceServer<TAuthInfo = unknown>(
73
+ options: ServiceServerOptions,
74
+ ): ServiceServer<TAuthInfo>;
75
+ ```
76
+
77
+ | Parameter | Type | Description |
78
+ |-----------|------|-------------|
79
+ | `options` | `ServiceServerOptions` | Server configuration |
80
+
81
+ Returns a new `ServiceServer` instance. Call `listen()` to start accepting connections.
@@ -0,0 +1,31 @@
1
+ # Protocol
2
+
3
+ Server-side protocol wrapper that automatically delegates heavy message encoding/decoding to worker threads.
4
+
5
+ ## ServerProtocolWrapper
6
+
7
+ Protocol wrapper interface. Heavy messages are encoded/decoded in a worker thread; lightweight messages are processed on the main thread.
8
+
9
+ ```ts
10
+ interface ServerProtocolWrapper {
11
+ encode(uuid: string, message: ServiceMessage): Promise<{ chunks: Bytes[]; totalSize: number }>;
12
+ decode(bytes: Bytes): Promise<ServiceMessageDecodeResult<ServiceMessage>>;
13
+ dispose(): void;
14
+ }
15
+ ```
16
+
17
+ | Method | Parameters | Return | Description |
18
+ |--------|-----------|--------|-------------|
19
+ | `encode` | `uuid: string`, `message: ServiceMessage` | `Promise<{ chunks: Bytes[]; totalSize: number }>` | Encode a message into binary chunks |
20
+ | `decode` | `bytes: Bytes` | `Promise<ServiceMessageDecodeResult<ServiceMessage>>` | Decode received binary data |
21
+ | `dispose` | -- | `void` | Dispose the wrapper and terminate worker threads |
22
+
23
+ ## createServerProtocolWrapper
24
+
25
+ Create a `ServerProtocolWrapper` instance.
26
+
27
+ ```ts
28
+ function createServerProtocolWrapper(): ServerProtocolWrapper;
29
+ ```
30
+
31
+ Returns a new protocol wrapper with automatic worker thread delegation for heavy payloads.
package/docs/services.md CHANGED
@@ -1,58 +1,63 @@
1
- # Built-in Services
1
+ # Services
2
+
3
+ Built-in service definitions that can be included in `ServiceServerOptions.services`.
4
+
5
+ ## OrmService
6
+
7
+ Built-in ORM service definition. Provides database connection management, transaction control, and query execution over the RPC layer. Supports MySQL, MSSQL, and PostgreSQL.
8
+
9
+ ```ts
10
+ const OrmService: ServiceDefinition<{
11
+ getInfo(opt: DbConnOptions & { configName: string }): Promise<{ dialect: Dialect; database?: string; schema?: string }>;
12
+ connect(opt: DbConnOptions & { configName: string }): Promise<number>;
13
+ close(connId: number): Promise<void>;
14
+ beginTransaction(connId: number, isolationLevel?: IsolationLevel): Promise<void>;
15
+ commitTransaction(connId: number): Promise<void>;
16
+ rollbackTransaction(connId: number): Promise<void>;
17
+ executeParametrized(connId: number, query: string, params?: unknown[]): Promise<unknown[][]>;
18
+ executeDefs(connId: number, defs: QueryDef[], options?: (ResultMeta | undefined)[]): Promise<unknown[][]>;
19
+ bulkInsert(connId: number, tableName: string, columnDefs: Record<string, ColumnMeta>, records: Record<string, unknown>[]): Promise<void>;
20
+ }>;
21
+ ```
2
22
 
3
- Pre-defined service definitions ready to use with `ServiceServer`.
23
+ | Method | Parameters | Return | Description |
24
+ |--------|-----------|--------|-------------|
25
+ | `getInfo` | `opt` | `Promise<{ dialect; database?; schema? }>` | Get database dialect and schema info |
26
+ | `connect` | `opt` | `Promise<number>` | Open a connection; returns connection ID |
27
+ | `close` | `connId` | `Promise<void>` | Close a connection |
28
+ | `beginTransaction` | `connId`, `isolationLevel?` | `Promise<void>` | Begin a transaction |
29
+ | `commitTransaction` | `connId` | `Promise<void>` | Commit the current transaction |
30
+ | `rollbackTransaction` | `connId` | `Promise<void>` | Rollback the current transaction |
31
+ | `executeParametrized` | `connId`, `query`, `params?` | `Promise<unknown[][]>` | Execute a parameterized SQL query |
32
+ | `executeDefs` | `connId`, `defs`, `options?` | `Promise<unknown[][]>` | Execute query definitions |
33
+ | `bulkInsert` | `connId`, `tableName`, `columnDefs`, `records` | `Promise<void>` | Bulk insert records into a table |
4
34
 
5
- ## `OrmService`
35
+ ### OrmServiceType
6
36
 
7
- Server-side ORM service implementation. Requires authentication. Manages database connections per WebSocket socket (using `WeakMap`). Supports MySQL, MSSQL, and PostgreSQL via `@simplysm/orm-node`.
37
+ Utility type for extracting ORM service method signatures.
8
38
 
9
- ```typescript
10
- const OrmService: ServiceDefinition;
39
+ ```ts
40
+ type OrmServiceType = ServiceMethods<typeof OrmService>;
11
41
  ```
12
42
 
13
- Implements the `OrmService` interface from `@simplysm/service-common`:
14
-
15
- | Method | Description |
16
- |--------|-------------|
17
- | `getInfo()` | Get database dialect and connection info from config |
18
- | `connect()` | Open a new database connection, returns connection ID |
19
- | `close()` | Close a database connection |
20
- | `beginTransaction()` | Begin transaction |
21
- | `commitTransaction()` | Commit transaction |
22
- | `rollbackTransaction()` | Rollback transaction |
23
- | `executeParametrized()` | Execute parameterized SQL |
24
- | `executeDefs()` | Execute QueryDef array (builds SQL via QueryBuilder) |
25
- | `bulkInsert()` | Bulk insert records |
26
-
27
- **Note:** ORM service requires WebSocket connection (cannot be used over HTTP).
28
-
29
- ## `AutoUpdateService`
43
+ ## AutoUpdateService
30
44
 
31
- Server-side auto-update service implementation. Scans the client's platform-specific `updates/` directory for version files.
45
+ Built-in auto-update service definition. Retrieves the latest version information for client applications by platform.
32
46
 
33
- ```typescript
34
- const AutoUpdateService: ServiceDefinition;
47
+ ```ts
48
+ const AutoUpdateService: ServiceDefinition<{
49
+ getLastVersion(platform: string): Promise<{ version: string; downloadPath: string } | undefined>;
50
+ }>;
35
51
  ```
36
52
 
37
- Implements the `AutoUpdateService` interface from `@simplysm/service-common`:
53
+ | Method | Parameters | Return | Description |
54
+ |--------|-----------|--------|-------------|
55
+ | `getLastVersion` | `platform: string` | `Promise<{ version; downloadPath } \| undefined>` | Get latest version info for a platform |
38
56
 
39
- | Method | Description |
40
- |--------|-------------|
41
- | `getLastVersion(platform)` | Find latest version file for platform (win32, android, etc.) |
57
+ ### AutoUpdateServiceType
42
58
 
43
- Supported platforms and file extensions:
44
- - `android`: `.apk` files
45
- - Other platforms: `.exe` files
59
+ Utility type for extracting auto-update service method signatures.
46
60
 
47
- ## `SmtpClientService`
48
-
49
- Server-side SMTP email sending service. Uses `nodemailer` under the hood.
50
-
51
- ```typescript
52
- const SmtpClientService: ServiceDefinition;
61
+ ```ts
62
+ type AutoUpdateServiceType = ServiceMethods<typeof AutoUpdateService>;
53
63
  ```
54
-
55
- | Method | Description |
56
- |--------|-------------|
57
- | `send(options)` | Send email with full SMTP options |
58
- | `sendByDefault(options)` | Send email using server's default SMTP config |