@flux-control/effect-modbus-rs 0.3.0 → 0.4.0
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 +74 -18
- package/dist/index.d.ts +1 -1
- package/dist/index.js +114 -118
- package/dist/src/AsciiTransportService.d.ts +31 -22
- package/dist/src/RtuTransportService.d.ts +31 -22
- package/dist/src/SerialTransportService.d.ts +17 -7
- package/dist/src/TcpTransportService.d.ts +31 -22
- package/dist/src/WasmAsciiTransportService.d.ts +30 -21
- package/dist/src/WasmRtuTransportService.d.ts +30 -21
- package/dist/src/WasmSerialPort.d.ts +2 -2
- package/dist/src/WasmSerialTransportService.d.ts +20 -10
- package/dist/src/WasmWsTransportService.d.ts +30 -21
- package/dist/src/connection.d.ts +9 -9
- package/dist/src/mock-options.test.d.ts +1 -0
- package/dist/src/mocks.d.ts +41 -57
- package/dist/src/retry.d.ts +11 -8
- package/package.json +5 -5
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Context, Layer } from 'effect';
|
|
2
2
|
import { type AsciiTransportOpenOptions } from './AsciiTransportService';
|
|
3
|
-
import { type SlaveDeviceDefinitions } from './mocks';
|
|
3
|
+
import { type MockFaultOptions, type SlaveDeviceDefinitions } from './mocks';
|
|
4
4
|
import { type RtuTransportOpenOptions } from './RtuTransportService';
|
|
5
5
|
import type { TransportResilienceOptions, TransportServiceApi } from './shared-transport';
|
|
6
|
-
declare const SerialTransportService_base: Context.
|
|
6
|
+
declare const SerialTransportService_base: Context.ServiceClass<SerialTransportService, "SerialTransportService", TransportServiceApi>;
|
|
7
7
|
/**
|
|
8
8
|
* Abstract serial Modbus transport service tag.
|
|
9
9
|
*
|
|
@@ -35,12 +35,22 @@ export declare class SerialTransportService extends SerialTransportService_base
|
|
|
35
35
|
*/
|
|
36
36
|
static fromRtu(options: RtuTransportOpenOptions & TransportResilienceOptions): Layer.Layer<SerialTransportService>;
|
|
37
37
|
/**
|
|
38
|
-
* Creates a mock {@link Layer}
|
|
39
|
-
* for
|
|
38
|
+
* Creates a mock {@link Layer} that provides {@link SerialTransportService}
|
|
39
|
+
* for tests or development.
|
|
40
40
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
41
|
+
* The `devices` parameter is an array of {@link SlaveDeviceDefinition}. Each
|
|
42
|
+
* definition gives the coil map and the register map of one simulated slave.
|
|
43
|
+
*
|
|
44
|
+
* The option set is the same as the option set of the concrete tags. Thus a
|
|
45
|
+
* test that keeps the framing abstract can also set `retry`, `reconnect`,
|
|
46
|
+
* `fault`, and `reconnectFault`.
|
|
47
|
+
*
|
|
48
|
+
* @param devices - The slave device definitions for the mock.
|
|
49
|
+
* @returns A function that takes the mock options and gives a scoped
|
|
50
|
+
* {@link Layer} that provides the mock service.
|
|
51
|
+
* @see MockFaultOptions — The `fault` hook and the `reconnectFault` hook.
|
|
52
|
+
* @see makeMockTransport — The mock factory that this method uses.
|
|
43
53
|
*/
|
|
44
|
-
static makeMockTransport: (devices: SlaveDeviceDefinitions) => (options: (AsciiTransportOpenOptions | RtuTransportOpenOptions) & TransportResilienceOptions) => Layer.Layer<SerialTransportService>;
|
|
54
|
+
static makeMockTransport: (devices: SlaveDeviceDefinitions) => (options: (AsciiTransportOpenOptions | RtuTransportOpenOptions) & TransportResilienceOptions & MockFaultOptions) => Layer.Layer<SerialTransportService>;
|
|
45
55
|
}
|
|
46
56
|
export {};
|
|
@@ -1,16 +1,37 @@
|
|
|
1
|
-
import { Effect, Layer } from 'effect';
|
|
1
|
+
import { Context, Effect, Layer } from 'effect';
|
|
2
2
|
import type { TcpTransportOptions } from 'modbus-rs';
|
|
3
3
|
import { SlaveDeviceDefinitions } from './mocks';
|
|
4
4
|
import type { MockFaultOptions } from './mocks';
|
|
5
|
-
import type { TransportResilienceOptions, WithoutUpstreamRetry } from './shared-transport';
|
|
5
|
+
import type { TransportResilienceOptions, TransportServiceApi, WithoutUpstreamRetry } from './shared-transport';
|
|
6
6
|
/**
|
|
7
7
|
* {@link TcpTransportOptions} minus the upstream retry knobs.
|
|
8
8
|
*
|
|
9
9
|
* @see WithoutUpstreamRetry — Why they are withheld.
|
|
10
10
|
*/
|
|
11
11
|
export type TcpTransportOpenOptions = WithoutUpstreamRetry<TcpTransportOptions>;
|
|
12
|
-
declare const TcpTransportService_base:
|
|
13
|
-
|
|
12
|
+
declare const TcpTransportService_base: Context.ServiceClass<TcpTransportService, "TcpTransportService", TransportServiceApi>;
|
|
13
|
+
/**
|
|
14
|
+
* Scoped Effect service wrapping the `modbus-rs` {@link AsyncTcpTransport}
|
|
15
|
+
* for TCP/IP Modbus communication.
|
|
16
|
+
*
|
|
17
|
+
* The transport connection is opened lazily on the first call to
|
|
18
|
+
* `withClient(unitId)` and automatically closed when the consuming
|
|
19
|
+
* {@link Effect.Scope | Scope} finalizes.
|
|
20
|
+
*
|
|
21
|
+
* Clients are created per `unitId` via
|
|
22
|
+
* {@link AsyncTcpTransport.createClient} and cached, so repeated
|
|
23
|
+
* requests for the same unit ID reuse the same client.
|
|
24
|
+
*
|
|
25
|
+
* @see AsyncTcpTransport — Upstream `modbus-rs` TCP transport.
|
|
26
|
+
* @see TcpTransportOpenOptions — Configuration for the TCP connection.
|
|
27
|
+
* @see makeTransportScoped — Generic lifecycle logic from shared-transport.
|
|
28
|
+
*/
|
|
29
|
+
export declare class TcpTransportService extends TcpTransportService_base {
|
|
30
|
+
/**
|
|
31
|
+
* Scoped constructor effect for the service. v4 does not auto-generate a
|
|
32
|
+
* layer from this, so {@link TcpTransportService.make} builds one explicitly.
|
|
33
|
+
*/
|
|
34
|
+
static readonly makeScoped: (options: TcpTransportOpenOptions & TransportResilienceOptions) => Effect.Effect<{
|
|
14
35
|
connectionState: import("effect/SubscriptionRef").SubscriptionRef<{
|
|
15
36
|
readonly _tag: "Connected";
|
|
16
37
|
} | {
|
|
@@ -31,24 +52,12 @@ declare const TcpTransportService_base: Effect.Service.Class<TcpTransportService
|
|
|
31
52
|
close: () => Effect.Effect<void, import("./errors").ModbusError, import("effect/Scope").Scope>;
|
|
32
53
|
hasPendingRequests: () => boolean;
|
|
33
54
|
}, never, import("effect/Scope").Scope>;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
* `withClient(unitId)` and automatically closed when the consuming
|
|
41
|
-
* {@link Effect.Scope | Scope} finalizes.
|
|
42
|
-
*
|
|
43
|
-
* Clients are created per `unitId` via
|
|
44
|
-
* {@link AsyncTcpTransport.createClient} and cached, so repeated
|
|
45
|
-
* requests for the same unit ID reuse the same client.
|
|
46
|
-
*
|
|
47
|
-
* @see AsyncTcpTransport — Upstream `modbus-rs` TCP transport.
|
|
48
|
-
* @see TcpTransportOpenOptions — Configuration for the TCP connection.
|
|
49
|
-
* @see makeTransportScoped — Generic lifecycle logic from shared-transport.
|
|
50
|
-
*/
|
|
51
|
-
export declare class TcpTransportService extends TcpTransportService_base {
|
|
55
|
+
/**
|
|
56
|
+
* Creates a {@link Layer} providing a live {@link TcpTransportService}.
|
|
57
|
+
*
|
|
58
|
+
* @param options - Connection and resilience options for the TCP transport.
|
|
59
|
+
*/
|
|
60
|
+
static readonly make: (options: TcpTransportOpenOptions & TransportResilienceOptions) => Layer.Layer<TcpTransportService>;
|
|
52
61
|
/**
|
|
53
62
|
* Creates a {@link Layer} providing an in-memory mock
|
|
54
63
|
* {@link TcpTransportService} for testing or development.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Effect, Layer } from 'effect';
|
|
1
|
+
import { Context, Effect, Layer } from 'effect';
|
|
2
2
|
import type { WasmSerialPortHandle, WasmSerialTransportOptions } from 'modbus-rs/web';
|
|
3
3
|
import { SlaveDeviceDefinitions } from './mocks';
|
|
4
4
|
import type { MockFaultOptions } from './mocks';
|
|
5
|
-
import type { TransportResilienceOptions } from './shared-transport';
|
|
5
|
+
import type { TransportResilienceOptions, TransportServiceApi } from './shared-transport';
|
|
6
6
|
/**
|
|
7
7
|
* Options for {@link WasmAsciiTransportService}. `WasmAsciiTransport.open()` takes the
|
|
8
8
|
* serial port handle and the connection options as two separate arguments; this
|
|
@@ -14,8 +14,28 @@ import type { TransportResilienceOptions } from './shared-transport';
|
|
|
14
14
|
export type WasmAsciiTransportOpenOptions = WasmSerialTransportOptions & {
|
|
15
15
|
port: WasmSerialPortHandle;
|
|
16
16
|
};
|
|
17
|
-
declare const WasmAsciiTransportService_base:
|
|
18
|
-
|
|
17
|
+
declare const WasmAsciiTransportService_base: Context.ServiceClass<WasmAsciiTransportService, "WasmAsciiTransportService", TransportServiceApi>;
|
|
18
|
+
/**
|
|
19
|
+
* Scoped Effect service wrapping `modbus-rs`'s browser {@link WasmAsciiTransport}
|
|
20
|
+
* for Modbus ASCII over the Web Serial API.
|
|
21
|
+
*
|
|
22
|
+
* The transport connection is opened lazily on the first call to
|
|
23
|
+
* `withClient(unitId)` and automatically closed when the consuming
|
|
24
|
+
* {@link Effect.Scope | Scope} finalizes.
|
|
25
|
+
*
|
|
26
|
+
* Clients are created per `unitId` via {@link WasmAsciiTransport.createClient} and
|
|
27
|
+
* cached, so repeated requests for the same unit ID reuse the same client.
|
|
28
|
+
*
|
|
29
|
+
* @see WasmAsciiTransport — Upstream `modbus-rs` browser Web Serial ASCII transport.
|
|
30
|
+
* @see requestSerialPort — Obtains the serial port handle this service's `port` option needs.
|
|
31
|
+
* @see makeTransportScoped — Generic lifecycle logic from shared-transport.
|
|
32
|
+
*/
|
|
33
|
+
export declare class WasmAsciiTransportService extends WasmAsciiTransportService_base {
|
|
34
|
+
/**
|
|
35
|
+
* Scoped constructor effect for the service. v4 does not auto-generate a
|
|
36
|
+
* layer from this, so {@link WasmAsciiTransportService.make} builds one explicitly.
|
|
37
|
+
*/
|
|
38
|
+
static readonly makeScoped: (options: WasmSerialTransportOptions & {
|
|
19
39
|
port: WasmSerialPortHandle;
|
|
20
40
|
} & TransportResilienceOptions) => Effect.Effect<{
|
|
21
41
|
connectionState: import("effect/SubscriptionRef").SubscriptionRef<{
|
|
@@ -38,23 +58,12 @@ declare const WasmAsciiTransportService_base: Effect.Service.Class<WasmAsciiTran
|
|
|
38
58
|
close: () => Effect.Effect<void, import("./errors").ModbusError, import("effect/Scope").Scope>;
|
|
39
59
|
hasPendingRequests: () => boolean;
|
|
40
60
|
}, never, import("effect/Scope").Scope>;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
* `withClient(unitId)` and automatically closed when the consuming
|
|
48
|
-
* {@link Effect.Scope | Scope} finalizes.
|
|
49
|
-
*
|
|
50
|
-
* Clients are created per `unitId` via {@link WasmAsciiTransport.createClient} and
|
|
51
|
-
* cached, so repeated requests for the same unit ID reuse the same client.
|
|
52
|
-
*
|
|
53
|
-
* @see WasmAsciiTransport — Upstream `modbus-rs` browser Web Serial ASCII transport.
|
|
54
|
-
* @see requestSerialPort — Obtains the serial port handle this service's `port` option needs.
|
|
55
|
-
* @see makeTransportScoped — Generic lifecycle logic from shared-transport.
|
|
56
|
-
*/
|
|
57
|
-
export declare class WasmAsciiTransportService extends WasmAsciiTransportService_base {
|
|
61
|
+
/**
|
|
62
|
+
* Creates a {@link Layer} providing a live {@link WasmAsciiTransportService}.
|
|
63
|
+
*
|
|
64
|
+
* @param options - Connection and resilience options for the transport.
|
|
65
|
+
*/
|
|
66
|
+
static readonly make: (options: WasmAsciiTransportOpenOptions & TransportResilienceOptions) => Layer.Layer<WasmAsciiTransportService>;
|
|
58
67
|
/**
|
|
59
68
|
* Creates a {@link Layer} providing an in-memory mock
|
|
60
69
|
* {@link WasmAsciiTransportService} for testing or development.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Effect, Layer } from 'effect';
|
|
1
|
+
import { Context, Effect, Layer } from 'effect';
|
|
2
2
|
import type { WasmSerialPortHandle, WasmSerialTransportOptions } from 'modbus-rs/web';
|
|
3
3
|
import { SlaveDeviceDefinitions } from './mocks';
|
|
4
4
|
import type { MockFaultOptions } from './mocks';
|
|
5
|
-
import type { TransportResilienceOptions } from './shared-transport';
|
|
5
|
+
import type { TransportResilienceOptions, TransportServiceApi } from './shared-transport';
|
|
6
6
|
/**
|
|
7
7
|
* Options for {@link WasmRtuTransportService}. `WasmRtuTransport.open()` takes the
|
|
8
8
|
* serial port handle and the connection options as two separate arguments; this
|
|
@@ -14,8 +14,28 @@ import type { TransportResilienceOptions } from './shared-transport';
|
|
|
14
14
|
export type WasmRtuTransportOpenOptions = WasmSerialTransportOptions & {
|
|
15
15
|
port: WasmSerialPortHandle;
|
|
16
16
|
};
|
|
17
|
-
declare const WasmRtuTransportService_base:
|
|
18
|
-
|
|
17
|
+
declare const WasmRtuTransportService_base: Context.ServiceClass<WasmRtuTransportService, "WasmRtuTransportService", TransportServiceApi>;
|
|
18
|
+
/**
|
|
19
|
+
* Scoped Effect service wrapping `modbus-rs`'s browser {@link WasmRtuTransport}
|
|
20
|
+
* for Modbus RTU over the Web Serial API.
|
|
21
|
+
*
|
|
22
|
+
* The transport connection is opened lazily on the first call to
|
|
23
|
+
* `withClient(unitId)` and automatically closed when the consuming
|
|
24
|
+
* {@link Effect.Scope | Scope} finalizes.
|
|
25
|
+
*
|
|
26
|
+
* Clients are created per `unitId` via {@link WasmRtuTransport.createClient} and
|
|
27
|
+
* cached, so repeated requests for the same unit ID reuse the same client.
|
|
28
|
+
*
|
|
29
|
+
* @see WasmRtuTransport — Upstream `modbus-rs` browser Web Serial RTU transport.
|
|
30
|
+
* @see requestSerialPort — Obtains the serial port handle this service's `port` option needs.
|
|
31
|
+
* @see makeTransportScoped — Generic lifecycle logic from shared-transport.
|
|
32
|
+
*/
|
|
33
|
+
export declare class WasmRtuTransportService extends WasmRtuTransportService_base {
|
|
34
|
+
/**
|
|
35
|
+
* Scoped constructor effect for the service. v4 does not auto-generate a
|
|
36
|
+
* layer from this, so {@link WasmRtuTransportService.make} builds one explicitly.
|
|
37
|
+
*/
|
|
38
|
+
static readonly makeScoped: (options: WasmSerialTransportOptions & {
|
|
19
39
|
port: WasmSerialPortHandle;
|
|
20
40
|
} & TransportResilienceOptions) => Effect.Effect<{
|
|
21
41
|
connectionState: import("effect/SubscriptionRef").SubscriptionRef<{
|
|
@@ -38,23 +58,12 @@ declare const WasmRtuTransportService_base: Effect.Service.Class<WasmRtuTranspor
|
|
|
38
58
|
close: () => Effect.Effect<void, import("./errors").ModbusError, import("effect/Scope").Scope>;
|
|
39
59
|
hasPendingRequests: () => boolean;
|
|
40
60
|
}, never, import("effect/Scope").Scope>;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
* `withClient(unitId)` and automatically closed when the consuming
|
|
48
|
-
* {@link Effect.Scope | Scope} finalizes.
|
|
49
|
-
*
|
|
50
|
-
* Clients are created per `unitId` via {@link WasmRtuTransport.createClient} and
|
|
51
|
-
* cached, so repeated requests for the same unit ID reuse the same client.
|
|
52
|
-
*
|
|
53
|
-
* @see WasmRtuTransport — Upstream `modbus-rs` browser Web Serial RTU transport.
|
|
54
|
-
* @see requestSerialPort — Obtains the serial port handle this service's `port` option needs.
|
|
55
|
-
* @see makeTransportScoped — Generic lifecycle logic from shared-transport.
|
|
56
|
-
*/
|
|
57
|
-
export declare class WasmRtuTransportService extends WasmRtuTransportService_base {
|
|
61
|
+
/**
|
|
62
|
+
* Creates a {@link Layer} providing a live {@link WasmRtuTransportService}.
|
|
63
|
+
*
|
|
64
|
+
* @param options - Connection and resilience options for the transport.
|
|
65
|
+
*/
|
|
66
|
+
static readonly make: (options: WasmRtuTransportOpenOptions & TransportResilienceOptions) => Layer.Layer<WasmRtuTransportService>;
|
|
58
67
|
/**
|
|
59
68
|
* Creates a {@link Layer} providing an in-memory mock
|
|
60
69
|
* {@link WasmRtuTransportService} for testing or development.
|
|
@@ -4,7 +4,7 @@ import type { ModbusError } from './errors';
|
|
|
4
4
|
/**
|
|
5
5
|
* Requests a browser serial port handle via the Web Serial API, for use with
|
|
6
6
|
* {@link WasmSerialTransportService.fromRtu} / `.fromAscii` (or
|
|
7
|
-
* `WasmRtuTransportService.
|
|
7
|
+
* `WasmRtuTransportService.make` / `WasmAsciiTransportService.make` directly).
|
|
8
8
|
*
|
|
9
9
|
* **Must be called synchronously from within a user-gesture event handler**
|
|
10
10
|
* (e.g. a `click` listener) — this is a hard Web Serial API / browser security
|
|
@@ -16,7 +16,7 @@ import type { ModbusError } from './errors';
|
|
|
16
16
|
* button.addEventListener("click", () => {
|
|
17
17
|
* Effect.runPromise(
|
|
18
18
|
* requestSerialPort().pipe(
|
|
19
|
-
* Effect.flatMap((port) => Effect.provide(program, WasmRtuTransportService.
|
|
19
|
+
* Effect.flatMap((port) => Effect.provide(program, WasmRtuTransportService.make({ port, baudRate: 19200 }))),
|
|
20
20
|
* ),
|
|
21
21
|
* );
|
|
22
22
|
* });
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Context, Layer } from 'effect';
|
|
2
|
-
import { type SlaveDeviceDefinitions } from './mocks';
|
|
3
|
-
import type { TransportServiceApi } from './shared-transport';
|
|
2
|
+
import { type MockFaultOptions, type SlaveDeviceDefinitions } from './mocks';
|
|
3
|
+
import type { TransportResilienceOptions, TransportServiceApi } from './shared-transport';
|
|
4
4
|
import { type WasmAsciiTransportOpenOptions } from './WasmAsciiTransportService';
|
|
5
5
|
import { type WasmRtuTransportOpenOptions } from './WasmRtuTransportService';
|
|
6
|
-
declare const WasmSerialTransportService_base: Context.
|
|
6
|
+
declare const WasmSerialTransportService_base: Context.ServiceClass<WasmSerialTransportService, "WasmSerialTransportService", TransportServiceApi>;
|
|
7
7
|
/**
|
|
8
8
|
* Abstract browser (WASM) serial Modbus transport service tag.
|
|
9
9
|
*
|
|
@@ -30,19 +30,29 @@ export declare class WasmSerialTransportService extends WasmSerialTransportServi
|
|
|
30
30
|
* Creates a {@link Layer} providing {@link WasmSerialTransportService}
|
|
31
31
|
* backed by an ASCII transport.
|
|
32
32
|
*/
|
|
33
|
-
static fromAscii(options: WasmAsciiTransportOpenOptions): Layer.Layer<WasmSerialTransportService>;
|
|
33
|
+
static fromAscii(options: WasmAsciiTransportOpenOptions & TransportResilienceOptions): Layer.Layer<WasmSerialTransportService>;
|
|
34
34
|
/**
|
|
35
35
|
* Creates a {@link Layer} providing {@link WasmSerialTransportService}
|
|
36
36
|
* backed by an RTU transport.
|
|
37
37
|
*/
|
|
38
|
-
static fromRtu(options: WasmRtuTransportOpenOptions): Layer.Layer<WasmSerialTransportService>;
|
|
38
|
+
static fromRtu(options: WasmRtuTransportOpenOptions & TransportResilienceOptions): Layer.Layer<WasmSerialTransportService>;
|
|
39
39
|
/**
|
|
40
|
-
* Creates a mock {@link Layer}
|
|
41
|
-
* for
|
|
40
|
+
* Creates a mock {@link Layer} that provides {@link WasmSerialTransportService}
|
|
41
|
+
* for tests or development.
|
|
42
42
|
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
43
|
+
* The `devices` parameter is an array of {@link SlaveDeviceDefinition}. Each
|
|
44
|
+
* definition gives the coil map and the register map of one simulated slave.
|
|
45
|
+
*
|
|
46
|
+
* The option set is the same as the option set of the concrete tags. Thus a
|
|
47
|
+
* test that keeps the framing abstract can also set `retry`, `reconnect`,
|
|
48
|
+
* `fault`, and `reconnectFault`.
|
|
49
|
+
*
|
|
50
|
+
* @param devices - The slave device definitions for the mock.
|
|
51
|
+
* @returns A function that takes the mock options and gives a scoped
|
|
52
|
+
* {@link Layer} that provides the mock service.
|
|
53
|
+
* @see MockFaultOptions — The `fault` hook and the `reconnectFault` hook.
|
|
54
|
+
* @see makeMockTransport — The mock factory that this method uses.
|
|
45
55
|
*/
|
|
46
|
-
static makeMockTransport: (devices: SlaveDeviceDefinitions) => (options: WasmAsciiTransportOpenOptions | WasmRtuTransportOpenOptions) => Layer.Layer<WasmSerialTransportService>;
|
|
56
|
+
static makeMockTransport: (devices: SlaveDeviceDefinitions) => (options: (WasmAsciiTransportOpenOptions | WasmRtuTransportOpenOptions) & TransportResilienceOptions & MockFaultOptions) => Layer.Layer<WasmSerialTransportService>;
|
|
47
57
|
}
|
|
48
58
|
export {};
|
|
@@ -1,10 +1,30 @@
|
|
|
1
|
-
import { Effect, Layer } from 'effect';
|
|
1
|
+
import { Context, Effect, Layer } from 'effect';
|
|
2
2
|
import type { WasmWsTransportOptions } from 'modbus-rs/web';
|
|
3
3
|
import { SlaveDeviceDefinitions } from './mocks';
|
|
4
4
|
import type { MockFaultOptions } from './mocks';
|
|
5
|
-
import type { TransportResilienceOptions } from './shared-transport';
|
|
6
|
-
declare const WasmWsTransportService_base:
|
|
7
|
-
|
|
5
|
+
import type { TransportResilienceOptions, TransportServiceApi } from './shared-transport';
|
|
6
|
+
declare const WasmWsTransportService_base: Context.ServiceClass<WasmWsTransportService, "WasmWsTransportService", TransportServiceApi>;
|
|
7
|
+
/**
|
|
8
|
+
* Scoped Effect service wrapping `modbus-rs`'s browser {@link WasmWsTransport}
|
|
9
|
+
* for Modbus TCP over a WebSocket gateway (browsers can't open raw TCP sockets).
|
|
10
|
+
*
|
|
11
|
+
* The transport connection is opened lazily on the first call to
|
|
12
|
+
* `withClient(unitId)` and automatically closed when the consuming
|
|
13
|
+
* {@link Effect.Scope | Scope} finalizes.
|
|
14
|
+
*
|
|
15
|
+
* Clients are created per `unitId` via {@link WasmWsTransport.createClient} and
|
|
16
|
+
* cached, so repeated requests for the same unit ID reuse the same client.
|
|
17
|
+
*
|
|
18
|
+
* @see WasmWsTransport — Upstream `modbus-rs` browser WebSocket transport.
|
|
19
|
+
* @see WasmWsTransportOptions — Configuration for the WebSocket gateway connection.
|
|
20
|
+
* @see makeTransportScoped — Generic lifecycle logic from shared-transport.
|
|
21
|
+
*/
|
|
22
|
+
export declare class WasmWsTransportService extends WasmWsTransportService_base {
|
|
23
|
+
/**
|
|
24
|
+
* Scoped constructor effect for the service. v4 does not auto-generate a
|
|
25
|
+
* layer from this, so {@link WasmWsTransportService.make} builds one explicitly.
|
|
26
|
+
*/
|
|
27
|
+
static readonly makeScoped: (options: WasmWsTransportOptions & TransportResilienceOptions) => Effect.Effect<{
|
|
8
28
|
connectionState: import("effect/SubscriptionRef").SubscriptionRef<{
|
|
9
29
|
readonly _tag: "Connected";
|
|
10
30
|
} | {
|
|
@@ -25,23 +45,12 @@ declare const WasmWsTransportService_base: Effect.Service.Class<WasmWsTransportS
|
|
|
25
45
|
close: () => Effect.Effect<void, import("./errors").ModbusError, import("effect/Scope").Scope>;
|
|
26
46
|
hasPendingRequests: () => boolean;
|
|
27
47
|
}, never, import("effect/Scope").Scope>;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
* `withClient(unitId)` and automatically closed when the consuming
|
|
35
|
-
* {@link Effect.Scope | Scope} finalizes.
|
|
36
|
-
*
|
|
37
|
-
* Clients are created per `unitId` via {@link WasmWsTransport.createClient} and
|
|
38
|
-
* cached, so repeated requests for the same unit ID reuse the same client.
|
|
39
|
-
*
|
|
40
|
-
* @see WasmWsTransport — Upstream `modbus-rs` browser WebSocket transport.
|
|
41
|
-
* @see WasmWsTransportOptions — Configuration for the WebSocket gateway connection.
|
|
42
|
-
* @see makeTransportScoped — Generic lifecycle logic from shared-transport.
|
|
43
|
-
*/
|
|
44
|
-
export declare class WasmWsTransportService extends WasmWsTransportService_base {
|
|
48
|
+
/**
|
|
49
|
+
* Creates a {@link Layer} providing a live {@link WasmWsTransportService}.
|
|
50
|
+
*
|
|
51
|
+
* @param options - Connection and resilience options for the transport.
|
|
52
|
+
*/
|
|
53
|
+
static readonly make: (options: WasmWsTransportOptions & TransportResilienceOptions) => Layer.Layer<WasmWsTransportService>;
|
|
45
54
|
/**
|
|
46
55
|
* Creates a {@link Layer} providing an in-memory mock
|
|
47
56
|
* {@link WasmWsTransportService} for testing or development.
|
package/dist/src/connection.d.ts
CHANGED
|
@@ -47,7 +47,7 @@ export declare const ConnectionState: {
|
|
|
47
47
|
readonly _tag: Tag;
|
|
48
48
|
}>;
|
|
49
49
|
readonly $match: {
|
|
50
|
-
<
|
|
50
|
+
<Cases extends { readonly [Tag in "Connected" | "Disconnected" | "Down" | "Reconnecting"]: (args: Extract<{
|
|
51
51
|
readonly _tag: "Connected";
|
|
52
52
|
} | {
|
|
53
53
|
readonly _tag: "Disconnected";
|
|
@@ -59,7 +59,7 @@ export declare const ConnectionState: {
|
|
|
59
59
|
readonly attempt: number;
|
|
60
60
|
}, {
|
|
61
61
|
readonly _tag: Tag;
|
|
62
|
-
}>) => any; }>(cases: Cases
|
|
62
|
+
}>) => any; }>(cases: Cases): (value: {
|
|
63
63
|
readonly _tag: "Connected";
|
|
64
64
|
} | {
|
|
65
65
|
readonly _tag: "Disconnected";
|
|
@@ -70,7 +70,7 @@ export declare const ConnectionState: {
|
|
|
70
70
|
readonly _tag: "Reconnecting";
|
|
71
71
|
readonly attempt: number;
|
|
72
72
|
}) => import("effect/Unify").Unify<ReturnType<Cases["Connected" | "Disconnected" | "Down" | "Reconnecting"]>>;
|
|
73
|
-
<
|
|
73
|
+
<Cases extends { readonly [Tag in "Connected" | "Disconnected" | "Down" | "Reconnecting"]: (args: Extract<{
|
|
74
74
|
readonly _tag: "Connected";
|
|
75
75
|
} | {
|
|
76
76
|
readonly _tag: "Disconnected";
|
|
@@ -92,19 +92,19 @@ export declare const ConnectionState: {
|
|
|
92
92
|
} | {
|
|
93
93
|
readonly _tag: "Reconnecting";
|
|
94
94
|
readonly attempt: number;
|
|
95
|
-
}, cases: Cases
|
|
95
|
+
}, cases: Cases): import("effect/Unify").Unify<ReturnType<Cases["Connected" | "Disconnected" | "Down" | "Reconnecting"]>>;
|
|
96
96
|
};
|
|
97
|
-
readonly Connected: Data.
|
|
97
|
+
readonly Connected: Data.TaggedEnum.ConstructorFrom<{
|
|
98
98
|
readonly _tag: "Connected";
|
|
99
99
|
}, "_tag">;
|
|
100
|
-
readonly Disconnected: Data.
|
|
100
|
+
readonly Disconnected: Data.TaggedEnum.ConstructorFrom<{
|
|
101
101
|
readonly _tag: "Disconnected";
|
|
102
102
|
}, "_tag">;
|
|
103
|
-
readonly Down: Data.
|
|
103
|
+
readonly Down: Data.TaggedEnum.ConstructorFrom<{
|
|
104
104
|
readonly _tag: "Down";
|
|
105
105
|
readonly cause: ModbusError;
|
|
106
106
|
}, "_tag">;
|
|
107
|
-
readonly Reconnecting: Data.
|
|
107
|
+
readonly Reconnecting: Data.TaggedEnum.ConstructorFrom<{
|
|
108
108
|
readonly _tag: "Reconnecting";
|
|
109
109
|
readonly attempt: number;
|
|
110
110
|
}, "_tag">;
|
|
@@ -127,7 +127,7 @@ export interface ReconnectOptions {
|
|
|
127
127
|
* How long the circuit stays open after attempts are exhausted, before the
|
|
128
128
|
* supervisor probes again. Default `30 seconds`.
|
|
129
129
|
*/
|
|
130
|
-
readonly resetAfter?: Duration.
|
|
130
|
+
readonly resetAfter?: Duration.Input;
|
|
131
131
|
/**
|
|
132
132
|
* Which operation failures hand control to the supervisor.
|
|
133
133
|
* Default `["ModbusConnectionClosedError", "ModbusTransportError"]`.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/src/mocks.d.ts
CHANGED
|
@@ -36,8 +36,8 @@ export interface MockFaultOptions {
|
|
|
36
36
|
* used when the mock transport initialises.
|
|
37
37
|
*/
|
|
38
38
|
export declare const CoilDefinition: Schema.Struct<{
|
|
39
|
-
address:
|
|
40
|
-
default:
|
|
39
|
+
readonly address: Schema.Number;
|
|
40
|
+
readonly default: Schema.Boolean;
|
|
41
41
|
}>;
|
|
42
42
|
/**
|
|
43
43
|
* Schema for a single discrete input (digital input) definition.
|
|
@@ -46,8 +46,8 @@ export declare const CoilDefinition: Schema.Struct<{
|
|
|
46
46
|
* boolean state used when the mock transport initialises.
|
|
47
47
|
*/
|
|
48
48
|
export declare const DiscreteInputDefinition: Schema.Struct<{
|
|
49
|
-
address:
|
|
50
|
-
default:
|
|
49
|
+
readonly address: Schema.Number;
|
|
50
|
+
readonly default: Schema.Boolean;
|
|
51
51
|
}>;
|
|
52
52
|
/**
|
|
53
53
|
* Schema for a single register (holding or input) definition.
|
|
@@ -56,8 +56,8 @@ export declare const DiscreteInputDefinition: Schema.Struct<{
|
|
|
56
56
|
* value used when the mock transport initialises.
|
|
57
57
|
*/
|
|
58
58
|
export declare const RegisterDefinition: Schema.Struct<{
|
|
59
|
-
address:
|
|
60
|
-
default:
|
|
59
|
+
readonly address: Schema.Number;
|
|
60
|
+
readonly default: Schema.Number;
|
|
61
61
|
}>;
|
|
62
62
|
/**
|
|
63
63
|
* Schema for a complete slave device definition.
|
|
@@ -67,62 +67,46 @@ export declare const RegisterDefinition: Schema.Struct<{
|
|
|
67
67
|
* registers. All arrays default to `[]` when omitted.
|
|
68
68
|
*/
|
|
69
69
|
export declare const SlaveDeviceDefinition: Schema.Struct<{
|
|
70
|
-
unitId:
|
|
71
|
-
coils: Schema.
|
|
72
|
-
address:
|
|
73
|
-
default:
|
|
74
|
-
}>>,
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
default:
|
|
82
|
-
}>;
|
|
83
|
-
|
|
84
|
-
address:
|
|
85
|
-
default:
|
|
86
|
-
}>>,
|
|
87
|
-
default: () => never[];
|
|
88
|
-
}>;
|
|
89
|
-
inputRegisters: Schema.optionalWith<Schema.Array$<Schema.Struct<{
|
|
90
|
-
address: typeof Schema.Number;
|
|
91
|
-
default: typeof Schema.Number;
|
|
92
|
-
}>>, {
|
|
93
|
-
default: () => never[];
|
|
94
|
-
}>;
|
|
70
|
+
readonly unitId: Schema.Number;
|
|
71
|
+
readonly coils: Schema.withDecodingDefaultType<Schema.$Array<Schema.Struct<{
|
|
72
|
+
readonly address: Schema.Number;
|
|
73
|
+
readonly default: Schema.Boolean;
|
|
74
|
+
}>>, never>;
|
|
75
|
+
readonly discreteInputs: Schema.withDecodingDefaultType<Schema.$Array<Schema.Struct<{
|
|
76
|
+
readonly address: Schema.Number;
|
|
77
|
+
readonly default: Schema.Boolean;
|
|
78
|
+
}>>, never>;
|
|
79
|
+
readonly holdingRegisters: Schema.withDecodingDefaultType<Schema.$Array<Schema.Struct<{
|
|
80
|
+
readonly address: Schema.Number;
|
|
81
|
+
readonly default: Schema.Number;
|
|
82
|
+
}>>, never>;
|
|
83
|
+
readonly inputRegisters: Schema.withDecodingDefaultType<Schema.$Array<Schema.Struct<{
|
|
84
|
+
readonly address: Schema.Number;
|
|
85
|
+
readonly default: Schema.Number;
|
|
86
|
+
}>>, never>;
|
|
95
87
|
}>;
|
|
96
88
|
/**
|
|
97
89
|
* Schema for an array of {@link SlaveDeviceDefinition} — the complete
|
|
98
90
|
* set of slave devices the mock transport should simulate.
|
|
99
91
|
*/
|
|
100
|
-
export declare const SlaveDeviceDefinitions: Schema
|
|
101
|
-
unitId:
|
|
102
|
-
coils: Schema.
|
|
103
|
-
address:
|
|
104
|
-
default:
|
|
105
|
-
}>>,
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
default:
|
|
113
|
-
}>;
|
|
114
|
-
|
|
115
|
-
address:
|
|
116
|
-
default:
|
|
117
|
-
}>>,
|
|
118
|
-
default: () => never[];
|
|
119
|
-
}>;
|
|
120
|
-
inputRegisters: Schema.optionalWith<Schema.Array$<Schema.Struct<{
|
|
121
|
-
address: typeof Schema.Number;
|
|
122
|
-
default: typeof Schema.Number;
|
|
123
|
-
}>>, {
|
|
124
|
-
default: () => never[];
|
|
125
|
-
}>;
|
|
92
|
+
export declare const SlaveDeviceDefinitions: Schema.$Array<Schema.Struct<{
|
|
93
|
+
readonly unitId: Schema.Number;
|
|
94
|
+
readonly coils: Schema.withDecodingDefaultType<Schema.$Array<Schema.Struct<{
|
|
95
|
+
readonly address: Schema.Number;
|
|
96
|
+
readonly default: Schema.Boolean;
|
|
97
|
+
}>>, never>;
|
|
98
|
+
readonly discreteInputs: Schema.withDecodingDefaultType<Schema.$Array<Schema.Struct<{
|
|
99
|
+
readonly address: Schema.Number;
|
|
100
|
+
readonly default: Schema.Boolean;
|
|
101
|
+
}>>, never>;
|
|
102
|
+
readonly holdingRegisters: Schema.withDecodingDefaultType<Schema.$Array<Schema.Struct<{
|
|
103
|
+
readonly address: Schema.Number;
|
|
104
|
+
readonly default: Schema.Number;
|
|
105
|
+
}>>, never>;
|
|
106
|
+
readonly inputRegisters: Schema.withDecodingDefaultType<Schema.$Array<Schema.Struct<{
|
|
107
|
+
readonly address: Schema.Number;
|
|
108
|
+
readonly default: Schema.Number;
|
|
109
|
+
}>>, never>;
|
|
126
110
|
}>>;
|
|
127
111
|
/** Inferred TypeScript type for a {@link CoilDefinition} schema. */
|
|
128
112
|
export type CoilDefinition = Schema.Schema.Type<typeof CoilDefinition>;
|