@ya-modbus/transport 0.11.1 → 0.12.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/CHANGELOG.md +12 -0
- package/README.md +55 -0
- package/dist/cjs/src/index.d.ts +1 -0
- package/dist/cjs/src/index.d.ts.map +1 -1
- package/dist/cjs/src/index.js +4 -1
- package/dist/cjs/src/index.js.map +1 -1
- package/dist/cjs/src/serial-ports.d.ts +74 -0
- package/dist/cjs/src/serial-ports.d.ts.map +1 -0
- package/dist/cjs/src/serial-ports.js +152 -0
- package/dist/cjs/src/serial-ports.js.map +1 -0
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/index.d.ts +1 -0
- package/dist/esm/src/index.d.ts.map +1 -1
- package/dist/esm/src/index.js +1 -0
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/serial-ports.d.ts +74 -0
- package/dist/esm/src/serial-ports.d.ts.map +1 -0
- package/dist/esm/src/serial-ports.js +147 -0
- package/dist/esm/src/serial-ports.js.map +1 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +5 -4
package/dist/esm/src/index.d.ts
CHANGED
|
@@ -14,4 +14,5 @@ export { isConnectionLostError, ModbusConnection, type OpenClient } from './conn
|
|
|
14
14
|
export { TransportManager, type TransportManagerOptions, type TransportStats } from './manager.js';
|
|
15
15
|
export { MutexTransport } from './mutex-transport.js';
|
|
16
16
|
export { SlaveTransport } from './slave-transport.js';
|
|
17
|
+
export { listSerialPorts, matchSerialPorts, type SerialPortInfo, type SerialPortMatch, } from './serial-ports.js';
|
|
17
18
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,eAAe,EAAE,KAAK,eAAe,EAAE,MAAM,cAAc,CAAA;AAC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A;AAC1F,OAAO,EAAE,gBAAgB,EAAE,KAAK,uBAAuB,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAA;AAClG,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,KAAK,cAAc,EACnB,KAAK,eAAe,GACrB,MAAM,mBAAmB,CAAA"}
|
package/dist/esm/src/index.js
CHANGED
|
@@ -14,4 +14,5 @@ export { isConnectionLostError, ModbusConnection } from './connection.js';
|
|
|
14
14
|
export { TransportManager } from './manager.js';
|
|
15
15
|
export { MutexTransport } from './mutex-transport.js';
|
|
16
16
|
export { SlaveTransport } from './slave-transport.js';
|
|
17
|
+
export { listSerialPorts, matchSerialPorts, } from './serial-ports.js';
|
|
17
18
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,eAAe,EAAwB,MAAM,cAAc,CAAA;AACpE,OAAO,EAAE,kBAAkB,EAAkB,MAAM,oBAAoB,CAAA;AACvE,OAAO,EAAE,kBAAkB,EAAkB,MAAM,oBAAoB,CAAA;AACvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AACpE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,cAAc,EAAoB,MAAM,YAAY,CAAA;AACrF,OAAO,EAAE,oBAAoB,EAAoB,MAAM,sBAAsB,CAAA;AAC7E,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAmB,MAAM,iBAAiB,CAAA;AAC1F,OAAO,EAAE,gBAAgB,EAAqD,MAAM,cAAc,CAAA;AAClG,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,eAAe,EAAwB,MAAM,cAAc,CAAA;AACpE,OAAO,EAAE,kBAAkB,EAAkB,MAAM,oBAAoB,CAAA;AACvE,OAAO,EAAE,kBAAkB,EAAkB,MAAM,oBAAoB,CAAA;AACvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AACpE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,cAAc,EAAoB,MAAM,YAAY,CAAA;AACrF,OAAO,EAAE,oBAAoB,EAAoB,MAAM,sBAAsB,CAAA;AAC7E,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAmB,MAAM,iBAAiB,CAAA;AAC1F,OAAO,EAAE,gBAAgB,EAAqD,MAAM,cAAc,CAAA;AAClG,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EACL,eAAe,EACf,gBAAgB,GAGjB,MAAM,mBAAmB,CAAA"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* List serial ports with their USB identity and physical USB port, and select
|
|
3
|
+
* ports by these values
|
|
4
|
+
*
|
|
5
|
+
* USB serial adapters get a new device name when they are plugged in again
|
|
6
|
+
* (`/dev/ttyUSB0` becomes `/dev/ttyUSB1`). The USB vendor ID, product ID and
|
|
7
|
+
* serial number identify an adapter. Identical adapters without a serial number
|
|
8
|
+
* differ only in the physical USB port, which is the name of their link in
|
|
9
|
+
* `/dev/serial/by-path` (the location).
|
|
10
|
+
*/
|
|
11
|
+
/** A serial port with its USB identity */
|
|
12
|
+
export interface SerialPortInfo {
|
|
13
|
+
/** Device path, for example `/dev/ttyUSB0` */
|
|
14
|
+
path: string;
|
|
15
|
+
/** USB vendor ID as 4 lowercase hex digits, for example `1a86` */
|
|
16
|
+
vendorId?: string;
|
|
17
|
+
/** USB product ID as 4 lowercase hex digits, for example `7523` */
|
|
18
|
+
productId?: string;
|
|
19
|
+
/** USB serial number, when the adapter has one */
|
|
20
|
+
serialNumber?: string;
|
|
21
|
+
/** Manufacturer name, when the adapter has one */
|
|
22
|
+
manufacturer?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Names of the links in `/dev/serial/by-path` to this port, for example
|
|
25
|
+
* `pci-0000:00:1a.0-usb-0:1.3:1.0-port0`. Newer systemd versions add a
|
|
26
|
+
* second link (`...-usbv2-...`) for the same USB port. Empty when the port
|
|
27
|
+
* has no such link (not a USB adapter, or not Linux).
|
|
28
|
+
*/
|
|
29
|
+
locations: string[];
|
|
30
|
+
}
|
|
31
|
+
/** Values to select ports by. Leave out `serialNumber` or `location` to match any. */
|
|
32
|
+
export interface SerialPortMatch {
|
|
33
|
+
/** USB vendor ID in hex, for example `1a86` or `0x1A86` */
|
|
34
|
+
vendorId: string;
|
|
35
|
+
/** USB product ID in hex, for example `7523` */
|
|
36
|
+
productId: string;
|
|
37
|
+
/** USB serial number (case-sensitive) */
|
|
38
|
+
serialNumber?: string;
|
|
39
|
+
/** Name of a link in `/dev/serial/by-path`, or the full path of the link */
|
|
40
|
+
location?: string;
|
|
41
|
+
}
|
|
42
|
+
/** A port as serialport's list or sysfs reports it */
|
|
43
|
+
export interface ListedSerialPort {
|
|
44
|
+
path: string;
|
|
45
|
+
vendorId?: string | undefined;
|
|
46
|
+
productId?: string | undefined;
|
|
47
|
+
serialNumber?: string | undefined;
|
|
48
|
+
manufacturer?: string | undefined;
|
|
49
|
+
}
|
|
50
|
+
/** System access of {@link listSerialPorts}, replaced in tests */
|
|
51
|
+
export interface SerialPortsDeps {
|
|
52
|
+
list: () => Promise<ListedSerialPort[]>;
|
|
53
|
+
readdir: (path: string) => Promise<string[]>;
|
|
54
|
+
realpath: (path: string) => Promise<string>;
|
|
55
|
+
readFile: (path: string) => Promise<string>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* List the serial ports with their USB identity and locations
|
|
59
|
+
*
|
|
60
|
+
* On Linux the ports are read from sysfs (`/sys/class/tty`). This starts no
|
|
61
|
+
* other program, so it works in a hardened service. Without sysfs (other
|
|
62
|
+
* systems), the port list of serialport is used (through modbus-serial).
|
|
63
|
+
*
|
|
64
|
+
* @param deps - Replacements for the system access, for tests
|
|
65
|
+
*/
|
|
66
|
+
export declare function listSerialPorts(deps?: Partial<SerialPortsDeps>): Promise<SerialPortInfo[]>;
|
|
67
|
+
/**
|
|
68
|
+
* Select the ports that match all given values
|
|
69
|
+
*
|
|
70
|
+
* Returns every match, so the caller can tell a unique match from an
|
|
71
|
+
* ambiguous one. Ports without a USB vendor or product ID never match.
|
|
72
|
+
*/
|
|
73
|
+
export declare function matchSerialPorts(ports: readonly SerialPortInfo[], match: SerialPortMatch): SerialPortInfo[];
|
|
74
|
+
//# sourceMappingURL=serial-ports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serial-ports.d.ts","sourceRoot":"","sources":["../../../src/serial-ports.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAOH,0CAA0C;AAC1C,MAAM,WAAW,cAAc;IAC7B,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAA;IACZ,kEAAkE;IAClE,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,mEAAmE;IACnE,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,kDAAkD;IAClD,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,kDAAkD;IAClD,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;;;;OAKG;IACH,SAAS,EAAE,MAAM,EAAE,CAAA;CACpB;AAED,sFAAsF;AACtF,MAAM,WAAW,eAAe;IAC9B,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,CAAA;IAChB,gDAAgD;IAChD,SAAS,EAAE,MAAM,CAAA;IACjB,yCAAyC;IACzC,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,4EAA4E;IAC5E,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,sDAAsD;AACtD,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC9B,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACjC,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAClC;AAED,kEAAkE;AAClE,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAA;IACvC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;IAC5C,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;IAC3C,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;CAC5C;AAaD;;;;;;;;GAQG;AACH,wBAAsB,eAAe,CACnC,IAAI,GAAE,OAAO,CAAC,eAAe,CAAM,GAClC,OAAO,CAAC,cAAc,EAAE,CAAC,CAI3B;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,SAAS,cAAc,EAAE,EAChC,KAAK,EAAE,eAAe,GACrB,cAAc,EAAE,CAelB"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* List serial ports with their USB identity and physical USB port, and select
|
|
3
|
+
* ports by these values
|
|
4
|
+
*
|
|
5
|
+
* USB serial adapters get a new device name when they are plugged in again
|
|
6
|
+
* (`/dev/ttyUSB0` becomes `/dev/ttyUSB1`). The USB vendor ID, product ID and
|
|
7
|
+
* serial number identify an adapter. Identical adapters without a serial number
|
|
8
|
+
* differ only in the physical USB port, which is the name of their link in
|
|
9
|
+
* `/dev/serial/by-path` (the location).
|
|
10
|
+
*/
|
|
11
|
+
import { readdir, readFile, realpath } from 'node:fs/promises';
|
|
12
|
+
import { dirname, join } from 'node:path';
|
|
13
|
+
import ModbusRTU from 'modbus-serial';
|
|
14
|
+
const BY_PATH_DIR = '/dev/serial/by-path';
|
|
15
|
+
const SYS_TTY_DIR = '/sys/class/tty';
|
|
16
|
+
const systemDeps = {
|
|
17
|
+
// Loads the optional serialport package only when called
|
|
18
|
+
list: () => ModbusRTU.getPorts(),
|
|
19
|
+
readdir: (path) => readdir(path),
|
|
20
|
+
realpath: (path) => realpath(path),
|
|
21
|
+
readFile: (path) => readFile(path, 'utf8'),
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* List the serial ports with their USB identity and locations
|
|
25
|
+
*
|
|
26
|
+
* On Linux the ports are read from sysfs (`/sys/class/tty`). This starts no
|
|
27
|
+
* other program, so it works in a hardened service. Without sysfs (other
|
|
28
|
+
* systems), the port list of serialport is used (through modbus-serial).
|
|
29
|
+
*
|
|
30
|
+
* @param deps - Replacements for the system access, for tests
|
|
31
|
+
*/
|
|
32
|
+
export async function listSerialPorts(deps = {}) {
|
|
33
|
+
const system = { ...systemDeps, ...deps };
|
|
34
|
+
const [ports, locations] = await Promise.all([listPorts(system), readLocations(system)]);
|
|
35
|
+
return ports.map((port) => toPortInfo(port, locations.get(port.path) ?? []));
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Select the ports that match all given values
|
|
39
|
+
*
|
|
40
|
+
* Returns every match, so the caller can tell a unique match from an
|
|
41
|
+
* ambiguous one. Ports without a USB vendor or product ID never match.
|
|
42
|
+
*/
|
|
43
|
+
export function matchSerialPorts(ports, match) {
|
|
44
|
+
const vendorId = normalizeUsbId(match.vendorId);
|
|
45
|
+
const productId = normalizeUsbId(match.productId);
|
|
46
|
+
const location = match.location?.startsWith(`${BY_PATH_DIR}/`)
|
|
47
|
+
? match.location.slice(BY_PATH_DIR.length + 1)
|
|
48
|
+
: match.location;
|
|
49
|
+
return ports.filter((port) => vendorId !== undefined &&
|
|
50
|
+
port.vendorId === vendorId &&
|
|
51
|
+
productId !== undefined &&
|
|
52
|
+
port.productId === productId &&
|
|
53
|
+
(match.serialNumber === undefined || port.serialNumber === match.serialNumber) &&
|
|
54
|
+
(location === undefined || port.locations.includes(location)));
|
|
55
|
+
}
|
|
56
|
+
/** `1A86`, `0x1a86` and `1a86` become `1a86`; `403` becomes `0403` */
|
|
57
|
+
function normalizeUsbId(id) {
|
|
58
|
+
const hex = id?.match(/^(?:0x)?([0-9a-f]{1,4})$/i)?.[1];
|
|
59
|
+
return hex?.toLowerCase().padStart(4, '0');
|
|
60
|
+
}
|
|
61
|
+
function toPortInfo(port, locations) {
|
|
62
|
+
const vendorId = normalizeUsbId(port.vendorId);
|
|
63
|
+
const productId = normalizeUsbId(port.productId);
|
|
64
|
+
return {
|
|
65
|
+
path: port.path,
|
|
66
|
+
...(vendorId ? { vendorId } : {}),
|
|
67
|
+
...(productId ? { productId } : {}),
|
|
68
|
+
...(port.serialNumber ? { serialNumber: port.serialNumber } : {}),
|
|
69
|
+
...(port.manufacturer ? { manufacturer: port.manufacturer } : {}),
|
|
70
|
+
locations,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
async function listPorts(system) {
|
|
74
|
+
try {
|
|
75
|
+
return await listSysfsPorts(system);
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
if (!isNotFound(error))
|
|
79
|
+
throw error;
|
|
80
|
+
return system.list();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function isNotFound(error) {
|
|
84
|
+
return error.code === 'ENOENT';
|
|
85
|
+
}
|
|
86
|
+
/** Map each device path to the names of its links in /dev/serial/by-path */
|
|
87
|
+
async function readLocations(system) {
|
|
88
|
+
const locations = new Map();
|
|
89
|
+
let names;
|
|
90
|
+
try {
|
|
91
|
+
names = await system.readdir(BY_PATH_DIR);
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
// udev creates the directory only while a USB serial adapter is plugged in
|
|
95
|
+
if (isNotFound(error))
|
|
96
|
+
return locations;
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
const sorted = [...names].sort();
|
|
100
|
+
const targets = await Promise.all(sorted.map((name) =>
|
|
101
|
+
// A link points nowhere when its adapter is unplugged while listing
|
|
102
|
+
system.realpath(join(BY_PATH_DIR, name)).catch(() => undefined)));
|
|
103
|
+
sorted.forEach((name, index) => {
|
|
104
|
+
const target = targets[index];
|
|
105
|
+
if (target !== undefined)
|
|
106
|
+
locations.set(target, [...(locations.get(target) ?? []), name]);
|
|
107
|
+
});
|
|
108
|
+
return locations;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* List the ports in /sys/class/tty that belong to a device, and read the USB
|
|
112
|
+
* identity of the USB device above each one
|
|
113
|
+
*/
|
|
114
|
+
async function listSysfsPorts(system) {
|
|
115
|
+
const names = await system.readdir(SYS_TTY_DIR);
|
|
116
|
+
const ports = await Promise.all(names.map(async (name) => {
|
|
117
|
+
// Virtual terminals (tty0, console, ptmx) have no device
|
|
118
|
+
const device = await system.realpath(join(SYS_TTY_DIR, name, 'device')).catch(() => undefined);
|
|
119
|
+
return device === undefined
|
|
120
|
+
? undefined
|
|
121
|
+
: { path: join('/dev', name), ...(await readUsbIdentity(system, device)) };
|
|
122
|
+
}));
|
|
123
|
+
return ports.filter((port) => port !== undefined);
|
|
124
|
+
}
|
|
125
|
+
/** Walk up from a tty device to the USB device, which has the idVendor file */
|
|
126
|
+
async function readUsbIdentity(system, device) {
|
|
127
|
+
for (let dir = device; dir !== dirname(dir); dir = dirname(dir)) {
|
|
128
|
+
const vendorId = await readAttribute(system, dir, 'idVendor');
|
|
129
|
+
if (vendorId === undefined)
|
|
130
|
+
continue;
|
|
131
|
+
return {
|
|
132
|
+
vendorId,
|
|
133
|
+
productId: await readAttribute(system, dir, 'idProduct'),
|
|
134
|
+
serialNumber: await readAttribute(system, dir, 'serial'),
|
|
135
|
+
manufacturer: await readAttribute(system, dir, 'manufacturer'),
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
return {};
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Read a sysfs attribute without the newline that sysfs adds, or undefined
|
|
142
|
+
* when the device does not have it
|
|
143
|
+
*/
|
|
144
|
+
function readAttribute(system, dir, name) {
|
|
145
|
+
return system.readFile(join(dir, name)).then((value) => value.replace(/\n$/, ''), () => undefined);
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=serial-ports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serial-ports.js","sourceRoot":"","sources":["../../../src/serial-ports.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC9D,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEzC,OAAO,SAAS,MAAM,eAAe,CAAA;AAoDrC,MAAM,WAAW,GAAG,qBAAqB,CAAA;AACzC,MAAM,WAAW,GAAG,gBAAgB,CAAA;AAEpC,MAAM,UAAU,GAAoB;IAClC,yDAAyD;IACzD,IAAI,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE;IAChC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;IAChC,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC;IAClC,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CAC3C,CAAA;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,OAAiC,EAAE;IAEnC,MAAM,MAAM,GAA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