@flux-control/effect-modbus-rs 0.3.1 → 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 +16 -16
- 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 +1 -1
- 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 +1 -1
- package/dist/src/WasmWsTransportService.d.ts +30 -21
- package/dist/src/connection.d.ts +9 -9
- package/dist/src/mocks.d.ts +41 -57
- package/dist/src/retry.d.ts +11 -8
- package/package.json +5 -5
|
@@ -1,16 +1,37 @@
|
|
|
1
|
-
import { Effect, Layer } from 'effect';
|
|
1
|
+
import { Context, Effect, Layer } from 'effect';
|
|
2
2
|
import type { AsciiTransportOptions } 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, WithoutUpstreamRetry, TransportServiceApi } from './shared-transport';
|
|
6
6
|
/**
|
|
7
7
|
* {@link AsciiTransportOptions} minus the upstream retry knobs.
|
|
8
8
|
*
|
|
9
9
|
* @see WithoutUpstreamRetry — Why they are withheld.
|
|
10
10
|
*/
|
|
11
11
|
export type AsciiTransportOpenOptions = WithoutUpstreamRetry<AsciiTransportOptions>;
|
|
12
|
-
declare const AsciiTransportService_base:
|
|
13
|
-
|
|
12
|
+
declare const AsciiTransportService_base: Context.ServiceClass<AsciiTransportService, "AsciiTransportService", TransportServiceApi>;
|
|
13
|
+
/**
|
|
14
|
+
* Scoped Effect service wrapping the `modbus-rs` {@link AsyncAsciiTransport}
|
|
15
|
+
* for ASCII (serial) 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 AsyncAsciiTransport.createClient} and cached, so repeated
|
|
23
|
+
* requests for the same unit ID reuse the same client.
|
|
24
|
+
*
|
|
25
|
+
* @see AsyncAsciiTransport — Upstream `modbus-rs` ASCII transport.
|
|
26
|
+
* @see AsciiTransportOpenOptions — Configuration for the ASCII serial port.
|
|
27
|
+
* @see makeTransportScoped — Generic lifecycle logic from shared-transport.
|
|
28
|
+
*/
|
|
29
|
+
export declare class AsciiTransportService extends AsciiTransportService_base {
|
|
30
|
+
/**
|
|
31
|
+
* Scoped constructor effect for the service. v4 does not auto-generate a
|
|
32
|
+
* layer from this, so {@link AsciiTransportService.make} builds one explicitly.
|
|
33
|
+
*/
|
|
34
|
+
static readonly makeScoped: (options: AsciiTransportOpenOptions & TransportResilienceOptions) => Effect.Effect<{
|
|
14
35
|
connectionState: import("effect/SubscriptionRef").SubscriptionRef<{
|
|
15
36
|
readonly _tag: "Connected";
|
|
16
37
|
} | {
|
|
@@ -31,24 +52,12 @@ declare const AsciiTransportService_base: Effect.Service.Class<AsciiTransportSer
|
|
|
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 AsyncAsciiTransport.createClient} and cached, so repeated
|
|
45
|
-
* requests for the same unit ID reuse the same client.
|
|
46
|
-
*
|
|
47
|
-
* @see AsyncAsciiTransport — Upstream `modbus-rs` ASCII transport.
|
|
48
|
-
* @see AsciiTransportOpenOptions — Configuration for the ASCII serial port.
|
|
49
|
-
* @see makeTransportScoped — Generic lifecycle logic from shared-transport.
|
|
50
|
-
*/
|
|
51
|
-
export declare class AsciiTransportService extends AsciiTransportService_base {
|
|
55
|
+
/**
|
|
56
|
+
* Creates a {@link Layer} providing a live {@link AsciiTransportService}.
|
|
57
|
+
*
|
|
58
|
+
* @param options - Connection and resilience options for the transport.
|
|
59
|
+
*/
|
|
60
|
+
static readonly make: (options: AsciiTransportOpenOptions & TransportResilienceOptions) => Layer.Layer<AsciiTransportService>;
|
|
52
61
|
/**
|
|
53
62
|
* Creates a {@link Layer} providing an in-memory mock
|
|
54
63
|
* {@link AsciiTransportService} for testing or development.
|
|
@@ -1,16 +1,37 @@
|
|
|
1
|
-
import { Effect, Layer } from 'effect';
|
|
1
|
+
import { Context, Effect, Layer } from 'effect';
|
|
2
2
|
import type { RtuTransportOptions } from 'modbus-rs';
|
|
3
3
|
import type { MockFaultOptions } from './mocks';
|
|
4
4
|
import type { SlaveDeviceDefinitions } from './mocks';
|
|
5
|
-
import type { TransportResilienceOptions, WithoutUpstreamRetry } from './shared-transport';
|
|
5
|
+
import type { TransportResilienceOptions, WithoutUpstreamRetry, TransportServiceApi } from './shared-transport';
|
|
6
6
|
/**
|
|
7
7
|
* {@link RtuTransportOptions} minus the upstream retry knobs.
|
|
8
8
|
*
|
|
9
9
|
* @see WithoutUpstreamRetry — Why they are withheld.
|
|
10
10
|
*/
|
|
11
11
|
export type RtuTransportOpenOptions = WithoutUpstreamRetry<RtuTransportOptions>;
|
|
12
|
-
declare const RtuTransportService_base:
|
|
13
|
-
|
|
12
|
+
declare const RtuTransportService_base: Context.ServiceClass<RtuTransportService, "RtuTransportService", TransportServiceApi>;
|
|
13
|
+
/**
|
|
14
|
+
* Scoped Effect service wrapping the `modbus-rs` {@link AsyncRtuTransport}
|
|
15
|
+
* for RTU (serial) 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 AsyncRtuTransport.createClient} and cached, so repeated
|
|
23
|
+
* requests for the same unit ID reuse the same client.
|
|
24
|
+
*
|
|
25
|
+
* @see AsyncRtuTransport — Upstream `modbus-rs` RTU transport.
|
|
26
|
+
* @see RtuTransportOpenOptions — Configuration for the RTU serial port.
|
|
27
|
+
* @see makeTransportScoped — Generic lifecycle logic from shared-transport.
|
|
28
|
+
*/
|
|
29
|
+
export declare class RtuTransportService extends RtuTransportService_base {
|
|
30
|
+
/**
|
|
31
|
+
* Scoped constructor effect for the service. v4 does not auto-generate a
|
|
32
|
+
* layer from this, so {@link RtuTransportService.make} builds one explicitly.
|
|
33
|
+
*/
|
|
34
|
+
static readonly makeScoped: (options: RtuTransportOpenOptions & TransportResilienceOptions) => Effect.Effect<{
|
|
14
35
|
connectionState: import("effect/SubscriptionRef").SubscriptionRef<{
|
|
15
36
|
readonly _tag: "Connected";
|
|
16
37
|
} | {
|
|
@@ -31,24 +52,12 @@ declare const RtuTransportService_base: Effect.Service.Class<RtuTransportService
|
|
|
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 AsyncRtuTransport.createClient} and cached, so repeated
|
|
45
|
-
* requests for the same unit ID reuse the same client.
|
|
46
|
-
*
|
|
47
|
-
* @see AsyncRtuTransport — Upstream `modbus-rs` RTU transport.
|
|
48
|
-
* @see RtuTransportOpenOptions — Configuration for the RTU serial port.
|
|
49
|
-
* @see makeTransportScoped — Generic lifecycle logic from shared-transport.
|
|
50
|
-
*/
|
|
51
|
-
export declare class RtuTransportService extends RtuTransportService_base {
|
|
55
|
+
/**
|
|
56
|
+
* Creates a {@link Layer} providing a live {@link RtuTransportService}.
|
|
57
|
+
*
|
|
58
|
+
* @param options - Connection and resilience options for the transport.
|
|
59
|
+
*/
|
|
60
|
+
static readonly make: (options: RtuTransportOpenOptions & TransportResilienceOptions) => Layer.Layer<RtuTransportService>;
|
|
52
61
|
/**
|
|
53
62
|
* Creates a {@link Layer} providing an in-memory mock
|
|
54
63
|
* {@link RtuTransportService} for testing or development.
|
|
@@ -3,7 +3,7 @@ import { type AsciiTransportOpenOptions } from './AsciiTransportService';
|
|
|
3
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
|
*
|
|
@@ -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
|
* });
|
|
@@ -3,7 +3,7 @@ import { type MockFaultOptions, type SlaveDeviceDefinitions } from './mocks';
|
|
|
3
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
|
*
|
|
@@ -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"]`.
|