kuzzle-device-manager-types 2.4.0-beta.6 → 2.4.0-beta.7

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,9 +1,7 @@
1
1
  import { DeviceManagerPlugin } from "../plugin";
2
+ import { BaseService } from "../shared";
2
3
  import { AssetHistoryContent, AssetHistoryEvent } from "./types/AssetHistoryContent";
3
- export declare class AssetHistoryService {
4
- private context;
5
- private config;
6
- private get sdk();
4
+ export declare class AssetHistoryService extends BaseService {
7
5
  constructor(plugin: DeviceManagerPlugin);
8
6
  add<TAssetHistoryEvent extends AssetHistoryEvent>(engineId: string, histories: AssetHistoryContent[]): Promise<void>;
9
7
  }
@@ -1,39 +1,22 @@
1
- import { User } from "kuzzle";
1
+ import { KuzzleRequest, User } from "kuzzle";
2
2
  import { JSONObject, KDocument, KHit, SearchResult, mReplaceResponse } from "kuzzle-sdk";
3
3
  import { DeviceManagerPlugin } from "../plugin";
4
- import { Metadata } from "../shared";
4
+ import { Metadata, BaseService, SearchParams } from "../shared";
5
5
  import { AssetHistoryService } from "./AssetHistoryService";
6
6
  import { AssetContent } from "./types/AssetContent";
7
7
  import { ApiAssetMigrateTenantResult } from "./types/AssetApi";
8
- export declare class AssetService {
9
- private context;
10
- private config;
8
+ export declare class AssetService extends BaseService {
11
9
  private assetHistoryService;
12
- private get sdk();
13
- private get app();
14
- private get impersonatedSdk();
15
10
  constructor(plugin: DeviceManagerPlugin, assetHistoryService: AssetHistoryService);
16
11
  registerAskEvents(): void;
17
- get(engineId: string, assetId: string): Promise<KDocument<AssetContent>>;
12
+ get(engineId: string, assetId: string, request: KuzzleRequest): Promise<KDocument<AssetContent>>;
18
13
  /**
19
14
  * Updates an asset metadata
20
15
  */
21
- update(user: User, engineId: string, assetId: string, metadata: Metadata, { refresh }: {
22
- refresh: any;
23
- }): Promise<KDocument<AssetContent>>;
24
- create(user: User, engineId: string, model: string, reference: string, metadata: JSONObject, { refresh }: {
25
- refresh: any;
26
- }): Promise<KDocument<AssetContent>>;
27
- delete(user: User, engineId: string, assetId: string, { refresh, strict }: {
28
- refresh: any;
29
- strict: boolean;
30
- }): Promise<void>;
31
- search(engineId: string, searchBody: JSONObject, { from, size, scroll, lang, }: {
32
- from?: number;
33
- size?: number;
34
- scroll?: string;
35
- lang?: string;
36
- }): Promise<SearchResult<KHit<AssetContent>>>;
16
+ update(engineId: string, assetId: string, metadata: Metadata, request: KuzzleRequest): Promise<KDocument<AssetContent>>;
17
+ create(engineId: string, model: string, reference: string, metadata: JSONObject, request: KuzzleRequest): Promise<KDocument<AssetContent>>;
18
+ delete(engineId: string, assetId: string, request: KuzzleRequest): Promise<void>;
19
+ search(engineId: string, searchParams: SearchParams, request: KuzzleRequest): Promise<SearchResult<KHit<AssetContent>>>;
37
20
  migrateTenant(user: User, assetsList: string[], engineId: string, newEngineId: string): Promise<ApiAssetMigrateTenantResult>;
38
21
  /**
39
22
  * Replace an asset metadata
@@ -49,4 +49,4 @@ export type AssetMeasureContext<TMetadata extends Metadata = Metadata> = {
49
49
  * Name of the measure for the Asset
50
50
  */
51
51
  measureName: string;
52
- } & Pick<AssetContent<JSONObject, TMetadata>, "model" | "reference" | "metadata">;
52
+ } & Pick<AssetContent<JSONObject, TMetadata>, "model" | "reference" | "metadata" | "groups">;
@@ -3,12 +3,9 @@ import { JSONObject, KDocument } from "kuzzle-sdk";
3
3
  import { DeviceManagerPlugin } from "../plugin";
4
4
  import { DeviceContent } from "../device";
5
5
  import { DecodedMeasurement } from "../measure";
6
+ import { BaseService } from "../shared";
6
7
  import { Decoder } from "./Decoder";
7
- export declare class PayloadService {
8
- private config;
9
- private context;
10
- private get sdk();
11
- private get app();
8
+ export declare class PayloadService extends BaseService {
12
9
  constructor(plugin: DeviceManagerPlugin);
13
10
  /**
14
11
  * Process a payload by validating and decode it with the `decoder` associated
@@ -1,17 +1,13 @@
1
- import { Plugin, User } from "kuzzle";
1
+ import { KuzzleRequest } from "kuzzle";
2
2
  import { JSONObject, KDocument, KHit, SearchResult } from "kuzzle-sdk";
3
3
  import { AssetContent } from "./../asset";
4
- import { Metadata } from "../shared";
4
+ import { DeviceManagerPlugin } from "../plugin";
5
+ import { Metadata, BaseService, SearchParams } from "../shared";
5
6
  import { DecodedMeasurement } from "../measure";
6
7
  import { DeviceContent } from "./types/DeviceContent";
7
8
  import { ApiDeviceLinkAssetRequest } from "./types/DeviceApi";
8
- export declare class DeviceService {
9
- private config;
10
- private context;
11
- private get sdk();
12
- private get app();
13
- private get impersonatedSdk();
14
- constructor(plugin: Plugin);
9
+ export declare class DeviceService extends BaseService {
10
+ constructor(plugin: DeviceManagerPlugin);
15
11
  registerAskEvents(): void;
16
12
  /**
17
13
  * Create a new device.
@@ -20,23 +16,11 @@ export declare class DeviceService {
20
16
  * method since in this case "engineId" is not really an engine ID but still
21
17
  * required as an argument (in part to check the tenant rights)
22
18
  */
23
- create(user: User, model: string, reference: string, metadata: JSONObject, { engineId, refresh, }?: {
24
- engineId?: string;
25
- refresh?: any;
26
- }): Promise<KDocument<DeviceContent>>;
27
- get(index: string, deviceId: string): Promise<KDocument<DeviceContent>>;
28
- update(user: User, engineId: string, deviceId: string, metadata: Metadata, { refresh }: {
29
- refresh: any;
30
- }): Promise<KDocument<DeviceContent>>;
31
- delete(user: User, engineId: string, deviceId: string, { refresh }: {
32
- refresh: any;
33
- }): Promise<void>;
34
- search(engineId: string, searchBody: JSONObject, { from, size, scroll, lang, }: {
35
- from?: number;
36
- size?: number;
37
- scroll?: string;
38
- lang?: string;
39
- }): Promise<SearchResult<KHit<DeviceContent>>>;
19
+ create(model: string, reference: string, metadata: JSONObject, request: KuzzleRequest): Promise<KDocument<DeviceContent>>;
20
+ get(engineId: string, deviceId: string, request: KuzzleRequest): Promise<KDocument<DeviceContent>>;
21
+ update(engineId: string, deviceId: string, metadata: Metadata, request: KuzzleRequest): Promise<KDocument<DeviceContent>>;
22
+ delete(engineId: string, deviceId: string, request: KuzzleRequest): Promise<void>;
23
+ search(engineId: string, searchParams: SearchParams, request: KuzzleRequest): Promise<SearchResult<KHit<DeviceContent>>>;
40
24
  /**
41
25
  * Attach the device to an engine
42
26
  *
@@ -45,29 +29,22 @@ export declare class DeviceService {
45
29
  * @param options.refresh Wait for ES indexation
46
30
  * @param options.strict If true, throw if an operation isn't possible
47
31
  */
48
- attachEngine(user: User, engineId: string, deviceId: string, { refresh }?: {
49
- refresh?: any;
50
- }): Promise<KDocument<DeviceContent>>;
32
+ attachEngine(engineId: string, deviceId: string, request: KuzzleRequest): Promise<KDocument<DeviceContent>>;
51
33
  /**
52
34
  * Detach a device from its attached engine
53
35
  *
54
- * @param deviceId Device id
55
- * @param options.refresh Wait for ES indexation
36
+ * @param {string} deviceId Id of the device
37
+ * @param {KuzzleRequest} request kuzzle request
56
38
  */
57
- detachEngine(user: User, deviceId: string, { refresh }?: {
58
- refresh?: any;
59
- }): Promise<KDocument<DeviceContent>>;
39
+ detachEngine(deviceId: string, request: KuzzleRequest): Promise<KDocument<DeviceContent>>;
60
40
  /**
61
41
  * Link a device to an asset.
62
42
  */
63
- linkAsset(user: User, engineId: string, deviceId: string, assetId: string, measureNames: ApiDeviceLinkAssetRequest["body"]["measureNames"], { refresh, implicitMeasuresLinking, }?: {
64
- refresh?: any;
65
- implicitMeasuresLinking?: boolean;
66
- }): Promise<{
43
+ linkAsset(engineId: string, deviceId: string, assetId: string, measureNames: ApiDeviceLinkAssetRequest["body"]["measureNames"], implicitMeasuresLinking: boolean, request: KuzzleRequest): Promise<{
67
44
  asset: KDocument<AssetContent>;
68
45
  device: KDocument<DeviceContent>;
69
46
  }>;
70
- receiveMeasures(engineId: string, deviceId: string, measures: DecodedMeasurement[], payloadUuids: string[]): Promise<void>;
47
+ receiveMeasures(engineId: string, deviceId: string, measures: DecodedMeasurement[], payloadUuids: string[], request: KuzzleRequest): Promise<void>;
71
48
  /**
72
49
  * Checks if the asset does not already have a linked device using one of the
73
50
  * requested measure names.
@@ -83,12 +60,10 @@ export declare class DeviceService {
83
60
  /**
84
61
  * Unlink a device of an asset
85
62
  *
86
- * @param deviceId Id of the device
87
- * @param options.refresh Wait for ES indexation
63
+ * @param {string} deviceId Id of the device
64
+ * @param {KuzzleRequest} request kuzzle request
88
65
  */
89
- unlinkAsset(user: User, deviceId: string, { refresh }?: {
90
- refresh?: any;
91
- }): Promise<{
66
+ unlinkAsset(deviceId: string, request: KuzzleRequest): Promise<{
92
67
  asset: KDocument<AssetContent>;
93
68
  device: KDocument<DeviceContent>;
94
69
  }>;
@@ -1,51 +1,7 @@
1
+ import { CollectionMappings } from "kuzzle";
1
2
  /**
2
3
  * Base mappings for the "devices" collection.
3
4
  *
4
5
  * Those mappings does not contains the `measures` and `metadata` mappings.
5
6
  */
6
- export declare const devicesMappings: {
7
- dynamic: string;
8
- properties: {
9
- model: {
10
- type: string;
11
- fields: {
12
- text: {
13
- type: string;
14
- };
15
- };
16
- };
17
- reference: {
18
- type: string;
19
- fields: {
20
- text: {
21
- type: string;
22
- };
23
- };
24
- };
25
- assetId: {
26
- type: string;
27
- fields: {
28
- text: {
29
- type: string;
30
- };
31
- };
32
- };
33
- engineId: {
34
- type: string;
35
- fields: {
36
- text: {
37
- type: string;
38
- };
39
- };
40
- };
41
- metadata: {
42
- properties: {};
43
- };
44
- measures: {
45
- properties: {};
46
- };
47
- lastMeasuredAt: {
48
- type: string;
49
- };
50
- };
51
- };
7
+ export declare const devicesMappings: CollectionMappings;
@@ -1,13 +1,9 @@
1
1
  import { JSONObject, KDocument } from "kuzzle";
2
2
  import { DeviceContent } from "../device";
3
3
  import { DeviceManagerPlugin } from "../plugin";
4
- import { Metadata } from "../shared";
4
+ import { BaseService, Metadata } from "../shared";
5
5
  import { DecodedMeasurement } from "./types/MeasureContent";
6
- export declare class MeasureService {
7
- private config;
8
- private context;
9
- private get sdk();
10
- private get app();
6
+ export declare class MeasureService extends BaseService {
11
7
  constructor(plugin: DeviceManagerPlugin);
12
8
  /**
13
9
  * Register new measures from a device, updates :
@@ -35,6 +35,21 @@ export declare const measuresMappings: {
35
35
  metadata: {
36
36
  properties: {};
37
37
  };
38
+ groups: {
39
+ properties: {
40
+ id: {
41
+ type: string;
42
+ fields: {
43
+ text: {
44
+ type: string;
45
+ };
46
+ };
47
+ };
48
+ date: {
49
+ type: string;
50
+ };
51
+ };
52
+ };
38
53
  };
39
54
  };
40
55
  /**
@@ -1,10 +1,8 @@
1
1
  import { JSONObject, KDocument } from "kuzzle-sdk";
2
2
  import { DeviceManagerPlugin } from "../plugin";
3
+ import { BaseService } from "../shared";
3
4
  import { AssetModelContent, DeviceModelContent, MeasureModelContent } from "./types/ModelContent";
4
- export declare class ModelService {
5
- private config;
6
- private context;
7
- private get sdk();
5
+ export declare class ModelService extends BaseService {
8
6
  constructor(plugin: DeviceManagerPlugin);
9
7
  registerAskEvents(): void;
10
8
  writeAsset(engineGroup: string, model: string, metadataMappings: JSONObject, defaultMetadata: JSONObject, measures: AssetModelContent["asset"]["measures"]): Promise<KDocument<AssetModelContent>>;
@@ -1,2 +1,2 @@
1
- export * from "./types/DeviceManagerConfiguration";
1
+ export * from "./types/exports";
2
2
  export * from "./DeviceManagerPlugin";
@@ -1,4 +1,3 @@
1
- export * from "./types/DeviceManagerConfiguration";
1
+ export * from "./types";
2
2
  export * from "./DeviceManagerEngine";
3
3
  export * from "./DeviceManagerPlugin";
4
- export * from "./types/InternalCollection";
@@ -1,4 +1,4 @@
1
- import { JSONObject } from "kuzzle-sdk";
1
+ import { CollectionMappings, JSONObject } from "kuzzle-sdk";
2
2
  export type DeviceManagerConfiguration = {
3
3
  /**
4
4
  * Ignore errors at startup such as wrong mappings update.
@@ -45,5 +45,13 @@ export type DeviceManagerConfiguration = {
45
45
  mappings: JSONObject;
46
46
  settings: JSONObject;
47
47
  };
48
+ asset: {
49
+ name: string;
50
+ mappings: CollectionMappings;
51
+ };
52
+ device: {
53
+ name: string;
54
+ mappings: CollectionMappings;
55
+ };
48
56
  };
49
57
  };
@@ -0,0 +1,17 @@
1
+ import { JSONObject, KDocumentContent, KHit, KuzzleRequest } from "kuzzle";
2
+ export interface SearchQueryResult<T extends KDocumentContent> {
3
+ aggregations?: JSONObject;
4
+ hits: Array<KHit<T>>;
5
+ remaining: unknown;
6
+ scrollId: string;
7
+ suggest: JSONObject;
8
+ total: number;
9
+ }
10
+ export type EventGenericDocumentBeforeSearch = {
11
+ name: `generic:document:beforeSearch`;
12
+ args: [JSONObject, KuzzleRequest];
13
+ };
14
+ export type EventGenericDocumentAfterSearch<T extends KDocumentContent = KDocumentContent> = {
15
+ name: `generic:document:afterSearch`;
16
+ args: [SearchQueryResult<T>, KuzzleRequest];
17
+ };
@@ -0,0 +1 @@
1
+ export * from "./DeviceManagerConfiguration";
@@ -0,0 +1,3 @@
1
+ export * from "./DeviceManagerConfiguration";
2
+ export * from "./InternalCollection";
3
+ export * from "./Pipes";
@@ -0,0 +1,67 @@
1
+ import { ArgsDocumentControllerCreate, ArgsDocumentControllerDelete, ArgsDocumentControllerUpdate, Backend, EmbeddedSDK, KDocument, KDocumentContent, KHit, KuzzleRequest, SearchResult, User } from "kuzzle";
2
+ import { DeviceManagerPlugin, DeviceManagerConfiguration, InternalCollection } from "../../plugin";
3
+ interface PayloadRequest {
4
+ collection: InternalCollection;
5
+ engineId: string;
6
+ }
7
+ export type SearchParams = ReturnType<KuzzleRequest["getSearchParams"]>;
8
+ export declare abstract class BaseService {
9
+ private plugin;
10
+ constructor(plugin: DeviceManagerPlugin);
11
+ protected get app(): Backend;
12
+ protected get sdk(): EmbeddedSDK;
13
+ protected get config(): DeviceManagerConfiguration;
14
+ protected get impersonatedSdk(): (user: User) => EmbeddedSDK;
15
+ /**
16
+ * Wrapper to SDK create method with trigger generic:document events
17
+ *
18
+ * @param {KuzzleRequest} request
19
+ * @param {KDocument} documentId
20
+ * @param {PayloadRequest} payload
21
+ * @param {ArgsDocumentControllerCreate} [options]
22
+ * @returns {Promise<KDocument>}
23
+ */
24
+ protected getDocument<T extends KDocumentContent = KDocumentContent>(request: KuzzleRequest, documentId: string, { engineId, collection }: PayloadRequest, options?: ArgsDocumentControllerCreate): Promise<KDocument<T>>;
25
+ /**
26
+ * Wrapper to SDK create method with trigger generic:document events
27
+ *
28
+ * @param {KuzzleRequest} request
29
+ * @param {KDocument} document
30
+ * @param {PayloadRequest} payload
31
+ * @param {ArgsDocumentControllerCreate} [options]
32
+ * @returns {Promise<KDocument>}
33
+ */
34
+ protected createDocument<T extends KDocumentContent = KDocumentContent>(request: KuzzleRequest, document: KDocument<T>, { engineId, collection }: PayloadRequest, options?: ArgsDocumentControllerCreate): Promise<KDocument<T>>;
35
+ /**
36
+ * Wrapper to SDK update method with trigger generic:document events
37
+ *
38
+ * @param {KuzzleRequest} request
39
+ * @param {KDocument} document
40
+ * @param {PayloadRequest} payload
41
+ * @param {ArgsDocumentControllerUpdate} [options]
42
+ * @returns {Promise<KDocument>}
43
+ */
44
+ protected updateDocument<T extends KDocumentContent = KDocumentContent>(request: KuzzleRequest, document: KDocument<Partial<T>>, { engineId, collection }: PayloadRequest, options?: ArgsDocumentControllerUpdate): Promise<KDocument<T>>;
45
+ /**
46
+ * Wrapper to SDK delete method with trigger generic:document events
47
+ *
48
+ * @param {KuzzleRequest} request
49
+ * @param {string} documentId
50
+ * @param {ArgsDocumentControllerUpdate} [options]
51
+ * @returns {Promise<{ _id: string }>}
52
+ */
53
+ protected deleteDocument(request: KuzzleRequest, documentId: string, { engineId, collection }: PayloadRequest, options?: ArgsDocumentControllerDelete): Promise<{
54
+ _id: string;
55
+ }>;
56
+ /**
57
+ * Wrapper to SDK search method with trigger generic:document events
58
+ * ! Caution the pipes are not applied on next()
59
+ *
60
+ * @param {KuzzleRequest} request
61
+ * @param {string} documentId
62
+ * @param {ArgsDocumentControllerUpdate} [options]
63
+ * @returns {Promise<{ _id: string }>}
64
+ */
65
+ protected searchDocument<T extends KDocumentContent = KDocumentContent>(request: KuzzleRequest, { from, size, scrollTTL: scroll }: SearchParams, { engineId, collection }: PayloadRequest): Promise<SearchResult<KHit<T>>>;
66
+ }
67
+ export {};
@@ -1,2 +1,3 @@
1
1
  export * from "./AbstractExporter";
2
+ export * from "./BaseService";
2
3
  export * from "./DigitalTwinExporter";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kuzzle-device-manager-types",
3
- "version": "2.4.0-beta.6",
3
+ "version": "2.4.0-beta.7",
4
4
  "description": "Shared types for Kuzzle Device Manager",
5
5
  "author": "The Kuzzle Team (support@kuzzle.io)",
6
6
  "main": "index.js",