From ba5a73e43c46a7189a9e58dbe2160a857a487df1 Mon Sep 17 00:00:00 2001 From: Vitaly Kravtsov Date: Mon, 21 Oct 2024 20:03:04 +0600 Subject: [PATCH] feat(typescript): add task and workflow utility types --- .../types/task/SystemSendMessage.ts | 13 +++++++++ resources/sdk/typescript/types/task/index.ts | 28 +++++++++++++++++++ .../types/workflow/SystemCheckOutWorkflow.ts | 17 +++++++++++ .../sdk/typescript/types/workflow/index.ts | 10 +++++++ src/aidbox_sdk/generator/typescript.clj | 14 +++++----- 5 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 resources/sdk/typescript/types/task/SystemSendMessage.ts create mode 100644 resources/sdk/typescript/types/task/index.ts create mode 100644 resources/sdk/typescript/types/workflow/SystemCheckOutWorkflow.ts create mode 100644 resources/sdk/typescript/types/workflow/index.ts diff --git a/resources/sdk/typescript/types/task/SystemSendMessage.ts b/resources/sdk/typescript/types/task/SystemSendMessage.ts new file mode 100644 index 0000000..06f4b06 --- /dev/null +++ b/resources/sdk/typescript/types/task/SystemSendMessage.ts @@ -0,0 +1,13 @@ +export type SystemSendMessageParams = { + phone: string; + message: string; +}; + +export type SystemSendMessageResult = { + status: string; +}; + +export type SystemSendMessage = { + params?: SystemSendMessageParams; + result?: SystemSendMessageResult; +}; diff --git a/resources/sdk/typescript/types/task/index.ts b/resources/sdk/typescript/types/task/index.ts new file mode 100644 index 0000000..11edad1 --- /dev/null +++ b/resources/sdk/typescript/types/task/index.ts @@ -0,0 +1,28 @@ +import { SystemSendMessage } from "./SystemSendMessage"; + +type WaitTaskDuration = { + duration: { + hours: number; + minutes: number; + seconds: number; + }; + until?: never; +}; + +type WaitTaskUntil = { + duration?: never; + until: string; +}; + +export type TaskDefinitionsMap = { + "awf.task/wait": { + params: WaitTaskDuration | WaitTaskUntil; + result: Record; + }; + "system/SendMessage": SystemSendMessage; +}; + +export declare const TaskDefinitionsNameMap: Record< + keyof TaskDefinitionsMap, + string +>; diff --git a/resources/sdk/typescript/types/workflow/SystemCheckOutWorkflow.ts b/resources/sdk/typescript/types/workflow/SystemCheckOutWorkflow.ts new file mode 100644 index 0000000..724e063 --- /dev/null +++ b/resources/sdk/typescript/types/workflow/SystemCheckOutWorkflow.ts @@ -0,0 +1,17 @@ +export type SystemCheckOutWorkflowParams = { + clientId: string; +}; + +export type SystemCheckOutWorkflowResult = { + messageId?: string; +}; + +export type SystemCheckOutWorkflowError = { + message?: string; +}; + +export type SystemCheckOutWorkflow = { + params?: SystemCheckOutWorkflowParams; + result?: SystemCheckOutWorkflowResult; + error?: SystemCheckOutWorkflowError; +}; diff --git a/resources/sdk/typescript/types/workflow/index.ts b/resources/sdk/typescript/types/workflow/index.ts new file mode 100644 index 0000000..4d54e1f --- /dev/null +++ b/resources/sdk/typescript/types/workflow/index.ts @@ -0,0 +1,10 @@ +import { SystemCheckOutWorkflow } from "./SystemCheckOutWorkflow"; + +export type WorkflowDefinitionsMap = { + "system/CheckOutWorkflow": SystemCheckOutWorkflow; +}; + +export declare const WorkflowDefinitionsNameMap: Record< + keyof WorkflowDefinitionsMap, + string +>; diff --git a/src/aidbox_sdk/generator/typescript.clj b/src/aidbox_sdk/generator/typescript.clj index 4b5df4e..4e6577e 100644 --- a/src/aidbox_sdk/generator/typescript.clj +++ b/src/aidbox_sdk/generator/typescript.clj @@ -21,15 +21,13 @@ [x] (str/replace x #"[\.#]" "-")) -(defn datatypes-file-path [] - (io/file "datatypes.ts")) - (defn resource-file-path [ir-schema] - (io/file (package->directory (:package ir-schema)) + (io/file "types" + (package->directory (:package ir-schema)) (str (->pascal-case (:resource-name ir-schema)) ".ts"))) (defn search-param-filepath [ir-schema] - (io/file "search" (str (:name ir-schema) "SearchParameters.ts"))) + (io/file "types" "search" (str (:name ir-schema) "SearchParameters.ts"))) (defn ->lang-type [fhir-type] (case fhir-type @@ -250,12 +248,14 @@ (generator/prepare-sdk-files :typescript ["index.ts" "eslint.config.mjs" "http-client.ts" "package.json" - "package-lock.json" "tsconfig.json" "types/index.ts"])) + "package-lock.json" "tsconfig.json" "types/index.ts" + "types/workflow/SystemCheckOutWorkflow.ts" "types/workflow/index.ts" + "types/task/SystemSendMessage.ts" "types/task/index.ts"])) (generate-valuesets [_ vs-schemas] (->> vs-schemas (map (fn [[fhir-version schemas]] - {:path (io/file (package->directory fhir-version) "valuesets.ts") + {:path (io/file "types" (package->directory fhir-version) "valuesets.ts") :content (->> schemas (mapv (fn [vs]