Skip to content

Add CREATE / ALTER JAVASCRIPT ACTION support (read-only today) #593

@ako

Description

@ako

Problem

mxcli can list, describe, and call JavaScript actions from microflows and nanoflows, but it cannot create or modify them. JavaScript actions still have to be authored in Studio Pro before any MDL script can reference them.

This forces awkward workarounds in doctype tests and example scripts: patterns from real projects (NanoflowCommons.SignIn, NanoflowCommons.RefreshObject, FeedbackModule.JS_PopulateFeedbackMetadata, etc.) cannot be reproduced end-to-end in a self-contained MDL example because there is no way to bring the called JS action into existence from MDL.

Current state

Supported (read-only):

  • Grammar: callJavaScriptActionStatementmdl/grammar/domains/MDLMicroflow.g4:328
  • Executor (call): addCallJavaScriptActionActionmdl/executor/cmd_microflows_builder_calls.go:428
  • Executor (list/describe): listJavaScriptActions, describeJavaScriptActionmdl/executor/cmd_javascript_actions.go:19,68
  • Backend reads: ListJavaScriptActions, ReadJavaScriptActionByNamemdl/backend/java.go:15,17
  • Parser: mdl/types/JavaScriptAction, parameters parsed via parser_javaactions.go
  • Writer (call site): Microflows$JavaScriptActionCallActionsdk/mpr/writer_microflow_actions.go:313
  • Nanoflow roundtrip test: TestRoundtripNanoflow_CallJavaScriptActionmdl/executor/roundtrip_nanoflow_test.go:851 (currently skips when no JS action is pre-provisioned)

Missing:

  • Grammar: no createJavaScriptActionStatement rule
  • AST: no CreateJavaScriptActionStmt
  • Executor: no execCreateJavaScriptAction
  • Backend writes: no CreateJavaScriptAction / UpdateJavaScriptAction
  • Writer: no serializeJavaScriptAction (only the call-site writer exists)
  • File side-channel: no WriteJavaScriptSourceFile equivalent of the existing WriteJavaSourceFile

Compare with Java actions, which have the full surface: CreateJavaActionStmt AST → execCreateJavaAction executor (cmd_javaactions.go:285) → Backend.CreateJavaAction → BSON write + .java file emission.

Proposed MDL syntax

Mirror create java action so the two surfaces stay symmetric:

create javascript action MyModule.JS_RefreshObject (
  $ObjectToRefresh: Object of MyModule.Item
) returns Boolean
folder 'JavaScript Actions'
as $$
  // @ts-check
  return Promise.resolve(true);
$$;

Open questions to nail down in a follow-up proposal:

  • Where does the JS source live on disk? Java actions live under javasource/ — JS actions presumably under javascriptsource/ (visible in the example projects). Need a WriteJavaScriptSourceFile symmetric with WriteJavaSourceFile.
  • BSON \$Type is JavaScriptActions\$JavaScriptAction (confirmed via parser). Need to dump a Studio-Pro-authored JS action and document the required fields (parameters, return type, MicroflowReturnType-style structure).
  • Should the body be inline (dollar-quoted) only, or also support external referring to an existing .js file authored elsewhere?

Why this matters

  • 02b-nanoflow-examples.mdl can finally cover the JS-action-call patterns from real projects.
  • mxcli init / scaffolding could ship reusable nanoflow helpers without requiring Studio Pro.
  • Reproducible bug repros for nanoflow bugs that involve JS actions don't need a pre-built .mpr.

Suggested implementation order

  1. Dump an existing JS action (e.g. NanoflowCommons.SignIn from any reference project) and document the BSON in a proposal — docs/11-proposals/PROPOSAL_create_javascript_action.md.
  2. Wire grammar → AST → visitor → executor → backend (Create/Update) following the Java action pattern.
  3. Add Backend.WriteJavaScriptSourceFile and emit .js to javascriptsource/.
  4. Add a doctype-test example exercising create javascript action + call javascript action in a nanoflow end-to-end. Unskip TestRoundtripNanoflow_CallJavaScriptAction so it provisions its own action.
  5. Update .claude/skills/mendix/write-nanoflows.md with the new syntax.

Found during

Expanding mdl-examples/doctype-tests/02b-nanoflow-examples.mdl with representative patterns from EnquiriesManagement, LatoProductInventory, Evora-FactoryManagement. JS-action-call patterns were dropped from the doctype examples because there is no way to bring the called JS action into existence from MDL alone.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions