From bde181e0931eef5bf23e00eea7c6d7c0c7f0eec6 Mon Sep 17 00:00:00 2001 From: Mateus Cardoso Date: Wed, 12 Jul 2023 17:33:02 -0300 Subject: [PATCH 1/2] Improvere the interface of the Actions class --- src/modules/Resources/actions.types.ts | 51 ++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/src/modules/Resources/actions.types.ts b/src/modules/Resources/actions.types.ts index 1daa1b6d0..559a9cb71 100644 --- a/src/modules/Resources/actions.types.ts +++ b/src/modules/Resources/actions.types.ts @@ -1,10 +1,10 @@ -import { GenericID, Conditionals, TagsObj, Query, ExpireTimeOption } from "../../common/common.types"; +import { Conditionals, ExpireTimeOption, GenericID, Query, TagsObj } from "../../common/common.types"; type ActionType = "condition" | "resource" | "interval" | "schedule" | "mqtt_topic"; type ActionTypeParams = | { - script: GenericID[]; + script: string | string[]; type: "script"; } | { @@ -34,17 +34,41 @@ type ActionTypeParams = payload: string; topic: string; type: "mqtt"; + qos?: number; + retain?: boolean; } | { headers: {}; + fallback_token?: string | null | undefined; type: "post"; url: string; + } + | { + type: "insert_bucket"; + } + | { + type: "tcore"; + tcore_id: string; + device_token: string; + } + | { + type: "tcore"; + device_token: string; + tcore_cluster_id: string; }; type ActionTriggerType = | { resource: "device" | "bucket" | "file" | "analysis" | "action" | "am" | "user" | "financial" | "profile"; - when: "create" | "update" | "delete"; + when: + | "create" + | "update" + | "delete" + | "mqtt_connect" + | "mqtt_disconnect" + | "login_success" + | "login_fail" + | "chunk_copied"; tag_key: string; tag_value: string; } @@ -63,6 +87,25 @@ type ActionTriggerType = second_value?: string; value_type: "string" | "number" | "boolean" | "*"; unlock?: boolean; + } + | { + variable: string; + is: Conditionals; + value: string; + second_value?: string; + value_type: "string" | "number" | "boolean" | "*"; + unlock?: boolean; + tag_key: string; + tag_value: string; + } + | { + device: string; + topic: string; + } + | { + tag_key: string; + tag_value: string; + topic: string; }; interface ActionCreateInfo { @@ -85,7 +128,7 @@ interface ActionCreateInfo { /** * Description of the action. */ - description?: string | null; + description?: string | null | undefined; lock?: boolean; /** * Type of action From f7959506a9bee2c46f3fe16cbe59a8e6567b0ffd Mon Sep 17 00:00:00 2001 From: Mateus Cardoso Date: Fri, 18 Aug 2023 16:58:27 -0300 Subject: [PATCH 2/2] Code review fixes --- src/modules/Resources/actions.types.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/modules/Resources/actions.types.ts b/src/modules/Resources/actions.types.ts index 559a9cb71..1c95e2f63 100644 --- a/src/modules/Resources/actions.types.ts +++ b/src/modules/Resources/actions.types.ts @@ -4,7 +4,7 @@ type ActionType = "condition" | "resource" | "interval" | "schedule" | "mqtt_top type ActionTypeParams = | { - script: string | string[]; + script: GenericID | GenericID[]; type: "script"; } | { @@ -34,12 +34,12 @@ type ActionTypeParams = payload: string; topic: string; type: "mqtt"; - qos?: number; + qos?: 1 | 2 | 3; retain?: boolean; } | { - headers: {}; - fallback_token?: string | null | undefined; + headers: Record; + fallback_token?: string; type: "post"; url: string; } @@ -48,7 +48,7 @@ type ActionTypeParams = } | { type: "tcore"; - tcore_id: string; + tcore_id: GenericID; device_token: string; } | { @@ -128,7 +128,7 @@ interface ActionCreateInfo { /** * Description of the action. */ - description?: string | null | undefined; + description?: string; lock?: boolean; /** * Type of action