motion-master-client 0.0.339 → 0.0.340
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/src/api.js +79 -73
- package/src/api.js.map +1 -1
- package/src/lib/data-monitoring.d.ts +2 -2
- package/src/lib/data-monitoring.js +2 -2
- package/src/lib/device-parameter.d.ts +50 -3
- package/src/lib/device-parameter.js +117 -4
- package/src/lib/device-parameter.js.map +1 -1
- package/src/lib/motion-master-req-res-client.d.ts +12 -0
- package/src/lib/motion-master-req-res-client.js +14 -0
- package/src/lib/motion-master-req-res-client.js.map +1 -1
- package/src/lib/operators.d.ts +195 -1
- package/src/lib/operators.js +202 -1
- package/src/lib/operators.js.map +1 -1
- package/src/lib/util.d.ts +299 -160
- package/src/lib/util.js +301 -170
- package/src/lib/util.js.map +1 -1
package/src/lib/operators.d.ts
CHANGED
|
@@ -1,8 +1,49 @@
|
|
|
1
|
-
import { Observable, UnaryFunction, MonoTypeOperatorFunction } from 'rxjs';
|
|
1
|
+
import { Observable, UnaryFunction, MonoTypeOperatorFunction, OperatorFunction } from 'rxjs';
|
|
2
2
|
import { IMotionMasterMessage, MotionMasterMessage, ParameterValueType, StatusKey } from './types';
|
|
3
3
|
import { DeviceParameter } from './device-parameter';
|
|
4
4
|
import { MotionMasterReqResClient } from './motion-master-req-res-client';
|
|
5
|
+
import { NotificationEntry } from './util';
|
|
6
|
+
/**
|
|
7
|
+
* Creates an operator that filters Motion Master messages by message ID and extracts
|
|
8
|
+
* a specific status field from the message payload.
|
|
9
|
+
*
|
|
10
|
+
* If a message with the matching ID contains a `systemEvent` status instead of the expected status,
|
|
11
|
+
* an error is thrown. This typically happens when a request refers to an invalid device address.
|
|
12
|
+
*
|
|
13
|
+
* @typeParam T - The type corresponding to the selected status field.
|
|
14
|
+
* @param key - The status field name to extract from the message.
|
|
15
|
+
* @param id - The message ID that identifies the corresponding request/response pair.
|
|
16
|
+
*
|
|
17
|
+
* @returns An operator that emits the resolved status when a matching message arrives.
|
|
18
|
+
*
|
|
19
|
+
* @throws Error
|
|
20
|
+
* Thrown when a SystemEvent status is received while a different status type was expected.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* source$.pipe(
|
|
24
|
+
* selectMotionMasterMessageStatusByMessageId<'deviceInfo'>('deviceInfo', 'req-123')
|
|
25
|
+
* ).subscribe(info => console.log(info));
|
|
26
|
+
*/
|
|
5
27
|
export declare function selectMotionMasterMessageStatusByMessageId<T>(key: StatusKey, id?: string): UnaryFunction<Observable<IMotionMasterMessage>, Observable<T>>;
|
|
28
|
+
/**
|
|
29
|
+
* Enriches a status object by appending request metadata, including its originating message ID
|
|
30
|
+
* and a resolved request state derived from the status contents.
|
|
31
|
+
*
|
|
32
|
+
* This serves as a post-processing step after a status has been extracted from a message.
|
|
33
|
+
*
|
|
34
|
+
* @typeParam T - The status shape being extended.
|
|
35
|
+
* @param data - Context containing the originating message ID and the status key.
|
|
36
|
+
*
|
|
37
|
+
* @returns An operator that transforms each emitted status into an augmented status object.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* source$.pipe(
|
|
41
|
+
* extendStatus({ statusKey: 'deviceInfo', messageId: 'req-123' })
|
|
42
|
+
* ).subscribe(status => {
|
|
43
|
+
* console.log(status.messageId);
|
|
44
|
+
* console.log(status.request); // e.g. "pending", "succeeded", "failed"
|
|
45
|
+
* });
|
|
46
|
+
*/
|
|
6
47
|
export declare function extendStatus<T>(data: {
|
|
7
48
|
statusKey: StatusKey;
|
|
8
49
|
messageId: string;
|
|
@@ -10,12 +51,165 @@ export declare function extendStatus<T>(data: {
|
|
|
10
51
|
messageId: string;
|
|
11
52
|
request: import("./types").RequestStatus;
|
|
12
53
|
}>>;
|
|
54
|
+
/**
|
|
55
|
+
* Produces a complete request-response processing pipeline for Motion Master messages.
|
|
56
|
+
* This operator:
|
|
57
|
+
* 1. Extracts a specific status type from messages matching the given message ID.
|
|
58
|
+
* 2. Applies a timeout to fail if a response is not received in time.
|
|
59
|
+
* 3. Extends the emitted status with request metadata.
|
|
60
|
+
* 4. Continues emitting until the resolved request state reaches `"succeeded"` or `"failed"`.
|
|
61
|
+
*
|
|
62
|
+
* @typeParam T - Status type being tracked.
|
|
63
|
+
* @param statusKey - The status field name expected in the response.
|
|
64
|
+
* @param requestTimeout - Maximum allowed duration (ms) to wait for the response.
|
|
65
|
+
* @param messageId - Message ID identifying the request/response sequence.
|
|
66
|
+
*
|
|
67
|
+
* @returns Operator that emits request lifecycle updates until completion or failure.
|
|
68
|
+
*
|
|
69
|
+
* @throws Error
|
|
70
|
+
* If requestTimeout is not a number.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* source$.pipe(
|
|
74
|
+
* transformMotionMasterMessageToStatus('deviceInfo', 5000, 'req-123')
|
|
75
|
+
* ).subscribe(status => {
|
|
76
|
+
* console.log(status.request);
|
|
77
|
+
* });
|
|
78
|
+
*/
|
|
13
79
|
export declare function transformMotionMasterMessageToStatus<T>(statusKey: StatusKey, requestTimeout: number, messageId: string): UnaryFunction<Observable<IMotionMasterMessage>, Observable<T & {
|
|
14
80
|
messageId: string;
|
|
15
81
|
request: import("./types").RequestStatus;
|
|
16
82
|
}>>;
|
|
83
|
+
/**
|
|
84
|
+
* Creates an operator that selects only messages whose topic matches the specified topic
|
|
85
|
+
* and emits the associated data payload.
|
|
86
|
+
*
|
|
87
|
+
* This is commonly used when incoming data arrives as `[topic, payload]` tuples.
|
|
88
|
+
*
|
|
89
|
+
* @typeParam T - The payload type associated with the topic.
|
|
90
|
+
* @param topic - Topic identifier to match.
|
|
91
|
+
*
|
|
92
|
+
* @returns Operator that emits only payloads belonging to the given topic.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* source$.pipe(
|
|
96
|
+
* selectMotionMasterMessageByTopic<DeviceStatus>('device/status')
|
|
97
|
+
* ).subscribe(status => console.log(status));
|
|
98
|
+
*/
|
|
17
99
|
export declare function selectMotionMasterMessageByTopic<T>(topic: string): UnaryFunction<Observable<[string, T]>, Observable<T>>;
|
|
100
|
+
/**
|
|
101
|
+
* Filters Motion Master messages that contain a specific status field and emits the value
|
|
102
|
+
* of that status field.
|
|
103
|
+
*
|
|
104
|
+
* This operator is useful when the source stream contains heterogeneous message types.
|
|
105
|
+
*
|
|
106
|
+
* @typeParam T - The type corresponding to the selected status entry.
|
|
107
|
+
* @param key - Status field key to extract if present.
|
|
108
|
+
*
|
|
109
|
+
* @returns Operator that emits typed status entries for matching messages.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* source$.pipe(
|
|
113
|
+
* selectMotionMasterMessageStatusByKey<DeviceInfo>('deviceInfo')
|
|
114
|
+
* ).subscribe(info => console.log(info));
|
|
115
|
+
*/
|
|
18
116
|
export declare function selectMotionMasterMessageStatusByKey<T>(key: keyof MotionMasterMessage.IStatus): UnaryFunction<Observable<IMotionMasterMessage>, Observable<T>>;
|
|
117
|
+
/**
|
|
118
|
+
* Creates an operator that extracts only the raw parameter values from monitoring status messages.
|
|
119
|
+
* If monitoring parameter values are present in the incoming message, each value is converted into
|
|
120
|
+
* its resolved primitive representation (e.g., number, boolean, string) via `getParameterValue`.
|
|
121
|
+
*
|
|
122
|
+
* When a message contains no monitoring payload or parameter value list, an empty array is emitted.
|
|
123
|
+
*
|
|
124
|
+
* @returns An operator that maps an `Observable<IMotionMasterMessage>` to an array of resolved parameter values.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* source$.pipe(
|
|
128
|
+
* mapMonitoringParameterValuesStatusMessageToParameterValues()
|
|
129
|
+
* ).subscribe(values => {
|
|
130
|
+
* console.log('Raw parameter values:', values);
|
|
131
|
+
* });
|
|
132
|
+
*
|
|
133
|
+
* @remarks
|
|
134
|
+
* - Does not perform device-level lookup or metadata resolution.
|
|
135
|
+
* - Produces values in the same order as provided by the device.
|
|
136
|
+
*/
|
|
19
137
|
export declare function mapMonitoringParameterValuesStatusMessageToParameterValues(): UnaryFunction<Observable<IMotionMasterMessage>, Observable<ParameterValueType[]>>;
|
|
138
|
+
/**
|
|
139
|
+
* Creates an operator that transforms Motion Master monitoring status messages into a list of
|
|
140
|
+
* resolved `DeviceParameter` objects. For each incoming message, parameter values are extracted,
|
|
141
|
+
* device parameter metadata is resolved using the provided request client, and both pieces of
|
|
142
|
+
* information are merged into a final typed representation.
|
|
143
|
+
*
|
|
144
|
+
* More specifically:
|
|
145
|
+
* - Extracts raw parameter values from a monitoring status message.
|
|
146
|
+
* - Determines the associated device address.
|
|
147
|
+
* - Fetches a parameter info map for that device via `request.resolveDeviceParameterInfoMap(...)`.
|
|
148
|
+
* - Combines resolved metadata (e.g., name, unit, scaling) with current parameter values.
|
|
149
|
+
* - Produces a `DeviceParameter[]` representing the current state.
|
|
150
|
+
*
|
|
151
|
+
* If the incoming message does not include parameter values, an empty array is emitted.
|
|
152
|
+
*
|
|
153
|
+
* @param request - A client used to resolve parameter info metadata per device.
|
|
154
|
+
* @returns Operator that maps a stream of `IMotionMasterMessage` into parameter arrays.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* source$.pipe(
|
|
158
|
+
* mapMonitoringParameterValuesStatusMessageToDeviceParameters(request)
|
|
159
|
+
* ).subscribe(parameters => {
|
|
160
|
+
* console.log('Resolved device parameters:', parameters);
|
|
161
|
+
* });
|
|
162
|
+
*
|
|
163
|
+
* @remarks
|
|
164
|
+
* - The operator handles missing or incomplete monitoring payloads gracefully.
|
|
165
|
+
* - The returned parameters contain both identification (index/subindex) and resolved metadata.
|
|
166
|
+
*/
|
|
20
167
|
export declare function mapMonitoringParameterValuesStatusMessageToDeviceParameters(request: MotionMasterReqResClient): UnaryFunction<Observable<IMotionMasterMessage>, Observable<DeviceParameter[]>>;
|
|
168
|
+
/**
|
|
169
|
+
* Returns an operator that completes the source observable when the notifier observable either
|
|
170
|
+
* completes or errors. Unlike `takeUntil`, which reacts only to the notifier’s `next` emissions,
|
|
171
|
+
* this operator also stops the source when the notifier finishes or fails.
|
|
172
|
+
*
|
|
173
|
+
* @typeParam T - The value type of the source observable.
|
|
174
|
+
* @param notifier$ - Observable whose termination (complete or error) will stop the source.
|
|
175
|
+
* @returns A `MonoTypeOperatorFunction` that completes the source when the notifier completes or errors.
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* const notifier$ = ajax.getJSON('/config'); // May error or complete
|
|
179
|
+
*
|
|
180
|
+
* source$.pipe(
|
|
181
|
+
* takeUntilCompleteOrError(notifier$)
|
|
182
|
+
* ).subscribe({
|
|
183
|
+
* next: console.log,
|
|
184
|
+
* complete: () => console.log('Stopped due to notifier completing'),
|
|
185
|
+
* error: console.error
|
|
186
|
+
* });
|
|
187
|
+
*
|
|
188
|
+
* // The subscription to source$ ends as soon as:
|
|
189
|
+
* // 1) notifier$ completes, or
|
|
190
|
+
* // 2) notifier$ errors.
|
|
191
|
+
*
|
|
192
|
+
* // NOTE: Any values emitted by notifier$ are ignored.
|
|
193
|
+
*/
|
|
21
194
|
export declare function takeUntilCompleteOrError<T>(notifier$: Observable<any>): MonoTypeOperatorFunction<T>;
|
|
195
|
+
/**
|
|
196
|
+
* Custom RxJS operator that accumulates notifications with their
|
|
197
|
+
* elapsed time relative to a provided start time.
|
|
198
|
+
*
|
|
199
|
+
* Each emitted notification string is converted into a `NotificationEntry`
|
|
200
|
+
* object, and the operator maintains an array of all previous entries.
|
|
201
|
+
*
|
|
202
|
+
* @param startTime - The timestamp (in milliseconds) to use as the reference
|
|
203
|
+
* point for calculating elapsed time. Typically obtained via `performance.now()`.
|
|
204
|
+
* @returns An OperatorFunction that transforms an Observable of strings into
|
|
205
|
+
* an Observable of `NotificationEntry[]`.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```ts
|
|
209
|
+
* const startTime = performance.now();
|
|
210
|
+
* notifications$.pipe(withTimeDifference(startTime)).subscribe(entries => {
|
|
211
|
+
* console.log(entries); // Array of NotificationEntry objects with elapsed time
|
|
212
|
+
* });
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
export declare function withTimeDifference(startTime: number): OperatorFunction<string, NotificationEntry[]>;
|
package/src/lib/operators.js
CHANGED
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.takeUntilCompleteOrError = exports.mapMonitoringParameterValuesStatusMessageToDeviceParameters = exports.mapMonitoringParameterValuesStatusMessageToParameterValues = exports.selectMotionMasterMessageStatusByKey = exports.selectMotionMasterMessageByTopic = exports.transformMotionMasterMessageToStatus = exports.extendStatus = exports.selectMotionMasterMessageStatusByMessageId = void 0;
|
|
3
|
+
exports.withTimeDifference = exports.takeUntilCompleteOrError = exports.mapMonitoringParameterValuesStatusMessageToDeviceParameters = exports.mapMonitoringParameterValuesStatusMessageToParameterValues = exports.selectMotionMasterMessageStatusByKey = exports.selectMotionMasterMessageByTopic = exports.transformMotionMasterMessageToStatus = exports.extendStatus = exports.selectMotionMasterMessageStatusByMessageId = void 0;
|
|
4
4
|
const rxjs_1 = require("rxjs");
|
|
5
5
|
const request_status_resolver_1 = require("./request-status-resolver");
|
|
6
6
|
const parameter_1 = require("./parameter");
|
|
7
|
+
/**
|
|
8
|
+
* Creates an operator that filters Motion Master messages by message ID and extracts
|
|
9
|
+
* a specific status field from the message payload.
|
|
10
|
+
*
|
|
11
|
+
* If a message with the matching ID contains a `systemEvent` status instead of the expected status,
|
|
12
|
+
* an error is thrown. This typically happens when a request refers to an invalid device address.
|
|
13
|
+
*
|
|
14
|
+
* @typeParam T - The type corresponding to the selected status field.
|
|
15
|
+
* @param key - The status field name to extract from the message.
|
|
16
|
+
* @param id - The message ID that identifies the corresponding request/response pair.
|
|
17
|
+
*
|
|
18
|
+
* @returns An operator that emits the resolved status when a matching message arrives.
|
|
19
|
+
*
|
|
20
|
+
* @throws Error
|
|
21
|
+
* Thrown when a SystemEvent status is received while a different status type was expected.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* source$.pipe(
|
|
25
|
+
* selectMotionMasterMessageStatusByMessageId<'deviceInfo'>('deviceInfo', 'req-123')
|
|
26
|
+
* ).subscribe(info => console.log(info));
|
|
27
|
+
*/
|
|
7
28
|
function selectMotionMasterMessageStatusByMessageId(key, id) {
|
|
8
29
|
return (0, rxjs_1.pipe)((0, rxjs_1.filter)((message) => message.id === id), (0, rxjs_1.map)((message) => {
|
|
9
30
|
var _a, _b, _c;
|
|
@@ -21,6 +42,25 @@ function selectMotionMasterMessageStatusByMessageId(key, id) {
|
|
|
21
42
|
}));
|
|
22
43
|
}
|
|
23
44
|
exports.selectMotionMasterMessageStatusByMessageId = selectMotionMasterMessageStatusByMessageId;
|
|
45
|
+
/**
|
|
46
|
+
* Enriches a status object by appending request metadata, including its originating message ID
|
|
47
|
+
* and a resolved request state derived from the status contents.
|
|
48
|
+
*
|
|
49
|
+
* This serves as a post-processing step after a status has been extracted from a message.
|
|
50
|
+
*
|
|
51
|
+
* @typeParam T - The status shape being extended.
|
|
52
|
+
* @param data - Context containing the originating message ID and the status key.
|
|
53
|
+
*
|
|
54
|
+
* @returns An operator that transforms each emitted status into an augmented status object.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* source$.pipe(
|
|
58
|
+
* extendStatus({ statusKey: 'deviceInfo', messageId: 'req-123' })
|
|
59
|
+
* ).subscribe(status => {
|
|
60
|
+
* console.log(status.messageId);
|
|
61
|
+
* console.log(status.request); // e.g. "pending", "succeeded", "failed"
|
|
62
|
+
* });
|
|
63
|
+
*/
|
|
24
64
|
function extendStatus(data) {
|
|
25
65
|
return (0, rxjs_1.pipe)((0, rxjs_1.map)((status) => {
|
|
26
66
|
var _a;
|
|
@@ -30,6 +70,31 @@ function extendStatus(data) {
|
|
|
30
70
|
}));
|
|
31
71
|
}
|
|
32
72
|
exports.extendStatus = extendStatus;
|
|
73
|
+
/**
|
|
74
|
+
* Produces a complete request-response processing pipeline for Motion Master messages.
|
|
75
|
+
* This operator:
|
|
76
|
+
* 1. Extracts a specific status type from messages matching the given message ID.
|
|
77
|
+
* 2. Applies a timeout to fail if a response is not received in time.
|
|
78
|
+
* 3. Extends the emitted status with request metadata.
|
|
79
|
+
* 4. Continues emitting until the resolved request state reaches `"succeeded"` or `"failed"`.
|
|
80
|
+
*
|
|
81
|
+
* @typeParam T - Status type being tracked.
|
|
82
|
+
* @param statusKey - The status field name expected in the response.
|
|
83
|
+
* @param requestTimeout - Maximum allowed duration (ms) to wait for the response.
|
|
84
|
+
* @param messageId - Message ID identifying the request/response sequence.
|
|
85
|
+
*
|
|
86
|
+
* @returns Operator that emits request lifecycle updates until completion or failure.
|
|
87
|
+
*
|
|
88
|
+
* @throws Error
|
|
89
|
+
* If requestTimeout is not a number.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* source$.pipe(
|
|
93
|
+
* transformMotionMasterMessageToStatus('deviceInfo', 5000, 'req-123')
|
|
94
|
+
* ).subscribe(status => {
|
|
95
|
+
* console.log(status.request);
|
|
96
|
+
* });
|
|
97
|
+
*/
|
|
33
98
|
function transformMotionMasterMessageToStatus(statusKey, requestTimeout, messageId) {
|
|
34
99
|
if (typeof requestTimeout !== 'number') {
|
|
35
100
|
throw new Error(`Invalid requestTimeout=${requestTimeout} provided for ${statusKey}`);
|
|
@@ -37,14 +102,66 @@ function transformMotionMasterMessageToStatus(statusKey, requestTimeout, message
|
|
|
37
102
|
return (0, rxjs_1.pipe)(selectMotionMasterMessageStatusByMessageId(statusKey, messageId), (0, rxjs_1.timeout)(requestTimeout), extendStatus({ statusKey, messageId }), (0, rxjs_1.takeWhile)((status) => status.request !== 'succeeded' && status.request !== 'failed', true));
|
|
38
103
|
}
|
|
39
104
|
exports.transformMotionMasterMessageToStatus = transformMotionMasterMessageToStatus;
|
|
105
|
+
/**
|
|
106
|
+
* Creates an operator that selects only messages whose topic matches the specified topic
|
|
107
|
+
* and emits the associated data payload.
|
|
108
|
+
*
|
|
109
|
+
* This is commonly used when incoming data arrives as `[topic, payload]` tuples.
|
|
110
|
+
*
|
|
111
|
+
* @typeParam T - The payload type associated with the topic.
|
|
112
|
+
* @param topic - Topic identifier to match.
|
|
113
|
+
*
|
|
114
|
+
* @returns Operator that emits only payloads belonging to the given topic.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* source$.pipe(
|
|
118
|
+
* selectMotionMasterMessageByTopic<DeviceStatus>('device/status')
|
|
119
|
+
* ).subscribe(status => console.log(status));
|
|
120
|
+
*/
|
|
40
121
|
function selectMotionMasterMessageByTopic(topic) {
|
|
41
122
|
return (0, rxjs_1.pipe)((0, rxjs_1.filter)(([t]) => t === topic), (0, rxjs_1.map)(([, data]) => data));
|
|
42
123
|
}
|
|
43
124
|
exports.selectMotionMasterMessageByTopic = selectMotionMasterMessageByTopic;
|
|
125
|
+
/**
|
|
126
|
+
* Filters Motion Master messages that contain a specific status field and emits the value
|
|
127
|
+
* of that status field.
|
|
128
|
+
*
|
|
129
|
+
* This operator is useful when the source stream contains heterogeneous message types.
|
|
130
|
+
*
|
|
131
|
+
* @typeParam T - The type corresponding to the selected status entry.
|
|
132
|
+
* @param key - Status field key to extract if present.
|
|
133
|
+
*
|
|
134
|
+
* @returns Operator that emits typed status entries for matching messages.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* source$.pipe(
|
|
138
|
+
* selectMotionMasterMessageStatusByKey<DeviceInfo>('deviceInfo')
|
|
139
|
+
* ).subscribe(info => console.log(info));
|
|
140
|
+
*/
|
|
44
141
|
function selectMotionMasterMessageStatusByKey(key) {
|
|
45
142
|
return (0, rxjs_1.pipe)((0, rxjs_1.filter)((message) => !!(message.status && message.status[key])), (0, rxjs_1.map)((message) => { var _a; return (_a = message.status) === null || _a === void 0 ? void 0 : _a[key]; }));
|
|
46
143
|
}
|
|
47
144
|
exports.selectMotionMasterMessageStatusByKey = selectMotionMasterMessageStatusByKey;
|
|
145
|
+
/**
|
|
146
|
+
* Creates an operator that extracts only the raw parameter values from monitoring status messages.
|
|
147
|
+
* If monitoring parameter values are present in the incoming message, each value is converted into
|
|
148
|
+
* its resolved primitive representation (e.g., number, boolean, string) via `getParameterValue`.
|
|
149
|
+
*
|
|
150
|
+
* When a message contains no monitoring payload or parameter value list, an empty array is emitted.
|
|
151
|
+
*
|
|
152
|
+
* @returns An operator that maps an `Observable<IMotionMasterMessage>` to an array of resolved parameter values.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* source$.pipe(
|
|
156
|
+
* mapMonitoringParameterValuesStatusMessageToParameterValues()
|
|
157
|
+
* ).subscribe(values => {
|
|
158
|
+
* console.log('Raw parameter values:', values);
|
|
159
|
+
* });
|
|
160
|
+
*
|
|
161
|
+
* @remarks
|
|
162
|
+
* - Does not perform device-level lookup or metadata resolution.
|
|
163
|
+
* - Produces values in the same order as provided by the device.
|
|
164
|
+
*/
|
|
48
165
|
function mapMonitoringParameterValuesStatusMessageToParameterValues() {
|
|
49
166
|
return (0, rxjs_1.pipe)((0, rxjs_1.map)((message) => {
|
|
50
167
|
var _a;
|
|
@@ -58,6 +175,35 @@ function mapMonitoringParameterValuesStatusMessageToParameterValues() {
|
|
|
58
175
|
}));
|
|
59
176
|
}
|
|
60
177
|
exports.mapMonitoringParameterValuesStatusMessageToParameterValues = mapMonitoringParameterValuesStatusMessageToParameterValues;
|
|
178
|
+
/**
|
|
179
|
+
* Creates an operator that transforms Motion Master monitoring status messages into a list of
|
|
180
|
+
* resolved `DeviceParameter` objects. For each incoming message, parameter values are extracted,
|
|
181
|
+
* device parameter metadata is resolved using the provided request client, and both pieces of
|
|
182
|
+
* information are merged into a final typed representation.
|
|
183
|
+
*
|
|
184
|
+
* More specifically:
|
|
185
|
+
* - Extracts raw parameter values from a monitoring status message.
|
|
186
|
+
* - Determines the associated device address.
|
|
187
|
+
* - Fetches a parameter info map for that device via `request.resolveDeviceParameterInfoMap(...)`.
|
|
188
|
+
* - Combines resolved metadata (e.g., name, unit, scaling) with current parameter values.
|
|
189
|
+
* - Produces a `DeviceParameter[]` representing the current state.
|
|
190
|
+
*
|
|
191
|
+
* If the incoming message does not include parameter values, an empty array is emitted.
|
|
192
|
+
*
|
|
193
|
+
* @param request - A client used to resolve parameter info metadata per device.
|
|
194
|
+
* @returns Operator that maps a stream of `IMotionMasterMessage` into parameter arrays.
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* source$.pipe(
|
|
198
|
+
* mapMonitoringParameterValuesStatusMessageToDeviceParameters(request)
|
|
199
|
+
* ).subscribe(parameters => {
|
|
200
|
+
* console.log('Resolved device parameters:', parameters);
|
|
201
|
+
* });
|
|
202
|
+
*
|
|
203
|
+
* @remarks
|
|
204
|
+
* - The operator handles missing or incomplete monitoring payloads gracefully.
|
|
205
|
+
* - The returned parameters contain both identification (index/subindex) and resolved metadata.
|
|
206
|
+
*/
|
|
61
207
|
function mapMonitoringParameterValuesStatusMessageToDeviceParameters(request) {
|
|
62
208
|
return (0, rxjs_1.pipe)((0, rxjs_1.mergeMap)((message) => {
|
|
63
209
|
var _a, _b, _c, _d, _e, _f;
|
|
@@ -80,6 +226,32 @@ function mapMonitoringParameterValuesStatusMessageToDeviceParameters(request) {
|
|
|
80
226
|
}));
|
|
81
227
|
}
|
|
82
228
|
exports.mapMonitoringParameterValuesStatusMessageToDeviceParameters = mapMonitoringParameterValuesStatusMessageToDeviceParameters;
|
|
229
|
+
/**
|
|
230
|
+
* Returns an operator that completes the source observable when the notifier observable either
|
|
231
|
+
* completes or errors. Unlike `takeUntil`, which reacts only to the notifier’s `next` emissions,
|
|
232
|
+
* this operator also stops the source when the notifier finishes or fails.
|
|
233
|
+
*
|
|
234
|
+
* @typeParam T - The value type of the source observable.
|
|
235
|
+
* @param notifier$ - Observable whose termination (complete or error) will stop the source.
|
|
236
|
+
* @returns A `MonoTypeOperatorFunction` that completes the source when the notifier completes or errors.
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* const notifier$ = ajax.getJSON('/config'); // May error or complete
|
|
240
|
+
*
|
|
241
|
+
* source$.pipe(
|
|
242
|
+
* takeUntilCompleteOrError(notifier$)
|
|
243
|
+
* ).subscribe({
|
|
244
|
+
* next: console.log,
|
|
245
|
+
* complete: () => console.log('Stopped due to notifier completing'),
|
|
246
|
+
* error: console.error
|
|
247
|
+
* });
|
|
248
|
+
*
|
|
249
|
+
* // The subscription to source$ ends as soon as:
|
|
250
|
+
* // 1) notifier$ completes, or
|
|
251
|
+
* // 2) notifier$ errors.
|
|
252
|
+
*
|
|
253
|
+
* // NOTE: Any values emitted by notifier$ are ignored.
|
|
254
|
+
*/
|
|
83
255
|
function takeUntilCompleteOrError(notifier$) {
|
|
84
256
|
// Transform notifier to emit a value on complete or error
|
|
85
257
|
const stop$ = notifier$.pipe((0, rxjs_1.materialize)(), // Convert next/error/complete to Notification objects
|
|
@@ -88,4 +260,33 @@ function takeUntilCompleteOrError(notifier$) {
|
|
|
88
260
|
return (0, rxjs_1.takeUntil)(stop$);
|
|
89
261
|
}
|
|
90
262
|
exports.takeUntilCompleteOrError = takeUntilCompleteOrError;
|
|
263
|
+
/**
|
|
264
|
+
* Custom RxJS operator that accumulates notifications with their
|
|
265
|
+
* elapsed time relative to a provided start time.
|
|
266
|
+
*
|
|
267
|
+
* Each emitted notification string is converted into a `NotificationEntry`
|
|
268
|
+
* object, and the operator maintains an array of all previous entries.
|
|
269
|
+
*
|
|
270
|
+
* @param startTime - The timestamp (in milliseconds) to use as the reference
|
|
271
|
+
* point for calculating elapsed time. Typically obtained via `performance.now()`.
|
|
272
|
+
* @returns An OperatorFunction that transforms an Observable of strings into
|
|
273
|
+
* an Observable of `NotificationEntry[]`.
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* ```ts
|
|
277
|
+
* const startTime = performance.now();
|
|
278
|
+
* notifications$.pipe(withTimeDifference(startTime)).subscribe(entries => {
|
|
279
|
+
* console.log(entries); // Array of NotificationEntry objects with elapsed time
|
|
280
|
+
* });
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
function withTimeDifference(startTime) {
|
|
284
|
+
return (source) => source.pipe((0, rxjs_1.scan)((acc, message) => {
|
|
285
|
+
const endTime = performance.now();
|
|
286
|
+
const timeDifference = endTime - startTime;
|
|
287
|
+
acc.push({ message, timeDifference });
|
|
288
|
+
return acc;
|
|
289
|
+
}, []));
|
|
290
|
+
}
|
|
291
|
+
exports.withTimeDifference = withTimeDifference;
|
|
91
292
|
//# sourceMappingURL=operators.js.map
|
package/src/lib/operators.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operators.js","sourceRoot":"","sources":["../../../../../libs/motion-master-client/src/lib/operators.ts"],"names":[],"mappings":";;;AAAA,+
|
|
1
|
+
{"version":3,"file":"operators.js","sourceRoot":"","sources":["../../../../../libs/motion-master-client/src/lib/operators.ts"],"names":[],"mappings":";;;AAAA,+BAec;AACd,uEAAkE;AAIlE,2CAAiE;AAGjE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,0CAA0C,CAAI,GAAc,EAAE,EAAW;IACvF,OAAO,IAAA,WAAI,EACT,IAAA,aAAM,EAAC,CAAC,OAA6B,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC,EAC5D,IAAA,UAAG,EAAC,CAAC,OAAO,EAAE,EAAE;;QACd,gHAAgH;QAChH,kHAAkH;QAClH,IAAI,CAAA,MAAA,OAAO,CAAC,MAAM,0CAAE,WAAW,KAAI,GAAG,KAAK,aAAa,EAAE;YACxD,IAAI,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE;gBACpC,MAAM,IAAI,KAAK,CAAC,4BAA4B,MAAA,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,mCAAI,EAAE,EAAE,CAAC,CAAC;aAC/F;iBAAM;gBACL,MAAM,IAAI,KAAK,CACb,8DAA8D,GAAG,CAAC,QAA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