@simplysm/service-client 13.0.99 → 14.0.1

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 (55) hide show
  1. package/dist/features/event-client.d.ts.map +1 -1
  2. package/dist/features/event-client.js +75 -67
  3. package/dist/features/event-client.js.map +1 -6
  4. package/dist/features/file-client.js +41 -39
  5. package/dist/features/file-client.js.map +1 -6
  6. package/dist/features/orm/orm-client-connector.js +37 -38
  7. package/dist/features/orm/orm-client-connector.js.map +1 -6
  8. package/dist/features/orm/orm-client-db-context-executor.d.ts.map +1 -1
  9. package/dist/features/orm/orm-client-db-context-executor.js +60 -60
  10. package/dist/features/orm/orm-client-db-context-executor.js.map +1 -6
  11. package/dist/features/orm/orm-connect-options.js +2 -1
  12. package/dist/features/orm/orm-connect-options.js.map +1 -6
  13. package/dist/index.js +6 -1
  14. package/dist/index.js.map +1 -6
  15. package/dist/protocol/client-protocol-wrapper.d.ts +1 -0
  16. package/dist/protocol/client-protocol-wrapper.d.ts.map +1 -1
  17. package/dist/protocol/client-protocol-wrapper.js +92 -70
  18. package/dist/protocol/client-protocol-wrapper.js.map +1 -6
  19. package/dist/service-client.d.ts +2 -0
  20. package/dist/service-client.d.ts.map +1 -1
  21. package/dist/service-client.js +113 -111
  22. package/dist/service-client.js.map +1 -6
  23. package/dist/transport/service-transport.js +121 -104
  24. package/dist/transport/service-transport.js.map +1 -6
  25. package/dist/transport/socket-provider.js +180 -155
  26. package/dist/transport/socket-provider.js.map +1 -6
  27. package/dist/types/connection-options.d.ts +1 -1
  28. package/dist/types/connection-options.d.ts.map +1 -1
  29. package/dist/types/connection-options.js +2 -1
  30. package/dist/types/connection-options.js.map +1 -6
  31. package/dist/types/progress.types.d.ts +1 -0
  32. package/dist/types/progress.types.d.ts.map +1 -1
  33. package/dist/types/progress.types.js +2 -1
  34. package/dist/types/progress.types.js.map +1 -6
  35. package/dist/workers/client-protocol.worker.js +38 -24
  36. package/dist/workers/client-protocol.worker.js.map +1 -6
  37. package/package.json +16 -9
  38. package/src/features/event-client.ts +19 -17
  39. package/src/features/file-client.ts +5 -5
  40. package/src/features/orm/orm-client-connector.ts +2 -2
  41. package/src/features/orm/orm-client-db-context-executor.ts +8 -7
  42. package/src/index.ts +5 -5
  43. package/src/protocol/client-protocol-wrapper.ts +24 -19
  44. package/src/service-client.ts +22 -15
  45. package/src/transport/service-transport.ts +19 -19
  46. package/src/transport/socket-provider.ts +38 -38
  47. package/src/types/connection-options.ts +1 -1
  48. package/src/types/progress.types.ts +1 -0
  49. package/src/workers/client-protocol.worker.ts +9 -9
  50. package/README.md +0 -126
  51. package/docs/features.md +0 -143
  52. package/docs/protocol.md +0 -29
  53. package/docs/service-client.md +0 -93
  54. package/docs/transport.md +0 -96
  55. package/docs/types.md +0 -55
