kuzzle-device-manager-types 2.1.4 → 2.2.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.
Files changed (86) hide show
  1. package/dist/index.d.ts +7 -7
  2. package/dist/lib/modules/asset/AssetHistoryService.d.ts +3 -5
  3. package/dist/lib/modules/asset/AssetService.d.ts +11 -22
  4. package/dist/lib/modules/asset/AssetsController.d.ts +8 -3
  5. package/dist/lib/modules/asset/collections/assetsHistoryMappings.d.ts +8 -0
  6. package/dist/lib/modules/asset/collections/assetsMappings.d.ts +8 -0
  7. package/dist/lib/modules/asset/exports.d.ts +2 -0
  8. package/dist/lib/modules/asset/roles/RoleAssetsAdmin.d.ts +1 -0
  9. package/dist/lib/modules/asset/roles/RoleAssetsReader.d.ts +2 -0
  10. package/dist/lib/modules/asset/types/AssetApi.d.ts +20 -0
  11. package/dist/lib/modules/asset/types/AssetContent.d.ts +3 -2
  12. package/dist/lib/modules/asset/types/AssetEvents.d.ts +10 -3
  13. package/dist/lib/modules/asset/types/AssetHistoryContent.d.ts +14 -3
  14. package/dist/lib/modules/decoder/Decoder.d.ts +2 -2
  15. package/dist/lib/modules/decoder/DecodersController.d.ts +1 -1
  16. package/dist/lib/{core/registers → modules/decoder}/DecodersRegister.d.ts +3 -2
  17. package/dist/lib/modules/decoder/DecodingState.d.ts +5 -0
  18. package/dist/lib/modules/decoder/PayloadService.d.ts +1 -1
  19. package/dist/lib/modules/decoder/PayloadsController.d.ts +1 -1
  20. package/dist/lib/modules/decoder/SkipError.d.ts +3 -0
  21. package/dist/lib/modules/decoder/collections/payloadsMappings.d.ts +6 -0
  22. package/dist/lib/modules/decoder/index.d.ts +1 -0
  23. package/dist/lib/modules/device/DeviceService.d.ts +1 -10
  24. package/dist/lib/modules/device/DevicesController.d.ts +8 -3
  25. package/dist/lib/modules/device/collections/deviceMappings.d.ts +5 -0
  26. package/dist/lib/modules/device/exports.d.ts +1 -0
  27. package/dist/lib/modules/device/roles/RoleDevicesAdmin.d.ts +3 -0
  28. package/dist/lib/modules/device/roles/RoleDevicesReader.d.ts +3 -0
  29. package/dist/lib/modules/device/types/DeviceApi.d.ts +20 -0
  30. package/dist/lib/modules/measure/MeasureExporter.d.ts +61 -0
  31. package/dist/lib/modules/measure/MeasureService.d.ts +9 -4
  32. package/dist/lib/modules/measure/collections/measuresMappings.d.ts +5 -0
  33. package/dist/lib/modules/measure/exports.d.ts +1 -0
  34. package/dist/lib/modules/measure/index.d.ts +1 -0
  35. package/dist/lib/modules/model/ModelService.d.ts +1 -1
  36. package/dist/lib/{core/registers → modules/model}/ModelsRegister.d.ts +3 -3
  37. package/dist/lib/modules/model/collections/modelsMappings.d.ts +3 -0
  38. package/dist/lib/modules/model/index.d.ts +1 -0
  39. package/dist/lib/{core → modules/plugin}/DeviceManagerEngine.d.ts +11 -3
  40. package/dist/lib/{core → modules/plugin}/DeviceManagerPlugin.d.ts +3 -3
  41. package/dist/lib/modules/plugin/exports.d.ts +2 -0
  42. package/dist/lib/modules/plugin/index.d.ts +4 -0
  43. package/dist/lib/modules/shared/Module.d.ts +1 -1
  44. package/dist/lib/modules/shared/types/Metadata.d.ts +2 -1
  45. package/dist/tests/application/decoders/DummyTempDecoder.d.ts +3 -2
  46. package/package.json +1 -1
  47. package/dist/lib/core/exports.d.ts +0 -2
  48. package/dist/lib/core/index.d.ts +0 -4
  49. package/dist/tests/fixtures/fixtures.d.ts +0 -42
  50. package/dist/tests/helpers/document.d.ts +0 -5
  51. package/dist/tests/helpers/index.d.ts +0 -4
  52. package/dist/tests/helpers/payloads.d.ts +0 -18
  53. package/dist/tests/helpers/sdk.d.ts +0 -2
  54. package/dist/tests/helpers/setup.d.ts +0 -1
  55. package/dist/tests/hooks/collections.d.ts +0 -3
  56. package/dist/tests/hooks/engines.d.ts +0 -2
  57. package/dist/tests/hooks/fixtures.d.ts +0 -2
  58. package/dist/tests/scenario/migrated/asset-controller.test.d.ts +0 -1
  59. package/dist/tests/scenario/migrated/asset-history.test.d.ts +0 -1
  60. package/dist/tests/scenario/migrated/asset-roles.test.d.ts +0 -1
  61. package/dist/tests/scenario/migrated/decoder-decoders-controller.test.d.ts +0 -1
  62. package/dist/tests/scenario/migrated/decoder-default-rights.test.d.ts +0 -1
  63. package/dist/tests/scenario/migrated/decoder-payload-controller.test.d.ts +0 -1
  64. package/dist/tests/scenario/migrated/decoder-payloads-mappings.test.d.ts +0 -1
  65. package/dist/tests/scenario/migrated/decoder-roles.test.d.ts +0 -1
  66. package/dist/tests/scenario/migrated/device-controller-attach-engine.test.d.ts +0 -1
  67. package/dist/tests/scenario/migrated/device-controller-detach-engine.test.d.ts +0 -1
  68. package/dist/tests/scenario/migrated/device-controller-get-measures.test.d.ts +0 -1
  69. package/dist/tests/scenario/migrated/device-controller-unlink-asset.test.d.ts +0 -1
  70. package/dist/tests/scenario/migrated/device-metadata.test.d.ts +0 -1
  71. package/dist/tests/scenario/migrated/device-roles.test.d.ts +0 -1
  72. package/dist/tests/scenario/migrated/measure-ingestion-pipeline.test.d.ts +0 -1
  73. package/dist/tests/scenario/migrated/measure-provisionning.test.d.ts +0 -1
  74. package/dist/tests/scenario/migrated/measure-roles.test.d.ts +0 -1
  75. package/dist/tests/scenario/migrated/model-controller.test.d.ts +0 -1
  76. package/dist/tests/scenario/modules/assets/action-get-measures.test.d.ts +0 -1
  77. package/dist/tests/scenario/modules/assets/asset-history.test.d.ts +0 -1
  78. package/dist/tests/scenario/modules/devices/action-attach-engine.test.d.ts +0 -1
  79. package/dist/tests/scenario/modules/devices/action-link-asset.test.d.ts +0 -1
  80. package/dist/tests/scenario/modules/devices/action-receive-measure.test.d.ts +0 -1
  81. package/dist/tests/scenario/modules/devices/action-scrud.test.d.ts +0 -1
  82. package/dist/tests/scenario/modules/ingestion-pipeline/before-ingestion.test.d.ts +0 -1
  83. package/dist/tests/scenario/modules/ingestion-pipeline/propagation.test.d.ts +0 -1
  84. package/dist/tests/scenario/usecase/dynamicaly-register-device-model.test.d.ts +0 -1
  85. /package/dist/lib/{core → modules/plugin/types}/DeviceManagerConfiguration.d.ts +0 -0
  86. /package/dist/lib/{core → modules/plugin/types}/InternalCollection.d.ts +0 -0
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export * from './lib/core/exports';
2
- export * from './lib/modules/asset/exports';
3
- export * from './lib/modules/device/exports';
4
- export * from './lib/modules/measure/exports';
5
- export * from './lib/modules/decoder/exports';
6
- export * from './lib/modules/shared/exports';
7
- export * from './lib/modules/model/exports';
1
+ export * from "./lib/modules/plugin/exports";
2
+ export * from "./lib/modules/asset/exports";
3
+ export * from "./lib/modules/device/exports";
4
+ export * from "./lib/modules/measure/exports";
5
+ export * from "./lib/modules/decoder/exports";
6
+ export * from "./lib/modules/shared/exports";
7
+ export * from "./lib/modules/model/exports";
@@ -1,11 +1,9 @@
1
- import { KDocument } from "kuzzle-sdk";
2
- import { DeviceManagerPlugin } from "../../core";
3
- import { AssetHistoryEvent } from "./types/AssetHistoryContent";
4
- import { AssetContent } from "./types/AssetContent";
1
+ import { DeviceManagerPlugin } from "../plugin";
2
+ import { AssetHistoryContent, AssetHistoryEvent } from "./types/AssetHistoryContent";
5
3
  export declare class AssetHistoryService {
6
4
  private context;
7
5
  private config;
8
6
  private get sdk();
9
7
  constructor(plugin: DeviceManagerPlugin);
10
- add<TAssetHistoryEvent extends AssetHistoryEvent>(engineId: string, event: TAssetHistoryEvent, asset: KDocument<AssetContent>): Promise<void>;
8
+ add<TAssetHistoryEvent extends AssetHistoryEvent>(engineId: string, histories: AssetHistoryContent[]): Promise<void>;
11
9
  }
