mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-03-21 03:30:42 +00:00
* fix: aiscript 1.0.0 以外が全部レガシー扱いになる問題を修正 (MisskeyIO#1129) * Update Changelog --------- Co-authored-by: あわわわとーにゅ <17376330+u1-liquid@users.noreply.github.com>
24 lines
920 B
TypeScript
24 lines
920 B
TypeScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import { errors, utils } from '@syuilo/aiscript';
|
|
import type { values } from '@syuilo/aiscript';
|
|
|
|
const extractVersionIdentifier = /^\/\/\/\s*@\s*(\d+)\.(\d+)\.\d+$/m;
|
|
|
|
export function getAiScriptVersion(script: string): { major: number; minor: number } | undefined {
|
|
const match = extractVersionIdentifier.exec(script);
|
|
return match ? { major: Number(match[1]), minor: Number(match[2]) } : undefined;
|
|
}
|
|
|
|
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}`);
|
|
}
|
|
}
|