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.
@@ -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" method must be implemented.
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 true: the payload will be processed (status 200)
89
- * - return false: the payload will be skipped (status 200)
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 A boolean indicating if the payload is valid
117
+ * @return The validation result
96
118
  */
97
- validate(payload: JSONObject, request: KuzzleRequest): Promise<boolean> | never;
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: boolean;
20
+ valid: true;
21
21
  }>;
22
22
  receiveFormated(device: KDocument<DeviceContent>, measurements: DecodedMeasurement[], { payloadUuids }?: {
23
23
  payloadUuids?: string[];
@@ -23,5 +23,9 @@ export declare const payloadsMappings: {
23
23
  reason: {
24
24
  type: string;
25
25
  };
26
+ customData: {
27
+ dynamic: string;
28
+ properties: {};
29
+ };
26
30
  };
27
31
  };
@@ -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<boolean>;
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<boolean>;
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<boolean>;
6
+ validate(rawPayload: JSONObject): Promise<DecoderValidationResult>;
7
7
  decode(decodedPayload: DecodedPayload<EmptyTempDecoder>, rawPayload: JSONObject): Promise<DecodedPayload<EmptyTempDecoder>>;
8
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kuzzle-device-manager-types",
3
- "version": "3.0.0-3-dev.18",
3
+ "version": "3.0.0-3-dev.19",
4
4
  "description": "Shared types for Kuzzle Device Manager",
5
5
  "author": "The Kuzzle Team (support@kuzzle.io)",
6
6
  "main": "index.js",
@@ -1,3 +0,0 @@
1
- export declare class SkipError extends Error {
2
- constructor(message: string);
3
- }