@simplysm/service-client 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 +403 -89
- package/dist/features/event-client.d.ts.map +1 -1
- package/dist/features/event-client.js +75 -67
- package/dist/features/event-client.js.map +1 -6
- package/dist/features/file-client.d.ts +3 -2
- package/dist/features/file-client.d.ts.map +1 -1
- package/dist/features/file-client.js +41 -39
- package/dist/features/file-client.js.map +1 -6
- package/dist/features/orm/orm-client-connector.js +37 -38
- package/dist/features/orm/orm-client-connector.js.map +1 -6
- package/dist/features/orm/orm-client-db-context-executor.d.ts.map +1 -1
- package/dist/features/orm/orm-client-db-context-executor.js +60 -60
- package/dist/features/orm/orm-client-db-context-executor.js.map +1 -6
- package/dist/features/orm/orm-connect-options.js +2 -1
- package/dist/features/orm/orm-connect-options.js.map +1 -6
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -6
- package/dist/protocol/client-protocol-wrapper.d.ts +1 -0
- package/dist/protocol/client-protocol-wrapper.d.ts.map +1 -1
- package/dist/protocol/client-protocol-wrapper.js +93 -70
- package/dist/protocol/client-protocol-wrapper.js.map +1 -6
- package/dist/service-client.d.ts +5 -3
- package/dist/service-client.d.ts.map +1 -1
- package/dist/service-client.js +110 -111
- package/dist/service-client.js.map +1 -6
- package/dist/transport/service-transport.d.ts +0 -1
- package/dist/transport/service-transport.d.ts.map +1 -1
- package/dist/transport/service-transport.js +115 -104
- package/dist/transport/service-transport.js.map +1 -6
- package/dist/transport/socket-provider.d.ts.map +1 -1
- package/dist/transport/socket-provider.js +185 -155
- package/dist/transport/socket-provider.js.map +1 -6
- package/dist/types/browser-compat.d.ts +33 -0
- package/dist/types/browser-compat.d.ts.map +1 -0
- package/dist/types/browser-compat.js +17 -0
- package/dist/types/browser-compat.js.map +1 -0
- package/dist/types/connection-options.d.ts +1 -1
- package/dist/types/connection-options.d.ts.map +1 -1
- package/dist/types/connection-options.js +2 -1
- package/dist/types/connection-options.js.map +1 -6
- package/dist/types/progress.types.d.ts +1 -0
- package/dist/types/progress.types.d.ts.map +1 -1
- package/dist/types/progress.types.js +2 -1
- package/dist/types/progress.types.js.map +1 -6
- package/dist/workers/client-protocol.worker.js +38 -24
- package/dist/workers/client-protocol.worker.js.map +1 -6
- package/package.json +16 -9
- package/src/features/event-client.ts +19 -17
- package/src/features/file-client.ts +11 -10
- package/src/features/orm/orm-client-connector.ts +2 -2
- package/src/features/orm/orm-client-db-context-executor.ts +8 -7
- package/src/index.ts +6 -5
- package/src/protocol/client-protocol-wrapper.ts +37 -28
- package/src/service-client.ts +24 -20
- package/src/transport/service-transport.ts +19 -25
- package/src/transport/socket-provider.ts +44 -38
- package/src/types/browser-compat.ts +47 -0
- package/src/types/connection-options.ts +1 -1
- package/src/types/progress.types.ts +1 -0
- package/src/workers/client-protocol.worker.ts +10 -10
- package/docs/features.md +0 -143
- package/docs/protocol.md +0 -29
- package/docs/service-client.md +0 -93
- package/docs/transport.md +0 -96
- package/docs/types.md +0 -55
package/README.md
CHANGED
|
@@ -1,126 +1,440 @@
|
|
|
1
1
|
# @simplysm/service-client
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Service client SDK -- WebSocket-based RPC client with type-safe service proxy, event subscription, file upload/download, and ORM connector.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Depends on `@simplysm/service-common` for protocol and shared types.
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## API
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
| Export | Kind | Category | Description |
|
|
10
|
+
|--------|------|----------|-------------|
|
|
11
|
+
| `ServiceConnectionOptions` | interface | Types | Connection options (host, port, SSL, reconnect) |
|
|
12
|
+
| `ServiceProgress` | interface | Types | Progress callback hooks for request/response/server |
|
|
13
|
+
| `ServiceProgressState` | interface | Types | Progress state (uuid, totalSize, completedSize) |
|
|
14
|
+
| `SocketProviderEvents` | interface | Transport | Socket provider event map |
|
|
15
|
+
| `SocketProvider` | interface | Transport | Low-level WebSocket abstraction |
|
|
16
|
+
| `createSocketProvider` | function | Transport | Create a socket provider instance |
|
|
17
|
+
| `ServiceTransportEvents` | interface | Transport | Transport event map |
|
|
18
|
+
| `ServiceTransport` | interface | Transport | Service-level message transport |
|
|
19
|
+
| `createServiceTransport` | function | Transport | Create a service transport instance |
|
|
20
|
+
| `ClientProtocolWrapper` | interface | Protocol | Client-side protocol encoder/decoder wrapper |
|
|
21
|
+
| `createClientProtocolWrapper` | function | Protocol | Create a client protocol wrapper |
|
|
22
|
+
| `EventClient` | interface | Features | Event subscription client |
|
|
23
|
+
| `createEventClient` | function | Features | Create an event client |
|
|
24
|
+
| `FileClient` | interface | Features | File upload/download client |
|
|
25
|
+
| `createFileClient` | function | Features | Create a file client |
|
|
26
|
+
| `OrmConnectOptions` | interface | Features | ORM connection options |
|
|
27
|
+
| `OrmClientConnector` | interface | Features | ORM client connector (with/without transaction) |
|
|
28
|
+
| `createOrmClientConnector` | function | Features | Create an ORM client connector |
|
|
29
|
+
| `OrmClientDbContextExecutor` | class | Features | ORM DbContext executor for client-side use |
|
|
30
|
+
| `ServiceClient` | class | Main | Main service client class |
|
|
31
|
+
| `ServiceProxy` | type | Main | Type-safe service proxy mapping |
|
|
32
|
+
| `createServiceClient` | function | Main | Create a ServiceClient instance |
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { createServiceClient } from "@simplysm/service-client";
|
|
38
|
+
|
|
39
|
+
// Create and connect
|
|
40
|
+
const client = createServiceClient("my-app", {
|
|
41
|
+
host: "localhost",
|
|
42
|
+
port: 3000,
|
|
43
|
+
ssl: false,
|
|
44
|
+
});
|
|
45
|
+
await client.connect();
|
|
46
|
+
|
|
47
|
+
// Type-safe RPC calls via proxy
|
|
48
|
+
interface MyService {
|
|
49
|
+
greet(name: string): Promise<string>;
|
|
50
|
+
}
|
|
51
|
+
const myService = client.getService<MyService>("MyService");
|
|
52
|
+
const result = await myService.greet("world");
|
|
53
|
+
|
|
54
|
+
// Authenticate
|
|
55
|
+
await client.auth(token);
|
|
56
|
+
|
|
57
|
+
// File upload
|
|
58
|
+
const uploadResults = await client.uploadFile(fileList);
|
|
59
|
+
|
|
60
|
+
// File download
|
|
61
|
+
const bytes = await client.downloadFileBuffer("uploads/file.txt");
|
|
62
|
+
|
|
63
|
+
// Event subscription
|
|
64
|
+
import { defineEvent } from "@simplysm/service-common";
|
|
65
|
+
const ChatEvent = defineEvent<{ roomId: number }, { text: string }>("ChatEvent");
|
|
66
|
+
|
|
67
|
+
const listenerKey = await client.addListener(ChatEvent, { roomId: 1 }, async (data) => {
|
|
68
|
+
// handle event
|
|
69
|
+
});
|
|
70
|
+
await client.removeListener(listenerKey);
|
|
71
|
+
|
|
72
|
+
// Clean up
|
|
73
|
+
await client.close();
|
|
11
74
|
```
|
|
12
75
|
|
|
13
|
-
##
|
|
76
|
+
## Types
|
|
14
77
|
|
|
15
|
-
###
|
|
16
|
-
| API | Type | Description |
|
|
17
|
-
|-----|------|-------------|
|
|
18
|
-
| `ServiceConnectionOptions` | interface | Connection options (host, port, ssl, reconnect) |
|
|
19
|
-
| `ServiceProgress` | interface | Progress callback config for requests |
|
|
20
|
-
| `ServiceProgressState` | interface | Progress state (uuid, totalSize, completedSize) |
|
|
78
|
+
### ServiceConnectionOptions
|
|
21
79
|
|
|
22
|
-
|
|
80
|
+
```ts
|
|
81
|
+
interface ServiceConnectionOptions {
|
|
82
|
+
port: number;
|
|
83
|
+
host: string;
|
|
84
|
+
ssl?: boolean;
|
|
85
|
+
maxReconnectCount?: number;
|
|
86
|
+
}
|
|
87
|
+
```
|
|
23
88
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
| `
|
|
28
|
-
| `
|
|
29
|
-
| `
|
|
30
|
-
| `ServiceTransport` | interface | Message routing and request/response correlation |
|
|
31
|
-
| `ServiceTransportEvents` | interface | Transport events (reload, event) |
|
|
32
|
-
| `createServiceTransport` | function | Create transport instance |
|
|
89
|
+
| Field | Type | Description |
|
|
90
|
+
|-------|------|-------------|
|
|
91
|
+
| `port` | `number` | Server port |
|
|
92
|
+
| `host` | `string` | Server hostname |
|
|
93
|
+
| `ssl` | `boolean?` | Enable SSL/TLS |
|
|
94
|
+
| `maxReconnectCount` | `number?` | Max reconnection attempts. Set to `0` to disable reconnection and disconnect immediately. |
|
|
33
95
|
|
|
34
|
-
|
|
96
|
+
### ServiceProgress
|
|
35
97
|
|
|
36
|
-
|
|
37
|
-
| API | Type | Description |
|
|
38
|
-
|-----|------|-------------|
|
|
39
|
-
| `ClientProtocolWrapper` | interface | Protocol wrapper with Web Worker offloading |
|
|
40
|
-
| `createClientProtocolWrapper` | function | Create protocol wrapper |
|
|
98
|
+
Callback hooks for monitoring message progress.
|
|
41
99
|
|
|
42
|
-
|
|
100
|
+
```ts
|
|
101
|
+
interface ServiceProgress {
|
|
102
|
+
request?: (s: ServiceProgressState) => void;
|
|
103
|
+
response?: (s: ServiceProgressState) => void;
|
|
104
|
+
server?: (s: ServiceProgressState) => void;
|
|
105
|
+
}
|
|
106
|
+
```
|
|
43
107
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
| `
|
|
48
|
-
| `
|
|
49
|
-
| `FileClient` | interface | File upload/download |
|
|
50
|
-
| `createFileClient` | function | Create file client |
|
|
51
|
-
| `OrmConnectOptions` | interface | ORM connection options |
|
|
52
|
-
| `OrmClientConnector` | interface | Client-side ORM connector |
|
|
53
|
-
| `createOrmClientConnector` | function | Create ORM connector |
|
|
54
|
-
| `OrmClientDbContextExecutor` | class | DbContext executor via service protocol |
|
|
108
|
+
| Field | Type | Description |
|
|
109
|
+
|-------|------|-------------|
|
|
110
|
+
| `request` | `(s: ServiceProgressState) => void` | Called during request encoding/sending progress |
|
|
111
|
+
| `response` | `(s: ServiceProgressState) => void` | Called during response decoding progress |
|
|
112
|
+
| `server` | `(s: ServiceProgressState) => void` | Called when server reports chunk receive progress |
|
|
55
113
|
|
|
56
|
-
|
|
114
|
+
### ServiceProgressState
|
|
57
115
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
116
|
+
```ts
|
|
117
|
+
interface ServiceProgressState {
|
|
118
|
+
uuid: string;
|
|
119
|
+
totalSize: number;
|
|
120
|
+
completedSize: number;
|
|
121
|
+
}
|
|
122
|
+
```
|
|
65
123
|
|
|
66
|
-
|
|
124
|
+
| Field | Type | Description |
|
|
125
|
+
|-------|------|-------------|
|
|
126
|
+
| `uuid` | `string` | Message UUID |
|
|
127
|
+
| `totalSize` | `number` | Total message size in bytes |
|
|
128
|
+
| `completedSize` | `number` | Bytes transferred so far |
|
|
67
129
|
|
|
68
|
-
##
|
|
130
|
+
## Transport
|
|
69
131
|
|
|
70
|
-
###
|
|
132
|
+
### SocketProviderEvents
|
|
71
133
|
|
|
72
|
-
```
|
|
73
|
-
|
|
134
|
+
```ts
|
|
135
|
+
interface SocketProviderEvents {
|
|
136
|
+
message: Bytes;
|
|
137
|
+
state: "connected" | "closed" | "reconnecting";
|
|
138
|
+
}
|
|
139
|
+
```
|
|
74
140
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
141
|
+
| Event | Data Type | Description |
|
|
142
|
+
|-------|-----------|-------------|
|
|
143
|
+
| `message` | `Bytes` | Raw binary message received |
|
|
144
|
+
| `state` | `"connected" \| "closed" \| "reconnecting"` | Connection state change |
|
|
79
145
|
|
|
80
|
-
|
|
81
|
-
await client.auth(jwtToken);
|
|
146
|
+
### SocketProvider
|
|
82
147
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
148
|
+
Low-level WebSocket abstraction with auto-reconnect.
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
interface SocketProvider {
|
|
152
|
+
readonly clientName: string;
|
|
153
|
+
readonly connected: boolean;
|
|
154
|
+
on<K extends keyof SocketProviderEvents & string>(type: K, listener: (data: SocketProviderEvents[K]) => void): void;
|
|
155
|
+
off<K extends keyof SocketProviderEvents & string>(type: K, listener: (data: SocketProviderEvents[K]) => void): void;
|
|
156
|
+
connect(): Promise<void>;
|
|
157
|
+
close(): Promise<void>;
|
|
158
|
+
send(data: Bytes): Promise<void>;
|
|
87
159
|
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
| Member | Kind | Description |
|
|
163
|
+
|--------|------|-------------|
|
|
164
|
+
| `clientName` | property | Client identifier name |
|
|
165
|
+
| `connected` | property | Whether currently connected |
|
|
166
|
+
| `on` | method | Subscribe to an event |
|
|
167
|
+
| `off` | method | Unsubscribe from an event |
|
|
168
|
+
| `connect` | method | Open the WebSocket connection |
|
|
169
|
+
| `close` | method | Close the connection |
|
|
170
|
+
| `send` | method | Send binary data |
|
|
88
171
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
172
|
+
### createSocketProvider
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
function createSocketProvider(url: string, clientName: string, maxReconnectCount: number): SocketProvider;
|
|
92
176
|
```
|
|
93
177
|
|
|
94
|
-
|
|
178
|
+
| Parameter | Type | Description |
|
|
179
|
+
|-----------|------|-------------|
|
|
180
|
+
| `url` | `string` | WebSocket URL |
|
|
181
|
+
| `clientName` | `string` | Client identifier |
|
|
182
|
+
| `maxReconnectCount` | `number` | Maximum reconnection attempts |
|
|
183
|
+
|
|
184
|
+
### ServiceTransportEvents
|
|
185
|
+
|
|
186
|
+
```ts
|
|
187
|
+
interface ServiceTransportEvents {
|
|
188
|
+
event: { keys: string[]; data: unknown };
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
| Event | Data Type | Description |
|
|
193
|
+
|-------|-----------|-------------|
|
|
194
|
+
| `event` | `{ keys: string[]; data: unknown }` | Server-side event broadcast received |
|
|
195
|
+
|
|
196
|
+
### ServiceTransport
|
|
95
197
|
|
|
96
|
-
|
|
97
|
-
import { createOrmClientConnector } from "@simplysm/service-client";
|
|
198
|
+
Service-level message transport built on top of `SocketProvider`.
|
|
98
199
|
|
|
99
|
-
|
|
200
|
+
```ts
|
|
201
|
+
interface ServiceTransport {
|
|
202
|
+
on<K extends keyof ServiceTransportEvents & string>(type: K, listener: (data: ServiceTransportEvents[K]) => void): void;
|
|
203
|
+
off<K extends keyof ServiceTransportEvents & string>(type: K, listener: (data: ServiceTransportEvents[K]) => void): void;
|
|
204
|
+
send(message: ServiceClientMessage, progress?: ServiceProgress): Promise<unknown>;
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
| Method | Parameters | Return | Description |
|
|
209
|
+
|--------|-----------|--------|-------------|
|
|
210
|
+
| `on` | `type`, `listener` | `void` | Subscribe to transport events |
|
|
211
|
+
| `off` | `type`, `listener` | `void` | Unsubscribe from transport events |
|
|
212
|
+
| `send` | `message: ServiceClientMessage`, `progress?: ServiceProgress` | `Promise<unknown>` | Send a service message and await the response |
|
|
213
|
+
|
|
214
|
+
### createServiceTransport
|
|
100
215
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
async (db) => {
|
|
104
|
-
return db.user().where((u) => [expr.eq(u.status, "active")]).execute();
|
|
105
|
-
},
|
|
106
|
-
);
|
|
216
|
+
```ts
|
|
217
|
+
function createServiceTransport(socket: SocketProvider, protocol: ClientProtocolWrapper): ServiceTransport;
|
|
107
218
|
```
|
|
108
219
|
|
|
109
|
-
|
|
220
|
+
## Protocol
|
|
110
221
|
|
|
111
|
-
|
|
112
|
-
|
|
222
|
+
### ClientProtocolWrapper
|
|
223
|
+
|
|
224
|
+
Client-side protocol encoder/decoder wrapper.
|
|
225
|
+
|
|
226
|
+
```ts
|
|
227
|
+
interface ClientProtocolWrapper {
|
|
228
|
+
encode(uuid: string, message: ServiceMessage): Promise<{ chunks: Bytes[]; totalSize: number }>;
|
|
229
|
+
decode(bytes: Bytes): Promise<ServiceMessageDecodeResult<ServiceMessage>>;
|
|
230
|
+
dispose(): void;
|
|
231
|
+
}
|
|
232
|
+
```
|
|
113
233
|
|
|
114
|
-
|
|
234
|
+
| Method | Parameters | Return | Description |
|
|
235
|
+
|--------|-----------|--------|-------------|
|
|
236
|
+
| `encode` | `uuid: string`, `message: ServiceMessage` | `Promise<{ chunks: Bytes[]; totalSize: number }>` | Encode a message into binary chunks |
|
|
237
|
+
| `decode` | `bytes: Bytes` | `Promise<ServiceMessageDecodeResult<ServiceMessage>>` | Decode received binary data |
|
|
238
|
+
| `dispose` | -- | `void` | Clean up resources |
|
|
115
239
|
|
|
116
|
-
|
|
117
|
-
OrderUpdated,
|
|
118
|
-
{ orderId: 123 },
|
|
119
|
-
async (data) => {
|
|
120
|
-
console.log("Order status:", data.status);
|
|
121
|
-
},
|
|
122
|
-
);
|
|
240
|
+
### createClientProtocolWrapper
|
|
123
241
|
|
|
124
|
-
|
|
125
|
-
|
|
242
|
+
```ts
|
|
243
|
+
function createClientProtocolWrapper(protocol: ServiceProtocol): ClientProtocolWrapper;
|
|
126
244
|
```
|
|
245
|
+
|
|
246
|
+
Creates a `ClientProtocolWrapper` from a `ServiceProtocol` instance.
|
|
247
|
+
|
|
248
|
+
## Features
|
|
249
|
+
|
|
250
|
+
### EventClient
|
|
251
|
+
|
|
252
|
+
Event subscription client for the service event system.
|
|
253
|
+
|
|
254
|
+
```ts
|
|
255
|
+
interface EventClient {
|
|
256
|
+
addListener<TInfo, TData>(eventDef: ServiceEventDef<TInfo, TData>, info: TInfo, cb: (data: TData) => PromiseLike<void>): Promise<string>;
|
|
257
|
+
removeListener(key: string): Promise<void>;
|
|
258
|
+
emit<TInfo, TData>(eventDef: ServiceEventDef<TInfo, TData>, infoSelector: (item: TInfo) => boolean, data: TData): Promise<void>;
|
|
259
|
+
resubscribeAll(): Promise<void>;
|
|
260
|
+
}
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
| Method | Parameters | Return | Description |
|
|
264
|
+
|--------|-----------|--------|-------------|
|
|
265
|
+
| `addListener` | `eventDef`, `info: TInfo`, `cb` | `Promise<string>` | Subscribe to an event; returns listener key |
|
|
266
|
+
| `removeListener` | `key: string` | `Promise<void>` | Unsubscribe by listener key |
|
|
267
|
+
| `emit` | `eventDef`, `infoSelector`, `data: TData` | `Promise<void>` | Emit an event to matching listeners |
|
|
268
|
+
| `resubscribeAll` | -- | `Promise<void>` | Resubscribe all listeners (e.g., after reconnect) |
|
|
269
|
+
|
|
270
|
+
### createEventClient
|
|
271
|
+
|
|
272
|
+
```ts
|
|
273
|
+
function createEventClient(transport: ServiceTransport): EventClient;
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### FileClient
|
|
277
|
+
|
|
278
|
+
File upload and download client.
|
|
279
|
+
|
|
280
|
+
```ts
|
|
281
|
+
interface FileClient {
|
|
282
|
+
download(relPath: string): Promise<Bytes>;
|
|
283
|
+
upload(files: File[] | FileList | { name: string; data: BlobPart }[], authToken: string): Promise<ServiceUploadResult[]>;
|
|
284
|
+
}
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
| Method | Parameters | Return | Description |
|
|
288
|
+
|--------|-----------|--------|-------------|
|
|
289
|
+
| `download` | `relPath: string` | `Promise<Bytes>` | Download a file by relative path |
|
|
290
|
+
| `upload` | `files`, `authToken: string` | `Promise<ServiceUploadResult[]>` | Upload files with authentication |
|
|
291
|
+
|
|
292
|
+
### createFileClient
|
|
293
|
+
|
|
294
|
+
```ts
|
|
295
|
+
function createFileClient(hostUrl: string, clientName: string): FileClient;
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
### OrmConnectOptions\<TDef\>
|
|
299
|
+
|
|
300
|
+
```ts
|
|
301
|
+
interface OrmConnectOptions<TDef extends DbContextDef<any, any, any>> {
|
|
302
|
+
dbContextDef: TDef;
|
|
303
|
+
connOpt: DbConnOptions & { configName: string };
|
|
304
|
+
dbContextOpt?: {
|
|
305
|
+
database: string;
|
|
306
|
+
schema: string;
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
| Field | Type | Description |
|
|
312
|
+
|-------|------|-------------|
|
|
313
|
+
| `dbContextDef` | `TDef` | Database context definition |
|
|
314
|
+
| `connOpt` | `DbConnOptions & { configName: string }` | Connection options with required config name |
|
|
315
|
+
| `dbContextOpt` | `{ database: string; schema: string }?` | Optional database/schema override |
|
|
316
|
+
|
|
317
|
+
### OrmClientConnector
|
|
318
|
+
|
|
319
|
+
ORM client connector that opens a database context over the service RPC layer.
|
|
320
|
+
|
|
321
|
+
```ts
|
|
322
|
+
interface OrmClientConnector {
|
|
323
|
+
connect<TDef extends DbContextDef<any, any, any>, R>(
|
|
324
|
+
config: OrmConnectOptions<TDef>,
|
|
325
|
+
callback: (db: DbContextInstance<TDef>) => Promise<R> | R,
|
|
326
|
+
): Promise<R>;
|
|
327
|
+
connectWithoutTransaction<TDef extends DbContextDef<any, any, any>, R>(
|
|
328
|
+
config: OrmConnectOptions<TDef>,
|
|
329
|
+
callback: (db: DbContextInstance<TDef>) => Promise<R> | R,
|
|
330
|
+
): Promise<R>;
|
|
331
|
+
}
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
| Method | Parameters | Return | Description |
|
|
335
|
+
|--------|-----------|--------|-------------|
|
|
336
|
+
| `connect` | `config`, `callback` | `Promise<R>` | Open a DB context with automatic transaction (begin/commit/rollback) |
|
|
337
|
+
| `connectWithoutTransaction` | `config`, `callback` | `Promise<R>` | Open a DB context without automatic transaction management |
|
|
338
|
+
|
|
339
|
+
### createOrmClientConnector
|
|
340
|
+
|
|
341
|
+
```ts
|
|
342
|
+
function createOrmClientConnector(serviceClient: ServiceClient): OrmClientConnector;
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
### OrmClientDbContextExecutor
|
|
346
|
+
|
|
347
|
+
Implements `DbContextExecutor` for client-side ORM usage over the service RPC layer.
|
|
348
|
+
|
|
349
|
+
```ts
|
|
350
|
+
class OrmClientDbContextExecutor implements DbContextExecutor {
|
|
351
|
+
constructor(client: ServiceClient, opt: DbConnOptions & { configName: string });
|
|
352
|
+
}
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
| Method | Parameters | Return | Description |
|
|
356
|
+
|--------|-----------|--------|-------------|
|
|
357
|
+
| `getInfo` | -- | `Promise<{ dialect; database?; schema? }>` | Get database info |
|
|
358
|
+
| `connect` | -- | `Promise<void>` | Open the connection |
|
|
359
|
+
| `beginTransaction` | `isolationLevel?: IsolationLevel` | `Promise<void>` | Begin a transaction |
|
|
360
|
+
| `commitTransaction` | -- | `Promise<void>` | Commit the transaction |
|
|
361
|
+
| `rollbackTransaction` | -- | `Promise<void>` | Rollback the transaction |
|
|
362
|
+
| `close` | -- | `Promise<void>` | Close the connection |
|
|
363
|
+
| `executeDefs` | `defs: QueryDef[]`, `options?: (ResultMeta \| undefined)[]` | `Promise<T[][]>` | Execute query definitions |
|
|
364
|
+
| `executeParametrized` | `query: string`, `params?: unknown[]` | `Promise<unknown[][]>` | Execute a parameterized query |
|
|
365
|
+
| `bulkInsert` | `tableName: string`, `columnDefs: Record<string, ColumnMeta>`, `records: Record<string, unknown>[]` | `Promise<void>` | Bulk insert records |
|
|
366
|
+
|
|
367
|
+
## Main
|
|
368
|
+
|
|
369
|
+
### ServiceClient
|
|
370
|
+
|
|
371
|
+
Main service client class. Extends `EventEmitter` with progress and state events.
|
|
372
|
+
|
|
373
|
+
```ts
|
|
374
|
+
class ServiceClient extends EventEmitter<{
|
|
375
|
+
"request-progress": ServiceProgressState;
|
|
376
|
+
"response-progress": ServiceProgressState;
|
|
377
|
+
"server-progress": ServiceProgressState;
|
|
378
|
+
"state": "connected" | "closed" | "reconnecting";
|
|
379
|
+
}> {
|
|
380
|
+
constructor(name: string, options: ServiceConnectionOptions);
|
|
381
|
+
}
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
#### Events
|
|
385
|
+
|
|
386
|
+
| Event | Data Type | Description |
|
|
387
|
+
|-------|-----------|-------------|
|
|
388
|
+
| `request-progress` | `ServiceProgressState` | Request sending progress |
|
|
389
|
+
| `response-progress` | `ServiceProgressState` | Response receiving progress |
|
|
390
|
+
| `server-progress` | `ServiceProgressState` | Server-side chunk progress |
|
|
391
|
+
| `state` | `"connected" \| "closed" \| "reconnecting"` | Connection state change |
|
|
392
|
+
|
|
393
|
+
#### Properties
|
|
394
|
+
|
|
395
|
+
| Property | Type | Description |
|
|
396
|
+
|----------|------|-------------|
|
|
397
|
+
| `name` | `string` | Client name |
|
|
398
|
+
| `options` | `ServiceConnectionOptions` | Connection options |
|
|
399
|
+
| `connected` | `boolean` | Whether the client is connected |
|
|
400
|
+
| `hostUrl` | `string` | Full host URL (computed from options) |
|
|
401
|
+
|
|
402
|
+
#### Methods
|
|
403
|
+
|
|
404
|
+
| Method | Parameters | Return | Description |
|
|
405
|
+
|--------|-----------|--------|-------------|
|
|
406
|
+
| `getService<TService>` | `serviceName: string` | `ServiceProxy<TService>` | Get a type-safe service proxy |
|
|
407
|
+
| `connect` | -- | `Promise<void>` | Open the WebSocket connection |
|
|
408
|
+
| `close` | -- | `Promise<void>` | Close the connection |
|
|
409
|
+
| `send` | `serviceName`, `methodName`, `params`, `progress?` | `Promise<unknown>` | Send an RPC call |
|
|
410
|
+
| `auth` | `token: string` | `Promise<void>` | Authenticate with a JWT token |
|
|
411
|
+
| `addListener` | `eventDef`, `info`, `cb` | `Promise<string>` | Subscribe to an event |
|
|
412
|
+
| `removeListener` | `key: string` | `Promise<void>` | Unsubscribe from an event |
|
|
413
|
+
| `emitEvent` | `eventDef`, `infoSelector`, `data` | `Promise<void>` | Emit an event |
|
|
414
|
+
| `uploadFile` | `files` | `Promise<ServiceUploadResult[]>` | Upload files |
|
|
415
|
+
| `downloadFileBuffer` | `relPath: string` | `Promise<Bytes>` | Download a file |
|
|
416
|
+
|
|
417
|
+
### ServiceProxy\<TService\>
|
|
418
|
+
|
|
419
|
+
Maps service method signatures to async versions. Every method returns `Promise<Awaited<R>>`.
|
|
420
|
+
|
|
421
|
+
```ts
|
|
422
|
+
type ServiceProxy<TService> = {
|
|
423
|
+
[K in keyof TService]: TService[K] extends (...args: infer P) => infer R
|
|
424
|
+
? (...args: P) => Promise<Awaited<R>>
|
|
425
|
+
: never;
|
|
426
|
+
};
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
### createServiceClient
|
|
430
|
+
|
|
431
|
+
```ts
|
|
432
|
+
function createServiceClient(name: string, options: ServiceConnectionOptions): ServiceClient;
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
Factory function to create a `ServiceClient` instance.
|
|
436
|
+
|
|
437
|
+
| Parameter | Type | Description |
|
|
438
|
+
|-----------|------|-------------|
|
|
439
|
+
| `name` | `string` | Client identifier name |
|
|
440
|
+
| `options` | `ServiceConnectionOptions` | Connection options |
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-client.d.ts","sourceRoot":"","sources":["..\\..\\src\\features\\event-client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAKvE,MAAM,WAAW,WAAW;IAC1B,WAAW,CAAC,KAAK,EAAE,KAAK,EACtB,QAAQ,EAAE,eAAe,CAAC,KAAK,EAAE,KAAK,CAAC,EACvC,IAAI,EAAE,KAAK,EACX,EAAE,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,WAAW,CAAC,IAAI,CAAC,GACrC,OAAO,CAAC,MAAM,CAAC,CAAC;IACnB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,IAAI,CAAC,KAAK,EAAE,KAAK,EACf,QAAQ,EAAE,eAAe,CAAC,KAAK,EAAE,KAAK,CAAC,EACvC,YAAY,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,OAAO,EACtC,IAAI,EAAE,KAAK,GACV,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACjC;AAED,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,gBAAgB,GAAG,WAAW,
|
|
1
|
+
{"version":3,"file":"event-client.d.ts","sourceRoot":"","sources":["..\\..\\src\\features\\event-client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAKvE,MAAM,WAAW,WAAW;IAC1B,WAAW,CAAC,KAAK,EAAE,KAAK,EACtB,QAAQ,EAAE,eAAe,CAAC,KAAK,EAAE,KAAK,CAAC,EACvC,IAAI,EAAE,KAAK,EACX,EAAE,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,WAAW,CAAC,IAAI,CAAC,GACrC,OAAO,CAAC,MAAM,CAAC,CAAC;IACnB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,IAAI,CAAC,KAAK,EAAE,KAAK,EACf,QAAQ,EAAE,eAAe,CAAC,KAAK,EAAE,KAAK,CAAC,EACvC,YAAY,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,OAAO,EACtC,IAAI,EAAE,KAAK,GACV,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACjC;AAED,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,gBAAgB,GAAG,WAAW,CAwG1E"}
|