Morit Script 레퍼런스
Morit Script는 Runtime v3 화면에서 API 응답을 화면용 데이터로 바꾸는 작은 순수 함수 언어입니다.
logic/*.morit 파일에 작성하고, SDK가 build할 때 AST로 컴파일해 패키지에 넣습니다. Host와 서버는
컴파일된 AST만 실행하며 파일·네트워크·credential·프로세스에 접근할 수 없습니다.
이 문서는 @morit/cli의 SDK 파서(morit-script.js)와 런타임(script-runtime.js) 기준입니다.
모듈 선언, computed_state, data source transform 연결은
Runtime v3와 Morit Script를 참고하세요.
예제
function cleanMenu(items) {
return items.map(item => html.toText(item)).filter(item => item != "");
}
export function normalizeDay(input) {
const days = input.days.map(day => ({
date: day.date,
lessons: day.lessons.map(lesson => ({
period: lesson.period,
label: string.from(lesson.period) + "교시"
})),
meals: day.meals.map(meal => ({ name: meal.name, menu: cleanMenu(meal.menu) }))
}));
return {days: days, lessonCount: days.reduce((count, day) => count + day.lessons.length, 0)};
}
export한 함수만 manifest의 logic_modules[].exports와 data source transform에서 부를 수 있고,
각 export에는 input_schema와 output_schema를 선언합니다.
문법
연산자는 우선순위가 낮은 것부터 ??, ||, &&, == != === !==, < > <= >=, + -, * / %이고,
단항 연산자는 !, -, +입니다.
배열 메서드는 items.map(fn), items.filter(fn), items.reduce(fn, initial) 세 가지입니다.
사용할 수 없는 것
while, class, new, this, async, await, delete, import, require, eval,
Function, globalThis, process, __proto__, prototype, constructor는 예약어로 거부됩니다.
재귀 호출, 네트워크·파일·환경변수·난수·현재 시각 접근도 없습니다. 시각이 필요하면 화면
식에서 runtime.now·runtime.today를 계산해 인자로 넘깁니다.
내장 함수
date.*는 YYYY-MM-DD 또는 시간대가 있는 ISO 시각만 받습니다. 타입이 맞지 않거나 목록에 없는
함수를 부르면 실행 오류(TYPE, DATE, FUNCTION)가 됩니다.
한도
컴파일된 manifest는 모듈 소스와 AST를 함께 담고 256 KiB 설치 한도를 넘을 수 없습니다. AST는
소스보다 훨씬 크므로(예제 기준 약 18배) 실제로 쓸 수 있는 소스 크기는 위 한도보다 작습니다.
morit plugin validate가 한도 초과를 build 전에 알려 줍니다.
테스트
npx -y @morit/cli plugin runtime-test . --module school --export normalizeDay \
--fixture fixtures/day.json --now 2026-09-15T16:00:00Z --timezone Asia/Seoul --json
fixture 파일은 패키지에 포함되지 않습니다. 완성된 예제는 Runtime v3 예제를 참고하세요.