kuzzle-device-manager-types 3.0.0-3-dev.18 → 3.0.0-3-dev.19
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/dist/lib/modules/decoder/Decoder.d.ts +28 -6
- package/dist/lib/modules/decoder/PayloadService.d.ts +1 -1
- package/dist/lib/modules/decoder/collections/payloadsMappings.d.ts +4 -0
- package/dist/tests/application/decoders/DummyTempDecoder.d.ts +2 -2
- package/dist/tests/application/decoders/DummyTempPositionDecoder.d.ts +3 -1
- package/dist/tests/application/decoders/EmptyTempDecoder.d.ts +2 -2
- package/package.json +1 -1
- package/dist/lib/modules/decoder/SkipError.d.ts +0 -3
|
@@ -22,10 +22,30 @@ export type NamedMeasures = Array<{
|
|
|
22
22
|
[locale: string]: string;
|
|
23
23
|
};
|
|
24
24
|
}>;
|
|
25
|
+
/**
|
|
26
|
+
* Result of the payload validation made by a decoder.
|
|
27
|
+
*
|
|
28
|
+
* Stored alongside the raw payload in the "payloads" collection.
|
|
29
|
+
*/
|
|
30
|
+
export type DecoderValidationResult = {
|
|
31
|
+
/**
|
|
32
|
+
* "valid": the payload will be decoded
|
|
33
|
+
* "invalid": the payload will be skipped (status 400)
|
|
34
|
+
*/
|
|
35
|
+
status: "valid" | "invalid";
|
|
36
|
+
/**
|
|
37
|
+
* Why the payload has been rejected
|
|
38
|
+
*/
|
|
39
|
+
reason?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Custom data stored with the payload
|
|
42
|
+
*/
|
|
43
|
+
customData?: JSONObject;
|
|
44
|
+
};
|
|
25
45
|
/**
|
|
26
46
|
* Base class to implement a decoder for a device model.
|
|
27
47
|
* The device model must be passed to the parent constructor.
|
|
28
|
-
* The abstract "decode"
|
|
48
|
+
* The abstract "validate" and "decode" methods must be implemented.
|
|
29
49
|
*/
|
|
30
50
|
export declare abstract class Decoder {
|
|
31
51
|
private _http?;
|
|
@@ -85,16 +105,18 @@ export declare abstract class Decoder {
|
|
|
85
105
|
* Validate the payload format before processing.
|
|
86
106
|
*
|
|
87
107
|
* If the method:
|
|
88
|
-
* - return
|
|
89
|
-
* - return
|
|
108
|
+
* - return status "valid": the payload will be processed (status 200)
|
|
109
|
+
* - return status "invalid": the payload will be skipped (status 400)
|
|
90
110
|
* - throw an error: the payload will be skipped (status 4** or 5**)
|
|
91
111
|
*
|
|
112
|
+
* The returned `reason` and `customData` are stored in the "payloads" collection.
|
|
113
|
+
*
|
|
92
114
|
* @param payload Raw payload received in the API action body
|
|
93
115
|
* @param request Original request
|
|
94
116
|
*
|
|
95
|
-
* @return
|
|
117
|
+
* @return The validation result
|
|
96
118
|
*/
|
|
97
|
-
validate(payload: JSONObject, request: KuzzleRequest): Promise<
|
|
119
|
+
validate(payload: JSONObject, request: KuzzleRequest): Promise<DecoderValidationResult> | DecoderValidationResult;
|
|
98
120
|
/**
|
|
99
121
|
* Decode the payload:
|
|
100
122
|
* - set "reference"
|
|
@@ -106,7 +128,7 @@ export declare abstract class Decoder {
|
|
|
106
128
|
*
|
|
107
129
|
* @returns DecodedPayload
|
|
108
130
|
*/
|
|
109
|
-
abstract decode(decodedPayload: DecodedPayload<any>, payload: JSONObject, request: KuzzleRequest): Promise<DecodedPayload<any
|
|
131
|
+
abstract decode(decodedPayload: DecodedPayload<any>, payload: JSONObject, request: KuzzleRequest): Promise<DecodedPayload<any>> | DecodedPayload<any>;
|
|
110
132
|
/**
|
|
111
133
|
* Checks if the provided properties are present in the payload
|
|
112
134
|
*
|
|
@@ -17,7 +17,7 @@ export declare class PayloadService extends BaseService {
|
|
|
17
17
|
* - redirect measurements to MeasureService
|
|
18
18
|
*/
|
|
19
19
|
receive(request: KuzzleRequest, decoder: Decoder, { refresh }?: any): Promise<{
|
|
20
|
-
valid:
|
|
20
|
+
valid: true;
|
|
21
21
|
}>;
|
|
22
22
|
receiveFormated(device: KDocument<DeviceContent>, measurements: DecodedMeasurement[], { payloadUuids }?: {
|
|
23
23
|
payloadUuids?: string[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JSONObject } from "kuzzle-sdk";
|
|
2
|
-
import { Decoder, DecodedPayload } from "../../../index";
|
|
2
|
+
import { Decoder, DecodedPayload, DecoderValidationResult } from "../../../index";
|
|
3
3
|
export declare const dummyTempDeviceMeasures: readonly [{
|
|
4
4
|
readonly name: "temperature";
|
|
5
5
|
readonly type: "temperature";
|
|
@@ -22,7 +22,7 @@ export declare class DummyTempDecoder extends Decoder {
|
|
|
22
22
|
readonly type: "battery";
|
|
23
23
|
}];
|
|
24
24
|
constructor();
|
|
25
|
-
validate(rawPayload: JSONObject): Promise<
|
|
25
|
+
validate(rawPayload: JSONObject): Promise<DecoderValidationResult>;
|
|
26
26
|
decode(decodedPayload: DecodedPayload<DummyTempDecoder>, rawPayload: JSONObject): Promise<DecodedPayload<DummyTempDecoder>>;
|
|
27
27
|
decodeSimplePayload(decodedPayload: DecodedPayload<DummyTempDecoder>, payload: JSONObject): void;
|
|
28
28
|
}
|
|
@@ -22,6 +22,8 @@ export declare class DummyTempPositionDecoder extends Decoder {
|
|
|
22
22
|
readonly type: "position";
|
|
23
23
|
}];
|
|
24
24
|
constructor();
|
|
25
|
-
validate(payload: JSONObject): Promise<
|
|
25
|
+
validate(payload: JSONObject): Promise<{
|
|
26
|
+
status: "valid";
|
|
27
|
+
}>;
|
|
26
28
|
decode(decodedPayload: DecodedPayload<DummyTempPositionDecoder>, payload: JSONObject): Promise<DecodedPayload<DummyTempPositionDecoder>>;
|
|
27
29
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { JSONObject } from "kuzzle-sdk";
|
|
2
|
-
import { Decoder, DecodedPayload } from "../../../index";
|
|
2
|
+
import { Decoder, DecodedPayload, DecoderValidationResult } from "../../../index";
|
|
3
3
|
export declare class EmptyTempDecoder extends Decoder {
|
|
4
4
|
measures: any[];
|
|
5
5
|
constructor();
|
|
6
|
-
validate(rawPayload: JSONObject): Promise<
|
|
6
|
+
validate(rawPayload: JSONObject): Promise<DecoderValidationResult>;
|
|
7
7
|
decode(decodedPayload: DecodedPayload<EmptyTempDecoder>, rawPayload: JSONObject): Promise<DecodedPayload<EmptyTempDecoder>>;
|
|
8
8
|
}
|
package/package.json
CHANGED