@@ -1,10 +1,9 @@
1
1
  import { User } from "kuzzle";
2
- import { JSONObject, KDocument, KHit, SearchResult } from "kuzzle-sdk";
2
+ import { JSONObject, KDocument, KHit, SearchResult, mReplaceResponse } from "kuzzle-sdk";
3
+ import { DeviceManagerPlugin } from "../plugin";
3
4
  import { Metadata } from "../shared";
4
- import { DeviceManagerPlugin } from "../../core";
5
- import { AssetContent } from "./types/AssetContent";
6
5
  import { AssetHistoryService } from "./AssetHistoryService";
7
- import { ApiAssetGetMeasuresResult } from "./types/AssetApi";
6
+ import { AssetContent } from "./types/AssetContent";
8
7
  export declare class AssetService {
9
8
  private context;
10
9
  private config;
@@ -13,24 +12,7 @@ export declare class AssetService {
13
12
  private get app();
14
13
  private get impersonatedSdk();
15
14
  constructor(plugin: DeviceManagerPlugin, assetHistoryService: AssetHistoryService);
16
- /**
17
- * Returns measures history for an asset
18
- *
19
- * @param engineId Engine ID
20
- * @param assetId Asset ID
21
- * @param options.size Number of measures to return
22
- * @param options.startAt Returns measures starting from this date (ISO8601)
23
- * @param options.endAt Returns measures until this date (ISO8601)
24
- */
25
- getMeasureHistory(engineId: string, assetId: string, { size, from, endAt, startAt, query, sort, type, }: {
26
- sort?: JSONObject;
27
- query?: JSONObject;
28
- from?: number;
29
- size?: number;
30
- startAt?: string;
31
- endAt?: string;
32
- type?: string;
33
- }): Promise<ApiAssetGetMeasuresResult>;
15
+ registerAskEvents(): void;
34
16
  get(engineId: string, assetId: string): Promise<KDocument<AssetContent>>;
35
17
  /**
36
18
  * Updates an asset metadata
@@ -51,5 +33,12 @@ export declare class AssetService {
51
33
  scroll?: string;
52
34
  lang?: string;
53
35
  }): Promise<SearchResult<KHit<AssetContent>>>;
36
+ /**
37
+ * Replace an asset metadata
38
+ */
39
+ mReplaceAndHistorize(engineId: string, assets: KDocument<AssetContent>[], removedMetadata: string[], { refresh }: {
40
+ refresh: any;
41
+ }): Promise<mReplaceResponse>;
54
42
  private getEngine;
43
+ private refreshModel;
55
44
  }
@@ -1,14 +1,19 @@
1
- import { ControllerDefinition, KuzzleRequest } from "kuzzle";
1
+ import { ControllerDefinition, HttpStream, KuzzleRequest } from "kuzzle";
2
+ import { DeviceManagerPlugin } from "../plugin";
2
3
  import { AssetService } from "./AssetService";
3
4
  import { ApiAssetCreateResult, ApiAssetDeleteResult, ApiAssetGetMeasuresResult, ApiAssetGetResult, ApiAssetSearchResult, ApiAssetUpdateResult } from "./types/AssetApi";
4
5
  export declare class AssetsController {
5
- definition: ControllerDefinition;
6
+ private plugin;
6
7
  private assetService;
7
- constructor(assetService: AssetService);
8
+ definition: ControllerDefinition;
9
+ constructor(plugin: DeviceManagerPlugin, assetService: AssetService);
8
10
  get(request: KuzzleRequest): Promise<ApiAssetGetResult>;
9
11
  update(request: KuzzleRequest): Promise<ApiAssetUpdateResult>;
10
12
  create(request: KuzzleRequest): Promise<ApiAssetCreateResult>;
11
13
  delete(request: KuzzleRequest): Promise<ApiAssetDeleteResult>;
12
14
  search(request: KuzzleRequest): Promise<ApiAssetSearchResult>;
13
15
  getMeasures(request: KuzzleRequest): Promise<ApiAssetGetMeasuresResult>;
16
+ exportMeasures(request: KuzzleRequest): Promise<HttpStream | {
17
+ link: string;
18
+ }>;
14
19
  }
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Base mappings for the "assetsHistory" collection.
3
+ *
4
+ * Those mappings does not contains the `asset` mappings.
5
+ */
1
6
  export declare const assetsHistoryMappings: {
2
7
  dynamic: string;
3
8
  properties: {
@@ -59,5 +64,8 @@ export declare const assetsHistoryMappings: {
59
64
  };
60
65
  };
61
66
  };
67
+ timestamp: {
68
+ type: string;
69
+ };
62
70
  };