package/docs/features.md DELETED
@@ -1,143 +0,0 @@
1
- # Features
2
-
3
- ## `EventClient`
4
-
5
- Client-side event management interface. Handles event listener registration, removal, emission, and auto-recovery on reconnect.
6
-
7
- ```typescript
8
- interface EventClient {
9
- addListener<TInfo, TData>(
10
- eventDef: ServiceEventDef<TInfo, TData>,
11
- info: TInfo,
12
- cb: (data: TData) => PromiseLike<void>,
13
- ): Promise<string>;
14
- removeListener(key: string): Promise<void>;
15
- emit<TInfo, TData>(
16
- eventDef: ServiceEventDef<TInfo, TData>,
17
- infoSelector: (item: TInfo) => boolean,
18
- data: TData,
19
- ): Promise<void>;
20
- resubscribeAll(): Promise<void>;
21
- }
22
- ```
23
-
24
- | Method | Description |
25
- |--------|-------------|
26
- | `addListener()` | Register an event listener on the server, returns listener key |
27
- | `removeListener()` | Remove an event listener by key |
28
- | `emit()` | Emit an event to matching listeners (server-side filtering) |
29
- | `resubscribeAll()` | Re-register all listeners on reconnect |
30
-
31
- ## `createEventClient`
32
-
33
- Create an event client instance.
34
-
35
- ```typescript
36
- function createEventClient(transport: ServiceTransport): EventClient;
37
- ```
38
-
39
- ## `FileClient`
40
-
41
- File upload/download client interface.
42
-
43
- ```typescript
44
- interface FileClient {
45
- download(relPath: string): Promise<Bytes>;
46
- upload(
47
- files: File[] | FileList | { name: string; data: BlobPart }[],
48
- authToken: string,
49
- ): Promise<ServiceUploadResult[]>;
50
- }
51
- ```
52
-
53
- | Method | Description |
54
- |--------|-------------|
55
- | `download()` | Download a file by relative path, returns binary data |
56
- | `upload()` | Upload files via multipart form, returns upload results |
57
-
58
- ## `createFileClient`
59
-
60
- Create a file client instance.
61
-
62
- ```typescript
63
- function createFileClient(hostUrl: string, clientName: string): FileClient;
64
- ```
65
-
66
- | Parameter | Type | Description |
67
- |-----------|------|-------------|
68
- | `hostUrl` | `string` | Server base URL (http:// or https://) |
69
- | `clientName` | `string` | Client name for request headers |
70
-
71
- ## `OrmConnectOptions`
72
-
73
- ORM connection options for client-side database access.
74
-
75
- ```typescript
76
- interface OrmConnectOptions<TDef extends DbContextDef<any, any, any>> {
77
- dbContextDef: TDef;
78
- connOpt: DbConnOptions & { configName: string };
79
- dbContextOpt?: {
80
- database: string;
81
- schema: string;
82
- };
83
- }
84
- ```
85
-
86
- | Field | Type | Description |
87
- |-------|------|-------------|
88
- | `dbContextDef` | `TDef` | DbContext definition |
89
- | `connOpt` | `DbConnOptions & { configName: string }` | Connection options with config name |
90
- | `dbContextOpt` | `{ database: string; schema: string }` | Override database/schema from server config |
91
-
92
- ## `OrmClientConnector`
93
-
94
- Client-side ORM connector interface. Creates DbContext instances that execute queries via the service protocol.
95
-
96
- ```typescript
97
- interface OrmClientConnector {
98
- connect<TDef extends DbContextDef<any, any, any>, R>(
99
- config: OrmConnectOptions<TDef>,
100
- callback: (db: DbContextInstance<TDef>) => Promise<R> | R,
101
- ): Promise<R>;
102
- connectWithoutTransaction<TDef extends DbContextDef<any, any, any>, R>(
103
- config: OrmConnectOptions<TDef>,
104
- callback: (db: DbContextInstance<TDef>) => Promise<R> | R,
105
- ): Promise<R>;
106
- }
107
- ```
108
-
109
- | Method | Description |
110
- |--------|-------------|
111
- | `connect()` | Connect with transaction (auto commit/rollback) |
112
- | `connectWithoutTransaction()` | Connect without transaction |
113
-
114
- ## `createOrmClientConnector`
115
-
116
- Create an ORM client connector.
117
-
118
- ```typescript
119
- function createOrmClientConnector(serviceClient: ServiceClient): OrmClientConnector;
120
- ```
121
-
122
- ## `OrmClientDbContextExecutor`
123
-
124
- Client-side DbContext executor. Implements `DbContextExecutor` by delegating to the ORM service over the service protocol.
125
-
126
- ```typescript
127
- class OrmClientDbContextExecutor implements DbContextExecutor {
128
- constructor(
129
- private readonly _client: ServiceClient,
130
- private readonly _opt: DbConnOptions & { configName: string },
131
- );
132
-
133
- getInfo(): Promise<{ dialect: Dialect; database?: string; schema?: string }>;
134
- connect(): Promise<void>;
135
- beginTransaction(isolationLevel?: IsolationLevel): Promise<void>;
136
- commitTransaction(): Promise<void>;
137
- rollbackTransaction(): Promise<void>;
138
- close(): Promise<void>;
139
- executeDefs<T>(defs: QueryDef[], options?: (ResultMeta | undefined)[]): Promise<T[][]>;
140
- executeParametrized(query: string, params?: unknown[]): Promise<unknown[][]>;
141
- bulkInsert(tableName: string, columnDefs: Record<string, ColumnMeta>, records: Record<string, unknown>[]): Promise<void>;
142
- }
143
- ```
package/docs/protocol.md DELETED
@@ -1,29 +0,0 @@
1
- # Protocol
2
-
3
- ## `ClientProtocolWrapper`
4
-
5
- Client-side protocol wrapper interface. Handles message encoding/decoding with optional Web Worker offloading for large payloads (>30KB).
6
-
7
- ```typescript
8
- interface ClientProtocolWrapper {
9
- encode(uuid: string, message: ServiceMessage): Promise<{ chunks: Bytes[]; totalSize: number }>;
10
- decode(bytes: Bytes): Promise<ServiceMessageDecodeResult<ServiceMessage>>;
11
- }
12
- ```
13
-
14
- | Method | Description |
15
- |--------|-------------|
16
- | `encode()` | Encode a message (delegates to Web Worker for large payloads) |
17
- | `decode()` | Decode a message (delegates to Web Worker for large payloads) |
18
-
19
- ## `createClientProtocolWrapper`
20
-
21
- Create a client protocol wrapper instance. Automatically offloads heavy encoding/decoding to a Web Worker when available and payload exceeds 30KB.
22
-
23
- ```typescript
24
- function createClientProtocolWrapper(protocol: ServiceProtocol): ClientProtocolWrapper;
25
- ```
26
-
27
- | Parameter | Type | Description |
28
- |-----------|------|-------------|
29
- | `protocol` | `ServiceProtocol` | Base protocol instance from `createServiceProtocol()` |
@@ -1,93 +0,0 @@
1
- # ServiceClient
2
-
3
- ## `ServiceClient`
4
-
5
- Main client class that orchestrates all service communication modules. Extends `EventEmitter`.
6
-
7
- ```typescript
8
- class ServiceClient extends EventEmitter<ServiceClientEvents> {
9
- readonly name: string;
10
- readonly options: ServiceConnectionOptions;
11
- get connected(): boolean;
12
- get hostUrl(): string;
13
-
14
- constructor(name: string, options: ServiceConnectionOptions);
15
-
16
- getService<TService>(serviceName: string): ServiceProxy<TService>;
17
- connect(): Promise<void>;
18
- close(): Promise<void>;
19
- send(serviceName: string, methodName: string, params: unknown[], progress?: ServiceProgress): Promise<unknown>;
20
- auth(token: string): Promise<void>;
21
- addListener<TInfo, TData>(
22
- eventDef: ServiceEventDef<TInfo, TData>,
23
- info: TInfo,
24
- cb: (data: TData) => PromiseLike<void>,
25
- ): Promise<string>;
26
- removeListener(key: string): Promise<void>;
27
- emitEvent<TInfo, TData>(
28
- eventDef: ServiceEventDef<TInfo, TData>,
29
- infoSelector: (item: TInfo) => boolean,
30
- data: TData,
31
- ): Promise<void>;
32
- uploadFile(files: File[] | FileList | { name: string; data: BlobPart }[]): Promise<ServiceUploadResult[]>;
33
- downloadFileBuffer(relPath: string): Promise<Bytes>;
34
- }
35
- ```
36
-
37
- | Property | Type | Description |
38
- |----------|------|-------------|
39
- | `name` | `string` | Client name |
40
- | `options` | `ServiceConnectionOptions` | Connection options |
41
- | `connected` | `boolean` | Whether connected |
42
- | `hostUrl` | `string` | HTTP(S) base URL |
43
-
44
- | Method | Description |
45
- |--------|-------------|
46
- | `getService()` | Create a typed service proxy for calling remote methods |
47
- | `connect()` | Establish WebSocket connection |
48
- | `close()` | Close connection |
49
- | `send()` | Send a service method request |
50
- | `auth()` | Authenticate with JWT token |
51
- | `addListener()` | Add event listener |
52
- | `removeListener()` | Remove event listener |
53
- | `emitEvent()` | Emit event to matching listeners |
54
- | `uploadFile()` | Upload files (requires prior auth) |
55
- | `downloadFileBuffer()` | Download file as binary |
56
-
57
- ## `ServiceClientEvents`
58
-
59
- Events emitted by `ServiceClient`.
60
-
61
- ```typescript
62
- interface ServiceClientEvents {
63
- "request-progress": ServiceProgressState;
64
- "response-progress": ServiceProgressState;
65
- "state": "connected" | "closed" | "reconnecting";
66
- "reload": Set<string>;
67
- }
68
- ```
69
-
70
- ## `ServiceProxy`
71
-
72
- Type transformer that wraps all method return types of a service with `Promise`.
73
-
74
- ```typescript
75
- type ServiceProxy<TService> = {
76
- [K in keyof TService]: TService[K] extends (...args: infer P) => infer R
77
- ? (...args: P) => Promise<Awaited<R>>
78
- : never;
79
- };
80
- ```
81
-
82
- ## `createServiceClient`
83
-
84
- Factory function to create a `ServiceClient` instance.
85
-
86
- ```typescript
87
- function createServiceClient(name: string, options: ServiceConnectionOptions): ServiceClient;
88
- ```
89
-
90
- | Parameter | Type | Description |
91
- |-----------|------|-------------|
92
- | `name` | `string` | Client name identifier |
93
- | `options` | `ServiceConnectionOptions` | Connection options |
package/docs/transport.md DELETED
@@ -1,96 +0,0 @@
1
- # Transport
2
-
3
- ## `SocketProvider`
4
-
5
- WebSocket connection provider interface. Manages connection lifecycle, heartbeat, and auto-reconnect.
6
-
7
- ```typescript
8
- interface SocketProvider {
9
- readonly clientName: string;
10
- readonly connected: boolean;
11
- on<K extends keyof SocketProviderEvents & string>(type: K, listener: (data: SocketProviderEvents[K]) => void): void;
12
- off<K extends keyof SocketProviderEvents & string>(type: K, listener: (data: SocketProviderEvents[K]) => void): void;
13
- connect(): Promise<void>;
14
- close(): Promise<void>;
15
- send(data: Bytes): Promise<void>;
16
- }
17
- ```
18
-
19
- | Property/Method | Description |
20
- |-----------------|-------------|
21
- | `clientName` | Client name identifier |
22
- | `connected` | Whether WebSocket is currently open |
23
- | `on()` | Register event listener |
24
- | `off()` | Remove event listener |
25
- | `connect()` | Establish WebSocket connection |
26
- | `close()` | Close connection (graceful shutdown) |
27
- | `send()` | Send binary data |
28
-
29
- ## `SocketProviderEvents`
30
-
31
- Events emitted by `SocketProvider`.
32
-
33
- ```typescript
34
- interface SocketProviderEvents {
35
- message: Bytes;
36
- state: "connected" | "closed" | "reconnecting";
37
- }
38
- ```
39
-
40
- ## `createSocketProvider`
41
-
42
- Create a WebSocket provider with heartbeat and auto-reconnect.
43
-
44
- ```typescript
45
- function createSocketProvider(
46
- url: string,
47
- clientName: string,
48
- maxReconnectCount: number,
49
- ): SocketProvider;
50
- ```
51
-
52
- | Parameter | Type | Description |
53
- |-----------|------|-------------|
54
- | `url` | `string` | WebSocket URL (ws:// or wss://) |
55
- | `clientName` | `string` | Client name identifier |
56
- | `maxReconnectCount` | `number` | Max reconnect attempts |
57
-
58
- ## `ServiceTransport`
59
-
60
- Service transport interface. Handles message routing and request/response correlation.
61
-
62
- ```typescript
63
- interface ServiceTransport {
64
- on<K extends keyof ServiceTransportEvents & string>(type: K, listener: (data: ServiceTransportEvents[K]) => void): void;
65
- off<K extends keyof ServiceTransportEvents & string>(type: K, listener: (data: ServiceTransportEvents[K]) => void): void;
66
- send(message: ServiceClientMessage, progress?: ServiceProgress): Promise<unknown>;
67
- }
68
- ```
69
-
70
- | Method | Description |
71
- |--------|-------------|
72
- | `on()` | Register event listener (reload, event) |
73
- | `off()` | Remove event listener |
74
- | `send()` | Send a client message and await response |
75
-
76
- ## `ServiceTransportEvents`
77
-
78
- Events emitted by `ServiceTransport`.
79
-
80
- ```typescript
81
- interface ServiceTransportEvents {
82
- reload: Set<string>;
83
- event: { keys: string[]; data: unknown };
84
- }
85
- ```
86
-
87
- ## `createServiceTransport`
88
-
89
- Create a service transport instance.
90
-
91
- ```typescript
92
- function createServiceTransport(
93
- socket: SocketProvider,
94
- protocol: ClientProtocolWrapper,
95
- ): ServiceTransport;
96
- ```
package/docs/types.md DELETED
@@ -1,55 +0,0 @@
1
- # Types
2
-
3
- ## `ServiceConnectionOptions`
4
-
5
- Connection options for `ServiceClient`.
6
-
7
- ```typescript
8
- interface ServiceConnectionOptions {
9
- port: number;
10
- host: string;
11
- ssl?: boolean;
12
- maxReconnectCount?: number;
13
- }
14
- ```
15
-
16
- | Field | Type | Description |
17
- |-------|------|-------------|
18
- | `port` | `number` | Server port |
19
- | `host` | `string` | Server hostname |
20
- | `ssl` | `boolean` | Use SSL/TLS (wss:// and https://) |
21
- | `maxReconnectCount` | `number` | Max reconnect attempts (0 to disable, default: 10) |
22
-
23
- ## `ServiceProgress`
24
-
25
- Progress callback configuration for service requests.
26
-
27
- ```typescript
28
- interface ServiceProgress {
29
- request?: (s: ServiceProgressState) => void;
30
- response?: (s: ServiceProgressState) => void;
31
- }
32
- ```
33
-
34
- | Field | Type | Description |
35
- |-------|------|-------------|
36
- | `request` | `(s: ServiceProgressState) => void` | Request upload progress callback |
37
- | `response` | `(s: ServiceProgressState) => void` | Response download progress callback |
38
-
39
- ## `ServiceProgressState`
40
-
41
- Progress state for chunked message transfers.
42
-
43
- ```typescript
44
- interface ServiceProgressState {
45
- uuid: string;
46
- totalSize: number;
47
- completedSize: number;
48
- }
49
- ```
50
-
51
- | Field | Type | Description |
52
- |-------|------|-------------|
53
- | `uuid` | `string` | Request UUID |
54
- | `totalSize` | `number` | Total message size in bytes |
55
- | `completedSize` | `number` | Completed size in bytes |