kuzzle-device-manager-types 2.3.2 → 2.4.0-beta.1-2

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.
@@ -1,4 +1,4 @@
1
- import { ControllerDefinition, HttpStream, KuzzleRequest } from "kuzzle";
1
+ import { ControllerDefinition, KuzzleRequest } from "kuzzle";
2
2
  import { DeviceManagerPlugin } from "../plugin";
3
3
  import { AssetService } from "./AssetService";
4
4
  import { ApiAssetCreateResult, ApiAssetDeleteResult, ApiAssetGetMeasuresResult, ApiAssetGetResult, ApiAssetSearchResult, ApiAssetUpdateResult } from "./types/AssetApi";
@@ -6,6 +6,8 @@ export declare class AssetsController {
6
6
  private plugin;
7
7
  private assetService;
8
8
  definition: ControllerDefinition;
9
+ private exporter;
10
+ private measureExporter;
9
11
  constructor(plugin: DeviceManagerPlugin, assetService: AssetService);
10
12
  get(request: KuzzleRequest): Promise<ApiAssetGetResult>;
11
13
  update(request: KuzzleRequest): Promise<ApiAssetUpdateResult>;
@@ -13,7 +15,6 @@ export declare class AssetsController {
13
15
  delete(request: KuzzleRequest): Promise<ApiAssetDeleteResult>;
14
16
  search(request: KuzzleRequest): Promise<ApiAssetSearchResult>;
15
17
  getMeasures(request: KuzzleRequest): Promise<ApiAssetGetMeasuresResult>;
16
- exportMeasures(request: KuzzleRequest): Promise<HttpStream | {
17
- link: string;
18
- }>;
18
+ exportMeasures(request: KuzzleRequest): Promise<any>;
19
+ export(request: KuzzleRequest): Promise<any>;
19
20
  }
@@ -54,6 +54,7 @@ export interface ApiAssetGetMeasuresRequest extends AssetsControllerRequest {
54
54
  startAt?: string;
55
55
  endAt?: string;
56
56
  type?: string;
57
+ lang?: "koncorde" | "elasticsearch";
57
58
  body?: {
58
59
  query?: JSONObject;
59
60
  sort?: JSONObject;
@@ -75,6 +76,7 @@ export interface ApiAssetExportMeasuresRequest extends AssetsControllerRequest {
75
76
  startAt?: string;
76
77
  endAt?: string;
77
78
  type?: string;
79
+ lang?: "koncorde" | "elasticsearch";
78
80
  body?: {
79
81
  query?: JSONObject;
80
82
  sort?: JSONObject;
@@ -83,4 +85,15 @@ export interface ApiAssetExportMeasuresRequest extends AssetsControllerRequest {
83
85
  export type ApiAssetExportMeasuresResult = {
84
86
  link: string;
85
87
  };
88
+ export interface ApiAssetExportRequest extends AssetsControllerRequest {
89
+ action: "export";
90
+ lang?: "koncorde" | "elasticsearch";
91
+ body?: {
92
+ query?: JSONObject;
93
+ sort?: JSONObject;
94
+ };
95
+ }
96
+ export type ApiAssetExportResult = {
97
+ link: string;
98
+ };
86
99
  export {};
@@ -1,4 +1,4 @@
1
- import { ControllerDefinition, HttpStream, KuzzleRequest } from "kuzzle";
1
+ import { ControllerDefinition, KuzzleRequest } from "kuzzle";
2
2
  import { DeviceManagerPlugin } from "../plugin";
3
3
  import { DeviceService } from "./DeviceService";
4
4
  import { ApiDeviceAttachEngineResult, ApiDeviceCreateResult, ApiDeviceDeleteResult, ApiDeviceDetachEngineResult, ApiDeviceGetResult, ApiDeviceLinkAssetResult, ApiDeviceSearchResult, ApiDeviceUnlinkAssetResult, ApiDeviceUpdateResult, ApiDeviceGetMeasuresResult } from "./types/DeviceApi";
@@ -6,6 +6,8 @@ export declare class DevicesController {
6
6
  private plugin;
7
7
  private deviceService;
8
8
  definition: ControllerDefinition;
9
+ private exporter;
10
+ private measureExporter;
9
11
  constructor(plugin: DeviceManagerPlugin, deviceService: DeviceService);
10
12
  get(request: KuzzleRequest): Promise<ApiDeviceGetResult>;
11
13
  update(request: KuzzleRequest): Promise<ApiDeviceUpdateResult>;
@@ -32,8 +34,7 @@ export declare class DevicesController {
32
34
  */
33
35
  unlinkAsset(request: KuzzleRequest): Promise<ApiDeviceUnlinkAssetResult>;
34
36
  getMeasures(request: KuzzleRequest): Promise<ApiDeviceGetMeasuresResult>;
35
- exportMeasures(request: KuzzleRequest): Promise<HttpStream | {
36
- link: string;
37
- }>;
37
+ exportMeasures(request: KuzzleRequest): Promise<any>;
38
38
  receiveMeasures(request: KuzzleRequest): Promise<void>;
39
+ export(request: KuzzleRequest): Promise<any>;
39
40
  }
@@ -44,5 +44,8 @@ export declare const devicesMappings: {
44
44
  measures: {
45
45
  properties: {};
46
46
  };
47
+ lastMeasuredAt: {
48
+ type: string;
49
+ };
47
50
  };
48
51
  };
@@ -121,6 +121,7 @@ export interface ApiDeviceGetMeasuresRequest extends DevicesControllerRequest {
121
121
  startAt?: string;
122
122
  endAt?: string;
123
123
  type?: string;
124
+ lang?: "koncorde" | "elasticsearch";
124
125
  body?: {
125
126
  query?: JSONObject;
126
127
  sort?: JSONObject;
@@ -142,6 +143,7 @@ export interface ApiDeviceExportMeasuresRequest extends DevicesControllerRequest
142
143
  startAt?: string;
143
144
  endAt?: string;
144
145
  type?: string;
146
+ lang?: "koncorde" | "elasticsearch";
145
147
  body?: {
146
148
  query?: JSONObject;
147
149
  sort?: JSONObject;
@@ -164,4 +166,15 @@ export interface ApiDeviceReceiveMeasuresRequest<TMeasureValues extends JSONObje
164
166
  };
165
167
  }
166
168
  export type ApiDeviceReceiveMeasuresResult = void;
169
+ export interface ApiDeviceExportRequest extends DevicesControllerRequest {
170
+ action: "export";
171
+ lang?: "koncorde" | "elasticsearch";
172
+ body?: {
173
+ query?: JSONObject;
174
+ sort?: JSONObject;
175
+ };
176
+ }
177
+ export type ApiDeviceExportResult = {
178
+ link: string;
179
+ };
167
180
  export {};
@@ -1,37 +1,31 @@
1
1
  /// <reference types="node" />
2
- import { PassThrough } from "node:stream";
3
- import { JSONObject, User } from "kuzzle";
4
- import { DeviceManagerPlugin } from "../plugin";
2
+ /// <reference types="node" />
3
+ import { UUID } from "node:crypto";
4
+ import { KHit, User } from "kuzzle";
5
+ import { AbstractExporter, Column, ExportParams } from "../shared";
5
6
  import { MeasureContent } from "./exports";
6
- type ExportOptions = {
7
- sort?: JSONObject;
8
- query?: JSONObject;
9
- from?: number;
10
- size?: number;
7
+ interface MeasureSearchParams extends ExportParams {
8
+ id: string;
9
+ type?: string;
11
10
  startAt?: string;
12
11
  endAt?: string;
13
- type?: string;
14
- };
15
- type ExportParams = {
16
- query: JSONObject;
17
- target: "asset" | "device";
18
- model: string;
19
- sort: JSONObject;
12
+ }
13
+ interface MeasuresSearchOptions {
14
+ from?: number;
15
+ size?: number;
16
+ }
17
+ interface MeasureExportParams extends ExportParams {
20
18
  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
- });
19
+ model: string;
20
+ }
21
+ export declare class MeasureExporter extends AbstractExporter<MeasureExportParams> {
22
+ protected exportRedisKey(engineId: string, exportId: string): string;
23
+ protected getLink(engineId: string, exportId: UUID, params: MeasureExportParams): string;
30
24
  /**
31
25
  * Searches for measures and return them in a standard JSON
32
26
  */
33
- search(digitalTwinId: string, { size, from, endAt, startAt, query, sort, type, }: ExportOptions): Promise<{
34
- measures: import("kuzzle").KHit<MeasureContent<any, any>>[];
27
+ search(engineId: string, params: MeasureSearchParams, options?: MeasuresSearchOptions): Promise<{
28
+ measures: KHit<MeasureContent<any, any>>[];
35
29
  total: number;
36
30
  }>;
37
31
  /**
@@ -43,20 +37,16 @@ export declare class MeasureExporter {
43
37
  *
44
38
  * Never return a rejected promise and write potential error on the stream
45
39
  */
46
- prepareExport(user: User, digitalTwinId: string, { endAt, startAt, query, sort, type, }: ExportOptions): Promise<{
47
- link: string;
48
- }>;
40
+ prepareExport(engineId: string, user: User, params: MeasureSearchParams): Promise<string>;
41
+ protected formatHit(columns: Column[], hit: KHit<MeasureContent>): any[];
49
42
  /**
50
43
  * Retrieve a prepared export and write each document as a CSV in the stream
51
44
  *
52
45
  * This method never returns a rejected promise, but write potential error in
53
46
  * the stream.
54
47
  */
55
- sendExport(stream: PassThrough, exportId: string): Promise<void>;
48
+ sendExport(engineId: string, exportId: string): Promise<import("stream").PassThrough>;
56
49
  private generateMeasureColumns;
57
- getExport(exportId: string): Promise<ExportParams>;
58
- private exportRedisKey;
59
50
  private prepareMeasureSearch;
60
- private getEngine;
61
51
  }
62
52
  export {};
@@ -1,3 +1,4 @@
1
+ export * from "./services";
1
2
  export * from "./Module";
2
3
  export * from "./types/DigitalTwinContent";
3
4
  export * from "./types/Metadata";
@@ -0,0 +1,53 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { UUID } from "node:crypto";
4
+ import { PassThrough, Readable } from "node:stream";
5
+ import { JSONObject, KDocumentContentGeneric, KHit, SearchResult, User } from "kuzzle";
6
+ import { EngineContent } from "kuzzle-plugin-commons";
7
+ import { DeviceManagerPlugin, InternalCollection } from "../../plugin";
8
+ export interface ExporterOption {
9
+ /**
10
+ * Expiration time of export in seconds before being invalid
11
+ */
12
+ expireTime: number;
13
+ }
14
+ export interface ExportParams {
15
+ query: JSONObject;
16
+ sort?: JSONObject;
17
+ lang?: "elasticsearch" | "koncorde";
18
+ }
19
+ export interface Column {
20
+ header: string;
21
+ path: string;
22
+ isMeasure?: boolean;
23
+ }
24
+ export declare abstract class AbstractExporter<P extends ExportParams = ExportParams> {
25
+ protected plugin: DeviceManagerPlugin;
26
+ protected target: InternalCollection;
27
+ protected config: ExporterOption;
28
+ constructor(plugin: DeviceManagerPlugin, target: InternalCollection, config?: Partial<ExporterOption>);
29
+ protected get sdk(): import("kuzzle").EmbeddedSDK;
30
+ protected get ms(): any;
31
+ protected get log(): {
32
+ debug: (message: any) => void;
33
+ error: (message: any) => void;
34
+ info: (message: any) => void;
35
+ silly: (message: any) => void;
36
+ verbose: (message: any) => void;
37
+ warn: (message: any) => void;
38
+ };
39
+ protected getEngine(engineId: string): Promise<EngineContent>;
40
+ protected abstract exportRedisKey(engineId: string, exportId: string): string;
41
+ protected abstract getLink(engineId: string, exportId: UUID, params: P): string;
42
+ /**
43
+ * Retrieve a prepared export and write each document as a CSV in the stream
44
+ *
45
+ * This method never returns a rejected promise, but write potential error in
46
+ * the stream.
47
+ */
48
+ abstract sendExport(engineId: string, exportId: string): Promise<Readable>;
49
+ prepareExport(engineId: string, user: User, params: P): Promise<string>;
50
+ protected formatHit(columns: Column[], hit: KHit<KDocumentContentGeneric>): string[];
51
+ getExport(engineId: string, exportId: string): Promise<P>;
52
+ getExportStream(request: SearchResult<KHit<KDocumentContentGeneric>>, columns: Column[]): Promise<PassThrough>;
53
+ }
@@ -0,0 +1,14 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { UUID } from "node:crypto";
4
+ import { AbstractExporter } from "./AbstractExporter";
5
+ export declare class DigitalTwinExporter extends AbstractExporter {
6
+ protected exportRedisKey(engineId: string, exportId: string): string;
7
+ protected getLink(engineId: string, exportId: UUID): string;
8
+ sendExport(engineId: string, exportId: string): Promise<import("stream").PassThrough>;
9
+ /**
10
+ * Get the deduplicated Named Measures get from models
11
+ */
12
+ private getNamedMeasures;
13
+ private generateMeasureColumns;
14
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./AbstractExporter";
2
+ export * from "./DigitalTwinExporter";
@@ -8,4 +8,5 @@ export interface DigitalTwinContent<TMeasures extends JSONObject = JSONObject, T
8
8
  measures: {
9
9
  [Property in keyof TMeasures]: EmbeddedMeasure<TMeasures[Property]> | null;
10
10
  };
11
+ lastMeasuredAt: number;
11
12
  }
@@ -0,0 +1,36 @@
1
+ import { JSONObject, Kuzzle } from "kuzzle-sdk";
2
+ type MeasureDated<T> = {
3
+ value: T;
4
+ measuredAt: number;
5
+ };
6
+ export type MeasureValue<T> = T | MeasureDated<T>;
7
+ export declare function isMeasureDated<T>(measure: MeasureValue<T>): measure is MeasureDated<T>;
8
+ export interface Location {
9
+ lat: number;
10
+ lon: number;
11
+ accuracy?: number;
12
+ }
13
+ export interface Acceleration {
14
+ x: number;
15
+ y: number;
16
+ z: number;
17
+ accuracy: number;
18
+ }
19
+ export type DummyTempSimplePayload = {
20
+ deviceEUI: string;
21
+ temperature: MeasureValue<number>;
22
+ measuredAt?: number;
23
+ battery?: MeasureValue<number>;
24
+ acceleration?: MeasureValue<Acceleration>;
25
+ metadata?: JSONObject;
26
+ };
27
+ export type DummyTempPayload = DummyTempSimplePayload | {
28
+ measurements: DummyTempSimplePayload[];
29
+ };
30
+ export type DummyTempPositionPayload = DummyTempPayload & {
31
+ location: MeasureValue<Location>;
32
+ };
33
+ export declare function sendDummyTempPayloads(sdk: Kuzzle, payloads: DummyTempPayload[]): Promise<void>;
34
+ export declare function sendDummyTempPositionPayloads(sdk: Kuzzle, payloads: DummyTempPositionPayload[]): Promise<void>;
35
+ export declare function sendPayloads(sdk: Kuzzle, action: string, payloads: JSONObject[]): Promise<any>;
36
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kuzzle-device-manager-types",
3
- "version": "2.3.2",
3
+ "version": "2.4.0-beta.1-2",
4
4
  "description": "Shared types for Kuzzle Device Manager",
5
5
  "author": "The Kuzzle Team (support@kuzzle.io)",
6
6
  "main": "index.js",
@@ -17,4 +17,4 @@
17
17
  "files": [
18
18
  "dist/**/*.d.ts"
19
19
  ]
20
- }
20
+ }