@venizia/ignis-docs 0.0.5 → 0.0.6-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.
- package/package.json +1 -1
- package/wiki/best-practices/architectural-patterns.md +0 -2
- package/wiki/best-practices/architecture-decisions.md +0 -8
- package/wiki/best-practices/code-style-standards/control-flow.md +1 -1
- package/wiki/best-practices/code-style-standards/index.md +0 -1
- package/wiki/best-practices/code-style-standards/tooling.md +0 -3
- package/wiki/best-practices/contribution-workflow.md +12 -12
- package/wiki/best-practices/index.md +4 -14
- package/wiki/best-practices/performance-optimization.md +3 -3
- package/wiki/best-practices/security-guidelines.md +2 -2
- package/wiki/best-practices/troubleshooting-tips.md +1 -1
- package/wiki/guides/core-concepts/application/bootstrapping.md +6 -7
- package/wiki/guides/core-concepts/components-guide.md +1 -1
- package/wiki/guides/core-concepts/components.md +2 -2
- package/wiki/guides/core-concepts/dependency-injection.md +4 -5
- package/wiki/guides/core-concepts/persistent/datasources.md +4 -5
- package/wiki/guides/core-concepts/services.md +1 -1
- package/wiki/guides/get-started/5-minute-quickstart.md +4 -5
- package/wiki/guides/get-started/philosophy.md +12 -24
- package/wiki/guides/index.md +2 -9
- package/wiki/guides/reference/mcp-docs-server.md +13 -13
- package/wiki/guides/tutorials/building-a-crud-api.md +10 -10
- package/wiki/guides/tutorials/complete-installation.md +11 -12
- package/wiki/guides/tutorials/ecommerce-api.md +3 -3
- package/wiki/guides/tutorials/realtime-chat.md +6 -6
- package/wiki/guides/tutorials/testing.md +4 -5
- package/wiki/index.md +8 -14
- package/wiki/references/base/bootstrapping.md +0 -3
- package/wiki/references/base/components.md +2 -2
- package/wiki/references/base/controllers.md +0 -1
- package/wiki/references/base/datasources.md +1 -1
- package/wiki/references/base/dependency-injection.md +2 -2
- package/wiki/references/base/filter-system/default-filter.md +2 -3
- package/wiki/references/base/filter-system/index.md +1 -1
- package/wiki/references/base/filter-system/quick-reference.md +0 -14
- package/wiki/references/base/middlewares.md +0 -8
- package/wiki/references/base/providers.md +0 -9
- package/wiki/references/base/repositories/advanced.md +1 -1
- package/wiki/references/base/repositories/mixins.md +2 -3
- package/wiki/references/base/services.md +0 -1
- package/wiki/references/components/authentication/api.md +444 -0
- package/wiki/references/components/authentication/errors.md +177 -0
- package/wiki/references/components/authentication/index.md +571 -0
- package/wiki/references/components/authentication/usage.md +781 -0
- package/wiki/references/components/health-check.md +292 -103
- package/wiki/references/components/index.md +14 -12
- package/wiki/references/components/mail/api.md +505 -0
- package/wiki/references/components/mail/errors.md +176 -0
- package/wiki/references/components/mail/index.md +535 -0
- package/wiki/references/components/mail/usage.md +404 -0
- package/wiki/references/components/request-tracker.md +229 -25
- package/wiki/references/components/socket-io/api.md +1051 -0
- package/wiki/references/components/socket-io/errors.md +119 -0
- package/wiki/references/components/socket-io/index.md +410 -0
- package/wiki/references/components/socket-io/usage.md +322 -0
- package/wiki/references/components/static-asset/api.md +261 -0
- package/wiki/references/components/static-asset/errors.md +89 -0
- package/wiki/references/components/static-asset/index.md +617 -0
- package/wiki/references/components/static-asset/usage.md +364 -0
- package/wiki/references/components/swagger.md +390 -110
- package/wiki/references/components/template/api-page.md +125 -0
- package/wiki/references/components/template/errors-page.md +100 -0
- package/wiki/references/components/template/index.md +104 -0
- package/wiki/references/components/template/setup-page.md +134 -0
- package/wiki/references/components/template/single-page.md +132 -0
- package/wiki/references/components/template/usage-page.md +127 -0
- package/wiki/references/components/websocket/api.md +508 -0
- package/wiki/references/components/websocket/errors.md +123 -0
- package/wiki/references/components/websocket/index.md +453 -0
- package/wiki/references/components/websocket/usage.md +475 -0
- package/wiki/references/helpers/cron/index.md +224 -0
- package/wiki/references/helpers/crypto/index.md +537 -0
- package/wiki/references/helpers/env/index.md +214 -0
- package/wiki/references/helpers/error/index.md +232 -0
- package/wiki/references/helpers/index.md +16 -15
- package/wiki/references/helpers/inversion/index.md +608 -0
- package/wiki/references/helpers/logger/index.md +600 -0
- package/wiki/references/helpers/network/api.md +986 -0
- package/wiki/references/helpers/network/index.md +620 -0
- package/wiki/references/helpers/queue/index.md +589 -0
- package/wiki/references/helpers/redis/index.md +495 -0
- package/wiki/references/helpers/socket-io/api.md +497 -0
- package/wiki/references/helpers/socket-io/index.md +513 -0
- package/wiki/references/helpers/storage/api.md +705 -0
- package/wiki/references/helpers/storage/index.md +583 -0
- package/wiki/references/helpers/template/index.md +66 -0
- package/wiki/references/helpers/template/single-page.md +126 -0
- package/wiki/references/helpers/testing/index.md +510 -0
- package/wiki/references/helpers/types/index.md +512 -0
- package/wiki/references/helpers/uid/index.md +272 -0
- package/wiki/references/helpers/websocket/api.md +736 -0
- package/wiki/references/helpers/websocket/index.md +574 -0
- package/wiki/references/helpers/worker-thread/index.md +470 -0
- package/wiki/references/index.md +2 -9
- package/wiki/references/quick-reference.md +3 -18
- package/wiki/references/utilities/jsx.md +1 -8
- package/wiki/references/utilities/statuses.md +0 -7
- package/wiki/references/components/authentication.md +0 -476
- package/wiki/references/components/mail.md +0 -687
- package/wiki/references/components/socket-io.md +0 -562
- package/wiki/references/components/static-asset.md +0 -1277
- package/wiki/references/helpers/cron.md +0 -108
- package/wiki/references/helpers/crypto.md +0 -132
- package/wiki/references/helpers/env.md +0 -83
- package/wiki/references/helpers/error.md +0 -97
- package/wiki/references/helpers/inversion.md +0 -176
- package/wiki/references/helpers/logger.md +0 -296
- package/wiki/references/helpers/network.md +0 -396
- package/wiki/references/helpers/queue.md +0 -150
- package/wiki/references/helpers/redis.md +0 -142
- package/wiki/references/helpers/socket-io.md +0 -932
- package/wiki/references/helpers/storage.md +0 -665
- package/wiki/references/helpers/testing.md +0 -133
- package/wiki/references/helpers/types.md +0 -167
- package/wiki/references/helpers/uid.md +0 -167
- package/wiki/references/helpers/worker-thread.md +0 -178
- package/wiki/references/src-details/boot.md +0 -379
- package/wiki/references/src-details/core.md +0 -263
- package/wiki/references/src-details/dev-configs.md +0 -298
- package/wiki/references/src-details/docs.md +0 -71
- package/wiki/references/src-details/helpers.md +0 -211
- package/wiki/references/src-details/index.md +0 -86
- package/wiki/references/src-details/inversion.md +0 -340
|
@@ -0,0 +1,986 @@
|
|
|
1
|
+
# Network -- API Reference
|
|
2
|
+
|
|
3
|
+
## Architecture
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
BaseHelper
|
|
7
|
+
├── BaseNetworkRequest<T extends TFetcherVariant>
|
|
8
|
+
│ ├── AxiosNetworkRequest (T = 'axios')
|
|
9
|
+
│ └── NodeFetchNetworkRequest (T = 'node-fetch')
|
|
10
|
+
│
|
|
11
|
+
├── BaseNetworkTcpServer<ServerOpts, ServerType, ClientType>
|
|
12
|
+
│ ├── NetworkTcpServer (net.Server, net.Socket)
|
|
13
|
+
│ └── NetworkTlsTcpServer (tls.Server, tls.TLSSocket)
|
|
14
|
+
│
|
|
15
|
+
├── BaseNetworkTcpClient<ClientOpts, ClientType>
|
|
16
|
+
│ ├── NetworkTcpClient (net.TcpSocketConnectOpts, net.Socket)
|
|
17
|
+
│ └── NetworkTlsTcpClient (tls.ConnectionOptions, tls.TLSSocket)
|
|
18
|
+
│
|
|
19
|
+
└── NetworkUdpClient
|
|
20
|
+
|
|
21
|
+
AbstractNetworkFetchableHelper<V, RQ, RS> (implements IFetchable)
|
|
22
|
+
├── AxiosFetcher (V = 'axios')
|
|
23
|
+
└── NodeFetcher (V = 'node-fetch')
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
All classes that extend `BaseHelper` inherit scoped logging via `this.logger`.
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## HTTP Request API
|
|
31
|
+
|
|
32
|
+
### BaseNetworkRequest
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
class BaseNetworkRequest<T extends TFetcherVariant> extends BaseHelper
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Base class for HTTP request helpers. Holds a base URL and delegates to an `IFetchable` fetcher.
|
|
39
|
+
|
|
40
|
+
#### Constructor
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
constructor(opts: {
|
|
44
|
+
name: string;
|
|
45
|
+
baseUrl?: string;
|
|
46
|
+
fetcher: IFetchable<T, IRequestOptions, TFetcherResponse<T>>;
|
|
47
|
+
})
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
| Parameter | Type | Description |
|
|
51
|
+
|-----------|------|-------------|
|
|
52
|
+
| `name` | `string` | Helper name, used as both `scope` and `identifier` for logging |
|
|
53
|
+
| `baseUrl` | `string` | Base URL prepended to request paths. Defaults to `''` |
|
|
54
|
+
| `fetcher` | `IFetchable` | The underlying HTTP fetcher implementation |
|
|
55
|
+
|
|
56
|
+
#### Methods
|
|
57
|
+
|
|
58
|
+
##### `getRequestUrl(opts)`
|
|
59
|
+
|
|
60
|
+
Builds a full URL by combining a base URL with path segments. Throws if no base URL is available.
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
getRequestUrl(opts: {
|
|
64
|
+
baseUrl?: string;
|
|
65
|
+
paths: Array<string>;
|
|
66
|
+
}): string
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
| Parameter | Type | Description |
|
|
70
|
+
|-----------|------|-------------|
|
|
71
|
+
| `baseUrl` | `string` | Overrides the instance's base URL. Falls back to `this.baseUrl` |
|
|
72
|
+
| `paths` | `string[]` | Path segments to append. Each is prefixed with `/` if missing |
|
|
73
|
+
|
|
74
|
+
**Throws:** `Error` with message `'[getRequestUrl] Invalid configuration for third party request base url!'` when both `opts.baseUrl` and `this.baseUrl` are empty.
|
|
75
|
+
|
|
76
|
+
**Example:**
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
client.getRequestUrl({ paths: ['v1', 'users', '123'] });
|
|
80
|
+
// => 'https://api.example.com/v1/users/123'
|
|
81
|
+
|
|
82
|
+
client.getRequestUrl({ baseUrl: 'https://other.api.com', paths: ['health'] });
|
|
83
|
+
// => 'https://other.api.com/health'
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
##### `getRequestPath(opts)`
|
|
87
|
+
|
|
88
|
+
Joins path segments, ensuring each starts with `/`.
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
getRequestPath(opts: { paths: Array<string> }): string
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**Example:**
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
client.getRequestPath({ paths: ['v1', 'users'] });
|
|
98
|
+
// => '/v1/users'
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
##### `getNetworkService()`
|
|
102
|
+
|
|
103
|
+
Returns the underlying `IFetchable` fetcher instance.
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
getNetworkService(): IFetchable<T, IRequestOptions, TFetcherResponse<T>>
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
##### `getWorker()`
|
|
110
|
+
|
|
111
|
+
Returns the raw HTTP client from the fetcher (`AxiosInstance` for Axios, `typeof fetch` for Node Fetch).
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
getWorker(): TFetcherWorker<T>
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
### IFetchable Interface
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
interface IFetchable<
|
|
123
|
+
V extends TFetcherVariant,
|
|
124
|
+
RQ extends IRequestOptions,
|
|
125
|
+
RS extends TFetcherResponse<V>,
|
|
126
|
+
> {
|
|
127
|
+
send(opts: RQ, logger?: any): Promise<RS>;
|
|
128
|
+
get(opts: RQ, logger?: any): Promise<RS>;
|
|
129
|
+
post(opts: RQ, logger?: any): Promise<RS>;
|
|
130
|
+
put(opts: RQ, logger?: any): Promise<RS>;
|
|
131
|
+
patch(opts: RQ, logger?: any): Promise<RS>;
|
|
132
|
+
delete(opts: RQ, logger?: any): Promise<RS>;
|
|
133
|
+
getWorker(): TFetcherWorker<V>;
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
All HTTP method shortcuts (`get`, `post`, `put`, `patch`, `delete`) delegate to `send()` with the `method` field set accordingly.
|
|
138
|
+
|
|
139
|
+
### IRequestOptions
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
interface IRequestOptions {
|
|
143
|
+
url: string;
|
|
144
|
+
params?: Record<string | symbol, any>;
|
|
145
|
+
method?: string;
|
|
146
|
+
timeout?: number;
|
|
147
|
+
[extra: symbol | string]: any;
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
### AbstractNetworkFetchableHelper
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
abstract class AbstractNetworkFetchableHelper<
|
|
157
|
+
V extends TFetcherVariant,
|
|
158
|
+
RQ extends IRequestOptions,
|
|
159
|
+
RS extends TFetcherResponse<V>,
|
|
160
|
+
> implements IFetchable<V, RQ, RS>
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Abstract base for fetcher implementations. Provides convenience HTTP method wrappers and protocol detection.
|
|
164
|
+
|
|
165
|
+
#### Constructor
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
constructor(opts: { name: string; variant: V })
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
#### Methods
|
|
172
|
+
|
|
173
|
+
##### `abstract send(opts, logger?)`
|
|
174
|
+
|
|
175
|
+
Subclasses must implement the actual request dispatch.
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
abstract send(opts: RQ, logger?: any): Promise<RS>;
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
##### `get(opts, logger?)`
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
get(opts: RQ, logger?: any): Promise<RS>
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
Calls `send()` with `method: 'get'`.
|
|
188
|
+
|
|
189
|
+
##### `post(opts, logger?)`
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
post(opts: RQ, logger?: any): Promise<RS>
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Calls `send()` with `method: 'post'`.
|
|
196
|
+
|
|
197
|
+
##### `put(opts, logger?)`
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
put(opts: RQ, logger?: any): Promise<RS>
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Calls `send()` with `method: 'put'`.
|
|
204
|
+
|
|
205
|
+
##### `patch(opts, logger?)`
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
patch(opts: RQ, logger?: any): Promise<RS>
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
Calls `send()` with `method: 'patch'`.
|
|
212
|
+
|
|
213
|
+
##### `delete(opts, logger?)`
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
delete(opts: RQ, logger?: any): Promise<RS>
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Calls `send()` with `method: 'delete'`.
|
|
220
|
+
|
|
221
|
+
##### `getProtocol(url)`
|
|
222
|
+
|
|
223
|
+
Returns `'http'` or `'https'` based on the URL prefix.
|
|
224
|
+
|
|
225
|
+
```typescript
|
|
226
|
+
getProtocol(url: string): 'http' | 'https'
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
##### `getWorker()`
|
|
230
|
+
|
|
231
|
+
Returns the underlying HTTP client instance.
|
|
232
|
+
|
|
233
|
+
```typescript
|
|
234
|
+
getWorker(): TFetcherWorker<V>
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
### AxiosFetcher
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
class AxiosFetcher extends AbstractNetworkFetchableHelper<
|
|
243
|
+
'axios',
|
|
244
|
+
IAxiosRequestOptions,
|
|
245
|
+
AxiosResponse['data']
|
|
246
|
+
>
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
Axios-based fetcher implementation. Creates an `axios` instance with the provided default configuration.
|
|
250
|
+
|
|
251
|
+
#### Constructor
|
|
252
|
+
|
|
253
|
+
```typescript
|
|
254
|
+
constructor(opts: {
|
|
255
|
+
name: string;
|
|
256
|
+
defaultConfigs: AxiosRequestConfig;
|
|
257
|
+
logger?: any;
|
|
258
|
+
})
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
#### IAxiosRequestOptions
|
|
262
|
+
|
|
263
|
+
```typescript
|
|
264
|
+
interface IAxiosRequestOptions extends AxiosRequestConfig, IRequestOptions {
|
|
265
|
+
url: string;
|
|
266
|
+
method?: 'get' | 'post' | 'put' | 'patch' | 'delete' | 'options';
|
|
267
|
+
params?: AnyObject;
|
|
268
|
+
body?: AnyObject; // Mapped to Axios `data`
|
|
269
|
+
headers?: AnyObject;
|
|
270
|
+
}
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
> [!NOTE]
|
|
274
|
+
> The `body` field is mapped to Axios's `data` field internally. Query parameters are serialized using `node:querystring`. For HTTPS URLs, an `https.Agent` is automatically created with `rejectUnauthorized` defaulting to `false`.
|
|
275
|
+
|
|
276
|
+
#### Methods
|
|
277
|
+
|
|
278
|
+
##### `send(opts, logger?)`
|
|
279
|
+
|
|
280
|
+
```typescript
|
|
281
|
+
override send<T = any>(opts: IAxiosRequestOptions, logger?: any): Promise<AxiosResponse<T>>
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
Dispatches the request via the internal `axios` instance. For HTTPS URLs, automatically configures an `https.Agent`.
|
|
285
|
+
|
|
286
|
+
---
|
|
287
|
+
|
|
288
|
+
### AxiosNetworkRequest
|
|
289
|
+
|
|
290
|
+
```typescript
|
|
291
|
+
class AxiosNetworkRequest extends BaseNetworkRequest<'axios'>
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
Pre-configured HTTP client using Axios.
|
|
295
|
+
|
|
296
|
+
#### Constructor
|
|
297
|
+
|
|
298
|
+
```typescript
|
|
299
|
+
constructor(opts: IAxiosNetworkRequestOptions)
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
```typescript
|
|
303
|
+
interface IAxiosNetworkRequestOptions {
|
|
304
|
+
name: string;
|
|
305
|
+
networkOptions: Omit<AxiosRequestConfig, 'baseURL'> & {
|
|
306
|
+
baseUrl?: string;
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
**Default configuration applied:**
|
|
312
|
+
|
|
313
|
+
| Setting | Default |
|
|
314
|
+
|---------|---------|
|
|
315
|
+
| `headers['content-type']` | `'application/json; charset=utf-8'` |
|
|
316
|
+
| `withCredentials` | `true` |
|
|
317
|
+
| `validateStatus` | `(status) => status < 500` |
|
|
318
|
+
| `timeout` | `60000` (1 minute) |
|
|
319
|
+
|
|
320
|
+
User-provided values in `networkOptions` override all defaults.
|
|
321
|
+
|
|
322
|
+
---
|
|
323
|
+
|
|
324
|
+
### NodeFetcher
|
|
325
|
+
|
|
326
|
+
```typescript
|
|
327
|
+
class NodeFetcher extends AbstractNetworkFetchableHelper<
|
|
328
|
+
'node-fetch',
|
|
329
|
+
INodeFetchRequestOptions,
|
|
330
|
+
Awaited<ReturnType<typeof fetch>>
|
|
331
|
+
>
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
Native `fetch` based fetcher implementation.
|
|
335
|
+
|
|
336
|
+
#### Constructor
|
|
337
|
+
|
|
338
|
+
```typescript
|
|
339
|
+
constructor(opts: {
|
|
340
|
+
name: string;
|
|
341
|
+
defaultConfigs: RequestInit;
|
|
342
|
+
logger?: any;
|
|
343
|
+
})
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
#### INodeFetchRequestOptions
|
|
347
|
+
|
|
348
|
+
```typescript
|
|
349
|
+
interface INodeFetchRequestOptions extends RequestInit, IRequestOptions {
|
|
350
|
+
url: string;
|
|
351
|
+
params?: Record<string | symbol, any>;
|
|
352
|
+
}
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
#### Methods
|
|
356
|
+
|
|
357
|
+
##### `send(opts, logger?)`
|
|
358
|
+
|
|
359
|
+
```typescript
|
|
360
|
+
override async send(opts: INodeFetchRequestOptions, logger?: any): Promise<Response>
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
Dispatches the request using the native `fetch` API. If `timeout` is provided, creates an `AbortController` that aborts the request after the specified duration in milliseconds. Query `params` are serialized using `node:querystring` and appended to the URL.
|
|
364
|
+
|
|
365
|
+
---
|
|
366
|
+
|
|
367
|
+
### NodeFetchNetworkRequest
|
|
368
|
+
|
|
369
|
+
```typescript
|
|
370
|
+
class NodeFetchNetworkRequest extends BaseNetworkRequest<'node-fetch'>
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
Pre-configured HTTP client using native `fetch`.
|
|
374
|
+
|
|
375
|
+
#### Constructor
|
|
376
|
+
|
|
377
|
+
```typescript
|
|
378
|
+
constructor(opts: INodeFetchNetworkRequestOptions)
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
```typescript
|
|
382
|
+
interface INodeFetchNetworkRequestOptions {
|
|
383
|
+
name: string;
|
|
384
|
+
networkOptions: RequestInit & {
|
|
385
|
+
baseUrl?: string;
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
**Default configuration applied:**
|
|
391
|
+
|
|
392
|
+
| Setting | Default |
|
|
393
|
+
|---------|---------|
|
|
394
|
+
| `headers['content-type']` | `'application/json; charset=utf-8'` |
|
|
395
|
+
|
|
396
|
+
If `headers` is a `Headers` instance, it is converted to a plain object via `Object.fromEntries()` before merging.
|
|
397
|
+
|
|
398
|
+
---
|
|
399
|
+
|
|
400
|
+
## TCP Socket API
|
|
401
|
+
|
|
402
|
+
### BaseNetworkTcpServer
|
|
403
|
+
|
|
404
|
+
```typescript
|
|
405
|
+
class BaseNetworkTcpServer<
|
|
406
|
+
SocketServerOptions extends ServerOpts = ServerOpts,
|
|
407
|
+
SocketServerType extends SocketServer = SocketServer,
|
|
408
|
+
SocketClientType extends SocketClient = SocketClient,
|
|
409
|
+
> extends BaseHelper
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
Abstract TCP server with client tracking, authentication flow, and event delegation.
|
|
413
|
+
|
|
414
|
+
#### Constructor
|
|
415
|
+
|
|
416
|
+
```typescript
|
|
417
|
+
constructor(opts: ITcpSocketServerOptions<SocketServerOptions, SocketServerType, SocketClientType>)
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
**Throws:** `Error` with message `'TCP Server | Invalid authenticate duration | Required duration for authenticateOptions'` when `authenticateOptions.required` is `true` and `duration` is missing or negative.
|
|
421
|
+
|
|
422
|
+
The constructor automatically calls `configure()`, which creates the server and starts listening.
|
|
423
|
+
|
|
424
|
+
#### Protected Properties
|
|
425
|
+
|
|
426
|
+
| Property | Type | Description |
|
|
427
|
+
|----------|------|-------------|
|
|
428
|
+
| `serverOptions` | `Partial<SocketServerOptions>` | Server creation options |
|
|
429
|
+
| `listenOptions` | `Partial<ListenOptions>` | Listen configuration |
|
|
430
|
+
| `authenticateOptions` | `{ required: boolean; duration?: number }` | Auth settings |
|
|
431
|
+
| `clients` | `Record<string, ITcpSocketClient<SocketClientType>>` | Connected client registry |
|
|
432
|
+
| `server` | `SocketServerType` | The underlying server instance |
|
|
433
|
+
| `extraEvents` | `Record<string, (opts) => void>` | Additional per-client socket events |
|
|
434
|
+
|
|
435
|
+
#### Methods
|
|
436
|
+
|
|
437
|
+
##### `configure()`
|
|
438
|
+
|
|
439
|
+
Creates the server using `createServerFn` and starts listening. Called automatically by the constructor.
|
|
440
|
+
|
|
441
|
+
```typescript
|
|
442
|
+
configure(): void
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
##### `onNewConnection(opts)`
|
|
446
|
+
|
|
447
|
+
Handles a new client connection. Assigns a unique ID, registers `data`, `error`, `close`, and extra events, tracks the client, and starts the authentication timer if required.
|
|
448
|
+
|
|
449
|
+
```typescript
|
|
450
|
+
onNewConnection(opts: { socket: SocketClientType }): void
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
##### `getClients()`
|
|
454
|
+
|
|
455
|
+
Returns all connected clients as a record keyed by client ID.
|
|
456
|
+
|
|
457
|
+
```typescript
|
|
458
|
+
getClients(): Record<string, ITcpSocketClient<SocketClientType>>
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
##### `getClient(opts)`
|
|
462
|
+
|
|
463
|
+
Returns a specific connected client by ID, or `undefined` if not found.
|
|
464
|
+
|
|
465
|
+
```typescript
|
|
466
|
+
getClient(opts: { id: string }): ITcpSocketClient<SocketClientType> | undefined
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
##### `getServer()`
|
|
470
|
+
|
|
471
|
+
Returns the underlying server instance.
|
|
472
|
+
|
|
473
|
+
```typescript
|
|
474
|
+
getServer(): SocketServerType
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
##### `doAuthenticate(opts)`
|
|
478
|
+
|
|
479
|
+
Transitions a client's authentication state. Sets `authenticatedAt` timestamp when state becomes `'authenticated'`, clears it otherwise.
|
|
480
|
+
|
|
481
|
+
```typescript
|
|
482
|
+
doAuthenticate(opts: {
|
|
483
|
+
id: string;
|
|
484
|
+
state: 'unauthorized' | 'authenticating' | 'authenticated';
|
|
485
|
+
}): void
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
##### `emit(opts)`
|
|
489
|
+
|
|
490
|
+
Writes data to a specific client's socket. Silently returns (with a log warning) if the client is not found, the socket is not writable, or the payload is empty.
|
|
491
|
+
|
|
492
|
+
```typescript
|
|
493
|
+
emit(opts: { clientId: string; payload: Buffer | string }): void
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
---
|
|
497
|
+
|
|
498
|
+
### ITcpSocketClient
|
|
499
|
+
|
|
500
|
+
```typescript
|
|
501
|
+
interface ITcpSocketClient<SocketClientType> {
|
|
502
|
+
id: string;
|
|
503
|
+
socket: SocketClientType;
|
|
504
|
+
state: 'unauthorized' | 'authenticating' | 'authenticated';
|
|
505
|
+
subscriptions: Set<string>;
|
|
506
|
+
storage: {
|
|
507
|
+
connectedAt: dayjs.Dayjs;
|
|
508
|
+
authenticatedAt: dayjs.Dayjs | null;
|
|
509
|
+
[additionField: symbol | string]: any;
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
---
|
|
515
|
+
|
|
516
|
+
### NetworkTcpServer
|
|
517
|
+
|
|
518
|
+
```typescript
|
|
519
|
+
class NetworkTcpServer extends BaseNetworkTcpServer<ServerOpts, Server, Socket>
|
|
520
|
+
```
|
|
521
|
+
|
|
522
|
+
Plain TCP server using `net.createServer`.
|
|
523
|
+
|
|
524
|
+
#### Constructor
|
|
525
|
+
|
|
526
|
+
```typescript
|
|
527
|
+
constructor(opts: Omit<ITcpSocketServerOptions, 'createServerFn'>)
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
The `createServerFn` is pre-set to `net.createServer`. The `scope` is set to `'NetworkTcpServer'`.
|
|
531
|
+
|
|
532
|
+
#### Static Methods
|
|
533
|
+
|
|
534
|
+
##### `newInstance(opts)`
|
|
535
|
+
|
|
536
|
+
Factory method that creates a new `NetworkTcpServer`.
|
|
537
|
+
|
|
538
|
+
```typescript
|
|
539
|
+
static newInstance(
|
|
540
|
+
opts: Omit<ITcpSocketServerOptions, 'createServerFn'>
|
|
541
|
+
): NetworkTcpServer
|
|
542
|
+
```
|
|
543
|
+
|
|
544
|
+
---
|
|
545
|
+
|
|
546
|
+
### NetworkTlsTcpServer
|
|
547
|
+
|
|
548
|
+
```typescript
|
|
549
|
+
class NetworkTlsTcpServer extends BaseNetworkTcpServer<TlsOptions, tls.Server, TLSSocket>
|
|
550
|
+
```
|
|
551
|
+
|
|
552
|
+
TLS-encrypted TCP server using `tls.createServer`.
|
|
553
|
+
|
|
554
|
+
#### Constructor
|
|
555
|
+
|
|
556
|
+
```typescript
|
|
557
|
+
constructor(opts: Omit<ITcpSocketServerOptions, 'createServerFn'>)
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
The `createServerFn` is pre-set to `tls.createServer`. The `scope` is set to `'NetworkTlsTcpServer'`. Pass TLS certificates and keys in `serverOptions` (type `TlsOptions` from `node:tls`).
|
|
561
|
+
|
|
562
|
+
#### Static Methods
|
|
563
|
+
|
|
564
|
+
##### `newInstance(opts)`
|
|
565
|
+
|
|
566
|
+
```typescript
|
|
567
|
+
static newInstance(
|
|
568
|
+
opts: Omit<ITcpSocketServerOptions, 'createServerFn'>
|
|
569
|
+
): NetworkTlsTcpServer
|
|
570
|
+
```
|
|
571
|
+
|
|
572
|
+
---
|
|
573
|
+
|
|
574
|
+
### BaseNetworkTcpClient
|
|
575
|
+
|
|
576
|
+
```typescript
|
|
577
|
+
class BaseNetworkTcpClient<
|
|
578
|
+
SocketClientOptions extends PlainConnectionOptions | TlsConnectionOptions,
|
|
579
|
+
SocketClientType extends PlainSocketClient | TlsSocketClient,
|
|
580
|
+
> extends BaseHelper
|
|
581
|
+
```
|
|
582
|
+
|
|
583
|
+
Abstract TCP client with auto-reconnect, encoding support, and lifecycle hooks.
|
|
584
|
+
|
|
585
|
+
#### Constructor
|
|
586
|
+
|
|
587
|
+
```typescript
|
|
588
|
+
constructor(opts: INetworkTcpClientProps<SocketClientOptions, SocketClientType>)
|
|
589
|
+
```
|
|
590
|
+
|
|
591
|
+
#### Protected Properties
|
|
592
|
+
|
|
593
|
+
| Property | Type | Description |
|
|
594
|
+
|----------|------|-------------|
|
|
595
|
+
| `client` | `SocketClientType \| null` | The underlying socket, or `null` when disconnected |
|
|
596
|
+
| `options` | `SocketClientOptions` | Connection options |
|
|
597
|
+
| `reconnect` | `boolean` | Whether auto-reconnect is enabled (default: `false`) |
|
|
598
|
+
| `retry` | `{ maxReconnect: number; currentReconnect: number }` | Reconnect state. `maxReconnect` defaults to `5` |
|
|
599
|
+
| `encoding` | `BufferEncoding \| undefined` | Socket encoding |
|
|
600
|
+
|
|
601
|
+
#### Methods
|
|
602
|
+
|
|
603
|
+
##### `connect(opts)`
|
|
604
|
+
|
|
605
|
+
Establishes the connection. If already connected, logs and returns. Creates the socket using `createClientFn`, registers `data`, `close`, and `error` events, and applies encoding if set.
|
|
606
|
+
|
|
607
|
+
```typescript
|
|
608
|
+
connect(opts: { resetReconnectCounter: boolean }): void
|
|
609
|
+
```
|
|
610
|
+
|
|
611
|
+
| Parameter | Type | Description |
|
|
612
|
+
|-----------|------|-------------|
|
|
613
|
+
| `resetReconnectCounter` | `boolean` | If `true`, resets `retry.currentReconnect` to `0` |
|
|
614
|
+
|
|
615
|
+
##### `disconnect()`
|
|
616
|
+
|
|
617
|
+
Destroys the socket, clears the reconnect timeout, and sets `client` to `null`.
|
|
618
|
+
|
|
619
|
+
```typescript
|
|
620
|
+
disconnect(): void
|
|
621
|
+
```
|
|
622
|
+
|
|
623
|
+
##### `forceReconnect()`
|
|
624
|
+
|
|
625
|
+
Calls `disconnect()` then `connect({ resetReconnectCounter: true })`.
|
|
626
|
+
|
|
627
|
+
```typescript
|
|
628
|
+
forceReconnect(): void
|
|
629
|
+
```
|
|
630
|
+
|
|
631
|
+
##### `isConnected()`
|
|
632
|
+
|
|
633
|
+
Returns a truthy value if the client exists and its `readyState` is not `'closed'`.
|
|
634
|
+
|
|
635
|
+
```typescript
|
|
636
|
+
isConnected(): SocketClientType | null | undefined
|
|
637
|
+
```
|
|
638
|
+
|
|
639
|
+
##### `emit(opts)`
|
|
640
|
+
|
|
641
|
+
Writes data to the server. Silently returns (with a log) if the client is not initialized or the payload is empty.
|
|
642
|
+
|
|
643
|
+
```typescript
|
|
644
|
+
emit(opts: { payload: Buffer | string }): void
|
|
645
|
+
```
|
|
646
|
+
|
|
647
|
+
##### `getClient()`
|
|
648
|
+
|
|
649
|
+
Returns the underlying socket instance, or `null`/`undefined` if not connected.
|
|
650
|
+
|
|
651
|
+
```typescript
|
|
652
|
+
getClient(): SocketClientType | null | undefined
|
|
653
|
+
```
|
|
654
|
+
|
|
655
|
+
##### `handleConnected()`
|
|
656
|
+
|
|
657
|
+
Default connection handler. Logs the connection and resets the reconnect counter.
|
|
658
|
+
|
|
659
|
+
```typescript
|
|
660
|
+
handleConnected(): void
|
|
661
|
+
```
|
|
662
|
+
|
|
663
|
+
##### `handleData(_opts)`
|
|
664
|
+
|
|
665
|
+
Default data handler. No-op.
|
|
666
|
+
|
|
667
|
+
```typescript
|
|
668
|
+
handleData(_opts: { identifier: string; message: string | Buffer }): void
|
|
669
|
+
```
|
|
670
|
+
|
|
671
|
+
##### `handleClosed()`
|
|
672
|
+
|
|
673
|
+
Default close handler. Logs the closure.
|
|
674
|
+
|
|
675
|
+
```typescript
|
|
676
|
+
handleClosed(): void
|
|
677
|
+
```
|
|
678
|
+
|
|
679
|
+
##### `handleError(error)`
|
|
680
|
+
|
|
681
|
+
Default error handler. Logs the error. If `reconnect` is enabled and the retry limit has not been reached, schedules a reconnect after 5 seconds.
|
|
682
|
+
|
|
683
|
+
```typescript
|
|
684
|
+
handleError(error: any): void
|
|
685
|
+
```
|
|
686
|
+
|
|
687
|
+
---
|
|
688
|
+
|
|
689
|
+
### NetworkTcpClient
|
|
690
|
+
|
|
691
|
+
```typescript
|
|
692
|
+
class NetworkTcpClient extends BaseNetworkTcpClient<TcpSocketConnectOpts, Socket>
|
|
693
|
+
```
|
|
694
|
+
|
|
695
|
+
Plain TCP client using `net.connect`.
|
|
696
|
+
|
|
697
|
+
#### Constructor
|
|
698
|
+
|
|
699
|
+
```typescript
|
|
700
|
+
constructor(
|
|
701
|
+
opts: Omit<INetworkTcpClientProps<TcpSocketConnectOpts, Socket>, 'createClientFn'>
|
|
702
|
+
)
|
|
703
|
+
```
|
|
704
|
+
|
|
705
|
+
The `createClientFn` is pre-set to `net.connect`. The `scope` is set to `'NetworkTcpClient'`.
|
|
706
|
+
|
|
707
|
+
#### Static Methods
|
|
708
|
+
|
|
709
|
+
##### `newInstance(opts)`
|
|
710
|
+
|
|
711
|
+
```typescript
|
|
712
|
+
static newInstance(
|
|
713
|
+
opts: Omit<INetworkTcpClientProps<TcpSocketConnectOpts, Socket>, 'createClientFn'>
|
|
714
|
+
): NetworkTcpClient
|
|
715
|
+
```
|
|
716
|
+
|
|
717
|
+
---
|
|
718
|
+
|
|
719
|
+
### NetworkTlsTcpClient
|
|
720
|
+
|
|
721
|
+
```typescript
|
|
722
|
+
class NetworkTlsTcpClient extends BaseNetworkTcpClient<ConnectionOptions, TLSSocket>
|
|
723
|
+
```
|
|
724
|
+
|
|
725
|
+
TLS-encrypted TCP client using `tls.connect`.
|
|
726
|
+
|
|
727
|
+
#### Constructor
|
|
728
|
+
|
|
729
|
+
```typescript
|
|
730
|
+
constructor(
|
|
731
|
+
opts: Omit<INetworkTcpClientProps<ConnectionOptions, TLSSocket>, 'createClientFn'>
|
|
732
|
+
)
|
|
733
|
+
```
|
|
734
|
+
|
|
735
|
+
The `createClientFn` is pre-set to `tls.connect`. The `scope` is set to `'NetworkTlsTcpClient'`. Pass TLS certificates and keys in `options` (type `ConnectionOptions` from `node:tls`).
|
|
736
|
+
|
|
737
|
+
#### Static Methods
|
|
738
|
+
|
|
739
|
+
##### `newInstance(opts)`
|
|
740
|
+
|
|
741
|
+
```typescript
|
|
742
|
+
static newInstance(
|
|
743
|
+
opts: Omit<INetworkTcpClientProps<ConnectionOptions, TLSSocket>, 'createClientFn'>
|
|
744
|
+
): NetworkTlsTcpClient
|
|
745
|
+
```
|
|
746
|
+
|
|
747
|
+
---
|
|
748
|
+
|
|
749
|
+
## UDP Socket API
|
|
750
|
+
|
|
751
|
+
### NetworkUdpClient
|
|
752
|
+
|
|
753
|
+
```typescript
|
|
754
|
+
class NetworkUdpClient extends BaseHelper
|
|
755
|
+
```
|
|
756
|
+
|
|
757
|
+
UDP datagram client with multicast support, using `node:dgram` internally (UDP4).
|
|
758
|
+
|
|
759
|
+
#### Constructor
|
|
760
|
+
|
|
761
|
+
```typescript
|
|
762
|
+
constructor(opts: INetworkUdpClientProps)
|
|
763
|
+
```
|
|
764
|
+
|
|
765
|
+
```typescript
|
|
766
|
+
interface INetworkUdpClientProps {
|
|
767
|
+
identifier: string;
|
|
768
|
+
host?: string;
|
|
769
|
+
port: number;
|
|
770
|
+
reuseAddr?: boolean;
|
|
771
|
+
multicastAddress?: {
|
|
772
|
+
groups?: Array<string>;
|
|
773
|
+
interface?: string;
|
|
774
|
+
};
|
|
775
|
+
onConnected?: (opts: { identifier: string; host?: string; port: number }) => void;
|
|
776
|
+
onData?: (opts: {
|
|
777
|
+
identifier: string;
|
|
778
|
+
message: string | Buffer;
|
|
779
|
+
remoteInfo: dgram.RemoteInfo;
|
|
780
|
+
}) => void;
|
|
781
|
+
onClosed?: (opts: { identifier: string; host?: string; port: number }) => void;
|
|
782
|
+
onError?: (opts: { identifier: string; host?: string; port: number; error: Error }) => void;
|
|
783
|
+
onBind?: (opts: {
|
|
784
|
+
identifier: string;
|
|
785
|
+
socket: dgram.Socket;
|
|
786
|
+
host?: string;
|
|
787
|
+
port: number;
|
|
788
|
+
reuseAddr?: boolean;
|
|
789
|
+
multicastAddress?: { groups?: Array<string>; interface?: string };
|
|
790
|
+
}) => ValueOrPromise<void>;
|
|
791
|
+
}
|
|
792
|
+
```
|
|
793
|
+
|
|
794
|
+
#### Static Methods
|
|
795
|
+
|
|
796
|
+
##### `newInstance(opts)`
|
|
797
|
+
|
|
798
|
+
Factory method that creates a new `NetworkUdpClient`.
|
|
799
|
+
|
|
800
|
+
```typescript
|
|
801
|
+
static newInstance(opts: INetworkUdpClientProps): NetworkUdpClient
|
|
802
|
+
```
|
|
803
|
+
|
|
804
|
+
#### Methods
|
|
805
|
+
|
|
806
|
+
##### `connect()`
|
|
807
|
+
|
|
808
|
+
Creates a `dgram.Socket` (type `'udp4'`), registers `close`, `error`, `listening`, and `message` events, then binds to the configured `port` and `host`. The `onBind` callback is invoked after binding completes -- use it to join multicast groups.
|
|
809
|
+
|
|
810
|
+
```typescript
|
|
811
|
+
connect(): void
|
|
812
|
+
```
|
|
813
|
+
|
|
814
|
+
If the client is already initialized, logs a message and returns. If `port` is not set, logs a message and returns.
|
|
815
|
+
|
|
816
|
+
##### `disconnect()`
|
|
817
|
+
|
|
818
|
+
Closes the underlying `dgram.Socket` and sets the client to `null`.
|
|
819
|
+
|
|
820
|
+
```typescript
|
|
821
|
+
disconnect(): void
|
|
822
|
+
```
|
|
823
|
+
|
|
824
|
+
##### `isConnected()`
|
|
825
|
+
|
|
826
|
+
Returns the underlying socket if connected, or `null`/`undefined` if not.
|
|
827
|
+
|
|
828
|
+
```typescript
|
|
829
|
+
isConnected(): dgram.Socket | null | undefined
|
|
830
|
+
```
|
|
831
|
+
|
|
832
|
+
##### `getClient()`
|
|
833
|
+
|
|
834
|
+
Returns the underlying `dgram.Socket` instance, or `null`/`undefined` if not connected.
|
|
835
|
+
|
|
836
|
+
```typescript
|
|
837
|
+
getClient(): dgram.Socket | null | undefined
|
|
838
|
+
```
|
|
839
|
+
|
|
840
|
+
##### `handleConnected()`
|
|
841
|
+
|
|
842
|
+
Default connection handler. Logs the bind success with host, port, and multicast address.
|
|
843
|
+
|
|
844
|
+
```typescript
|
|
845
|
+
handleConnected(): void
|
|
846
|
+
```
|
|
847
|
+
|
|
848
|
+
##### `handleData(opts)`
|
|
849
|
+
|
|
850
|
+
Default data handler. Logs the received message and remote info.
|
|
851
|
+
|
|
852
|
+
```typescript
|
|
853
|
+
handleData(opts: {
|
|
854
|
+
identifier: string;
|
|
855
|
+
message: string | Buffer;
|
|
856
|
+
remoteInfo: dgram.RemoteInfo;
|
|
857
|
+
}): void
|
|
858
|
+
```
|
|
859
|
+
|
|
860
|
+
##### `handleClosed()`
|
|
861
|
+
|
|
862
|
+
Default close handler. Logs the closure with host and port.
|
|
863
|
+
|
|
864
|
+
```typescript
|
|
865
|
+
handleClosed(): void
|
|
866
|
+
```
|
|
867
|
+
|
|
868
|
+
##### `handleError(opts)`
|
|
869
|
+
|
|
870
|
+
Default error handler. Logs the error with host and port.
|
|
871
|
+
|
|
872
|
+
```typescript
|
|
873
|
+
handleError(opts: { identifier: string; error: Error }): void
|
|
874
|
+
```
|
|
875
|
+
|
|
876
|
+
---
|
|
877
|
+
|
|
878
|
+
## Types Reference
|
|
879
|
+
|
|
880
|
+
### TFetcherVariant
|
|
881
|
+
|
|
882
|
+
```typescript
|
|
883
|
+
type TFetcherVariant = 'node-fetch' | 'axios';
|
|
884
|
+
```
|
|
885
|
+
|
|
886
|
+
### TFetcherResponse
|
|
887
|
+
|
|
888
|
+
```typescript
|
|
889
|
+
type TFetcherResponse<T extends TFetcherVariant> =
|
|
890
|
+
T extends 'node-fetch' ? Response : AxiosResponse;
|
|
891
|
+
```
|
|
892
|
+
|
|
893
|
+
### TFetcherWorker
|
|
894
|
+
|
|
895
|
+
```typescript
|
|
896
|
+
type TFetcherWorker<T extends TFetcherVariant> =
|
|
897
|
+
T extends 'axios' ? AxiosInstance : typeof fetch;
|
|
898
|
+
```
|
|
899
|
+
|
|
900
|
+
### ITcpSocketServerOptions
|
|
901
|
+
|
|
902
|
+
```typescript
|
|
903
|
+
interface ITcpSocketServerOptions<
|
|
904
|
+
SocketServerOptions extends ServerOpts = ServerOpts,
|
|
905
|
+
SocketServerType extends SocketServer = SocketServer,
|
|
906
|
+
SocketClientType extends SocketClient = SocketClient,
|
|
907
|
+
> {
|
|
908
|
+
scope?: string;
|
|
909
|
+
identifier: string;
|
|
910
|
+
serverOptions: Partial<SocketServerOptions>;
|
|
911
|
+
listenOptions: Partial<ListenOptions>;
|
|
912
|
+
authenticateOptions: { required: boolean; duration?: number };
|
|
913
|
+
extraEvents?: Record<
|
|
914
|
+
string,
|
|
915
|
+
(opts: { id: string; socket: SocketClientType; args: any }) => ValueOrPromise<void>
|
|
916
|
+
>;
|
|
917
|
+
createServerFn: (
|
|
918
|
+
options: Partial<SocketServerOptions>,
|
|
919
|
+
connectionListener: (socket: SocketClientType) => void,
|
|
920
|
+
) => SocketServerType;
|
|
921
|
+
onServerReady?: (opts: { server: SocketServerType }) => void;
|
|
922
|
+
onClientConnected?: (opts: { id: string; socket: SocketClientType }) => void;
|
|
923
|
+
onClientData?: (opts: { id: string; socket: SocketClientType; data: Buffer | string }) => void;
|
|
924
|
+
onClientClose?: (opts: { id: string; socket: SocketClientType }) => void;
|
|
925
|
+
onClientError?: (opts: { id: string; socket: SocketClientType; error: Error }) => void;
|
|
926
|
+
}
|
|
927
|
+
```
|
|
928
|
+
|
|
929
|
+
### INetworkTcpClientProps
|
|
930
|
+
|
|
931
|
+
```typescript
|
|
932
|
+
interface INetworkTcpClientProps<
|
|
933
|
+
SocketClientOptions extends PlainConnectionOptions | TlsConnectionOptions,
|
|
934
|
+
SocketClientType extends PlainSocketClient | TlsSocketClient,
|
|
935
|
+
> {
|
|
936
|
+
identifier: string;
|
|
937
|
+
scope?: string;
|
|
938
|
+
options: SocketClientOptions;
|
|
939
|
+
reconnect?: boolean;
|
|
940
|
+
maxRetry?: number;
|
|
941
|
+
encoding?: BufferEncoding;
|
|
942
|
+
createClientFn: (
|
|
943
|
+
options: SocketClientOptions,
|
|
944
|
+
connectionListener?: () => void,
|
|
945
|
+
) => SocketClientType;
|
|
946
|
+
onConnected?: (opts: { client: SocketClientType }) => ValueOrPromise<void>;
|
|
947
|
+
onData?: (opts: { identifier: string; message: string | Buffer }) => ValueOrPromise<void>;
|
|
948
|
+
onClosed?: (opts: { client: SocketClientType }) => void;
|
|
949
|
+
onError?: (error: any) => void;
|
|
950
|
+
}
|
|
951
|
+
```
|
|
952
|
+
|
|
953
|
+
### INetworkUdpClientProps
|
|
954
|
+
|
|
955
|
+
```typescript
|
|
956
|
+
interface INetworkUdpClientProps {
|
|
957
|
+
identifier: string;
|
|
958
|
+
host?: string;
|
|
959
|
+
port: number;
|
|
960
|
+
reuseAddr?: boolean;
|
|
961
|
+
multicastAddress?: {
|
|
962
|
+
groups?: Array<string>;
|
|
963
|
+
interface?: string;
|
|
964
|
+
};
|
|
965
|
+
onConnected?: (opts: { identifier: string; host?: string; port: number }) => void;
|
|
966
|
+
onData?: (opts: {
|
|
967
|
+
identifier: string;
|
|
968
|
+
message: string | Buffer;
|
|
969
|
+
remoteInfo: dgram.RemoteInfo;
|
|
970
|
+
}) => void;
|
|
971
|
+
onClosed?: (opts: { identifier: string; host?: string; port: number }) => void;
|
|
972
|
+
onError?: (opts: { identifier: string; host?: string; port: number; error: Error }) => void;
|
|
973
|
+
onBind?: (opts: {
|
|
974
|
+
identifier: string;
|
|
975
|
+
socket: dgram.Socket;
|
|
976
|
+
host?: string;
|
|
977
|
+
port: number;
|
|
978
|
+
reuseAddr?: boolean;
|
|
979
|
+
multicastAddress?: { groups?: Array<string>; interface?: string };
|
|
980
|
+
}) => ValueOrPromise<void>;
|
|
981
|
+
}
|
|
982
|
+
```
|
|
983
|
+
|
|
984
|
+
## See Also
|
|
985
|
+
|
|
986
|
+
- [Setup & Usage](./) -- Getting started and examples
|