Files
windmill/frontend/src/lib/scripts.ts
centdix ade94f965b feat(cli): add lint command (#7917)
* feat(yaml-validator)!: unify flow, schedule, and trigger validation

- replace FlowValidator with WindmillYamlValidator.validate(doc, target)

- generate schedule/trigger schemas from backend OpenAPI and OpenFlow refs

- add schedule/trigger/filename-target tests and update AI agent fixtures

- bump windmill-yaml-validator to 2.0.0

BREAKING CHANGE: FlowValidator and validateFlow() are replaced by WindmillYamlValidator.validate(doc, target).

* add lint command

* add deno-compat script and docs for local yaml-validator testing

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: make nullable fields pass yaml validation

Add nullable: true to static_asset_config and authentication_resource_path
in HttpTrigger schema. Post-process generated JSON schemas to add null to
enums with nullable: true (AJV doesn't handle OpenAPI 3.0 nullable + enum).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: add nullable to all Option<T> fields in trigger and schedule OpenAPI schemas

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(frontend): handle nullable fields from updated OpenAPI types

Add ?? undefined coalescing at assignment sites where generated types
now include | null from the OpenAPI nullable additions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(lint): show allowed values in enum validation errors

Instead of "must be equal to one of the allowed values", now shows
"must be one of: 'r', 'w', 'rw'" for enum validation failures.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: add nullable to Edit/New trigger and schedule OpenAPI schemas

Ensures create/update request body types accept null for the same
fields that GET response types return as nullable, enabling clean
round-tripping without type mismatches.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* use published package

* publish

* refactor(lint): remove unused --includes/--excludes/--extra-includes CLI options

These options were defined but never wired to the file filtering logic.
The lint command still respects includes/excludes from wmill.yaml via
mergeConfigWithConfigFile.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat(lint): handle additionalProperties errors and expand test coverage

Add formatting for AJV additionalProperties keyword to show the unknown
property name. Add unit tests for all formatValidationError branches and
integration tests for --json report shape, --fail-on-warn with mixed
files, non-existent directory, and enum error output.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* test: add realistic validator tests for schedules, triggers, and edge cases

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: add email trigger validation support

Add email trigger schema generation, validation, and linting. Email
triggers are no longer skipped with a warning — they are validated
like all other trigger types.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* chore(cli): bump windmill-yaml-validator to 1.1.1 (email trigger support)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* publish

* rm

* fix: address PR review feedback for lint command

- Add email to trigger kinds test loop instead of separate test
- Add email to ValidationTarget docs in README
- Type formatYamlDiagnostics param directly instead of unsafe cast
- Destructure json option before mergeConfigWithConfigFile for clarity

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat(cli): add --lint option to sync push command

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 16:41:04 +00:00

231 lines
5.6 KiB
TypeScript

import { get } from 'svelte/store'
import { base } from '$lib/base'
import type { Schema, SupportedLanguage } from './common'
import { FlowService, type Script, ScriptService, ScheduleService } from './gen'
import { workspaceStore } from './stores'
export function scriptLangToEditorLang(
lang:
| Script['language']
| 'bunnative'
| 'javascript'
| 'frontend'
| 'jsx'
| 'tsx'
| 'text'
| 'json'
| undefined
) {
if (lang == 'deno') {
return 'typescript'
} else if (lang == 'bun' || lang == 'bunnative' || lang == 'frontend' || lang == 'tsx') {
return 'typescript'
} else if (lang == 'nativets') {
return 'typescript'
} else if (lang == 'text') {
return 'text'
} else if (lang == 'javascript' || lang == 'jsx') {
return 'javascript'
} else if (lang == 'postgresql') {
return 'sql'
} else if (lang == 'mysql') {
return 'sql'
} else if (lang == 'bigquery') {
return 'sql'
} else if (lang == 'oracledb') {
return 'sql'
} else if (lang == 'snowflake') {
return 'sql'
} else if (lang == 'mssql') {
return 'sql'
} else if (lang == 'duckdb') {
return 'sql'
} else if (lang == 'python3') {
return 'python'
} else if (lang == 'bash') {
return 'shell'
} else if (lang == 'powershell') {
return 'powershell'
} else if (lang == 'php') {
return 'php'
} else if (lang == 'rust') {
return 'rust'
} else if (lang == 'graphql') {
return 'graphql'
} else if (lang == 'ansible') {
return 'yaml'
} else if (lang == 'csharp') {
return 'csharp'
} else if (lang == 'nu') {
return 'nu'
} else if (lang == 'java') {
return 'java'
// for related places search: ADD_NEW_LANG
} else if (lang == undefined) {
return 'typescript'
} else {
return lang
}
}
export function extToScriptLang(lang: string): 'bun' | 'python3' | undefined {
switch (lang) {
case 'ts':
return 'bun'
case 'py':
return 'python3'
}
return undefined
}
export type ScriptSchedule = {
summary: string | undefined
args: Record<string, any>
cron: string
timezone: string
enabled: boolean
}
// Load the schedule of a flow given its path and the workspace
export async function loadScriptSchedule(
path: string,
workspace: string
): Promise<ScriptSchedule | undefined> {
const existsSchedule = await ScheduleService.existsSchedule({
workspace,
path
})
if (!existsSchedule) {
return undefined
}
const schedule = await ScheduleService.getSchedule({
workspace,
path
})
return {
summary: schedule.summary ?? undefined,
enabled: schedule.enabled,
cron: schedule.schedule,
timezone: schedule.timezone,
args: schedule.args ?? {}
}
}
export async function loadSchemaFlow(path: string): Promise<Schema> {
const flow = await FlowService.getFlowByPath({
workspace: get(workspaceStore)!,
path: path ?? ''
})
return flow.schema as any
}
export function scriptPathToHref(path: string, hubBaseUrl: string): string {
if (path.startsWith('hub/')) {
return hubBaseUrl + '/from_version/' + path.substring(4)
} else {
return `${base}/scripts/get/${path}?workspace=${get(workspaceStore)}`
}
}
const scriptLanguagesArray: [SupportedLanguage | 'docker' | 'bunnative', string][] = [
['bun', 'TypeScript (Bun)'],
['python3', 'Python'],
['deno', 'TypeScript (Deno)'],
['bash', 'Bash'],
['go', 'Go'],
['nativets', 'REST'],
['bunnative', 'REST'],
['postgresql', 'PostgreSQL'],
['mysql', 'MySQL'],
['bigquery', 'BigQuery'],
['oracledb', 'Oracle Database'],
['snowflake', 'Snowflake'],
['mssql', 'MS SQL Server'],
['graphql', 'GraphQL'],
['powershell', 'PowerShell'],
['php', 'PHP'],
['rust', 'Rust'],
['ansible', 'Ansible'],
['csharp', 'C#'],
['docker', 'Docker'],
['nu', 'Nu'],
['java', 'Java'],
['duckdb', 'DuckDB'],
['ruby', 'Ruby']
// for related places search: ADD_NEW_LANG
]
export function processLangs(selected: string | undefined, langs: string[]): string[] {
if (selected === 'nativets') {
return langs
} else {
let ls = langs.filter((lang) => lang !== 'nativets')
//those languages are newer and may not be in the saved list
let nl = ['bunnative', 'rust', 'ansible', 'csharp', 'nu', 'java', 'duckdb', 'ruby']
// for related places search: ADD_NEW_LANG
nl.forEach((lang) => {
if (!ls.includes(lang)) {
ls.push(lang)
}
})
return ls
}
}
export const defaultScriptLanguages = Object.fromEntries(scriptLanguagesArray)
export async function getScriptByPath(path: string): Promise<{
content: string
language: SupportedLanguage
schema: any
description: string
tag: string | undefined
concurrent_limit: number | undefined
concurrency_time_window_s: number | undefined
lock?: string
created_at?: string
hash?: string
}> {
if (path.startsWith('hub/')) {
const { content, language, schema, lockfile } = await ScriptService.getHubScriptByPath({ path })
return {
content,
language: language as SupportedLanguage,
schema,
description: '',
tag: undefined,
concurrent_limit: undefined,
concurrency_time_window_s: undefined,
lock: lockfile
}
} else {
const script = await ScriptService.getScriptByPath({
workspace: get(workspaceStore)!,
path: path ?? ''
})
return {
content: script.content,
language: script.language,
schema: script.schema,
description: script.description,
tag: script.tag,
concurrent_limit: script.concurrent_limit,
concurrency_time_window_s: script.concurrency_time_window_s,
lock: script.lock,
hash: script.hash,
created_at: script.created_at
}
}
}
export async function getLatestHashForScript(path: string): Promise<string> {
const script = await ScriptService.getScriptByPath({
workspace: get(workspaceStore)!,
path: path ?? ''
})
return script.hash
}