summaryrefslogtreecommitdiff
path: root/packages/frontend/src/scripts/aiscript/common.ts
diff options
context:
space:
mode:
authorTake-John <takejohn@takejohn.jp>2025-01-07 21:28:48 +0900
committerGitHub <noreply@github.com>2025-01-07 12:28:48 +0000
commitbbe80af1dde195ff0ac6713db967b556acebb30c (patch)
tree075a07368d678125cc0fd0327271823102e3e332 /packages/frontend/src/scripts/aiscript/common.ts
parentfix(frontend): frontend / frontend-embedにあるtsconfig.jsonのmoduleをES2... (diff)
downloadsharkey-bbe80af1dde195ff0ac6713db967b556acebb30c.tar.gz
sharkey-bbe80af1dde195ff0ac6713db967b556acebb30c.tar.bz2
sharkey-bbe80af1dde195ff0ac6713db967b556acebb30c.zip
Fix: aiscriptディレクトリ内の型エラー解消と単体テスト (#15191)
* AiScript APIの型エラーに対処 * AiScript UI APIのテスト作成 * onInputなどがPromiseを返すように * AiScript共通APIのテスト作成 * CHANGELOG記載 * 定数のテストをconcurrentに * vi.mockを使用 * misskeyApiをmisskeyApiUntypedのエイリアスとする * 期待されるエラーメッセージを修正 * Mk:removeのテスト * misskeyApiの型を変更
Diffstat (limited to 'packages/frontend/src/scripts/aiscript/common.ts')
-rw-r--r--packages/frontend/src/scripts/aiscript/common.ts15
1 files changed, 15 insertions, 0 deletions
diff --git a/packages/frontend/src/scripts/aiscript/common.ts b/packages/frontend/src/scripts/aiscript/common.ts
new file mode 100644
index 0000000000..de6fa1d633
--- /dev/null
+++ b/packages/frontend/src/scripts/aiscript/common.ts
@@ -0,0 +1,15 @@
+/*
+ * SPDX-FileCopyrightText: syuilo and misskey-project
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+import { errors, utils, type values } from '@syuilo/aiscript';
+
+export function assertStringAndIsIn<A extends readonly string[]>(value: values.Value | undefined, expects: A): asserts value is values.VStr & { value: A[number] } {
+ utils.assertString(value);
+ const str = value.value;
+ if (!expects.includes(str)) {
+ const expected = expects.map((expect) => `"${expect}"`).join(', ');
+ throw new errors.AiScriptRuntimeError(`"${value.value}" is not in ${expected}`);
+ }
+}