63
71
  };
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Base mappings for the "assets" collection.
3
+ *
4
+ * Those mappings does not contains the `measures` and `metadata` mappings.
5
+ */
1
6
  export declare const assetsMappings: {
2
7
  dynamic: string;
3
8
  properties: {
@@ -36,6 +41,9 @@ export declare const assetsMappings: {
36
41
  device: {
37
42
  type: string;
38
43
  };
44
+ type: {
45
+ type: string;
46
+ };
39
47
  };
40
48
  };
41
49
  };
@@ -4,3 +4,5 @@ export * from "./types/AssetEvents";
4
4
  export * from "./types/AssetApi";
5
5
  export * from "./roles/RoleAssetsAdmin";
6
6
  export * from "./roles/RoleAssetsReader";
7
+ export * from "./collections/assetsMappings";
8
+ export * from "./collections/assetsHistoryMappings";
@@ -17,6 +17,7 @@ import { KuzzleRole } from "../../shared/types/KuzzleRole";
17
17
  listAssets: true,
18
18
  getAsset: true,
19
19
  writeAsset: true,
20
+ listMeasures: true,
20
21
  },
21
22
  },
22
23
  */
@@ -9,12 +9,14 @@ import { KuzzleRole } from "../../shared/types/KuzzleRole";
9
9
  actions: {
10
10
  get: true,
11
11
  getMeasures: true,
12
+ exportMeasures: true,
12
13
  search: true,
13
14
  },
14
15
  },
15
16
  "device-manager/models": {
16
17
  actions: {
17
18
  listAssets: true,
19
+ listMeasures: true,
18
20
  getAsset: true,
19
21
  },
20
22
  },
@@ -63,4 +63,24 @@ export type ApiAssetGetMeasuresResult = {
63
63
  measures: Array<KDocument<MeasureContent<JSONObject>>>;
64
64
  total: number;
65
65
  };
66
+ /**
67
+ * This action can be used only with WebSocket or POST
68
+ *
69
+ * Then the export can be download using HTTP Get and the following route:
70
+ * `/_/device-manager/:engineId/devices/:_id/measures/_export/:exportId`
71
+ */
72
+ export interface ApiAssetExportMeasuresRequest extends AssetsControllerRequest {
73
+ action: "exportMeasures";
74
+ _id: string;
75
+ startAt?: string;
76
+ endAt?: string;
77
+ type?: string;
78
+ body?: {
79
+ query?: JSONObject;
80
+ sort?: JSONObject;
81
+ };
82
+ }
83
+ export type ApiAssetExportMeasuresResult = {
84
+ link: string;
85
+ };
66
86
  export {};
