開発中の機能
コード管理
SDK
defineAction

defineAction

アクションを定義する関数です。typeフィールドで種別を指定し、種別に応じたフィールドを設定します。

typeによって設定できるフィールドが型で絞り込まれるため、存在しないフィールドを指定するとTypeScriptのコンパイルエラーになります。

以下の設定項目はコード管理の対象外です。これらはベースマキナの管理画面から設定してください。

  • 結果の加工(加工スクリプト、ページネーション)
  • 環境ごとの有効/無効
  • 環境ごとのバージョン

共通フィールド

すべてのアクション種別で使用できるフィールドです。

フィールド必須説明
idstringはいアクションの識別子(ベースマキナ上の識別子に対応。内部IDとは異なる)
namestringはいアクション名
descriptionstringいいえ説明
parametersParameterDefinition[]いいえパラメーター定義
restrictedbooleanいいえ実行権限を制限するか
permissionsPermissionTarget[]いいえ実行権限の対象(restricted: trueの場合に必要)
preferJobExecutionbooleanいいえジョブ実行を優先的に表示するか
reviewSettingIdstringいいえレビュー設定の識別子
notificationSettingsNotificationSettingsConfigいいえ通知設定

gRPCアクション

import { defineAction } from "@basemachina/sdk";
 
export const fetchOrders = defineAction({
  id: "fetch-orders",
  name: "注文一覧取得",
  type: "grpc",
  datasource: "orders-service",
  fullyQualifiedMethodName: "orders.OrderService/ListOrders",
  parameters: [{ name: "customerId", type: "TEXT", required: true }],
});
フィールド必須説明
type"grpc"はいgRPCアクションを指定
datasourcestringはいデータソースの識別子
fullyQualifiedMethodNamestringはいgRPCメソッドの完全修飾名
headers{ name: string; value: string }[]いいえリクエストヘッダー
body{ payload: string }いいえリクエストボディ

JavaScriptアクション

import { defineAction, readFile } from "@basemachina/sdk";
 
export const createUser = defineAction({
  id: "create-user",
  name: "ユーザー作成",
  type: "javascript_server",
  code: readFile("./js-action-codes/create-user.ts"),
  parameters: [
    { name: "email", type: "TEXT", required: true },
    { name: "age", type: "NUMBER", required: true },
  ],
});
フィールド必須説明
type"javascript_server"はいJavaScriptアクションを指定
codestringはいJavaScriptコードまたはreadFile()の戻り値

パラメーター定義

パラメーターはtypeフィールドで種別を指定します。

TEXTパラメーター

{
  name: "email",
  type: "TEXT",
  required: true,
  defaultValue: "example@example.com",
  minLength: 1,
  maxLength: 255,
  multiline: false,
  regexpValidation: "^[\\w.+-]+@[\\w-]+\\.[\\w.]+$",
  regexErrorMessage: "メールアドレスの形式で入力してください",
}
フィールド必須説明
type"TEXT"はいテキストパラメーターを指定
namestringはいパラメーター名
descriptionstringいいえ説明
requiredbooleanいいえ必須かどうか
defaultValuestringいいえデフォルト値
minLengthnumberいいえ最小文字数
maxLengthnumberいいえ最大文字数
multilinebooleanいいえ複数行入力を許可するか
regexpValidationstringいいえ入力値のバリデーション正規表現
regexErrorMessagestringいいえバリデーションエラー時のメッセージ
selectOptions{ label: string; value: string }[]いいえ選択肢

NUMBERパラメーター

{
  name: "age",
  type: "NUMBER",
  required: true,
  min: 0,
  max: 150,
}
フィールド必須説明
type"NUMBER"はい数値パラメーターを指定
namestringはいパラメーター名
descriptionstringいいえ説明
requiredbooleanいいえ必須かどうか
defaultValuenumberいいえデフォルト値
minnumberいいえ最小値
maxnumberいいえ最大値
selectOptions{ label: string; value: number }[]いいえ選択肢