@@ -15,17 +15,18 @@ export interface AssetContent<TMeasures extends JSONObject = any, TMetadata exte
15
15
  /**
16
16
  * Names of the linked measures
17
17
  *
18
- * Array<{ asset: string, device: string }>
18
+ * Array<{ asset: string, device: string, type: string }>
19
19
  *
20
20
  * @example
21
21
  *
22
22
  * [
23
- * { asset: "externalTemperature", device: "temperature" }
23
+ * { asset: "externalTemperature", device: "temperature", type: "temperature" }
24
24
  * ]
25
25
  */
26
26
  measureNames: Array<{
27
27
  asset: string;
28
28
  device: string;
29
+ type: string;
29
30
  }>;
30
31
  }>;
31
32
  }
@@ -1,7 +1,8 @@
1
1
  import { KDocument } from "kuzzle-sdk";
2
+ import { AssetModelContent } from "lib/modules/model";
2
3
  import { Metadata } from "../../../modules/shared";
3
4
  import { AssetContent } from "./AssetContent";
4
- import { AssetHistoryEvent } from "./AssetHistoryContent";
5
+ import { AssetHistoryContent, AssetHistoryEvent } from "./AssetHistoryContent";
5
6
  export type EventAssetUpdateBefore = {
6
7
  name: "device-manager:asset:update:before";
7
8
  args: [{
@@ -16,6 +17,13 @@ export type EventAssetUpdateAfter = {
16
17
  metadata: Metadata;
17
18
  }];
18
19
  };
20
+ export type AskAssetRefreshModel = {
21
+ name: "ask:device-manager:asset:refresh-model";
22
+ payload: {
23
+ assetModel: AssetModelContent;
24
+ };
25
+ result: void;
26
+ };
19
27
  /**
20
28
  * @internal
21
29
  */
@@ -23,8 +31,7 @@ export type AskAssetHistoryAdd<TAssetHistoryEvent extends AssetHistoryEvent> = {
23
31
  name: "ask:device-manager:asset:history:add";
24
32
  payload: {
25
33
  engineId: string;
26
- event: TAssetHistoryEvent;
27
- asset: KDocument<AssetContent>;
34
+ histories: AssetHistoryContent<TAssetHistoryEvent>[];
28
35
  };
29
36
  result: void;
30
37
  };
@@ -1,17 +1,19 @@
1
1
  import { JSONObject, KDocumentContent } from "kuzzle-sdk";
2
2
  import { Metadata } from "../../shared";
3
3
  import { AssetContent } from "./AssetContent";
4
+ export type AssetHistoryMetadata = {
5
+ names: string[];
6
+ };
4
7
  export type AssetHistoryEventMeasure = {
5
8
  name: "measure";
6
9
  measure: {
7
10
  names: string[];
8
11
  };
12
+ metadata?: AssetHistoryMetadata;
9
13
  };
10
14
  export type AssetHistoryEventMetadata = {
11
15
  name: "metadata";
12
- metadata: {
13
- names: string[];
14
- };
16
+ metadata: AssetHistoryMetadata;
15
17
  };
16
18
  export type AssetHistoryEventLink = {
17
19
  name: "link";
@@ -47,4 +49,13 @@ export interface AssetHistoryContent<TAssetHistoryEvent extends AssetHistoryEven
47
49
  * Asset content after the event
48
50
  */
49
51
  asset: AssetContent<TMeasures, TMetadata>;
52
+ /**
53
+ * Timestamp of the event according to its type
54
+ *
55
+ * - `measure`: the date of measure (`measuredAt`)
56
+ * - `metadata`: the current date of the event
57
+ * - `link`: the current date of the event
58
+ * - `unlink`: the current date of the event
59
+ */
60
+ timestamp: number;
50
61
  }
@@ -8,7 +8,7 @@ import { DecoderContent } from "./types/DecoderContent";
8
8
  * This need to be read only so we can provide strong typing when decoding measures
9
9
  * with the DecodedPayload
10
10
  */
11
- export type NamedMeasures = ReadonlyArray<{
11
+ export type NamedMeasures = Array<{
12
12
  name: string;
13
13
  type: string;
14
14
  }>;
@@ -37,7 +37,7 @@ export declare abstract class Decoder {
37
37
  * { type: 'temperature', name: 'temperatureExterior' },
38
38
  * ];
39
39
  */
40
- measures: NamedMeasures;
40
+ measures: ReadonlyArray<NamedMeasures[0]>;
41
41
  /**
42
42
  * Custom name for the associated API action in the "payload" controller
43
43
  */
@@ -1,5 +1,5 @@
1
1
  import { ControllerDefinition, KuzzleRequest } from "kuzzle";
2
- import { DecodersRegister } from "../../core/registers/DecodersRegister";
2
+ import { DecodersRegister } from "./DecodersRegister";
3
3
  import { PayloadService } from "./PayloadService";
4
4
  import { ApiDecoderListResult, ApiDecoderPrunePayloadsResult } from "./types/DecoderApi";
5
5
  export declare class DecodersController {
@@ -1,6 +1,7 @@
1
1
  import { PluginContext } from "kuzzle";
2
- import { Decoder, DecoderContent } from "../../modules/decoder";
3
- import { DeviceManagerPlugin } from "..";
2
+ import { DeviceManagerPlugin } from "../plugin";
3
+ import { Decoder } from "./Decoder";
4
+ import { DecoderContent } from "./exports";
4
5
  export declare class DecodersRegister {
5
6
  private context;
6
7
  private plugin;
@@ -0,0 +1,5 @@
1
+ export declare enum DecodingState {
2
+ SKIP = 0,
3
+ ERROR = 1,
4
+ VALID = 2
5
+ }
@@ -1,6 +1,6 @@
1
1
  import { KuzzleRequest } from "kuzzle";
2
2
  import { JSONObject, KDocument } from "kuzzle-sdk";
3
- import { DeviceManagerPlugin } from "../../core";
3
+ import { DeviceManagerPlugin } from "../plugin";
4
4
  import { DeviceContent } from "../device";
5
5
  import { DecodedMeasurement } from "../measure";
6
6
  import { Decoder } from "./Decoder";
@@ -1,5 +1,5 @@
1
1
  import { ControllerDefinition, KuzzleRequest } from "kuzzle";
2
- import { DecodersRegister } from "../../core/registers/DecodersRegister";
2
+ import { DecodersRegister } from "./DecodersRegister";
3
3
  import { PayloadService } from "./PayloadService";
4
4
  import { ApiPayloadReceiveUnkownResult } from "./types/PayloadApi";
5
5
  export declare class PayloadsController {
@@ -0,0 +1,3 @@
1
+ export declare class SkipError extends Error {
2
+ constructor(message: string);
3
+ }
@@ -17,5 +17,11 @@ export declare const payloadsMappings: {
17
17
  apiAction: {
18
18
  type: string;
19
19
  };
20
+ state: {
21
+ type: string;
22
+ };
23
+ reason: {
24
+ type: string;
25
+ };
20
26
  };
21
27
  };
@@ -6,3 +6,4 @@ export * from "./Decoder";
6
6
  export * from "./DecoderModule";
7
7
  export * from "./roles/RolePayloadsAll";
8
8
  export * from "./roles/RoleDecodersAdmin";
9
+ export * from "./DecodersRegister";
@@ -4,7 +4,7 @@ import { AssetContent } from "./../asset";
4
4
  import { Metadata } from "../shared";
5
5
  import { DecodedMeasurement } from "../measure";
6
6
  import { DeviceContent } from "./types/DeviceContent";
7
- import { ApiDeviceLinkAssetRequest, ApiDeviceGetMeasuresResult } from "./types/DeviceApi";
7
+ import { ApiDeviceLinkAssetRequest } from "./types/DeviceApi";
8
8
  export declare class DeviceService {
9
9
  private config;
10
10
  private context;
@@ -91,15 +91,6 @@ export declare class DeviceService {
91
91
  asset: KDocument<AssetContent>;
92
92
  device: KDocument<DeviceContent>;
93
93
  }>;
94
- getMeasureHistory(engineId: string, deviceId: string, { size, from, endAt, startAt, query, sort, type, }: {
95
- sort?: JSONObject;
96
- query?: JSONObject;
97
- from?: number;
98
- size?: number;
99
- startAt?: string;
100
- endAt?: string;
101
- type?: string;
102
- }): Promise<ApiDeviceGetMeasuresResult>;
103
94
  private checkEngineExists;
104
95
  private checkAttachedToEngine;
105
96
  private getEngine;
@@ -1,10 +1,12 @@
1
- import { ControllerDefinition, KuzzleRequest } from "kuzzle";
1
+ import { ControllerDefinition, HttpStream, KuzzleRequest } from "kuzzle";
2
+ import { DeviceManagerPlugin } from "../plugin";
2
3
  import { DeviceService } from "./DeviceService";
3
4
  import { ApiDeviceAttachEngineResult, ApiDeviceCreateResult, ApiDeviceDeleteResult, ApiDeviceDetachEngineResult, ApiDeviceGetResult, ApiDeviceLinkAssetResult, ApiDeviceSearchResult, ApiDeviceUnlinkAssetResult, ApiDeviceUpdateResult, ApiDeviceGetMeasuresResult } from "./types/DeviceApi";
4
5
  export declare class DevicesController {
5
- definition: ControllerDefinition;
6
+ private plugin;
6
7
  private deviceService;
7
- constructor(deviceService: DeviceService);
8
+ definition: ControllerDefinition;
9
+ constructor(plugin: DeviceManagerPlugin, deviceService: DeviceService);
8
10
  get(request: KuzzleRequest): Promise<ApiDeviceGetResult>;
9
11
  update(request: KuzzleRequest): Promise<ApiDeviceUpdateResult>;
10
12
  delete(request: KuzzleRequest): Promise<ApiDeviceDeleteResult>;
@@ -30,5 +32,8 @@ export declare class DevicesController {
30
32
  */
31
33
  unlinkAsset(request: KuzzleRequest): Promise<ApiDeviceUnlinkAssetResult>;
32
34
  getMeasures(request: KuzzleRequest): Promise<ApiDeviceGetMeasuresResult>;
35
+ exportMeasures(request: KuzzleRequest): Promise<HttpStream | {
36
+ link: string;
37
+ }>;
33
38
  receiveMeasures(request: KuzzleRequest): Promise<void>;
34
39
  }
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Base mappings for the "devices" collection.
3
+ *
4
+ * Those mappings does not contains the `measures` and `metadata` mappings.
5
+ */
1
6
  export declare const devicesMappings: {
2
7
  dynamic: string;
3
8
  properties: {
@@ -4,3 +4,4 @@ export * from "./types/DeviceEvents";
4
4
  export * from "./roles/RoleDevicesAdmin";
5
5
  export * from "./roles/RoleDevicesPlatformAdmin";
6
6
  export * from "./roles/RoleDevicesReader";
7
+ export * from "./collections/deviceMappings";
@@ -14,6 +14,8 @@ import { KuzzleRole } from "../../shared/types/KuzzleRole";
14
14
  search: true,
15
15
  unlinkAsset: true,
16
16
  update: true,
17
+ getMeasures: true,
18
+ exportMeasures: true,
17
19
  },
18
20
  },
19
21
  "device-manager/models": {
@@ -22,6 +24,7 @@ import { KuzzleRole } from "../../shared/types/KuzzleRole";
22
24
  listDevices: true,
23
25
  getDevice: true,
24
26
  writeDevice: true,
27
+ listMeasures: true,
25
28
  },
26
29
  },
27
30
  */
@@ -9,12 +9,15 @@ import { KuzzleRole } from "../../shared/types/KuzzleRole";
9
9
  actions: {
10
10
  get: true,
11
11
  search: true,
12
+ getMeasures: true,
13
+ exportMeasures: true,
12
14
  },
13
15
  },
14
16
  "device-manager/models": {
15
17
  actions: {
16
18
  listDevices: true,
17
19
  getDevice: true,
20
+ listMeasures: true,
18
21
  },
19
22
  },
20
23
  }
@@ -130,6 +130,26 @@ export type ApiDeviceGetMeasuresResult = {
130
130
  measures: Array<KDocument<MeasureContent<JSONObject>>>;
131
131
  total: number;
132
132
  };
133
+ /**
134
+ * This action can be used only with WebSocket or POST
135
+ *
136
+ * Then the export can be download using HTTP Get and the following route:
137
+ * `/_/device-manager/:engineId/devices/:_id/measures/_export/:exportId`
138
+ */
139
+ export interface ApiDeviceExportMeasuresRequest extends DevicesControllerRequest {
140
+ action: "exportMeasures";
141
+ _id: string;
142
+ startAt?: string;
143
+ endAt?: string;
144
+ type?: string;
145
+ body?: {
146
+ query?: JSONObject;
147
+ sort?: JSONObject;
148
+ };
149
+ }
150
+ export type ApiDeviceExportMeasuresResult = {
151
+ link: string;
152
+ };
133
153
  export interface ApiDeviceReceiveMeasuresRequest<TMeasureValues extends JSONObject = JSONObject> extends DevicesControllerRequest {
134
154
  action: "receiveMeasures";
135
155
  _id: string;
@@ -0,0 +1,61 @@
1
+ /// <reference types="node" />
2
+ import { PassThrough } from "node:stream";
3
+ import { JSONObject, User } from "kuzzle";
4
+ import { DeviceManagerPlugin } from "../plugin";
5
+ import { MeasureContent } from "./exports";
6
+ type ExportOptions = {
7
+ sort?: JSONObject;
8
+ query?: JSONObject;
9
+ from?: number;
10
+ size?: number;
11
+ startAt?: string;
12
+ endAt?: string;
13
+ type?: string;
14
+ };
15
+ type ExportParams = {
16
+ query: JSONObject;
17
+ target: "asset" | "device";
18
+ model: string;
19
+ sort: JSONObject;
20
+ id: string;
21
+ };
22
+ export declare class MeasureExporter {
23
+ private plugin;
24
+ private engineId;
25
+ private target?;
26
+ private get sdk();
27
+ constructor(plugin: DeviceManagerPlugin, engineId: string, { target }?: {
28
+ target?: "asset" | "device";
29
+ });
30
+ /**
31
+ * Searches for measures and return them in a standard JSON
32
+ */
33
+ search(digitalTwinId: string, { size, from, endAt, startAt, query, sort, type, }: ExportOptions): Promise<{
34
+ measures: import("kuzzle").KHit<MeasureContent<any, any>>[];
35
+ total: number;
36
+ }>;
37
+ /**
38
+ * Prepare a measure export by saving the parameters in Redis.
39
+ *
40
+ * We need this method to process the export in 2 steps:
41
+ * - preparing the export with a POST or WebSocket request
42
+ * - download the export (only with a browser <a> link)
43
+ *
44
+ * Never return a rejected promise and write potential error on the stream
45
+ */
46
+ prepareExport(user: User, digitalTwinId: string, { endAt, startAt, query, sort, type, }: ExportOptions): Promise<{
47
+ link: string;
48
+ }>;
49
+ /**
50
+ * Retrieve a prepared export and write each document as a CSV in the stream
51
+ *
52
+ * This method never returns a rejected promise, but write potential error in
53
+ * the stream.
54
+ */
55
+ sendExport(stream: PassThrough, exportId: string): Promise<void>;
56
+ getExport(exportId: string): Promise<ExportParams>;
57
+ private exportRedisKey;
58
+ private prepareMeasureSearch;
59
+ private getEngine;
60
+ }
61
+ export {};
@@ -1,6 +1,6 @@
1
1
  import { JSONObject, KDocument } from "kuzzle";
2
- import { DeviceManagerPlugin } from "../../core";
3
- import { DeviceContent } from "./../device";
2
+ import { DeviceContent } from "../device";
3
+ import { DeviceManagerPlugin } from "../plugin";
4
4
  import { Metadata } from "../shared";
5
5
  import { DecodedMeasurement } from "./types/MeasureContent";
6
6
  export declare class MeasureService {
@@ -20,12 +20,17 @@ export declare class MeasureService {
20
20
  *
21
21
  * This method represents the ingestion pipeline:
22
22
  * - build measures documents and update digital twins (device and asset)
23
- * - trigger events to enrich measures documents
23
+ * - trigger events `before` (measure enrichment)
24
24
  * - save documents (measures, device and asset)
25
- * - trigger events to trigger business rules
25
+ * - trigger events `after`
26
26
  */
27
27
  ingest(device: KDocument<DeviceContent>, measurements: DecodedMeasurement<JSONObject>[], metadata: Metadata, payloadUuids: string[]): Promise<void>;
28
28
  private updateDeviceMeasures;
29
+ /**
30
+ * Update asset with each non-null non-computed measures.
31
+ *
32
+ * @returns A map of each asset state by measuredAt timestamp.
33
+ */
29
34
  private updateAssetMeasures;
30
35
  /**
31
36
  * Build the measures documents to save
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Base mappings for the "measures" collection.
3
+ *
4
+ * Those mappings does not contains the `values` mappings and `asset.metadata` mappings.
5
+ */
1
6
  export declare const measuresMappings: {
2
7
  dynamic: string;
3
8
  properties: {
@@ -4,3 +4,4 @@ export * from "./types/MeasureDefinition";
4
4
  export * from "./measures";
5
5
  export * from "./roles/RoleMeasuresAdmin";
6
6
  export * from "./roles/RoleMeasuresReader";
7
+ export * from "./collections/measuresMappings";
@@ -7,3 +7,4 @@ export * from "./MeasureModule";
7
7
  export * from "./roles/RoleMeasuresAdmin";
8
8
  export * from "./roles/RoleMeasuresReader";
9
9
  export * from "./collections/getEmbeddedMeasureMappings";
10
+ export * from "./MeasureExporter";
@@ -1,5 +1,5 @@
1
1
  import { JSONObject, KDocument } from "kuzzle-sdk";
2
- import { DeviceManagerPlugin } from "../../core";
2
+ import { DeviceManagerPlugin } from "../plugin";
3
3
  import { AssetModelContent, DeviceModelContent, MeasureModelContent } from "./types/ModelContent";
4
4
  export declare class ModelService {
5
5
  private config;
@@ -1,7 +1,7 @@
1
1
  import { JSONObject } from "kuzzle-sdk";
2
- import { NamedMeasures } from "../../modules/decoder";
3
- import { MeasureDefinition } from "../../modules/measure";
4
- import { DeviceManagerPlugin } from "../DeviceManagerPlugin";
2
+ import { DeviceManagerPlugin } from "../plugin";
3
+ import { NamedMeasures } from "../decoder";
4
+ import { MeasureDefinition } from "../measure";
5
5
  export declare class ModelsRegister {
6
6
  private config;
7
7
  private context;
@@ -1,2 +1,5 @@
1
1
  import { CollectionMappings } from "kuzzle";
2
+ /**
3
+ * Mappings for models configuration documents
4
+ */
2
5
  export declare const modelsMappings: CollectionMappings;
@@ -5,3 +5,4 @@ export * from "./types/ModelDefinition";
5
5
  export * from "./types/ModelEvents";
6
6
  export * from "./ModelModule";
7
7
  export * from "./ModelSerializer";
8
+ export * from "./ModelsRegister";
@@ -1,8 +1,16 @@
1
1
  import { Backend, Plugin } from "kuzzle";
2
2
  import { AbstractEngine, ConfigManager } from "kuzzle-plugin-commons";
3
- import { DeviceManagerConfiguration } from "./DeviceManagerConfiguration";
3
+ import { EngineContent } from "kuzzle-plugin-commons/lib/engine/EngineContent";
4
+ import { DeviceManagerConfiguration } from "./types/DeviceManagerConfiguration";
4
5
  import { DeviceManagerPlugin } from "./DeviceManagerPlugin";
5
- import { InternalCollection } from "./InternalCollection";
6
+ import { InternalCollection } from "./types/InternalCollection";
7
+ export type AskEngineList = {
8
+ name: "ask:device-manager:engine:list";
9
+ payload: {
10
+ group: string | null;
11
+ };
12
+ result: EngineContent[];
13
+ };
6
14
  export type AskEngineUpdateAll = {
7
15
  name: "ask:device-manager:engine:updateAll";
8
16
  payload: void;
@@ -14,7 +22,7 @@ export declare class DeviceManagerEngine extends AbstractEngine<DeviceManagerPlu
14
22
  constructor(plugin: Plugin, adminConfigManager: ConfigManager, engineConfigManager: ConfigManager);
15
23
  updateEngines(): Promise<void>;
16
24
  onCreate(index: string, group?: string): Promise<{
17
- collections: string[];
25
+ collections: any[];
18
26
  }>;
19
27
  onUpdate(index: string, group?: string): Promise<{
20
28
  collections: any[];
@@ -1,8 +1,8 @@
1
1
  import { Plugin, PluginContext } from "kuzzle";
2
2
  import { JSONObject } from "kuzzle-sdk";
3
- import { MeasureDefinition } from "../modules/measure";
4
- import { AssetModelDefinition, DeviceModelDefinition } from "../modules/model";
5
- import { DeviceManagerConfiguration } from "./DeviceManagerConfiguration";
3
+ import { MeasureDefinition } from "../measure";
4
+ import { AssetModelDefinition, DeviceModelDefinition } from "../model";
5
+ import { DeviceManagerConfiguration } from "./types/DeviceManagerConfiguration";
6
6
  export declare class DeviceManagerPlugin extends Plugin {
7
7
  config: DeviceManagerConfiguration;
8
8
  private deviceManagerEngine;
@@ -0,0 +1,2 @@
1
+ export * from "./types/DeviceManagerConfiguration";
2
+ export * from "./DeviceManagerPlugin";
@@ -0,0 +1,4 @@
1
+ export * from "./types/DeviceManagerConfiguration";
2
+ export * from "./DeviceManagerEngine";
3
+ export * from "./DeviceManagerPlugin";
4
+ export * from "./types/InternalCollection";
@@ -1,4 +1,4 @@
1
- import { DeviceManagerPlugin } from "../../core/DeviceManagerPlugin";
1
+ import { DeviceManagerPlugin } from "../plugin/DeviceManagerPlugin";
2
2
  export declare abstract class Module {
3
3
  protected plugin: DeviceManagerPlugin;
4
4
  protected get sdk(): import("kuzzle").EmbeddedSDK;
@@ -1,5 +1,6 @@
1
+ import { JSONObject } from "kuzzle-sdk";
1
2
  export type MetadataValue = boolean | number | string | {
2
3
  lat: number;
3
4
  lon: number;
4
- } | null;
5
+ } | null | JSONObject;
5
6
  export type Metadata = Record<string, MetadataValue | Record<string, MetadataValue>>;
@@ -9,6 +9,7 @@ export declare class DummyTempDecoder extends Decoder {
9
9
  readonly type: "battery";
10
10
  }];
11
11
  constructor();
12
- validate(payload: JSONObject): Promise<boolean>;
13
- decode(decodedPayload: DecodedPayload<DummyTempDecoder>, payload: JSONObject): Promise<DecodedPayload<DummyTempDecoder>>;
12
+ validate(rawPayload: JSONObject): Promise<boolean>;
13
+ decode(decodedPayload: DecodedPayload<DummyTempDecoder>, rawPayload: JSONObject): Promise<DecodedPayload<DummyTempDecoder>>;
14
+ decodeSimplePayload(decodedPayload: DecodedPayload<DummyTempDecoder>, payload: JSONObject): void;
14
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kuzzle-device-manager-types",
3
- "version": "2.1.4",
3
+ "version": "2.2.0",
4
4
  "description": "Shared types for Kuzzle Device Manager",
5
5
  "author": "The Kuzzle Team (support@kuzzle.io)",
6
6
  "types": "dist/index.d.ts",
@@ -1,2 +0,0 @@
1
- export * from "./DeviceManagerConfiguration";
2
- export * from "./DeviceManagerPlugin";
@@ -1,4 +0,0 @@
1
- export * from "./DeviceManagerConfiguration";
2
- export * from "./DeviceManagerEngine";
3
- export * from "./DeviceManagerPlugin";
4
- export * from "./InternalCollection";
@@ -1,42 +0,0 @@
1
- declare const _default: {
2
- "device-manager": {
3
- devices: ({
4
- model: string;
5
- reference: string;
6
- metadata: {};
7
- measures: {};
8
- } | {
9
- index: {
10
- _id: string;
11
- };
12
- })[];
13
- };
14
- "engine-ayse": {
15
- devices: ({
16
- model: string;
17
- reference: string;
18
- metadata: {};
19
- measures: {};
20
- engineId: string;
21
- assetId: any;
22
- } | {
23
- index: {
24
- _id: string;
25
- };
26
- })[];
27
- assets: ({
28
- model: string;
29
- reference: string;
30
- metadata: {
31
- weight: number;
32
- height: number;
33
- };
34
- linkedDevices: any[];
35
- } | {
36
- index: {
37
- _id: string;
38
- };
39
- })[];
40
- };
41
- };
42
- export default _default;
@@ -1,5 +0,0 @@
1
- import { Kuzzle } from "kuzzle-sdk";
2
- /**
3
- * Returns directly the document content
4
- */
5
- export declare function documentGet(sdk: Kuzzle, index: string, collection: string, id: string): Promise<import("kuzzle-sdk").KDocumentContentGeneric>;
@@ -1,4 +0,0 @@
1
- export * from "./sdk";
2
- export * from "./payloads";
3
- export * from "./document";
4
- export * from "./setup";
@@ -1,18 +0,0 @@
1
- import { JSONObject, Kuzzle } from "kuzzle-sdk";
2
- export type DummyTempPayload = {
3
- deviceEUI: string;
4
- temperature: number;
5
- measuredAt?: number;
6
- battery?: number;
7
- metadata?: JSONObject;
8
- };
9
- export type DummyTempPositionPayload = DummyTempPayload & {
10
- location: {
11
- lat: number;
12
- lon: number;
13
- accuracy?: number;
14
- };
15
- };
16
- export declare function sendDummyTempPayloads(sdk: Kuzzle, payloads: DummyTempPayload[]): Promise<void>;
17
- export declare function sendDummyTempPositionPayloads(sdk: Kuzzle, payloads: DummyTempPositionPayload[]): Promise<void>;
18
- export declare function sendPayloads(sdk: Kuzzle, action: string, payloads: JSONObject[]): Promise<any>;
@@ -1,2 +0,0 @@
1
- import { Kuzzle } from "kuzzle-sdk";
2
- export declare function useSdk(): Kuzzle;
@@ -1 +0,0 @@
1
- export declare function setupHooks(): import("kuzzle-sdk").Kuzzle;
@@ -1,3 +0,0 @@
1
- import { Kuzzle } from "kuzzle-sdk";
2
- export declare function truncateCollection(sdk: Kuzzle, index: string, collection: string): Promise<void>;
3
- export declare function beforeEachTruncateCollections(sdk: Kuzzle): Promise<void>;
@@ -1,2 +0,0 @@
1
- import { Kuzzle } from "kuzzle-sdk";
2
- export declare function beforeAllCreateEngines(sdk: Kuzzle): Promise<void>;
@@ -1,2 +0,0 @@
1
- import { Kuzzle } from "kuzzle-sdk";
2
- export declare function beforeEachLoadFixtures(sdk: Kuzzle): Promise<void>;
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};