@dforge-core/metadata 0.0.20 → 0.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/dsl/lexer.ts","../../src/dsl/parse.ts","../../src/dsl/builtins.ts","../../src/dsl/check.ts"],"sourcesContent":["// Hand-rolled lexer for the dForge action DSL.\n//\n// Deliberately not the tree-sitter grammar: that one exists to be compiled into\n// Zed, and pulling a native parser (or a wasm runtime) into an npx-launched\n// language server — or into a validator that runs before a pack — costs far\n// more than it buys for the handful of constructs the rules need.\n\nexport type TokenKind =\n\t| \"ident\"\n\t| \"number\"\n\t| \"string\"\n\t| \"template\"\n\t| \"regex\"\n\t| \"punct\"\n\t| \"comment\";\n\nexport interface Token {\n\tkind: TokenKind;\n\t/** Source text, verbatim — quotes included for strings. */\n\ttext: string;\n\tstart: number;\n\tend: number;\n\tline: number;\n\tcharacter: number;\n\t/** True when a line break sits between this token and the previous one. */\n\tstartsLine: boolean;\n}\n\nconst PUNCT3 = [\"===\", \"!==\"];\nconst PUNCT2 = [\n\t\"==\", \"!=\", \"<=\", \">=\", \"&&\", \"||\", \"++\", \"--\",\n\t\"+=\", \"-=\", \"*=\", \"/=\", \"%=\", \"${\", \"=>\",\n];\n\n/**\n * Template literals and the `${…}` holes in them. Inside a template we are\n * reading literal text; inside a hole we are reading code again, and the brace\n * count says which `}` closes it.\n */\ntype Frame =\n\t| { kind: \"template\"; chunkStart: number }\n\t| { kind: \"interp\"; braces: number };\n\n/**\n * Keywords whose `(…)` holds a condition rather than a parameter list. What\n * follows that `)` is a statement — so a regex may open there, and the brace\n * after it is not a function body.\n */\nexport const CONTROL_KEYWORDS = new Set([\n\t\"if\",\n\t\"while\",\n\t\"for\",\n\t\"switch\",\n\t\"catch\",\n\t\"with\",\n]);\n\nexport function tokenize(text: string): Token[] {\n\tconst tokens: Token[] = [];\n\tlet i = 0;\n\tlet line = 0;\n\tlet lineStart = 0;\n\tlet pendingLineBreak = true;\n\tconst frames: Frame[] = [];\n\t// Whether each open paren belongs to a control condition, so that the `)`\n\t// closing it is known to be followed by a statement.\n\tconst parenIsControl: boolean[] = [];\n\tlet closedControlParen = false;\n\t// Whether each open brace began a statement block rather than an object,\n\t// so that the `}` closing it is known to leave a statement position.\n\tconst braceIsBlock: boolean[] = [];\n\tlet closedBlockBrace = false;\n\n\tconst push = (kind: TokenKind, start: number, end: number) => {\n\t\ttokens.push({\n\t\t\tkind,\n\t\t\ttext: text.slice(start, end),\n\t\t\tstart,\n\t\t\tend,\n\t\t\tline,\n\t\t\tcharacter: start - lineStart,\n\t\t\tstartsLine: pendingLineBreak,\n\t\t});\n\t\tpendingLineBreak = false;\n\t};\n\n\twhile (i < text.length) {\n\t\tconst frame = frames[frames.length - 1];\n\n\t\t// ── literal text inside a template ──────────────────────────────\n\t\t// Emitted as one token per chunk, so the analyzer sees the code in\n\t\t// `${…}` but never the prose around it. The `${` closes the chunk\n\t\t// before it and the `}` opens the chunk after, which keeps the brace\n\t\t// count of anything reading these tokens balanced.\n\t\tif (frame?.kind === \"template\") {\n\t\t\tconst startLine = line;\n\t\t\tconst startLineStart = lineStart;\n\t\t\twhile (i < text.length) {\n\t\t\t\tconst ch = text[i]!;\n\t\t\t\tif (ch === \"\\\\\") {\n\t\t\t\t\ti += 2;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (ch === \"`\" || (ch === \"$\" && text[i + 1] === \"{\")) break;\n\t\t\t\tif (ch === \"\\n\") {\n\t\t\t\t\tline++;\n\t\t\t\t\tlineStart = i + 1;\n\t\t\t\t}\n\t\t\t\ti++;\n\t\t\t}\n\t\t\tif (text[i] === \"`\") {\n\t\t\t\ti++;\n\t\t\t\tframes.pop();\n\t\t\t} else if (i < text.length) {\n\t\t\t\ti += 2;\n\t\t\t\tframes.push({ kind: \"interp\", braces: 0 });\n\t\t\t} else {\n\t\t\t\tframes.pop(); // unterminated\n\t\t\t}\n\t\t\tconst savedLine = line;\n\t\t\tconst savedLineStart = lineStart;\n\t\t\tline = startLine;\n\t\t\tlineStart = startLineStart;\n\t\t\tpush(\"template\", frame.chunkStart, i);\n\t\t\tline = savedLine;\n\t\t\tlineStart = savedLineStart;\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst c = text[i]!;\n\n\t\t// A leading BOM is not a column. The compiler strips it before anchoring\n\t\t// block headers at `^execute:`, so the first real token must still land\n\t\t// at character 0 here or every block-scoped rule stands down.\n\t\tif (c === \"\\uFEFF\" && i === 0) {\n\t\t\ti++;\n\t\t\tlineStart = i;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (c === \"\\n\") {\n\t\t\ti++;\n\t\t\tline++;\n\t\t\tlineStart = i;\n\t\t\tpendingLineBreak = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (c === \" \" || c === \"\\t\" || c === \"\\r\") {\n\t\t\ti++;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (c === \"/\" && text[i + 1] === \"/\") {\n\t\t\tconst start = i;\n\t\t\twhile (i < text.length && text[i] !== \"\\n\") i++;\n\t\t\tpush(\"comment\", start, i);\n\t\t\tcontinue;\n\t\t}\n\t\tif (c === \"/\" && text[i + 1] === \"*\") {\n\t\t\tconst start = i;\n\t\t\tconst startLine = line;\n\t\t\tconst startLineStart = lineStart;\n\t\t\ti += 2;\n\t\t\twhile (i < text.length && !(text[i] === \"*\" && text[i + 1] === \"/\")) {\n\t\t\t\tif (text[i] === \"\\n\") {\n\t\t\t\t\tline++;\n\t\t\t\t\tlineStart = i + 1;\n\t\t\t\t}\n\t\t\t\ti++;\n\t\t\t}\n\t\t\ti = Math.min(i + 2, text.length);\n\t\t\t// Report the comment at its opening position, not its end.\n\t\t\tconst savedLine = line;\n\t\t\tconst savedLineStart = lineStart;\n\t\t\tline = startLine;\n\t\t\tlineStart = startLineStart;\n\t\t\tpush(\"comment\", start, i);\n\t\t\tline = savedLine;\n\t\t\tlineStart = savedLineStart;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (c === \"'\" || c === '\"') {\n\t\t\tconst start = i;\n\t\t\tconst quote = c;\n\t\t\ti++;\n\t\t\twhile (i < text.length && text[i] !== quote && text[i] !== \"\\n\") {\n\t\t\t\tif (text[i] === \"\\\\\") i++;\n\t\t\t\ti++;\n\t\t\t}\n\t\t\tif (text[i] === quote) i++;\n\t\t\tpush(\"string\", start, i);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (c === \"`\") {\n\t\t\tframes.push({ kind: \"template\", chunkStart: i });\n\t\t\ti++;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (\n\t\t\tc === \"/\" &&\n\t\t\tregexAllowedAfter(\n\t\t\t\ttokens[tokens.length - 1],\n\t\t\t\tclosedControlParen,\n\t\t\t\tclosedBlockBrace,\n\t\t\t)\n\t\t) {\n\t\t\tconst end = scanRegex(text, i);\n\t\t\tif (end > 0) {\n\t\t\t\tpush(\"regex\", i, end);\n\t\t\t\ti = end;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\n\t\tif (/[0-9]/.test(c)) {\n\t\t\tconst start = i;\n\t\t\twhile (i < text.length && /[0-9._eE]/.test(text[i]!)) i++;\n\t\t\tpush(\"number\", start, i);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (/[A-Za-z_$]/.test(c)) {\n\t\t\tconst start = i;\n\t\t\twhile (i < text.length && /[A-Za-z0-9_$]/.test(text[i]!)) i++;\n\t\t\tpush(\"ident\", start, i);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (c === \"(\") {\n\t\t\tconst prev = tokens[tokens.length - 1];\n\t\t\tparenIsControl.push(\n\t\t\t\tprev?.kind === \"ident\" && CONTROL_KEYWORDS.has(prev.text),\n\t\t\t);\n\t\t} else if (c === \")\") {\n\t\t\tclosedControlParen = parenIsControl.pop() ?? false;\n\t\t}\n\n\t\tif (frame?.kind === \"interp\") {\n\t\t\tif (c === \"}\" && frame.braces === 0) {\n\t\t\t\tframes.pop();\n\t\t\t\t// The `}` opens the next literal chunk rather than becoming a\n\t\t\t\t// token of its own — see the chunk comment above.\n\t\t\t\t(frames[frames.length - 1] as { chunkStart: number }).chunkStart = i;\n\t\t\t\ti++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (c === \"{\") frame.braces++;\n\t\t\telse if (c === \"}\") frame.braces--;\n\t\t}\n\n\t\tif (c === \"{\") {\n\t\t\tbraceIsBlock.push(isBlockBrace(tokens[tokens.length - 1]));\n\t\t} else if (c === \"}\") {\n\t\t\tclosedBlockBrace = braceIsBlock.pop() ?? false;\n\t\t}\n\n\t\tconst three = text.slice(i, i + 3);\n\t\tif (PUNCT3.includes(three)) {\n\t\t\tpush(\"punct\", i, i + 3);\n\t\t\ti += 3;\n\t\t\tcontinue;\n\t\t}\n\t\tconst two = text.slice(i, i + 2);\n\t\tif (PUNCT2.includes(two)) {\n\t\t\tpush(\"punct\", i, i + 2);\n\t\t\ti += 2;\n\t\t\tcontinue;\n\t\t}\n\t\tpush(\"punct\", i, i + 1);\n\t\ti++;\n\t}\n\n\treturn tokens;\n}\n\n/**\n * Whether a `/` here opens a regex literal rather than dividing. The usual\n * rule: a regex may start where an expression may start, so it follows an\n * operator or a keyword but not a value.\n *\n * A `)` depends on what it closed: after a control condition a statement\n * follows, so `if (x) /re/.test(s)` is a regex, while `(a + b) / 2` divides.\n * A template chunk likewise depends on which end it is — one that stops at\n * `${` opens an expression, one that ran to the closing backtick is a value.\n *\n * A `}` likewise depends on what it closed: ending a statement block leaves a\n * statement position, so `if (x) {}` may be followed by a regex, while an\n * object literal is a value and divides.\n */\nfunction regexAllowedAfter(\n\tprev: Token | undefined,\n\tclosedControlParen: boolean,\n\tclosedBlockBrace: boolean,\n): boolean {\n\tif (!prev) return true;\n\tif (prev.kind === \"number\" || prev.kind === \"string\") return false;\n\tif (prev.kind === \"template\") return prev.text.endsWith(\"${\");\n\tif (prev.kind === \"ident\") return REGEX_PRECEDING_KEYWORDS.has(prev.text);\n\tif (prev.kind === \"regex\") return false;\n\tif (prev.kind === \"comment\") return true;\n\tif (prev.text === \")\") return closedControlParen;\n\tif (prev.text === \"}\") return closedBlockBrace;\n\treturn !REGEX_BLOCKING_PUNCT.has(prev.text);\n}\n\n/**\n * Whether the `{` after `prev` opens a statement block rather than an object\n * literal. A block follows a condition, another block, a statement end or one\n * of the keywords that take a bare body; anything else — an `=`, a `(`, a `,`,\n * a `=>` — is expression position, where the brace is a value.\n */\nfunction isBlockBrace(prev: Token | undefined): boolean {\n\tif (!prev) return true;\n\tif (prev.kind === \"ident\") return BLOCK_PRECEDING_KEYWORDS.has(prev.text);\n\tif (prev.kind !== \"punct\") return false;\n\treturn prev.text === \")\" || prev.text === \"}\" || prev.text === \"{\" || prev.text === \";\";\n}\n\nconst BLOCK_PRECEDING_KEYWORDS = new Set([\"else\", \"do\", \"try\", \"finally\"]);\n\nconst REGEX_PRECEDING_KEYWORDS = new Set([\n\t\"return\", \"typeof\", \"instanceof\", \"in\", \"of\", \"new\", \"delete\", \"void\",\n\t\"case\", \"do\", \"else\", \"throw\", \"yield\", \"await\",\n]);\n\nconst REGEX_BLOCKING_PUNCT = new Set([\"]\", \"++\", \"--\"]);\n\n/**\n * End offset of the regex literal starting at `start`, or -1 if it is not one.\n * A `/` inside a character class does not close the literal, and a literal\n * never spans a line — hitting one means this was a division after all.\n */\nfunction scanRegex(text: string, start: number): number {\n\tlet i = start + 1;\n\tlet inClass = false;\n\t// An empty pattern would be the `//` comment the caller already handled.\n\tif (text[i] === \"/\" || text[i] === \"*\") return -1;\n\tfor (; i < text.length; i++) {\n\t\tconst c = text[i]!;\n\t\tif (c === \"\\\\\") {\n\t\t\ti++;\n\t\t\tcontinue;\n\t\t}\n\t\tif (c === \"\\n\") return -1;\n\t\tif (c === \"[\") inClass = true;\n\t\telse if (c === \"]\") inClass = false;\n\t\telse if (c === \"/\" && !inClass) {\n\t\t\ti++;\n\t\t\twhile (i < text.length && /[a-z]/.test(text[i]!)) i++;\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/** Strip the surrounding quotes from a string token's text. */\nexport function stringValue(token: Token): string {\n\tif (token.kind !== \"string\") return token.text;\n\tconst body = token.text.slice(1, token.text.endsWith(token.text[0]!) && token.text.length > 1 ? -1 : undefined);\n\treturn body.replace(/\\\\(.)/g, \"$1\");\n}\n","// Structural scan of a .dsl file: blocks, param declarations, record-field\n// reads, ref navigation chains and built-in calls — everything the diagnostics,\n// completion, hover and definition features need, and nothing else.\n\nimport { CONTROL_KEYWORDS, type Token, tokenize, stringValue } from \"./lexer\";\n\nexport type BlockKind =\n\t| \"params\"\n\t| \"canExecute\"\n\t| \"schema\"\n\t| \"onBeforeStart\"\n\t| \"execute\";\n\n/** In the order `ActionDslCompiler.ParseBlocks` expects them in a file. */\nexport const BLOCK_KINDS: BlockKind[] = [\n\t\"params\",\n\t\"canExecute\",\n\t\"schema\",\n\t\"onBeforeStart\",\n\t\"execute\",\n];\n\nconst BLOCK_BY_LOWER = new Map(BLOCK_KINDS.map((k) => [k.toLowerCase(), k]));\n\nexport interface Span {\n\tstart: number;\n\tend: number;\n}\n\nexport interface DslBlock {\n\tkind: BlockKind;\n\tlabel: Span;\n\t/** Span of the block body — label end to the next label (or EOF). */\n\tbody: Span;\n}\n\nexport interface DslParam {\n\tname: string;\n\tnameSpan: Span;\n\t/** fieldTypeCd, or the referenced entity code when `isRef`. */\n\ttype: string;\n\ttypeSpan: Span;\n\tisRef: boolean;\n\trequired: boolean;\n\tlabel?: string;\n}\n\n/**\n * A `[field]` read. `navigation` holds the property hops that follow it, each\n * remembering whether it was written `.[target]` or `.target`: the compiler\n * rewrites the FIRST hop either way, and then only a surviving `.[` is the\n * multi-hop compile error. A dotted tail is plain JavaScript on the value the\n * hop returned, so `[customer].[code]`, `[a].b.c` and `[plate].length` all\n * compile.\n */\nexport interface FieldRef {\n\tname: string;\n\tspan: Span;\n\t/** Span including the brackets. */\n\touterSpan: Span;\n\tnavigation: Array<{ name: string; span: Span; bracketed: boolean }>;\n\tblock: BlockKind | null;\n\t/**\n\t * False when the read is bound to a numbered record rather than the current\n\t * one — `records[0][status]`, which `RxRecordsFieldRead` rewrites ahead of\n\t * the generic `[field]` pass. The name is still a column of the entity, so\n\t * the column rules apply; the batch-mode rule does not.\n\t */\n\tisCurrentRecord: boolean;\n\t/** Index of the token that opens this read — the `[`. */\n\tstartIndex: number;\n\t/**\n\t * Index of the last token this read consumes, navigation included. A hop is\n\t * 2 tokens as `.prop` but 4 as `.[prop]`, so callers that need the token\n\t * after the read cannot compute it from `navigation.length`.\n\t */\n\tendIndex: number;\n}\n\n/** `params[x]` / `old[x]` — subscript reads off a DSL global. */\nexport interface GlobalRef {\n\tglobal: \"params\" | \"old\" | \"records\";\n\tproperty: string;\n\tspan: Span;\n\tblock: BlockKind | null;\n}\n\nexport interface CallRef {\n\tname: string;\n\tnameSpan: Span;\n\t/** First argument when it is a string literal — the entity code, usually. */\n\tfirstStringArg?: { value: string; span: Span };\n\tblock: BlockKind | null;\n}\n\nexport interface DslDocument {\n\tblocks: DslBlock[];\n\tparams: DslParam[];\n\tfieldRefs: FieldRef[];\n\tglobalRefs: GlobalRef[];\n\tcalls: CallRef[];\n\ttokens: Token[];\n\t/**\n\t * Every mention of `records`, subscript (`records[x]`) or bare\n\t * (`for x in records`). `globalRefs` only holds the subscript form, so a\n\t * rule that needs to point at the batch loop has nothing to anchor to.\n\t */\n\trecordsRefs: Span[];\n\t/** Names bound by `var`/`let`/`const` or a `for` head, plus declared params. */\n\tlocals: Set<string>;\n\t/**\n\t * Loop variables bound by `for x in records {` — `RxForLoop` and nothing\n\t * else, so an ordinary `for (var x of xs)` is not one. Their `x[field]`\n\t * subscripts read the entity's columns, which is why they come back as\n\t * field reads.\n\t */\n\trecordsLoopVars: Set<string>;\n}\n\nconst GLOBALS = new Set([\"params\", \"old\", \"records\"]);\n\nexport function parseDsl(text: string): DslDocument {\n\tconst all = tokenize(text);\n\tconst tokens = all.filter((t) => t.kind !== \"comment\");\n\n\tconst blocks = findBlocks(text, tokens);\n\tconst blockAt = (offset: number): BlockKind | null =>\n\t\tblocks.find((b) => offset >= b.body.start && offset < b.body.end)?.kind ??\n\t\tnull;\n\n\tconst params = parseParams(tokens, blocks);\n\tconst fieldRefs: FieldRef[] = [];\n\tconst globalRefs: GlobalRef[] = [];\n\tconst calls: CallRef[] = [];\n\tconst recordsRefs: Span[] = [];\n\tconst locals = collectLocals(tokens, params);\n\tconst recordsLoopVars = collectRecordsLoopVars(tokens);\n\n\tfor (let i = 0; i < tokens.length; i++) {\n\t\tconst t = tokens[i]!;\n\n\t\tif (t.kind === \"punct\" && t.text === \"[\" && isFieldAccessStart(text, t.start)) {\n\t\t\tconst name = tokens[i + 1];\n\t\t\tconst close = tokens[i + 2];\n\t\t\tif (name?.kind === \"ident\" && close?.text === \"]\") {\n\t\t\t\tconst ref: FieldRef = {\n\t\t\t\t\tname: name.text,\n\t\t\t\t\tspan: { start: name.start, end: name.end },\n\t\t\t\t\touterSpan: { start: t.start, end: close.end },\n\t\t\t\t\tnavigation: [],\n\t\t\t\t\tblock: blockAt(t.start),\n\t\t\t\t\tisCurrentRecord: true,\n\t\t\t\t\tstartIndex: i,\n\t\t\t\t\tendIndex: i + 2,\n\t\t\t\t};\n\t\t\t\tref.endIndex = collectNavigation(tokens, i + 2, ref);\n\t\t\t\ti = ref.endIndex;\n\t\t\t\tfieldRefs.push(ref);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\n\t\t// `x.records` is a property, not the batch global.\n\t\tif (t.kind === \"ident\" && t.text === \"records\" && tokens[i - 1]?.text !== \".\") {\n\t\t\trecordsRefs.push({ start: t.start, end: t.end });\n\n\t\t\t// `records[0][status]` is one read of a numbered record. Taken\n\t\t\t// apart, its tail looks exactly like a current-record read — which\n\t\t\t// is why the compiler rewrites this form first.\n\t\t\tconst field = indexedRecordField(tokens, i);\n\t\t\tif (field) {\n\t\t\t\tfieldRefs.push({\n\t\t\t\t\tname: field.name.text,\n\t\t\t\t\tspan: { start: field.name.start, end: field.name.end },\n\t\t\t\t\touterSpan: { start: field.open.start, end: field.close.end },\n\t\t\t\t\tnavigation: [],\n\t\t\t\t\tblock: blockAt(t.start),\n\t\t\t\t\tisCurrentRecord: false,\n\t\t\t\t\tstartIndex: field.openIndex,\n\t\t\t\t\tendIndex: field.openIndex + 2,\n\t\t\t\t});\n\t\t\t\ti = field.openIndex + 2;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\n\t\t// `x[field]` on a batch loop variable. The compiler rewrites it to\n\t\t// `x.get('field')` and checks the name against the entity's columns\n\t\t// exactly as it checks a bare `[field]`.\n\t\tif (t.kind === \"ident\" && recordsLoopVars.has(t.text)) {\n\t\t\tconst open = tokens[i + 1];\n\t\t\tconst name = tokens[i + 2];\n\t\t\tconst close = tokens[i + 3];\n\t\t\tif (open?.text === \"[\" && name?.kind === \"ident\" && close?.text === \"]\") {\n\t\t\t\tfieldRefs.push({\n\t\t\t\t\tname: name.text,\n\t\t\t\t\tspan: { start: name.start, end: name.end },\n\t\t\t\t\touterSpan: { start: open.start, end: close.end },\n\t\t\t\t\tnavigation: [],\n\t\t\t\t\tblock: blockAt(t.start),\n\t\t\t\t\tisCurrentRecord: false,\n\t\t\t\t\tstartIndex: i + 1,\n\t\t\t\t\tendIndex: i + 3,\n\t\t\t\t});\n\t\t\t\ti += 3;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\n\t\tif (t.kind === \"ident\" && GLOBALS.has(t.text)) {\n\t\t\tconst open = tokens[i + 1];\n\t\t\tconst prop = tokens[i + 2];\n\t\t\tconst close = tokens[i + 3];\n\t\t\tif (open?.text === \"[\" && prop?.kind === \"ident\" && close?.text === \"]\") {\n\t\t\t\tglobalRefs.push({\n\t\t\t\t\tglobal: t.text as GlobalRef[\"global\"],\n\t\t\t\t\tproperty: prop.text,\n\t\t\t\t\tspan: { start: prop.start, end: prop.end },\n\t\t\t\t\tblock: blockAt(t.start),\n\t\t\t\t});\n\t\t\t\ti += 3;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\n\t\tif (t.kind === \"ident\" && tokens[i + 1]?.text === \"(\") {\n\t\t\tconst prev = tokens[i - 1];\n\t\t\t// `.method(` is a call on a value, not a DSL built-in.\n\t\t\tif (prev?.text === \".\") continue;\n\t\t\tconst call: CallRef = {\n\t\t\t\tname: t.text,\n\t\t\t\tnameSpan: { start: t.start, end: t.end },\n\t\t\t\tblock: blockAt(t.start),\n\t\t\t};\n\t\t\tconst firstArg = tokens[i + 2];\n\t\t\tif (firstArg?.kind === \"string\") {\n\t\t\t\tcall.firstStringArg = {\n\t\t\t\t\tvalue: stringValue(firstArg),\n\t\t\t\t\tspan: { start: firstArg.start, end: firstArg.end },\n\t\t\t\t};\n\t\t\t}\n\t\t\tcalls.push(call);\n\t\t}\n\t}\n\n\treturn {\n\t\tblocks,\n\t\tparams,\n\t\tfieldRefs,\n\t\tglobalRefs,\n\t\tcalls,\n\t\ttokens,\n\t\trecordsRefs,\n\t\tlocals,\n\t\trecordsLoopVars,\n\t};\n}\n\n/**\n * `[` opens a record-field read unless a word character sits immediately\n * before it — the compiler's `(?<!\\w)\\[(\\w+)\\]`, character for character.\n *\n * It has to be the character and not the previous token: the lookbehind does\n * not skip whitespace, so `rec[qty]` is a subscript but `[qty]` opening a line\n * is a read however the line above ended. The same lookbehind is what keeps\n * `params[x]` and `old[x]` out of the field reads.\n *\n * A single-element array literal (`var ids = [orderId]`) is genuinely\n * ambiguous with a field read at this level: both are `[ident]` in expression\n * position, and `var total = [qty]` is a real field read. The disambiguation\n * needs to know whether the name is a column or a local, so it happens in the\n * diagnostics layer against `locals` rather than here.\n */\nfunction isFieldAccessStart(text: string, start: number): boolean {\n\treturn start === 0 || !/\\w/.test(text[start - 1]!);\n}\n\n/**\n * The `[field]` half of a `records[n][field]` read starting at `i`, or null.\n *\n * Mirrors `RxRecordsFieldRead`'s `\\brecords\\[(\\d+)\\]\\[(\\w+)\\]`: a literal\n * digit index only. `records[i][x]` with a variable index is not this form for\n * the compiler either — it leaves `records[i]` alone and then rewrites the tail\n * as a current-record read.\n */\nfunction indexedRecordField(\n\ttokens: Token[],\n\ti: number,\n): { name: Token; open: Token; close: Token; openIndex: number } | null {\n\tconst index = tokens[i + 2];\n\tif (tokens[i + 1]?.text !== \"[\") return null;\n\tif (index?.kind !== \"number\" || !/^\\d+$/.test(index.text)) return null;\n\tif (tokens[i + 3]?.text !== \"]\") return null;\n\n\tconst open = tokens[i + 4];\n\tconst name = tokens[i + 5];\n\tconst close = tokens[i + 6];\n\tif (open?.text !== \"[\" || name?.kind !== \"ident\" || close?.text !== \"]\")\n\t\treturn null;\n\treturn { name, open, close, openIndex: i + 4 };\n}\n\n/** Walk `.prop` / `.[prop]` hops after a field read. Returns the last index consumed. */\nfunction collectNavigation(tokens: Token[], closeIdx: number, ref: FieldRef): number {\n\tlet i = closeIdx;\n\tfor (;;) {\n\t\tconst dot = tokens[i + 1];\n\t\tif (dot?.text !== \".\") return i;\n\t\tconst next = tokens[i + 2];\n\t\tif (next?.kind === \"ident\") {\n\t\t\t// A method call is not navigation — `[items].length` is, `[x].trim()` isn't.\n\t\t\tif (tokens[i + 3]?.text === \"(\") return i;\n\t\t\tref.navigation.push({\n\t\t\t\tname: next.text,\n\t\t\t\tspan: { start: next.start, end: next.end },\n\t\t\t\tbracketed: false,\n\t\t\t});\n\t\t\ti += 2;\n\t\t\tcontinue;\n\t\t}\n\t\tif (next?.text === \"[\") {\n\t\t\tconst name = tokens[i + 3];\n\t\t\tconst close = tokens[i + 4];\n\t\t\tif (name?.kind === \"ident\" && close?.text === \"]\") {\n\t\t\t\tref.navigation.push({\n\t\t\t\t\tname: name.text,\n\t\t\t\t\tspan: { start: name.start, end: name.end },\n\t\t\t\t\tbracketed: true,\n\t\t\t\t});\n\t\t\t\ti += 4;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\treturn i;\n\t}\n}\n\n/**\n * `for x in records {` — `RxForLoop`'s shape, brace included. A loop written\n * any other way is not a batch loop to the compiler either, and its variable\n * does not carry record fields.\n */\nfunction collectRecordsLoopVars(tokens: Token[]): Set<string> {\n\tconst vars = new Set<string>();\n\tfor (let i = 0; i < tokens.length - 4; i++) {\n\t\tif (tokens[i]!.text !== \"for\" || tokens[i]!.kind !== \"ident\") continue;\n\t\tconst name = tokens[i + 1]!;\n\t\tif (name.kind !== \"ident\") continue;\n\t\tif (tokens[i + 2]!.text !== \"in\" || tokens[i + 3]!.text !== \"records\") continue;\n\t\tif (tokens[i + 4]!.text !== \"{\") continue;\n\t\tvars.add(name.text);\n\t}\n\treturn vars;\n}\n\nconst DECLARATORS = new Set([\"var\", \"let\", \"const\"]);\n\n/**\n * Names bound in the script itself. Used to tell `var ids = [orderId]` (an\n * array literal holding a local) from `[qty]` (a record-field read) — the two\n * are indistinguishable by token shape alone.\n */\nfunction collectLocals(tokens: Token[], params: DslParam[]): Set<string> {\n\tconst locals = new Set<string>(params.map((p) => p.name));\n\tcollectFunctionParams(tokens, locals);\n\tfor (let i = 0; i < tokens.length; i++) {\n\t\tconst t = tokens[i]!;\n\t\tif (t.kind !== \"ident\") continue;\n\n\t\tif (DECLARATORS.has(t.text)) {\n\t\t\tcollectDeclarations(tokens, i + 1, locals);\n\t\t\tcontinue;\n\t\t}\n\n\t\t// `for x in records` / `for (var x of xs)` — the loop variable.\n\t\tif (t.text === \"for\") {\n\t\t\tlet j = i + 1;\n\t\t\tif (tokens[j]?.text === \"(\") j++;\n\t\t\tif (tokens[j]?.kind === \"ident\" && DECLARATORS.has(tokens[j]!.text)) j++;\n\t\t\tconst name = tokens[j];\n\t\t\tif (name?.kind === \"ident\" && !DECLARATORS.has(name.text)) locals.add(name.text);\n\t\t}\n\t}\n\treturn locals;\n}\n\n/**\n * Parameter names of every function in the script — declarations, expressions,\n * arrows and method shorthand. They bind names exactly as `var` does, so\n * `function wrap(value) { return [value] }` holds an array literal rather than\n * a field read.\n */\nfunction collectFunctionParams(tokens: Token[], locals: Set<string>): void {\n\tfor (let i = 0; i < tokens.length; i++) {\n\t\tconst t = tokens[i]!;\n\n\t\tif (t.kind === \"ident\" && t.text === \"function\") {\n\t\t\tlet j = i + 1;\n\t\t\tif (tokens[j]?.kind === \"ident\") j++; // the name, when it has one\n\t\t\tif (tokens[j]?.text === \"(\") collectParenIdents(tokens, j, locals);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (t.text === \"=>\") {\n\t\t\tconst prev = tokens[i - 1];\n\t\t\t// `x => …` binds one name; `(x, y) => …` binds the list.\n\t\t\tif (prev?.kind === \"ident\") locals.add(prev.text);\n\t\t\telse if (prev?.text === \")\") {\n\t\t\t\tconst open = matchingOpenParen(tokens, i - 1);\n\t\t\t\tif (open >= 0) collectParenIdents(tokens, open, locals);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Method shorthand `f(a, b) { … }`. The body brace is what tells it from\n\t\t// a call, and a control keyword's `(…)` is a condition, not a list.\n\t\tif (\n\t\t\tt.kind === \"ident\" &&\n\t\t\t!CONTROL_KEYWORDS.has(t.text) &&\n\t\t\ttokens[i + 1]?.text === \"(\"\n\t\t) {\n\t\t\tconst close = matchingCloseParen(tokens, i + 1);\n\t\t\tif (close >= 0 && tokens[close + 1]?.text === \"{\")\n\t\t\t\tcollectParenIdents(tokens, i + 1, locals);\n\t\t}\n\t}\n}\n\n/**\n * Every ident between the `(` at `openIndex` and its match. Over-collects a\n * default value's names (`f(x = y)`), which only ever suppresses a diagnostic —\n * the same fail-open trade `collectPattern` makes.\n */\nfunction collectParenIdents(\n\ttokens: Token[],\n\topenIndex: number,\n\tlocals: Set<string>,\n): void {\n\tlet depth = 0;\n\tfor (let i = openIndex; i < tokens.length; i++) {\n\t\tconst t = tokens[i]!;\n\t\tif (t.text === \"(\") depth++;\n\t\telse if (t.text === \")\") {\n\t\t\tdepth--;\n\t\t\tif (depth === 0) return;\n\t\t} else if (t.kind === \"ident\") locals.add(t.text);\n\t}\n}\n\nfunction matchingCloseParen(tokens: Token[], openIndex: number): number {\n\tlet depth = 0;\n\tfor (let i = openIndex; i < tokens.length; i++) {\n\t\tif (tokens[i]!.text === \"(\") depth++;\n\t\telse if (tokens[i]!.text === \")\" && --depth === 0) return i;\n\t}\n\treturn -1;\n}\n\nfunction matchingOpenParen(tokens: Token[], closeIndex: number): number {\n\tlet depth = 0;\n\tfor (let i = closeIndex; i >= 0; i--) {\n\t\tif (tokens[i]!.text === \")\") depth++;\n\t\telse if (tokens[i]!.text === \"(\" && --depth === 0) return i;\n\t}\n\treturn -1;\n}\n\n/**\n * The binding list after a declarator: `a = 1, b = 2`, where each binding is\n * either a name or a destructuring pattern. Scans ahead without moving the\n * caller's cursor, so a `var` nested in an initializer is still visited.\n */\nfunction collectDeclarations(tokens: Token[], start: number, locals: Set<string>): void {\n\tlet j = start;\n\tfor (;;) {\n\t\tconst head = tokens[j];\n\t\tif (!head) return;\n\n\t\tif (head.text === \"{\" || head.text === \"[\") {\n\t\t\tj = collectPattern(tokens, j, locals);\n\t\t} else if (head.kind === \"ident\" && !DECLARATORS.has(head.text)) {\n\t\t\tlocals.add(head.text);\n\t\t\tj++;\n\t\t} else return;\n\n\t\t// Skip this binding's initializer and stop at the comma opening the\n\t\t// next one. Commas inside the initializer sit at depth 1+ (`f(x, y)`),\n\t\t// which is what keeps its arguments out of `locals`.\n\t\tlet depth = 0;\n\t\tfor (; j < tokens.length; j++) {\n\t\t\tconst n = tokens[j]!;\n\t\t\tif (n.text === \"(\" || n.text === \"[\" || n.text === \"{\") depth++;\n\t\t\telse if (n.text === \")\" || n.text === \"]\" || n.text === \"}\") depth--;\n\t\t\tif (depth < 0) return;\n\t\t\tif (depth > 0) continue;\n\t\t\tif (n.text === \";\") return;\n\t\t\tif (n.text === \",\") break;\n\t\t\t// A new line at depth 0 ends the statement; the alternative is\n\t\t\t// running to end-of-file on a declaration with no terminator.\n\t\t\tif (n.startsLine) return;\n\t\t}\n\t\tif (j >= tokens.length) return;\n\t\tj++;\n\t}\n}\n\n/**\n * Every ident inside a `{…}` / `[…]` binding pattern; returns the index after\n * it. The names of a pattern sit at depth 1+, out of reach of the comma rule\n * in `collectDeclarations`. This over-collects — the `a` of `{ a: b }` binds\n * nothing — but a name in `locals` only ever suppresses a diagnostic, so the\n * error is in the fail-open direction.\n */\nfunction collectPattern(tokens: Token[], start: number, locals: Set<string>): number {\n\tlet depth = 0;\n\tlet i = start;\n\tfor (; i < tokens.length; i++) {\n\t\tconst t = tokens[i]!;\n\t\tif (t.text === \"{\" || t.text === \"[\") depth++;\n\t\telse if (t.text === \"}\" || t.text === \"]\") {\n\t\t\tdepth--;\n\t\t\tif (depth === 0) return i + 1;\n\t\t} else if (t.kind === \"ident\") locals.add(t.text);\n\t}\n\treturn i;\n}\n\n/**\n * The block kind labelled at `i`, wherever on the line it sits.\n *\n * `findBlocks` additionally requires column 0, which is what the compiler's\n * `^execute:` anchor means. The un-anchored form exists for the diagnostic\n * that reports an indented header — body text as far as the compiler is\n * concerned, leaving the block it meant to open empty.\n */\nexport function blockLabelAt(tokens: Token[], i: number): BlockKind | null {\n\tconst t = tokens[i];\n\tif (!t || t.kind !== \"ident\" || !t.startsLine) return null;\n\tconst colon = tokens[i + 1];\n\t// `params :` does not match `^params:` either.\n\tif (colon?.text !== \":\" || colon.start !== t.end) return null;\n\treturn BLOCK_BY_LOWER.get(t.text.toLowerCase()) ?? null;\n}\n\nfunction findBlocks(text: string, tokens: Token[]): DslBlock[] {\n\tconst labels: Array<{ kind: BlockKind; span: Span }> = [];\n\tfor (let i = 0; i < tokens.length; i++) {\n\t\tconst t = tokens[i]!;\n\t\t// Column 0, like the compiler's `^`-anchored headers: an indented\n\t\t// `params:` is an object key inside a block body, not a new block.\n\t\tif (t.character !== 0) continue;\n\t\tconst kind = blockLabelAt(tokens, i);\n\t\tif (!kind) continue;\n\t\tlabels.push({ kind, span: { start: t.start, end: tokens[i + 1]!.end } });\n\t\t// `execute:` is `(.*?)\\z` — it runs to end-of-file, so a later header\n\t\t// is body text.\n\t\tif (kind === \"execute\") break;\n\t}\n\n\treturn labels.map((l, idx) => ({\n\t\tkind: l.kind,\n\t\tlabel: l.span,\n\t\tbody: {\n\t\t\tstart: l.span.end,\n\t\t\tend: labels[idx + 1]?.span.start ?? text.length,\n\t\t},\n\t}));\n}\n\nfunction parseParams(tokens: Token[], blocks: DslBlock[]): DslParam[] {\n\tconst block = blocks.find((b) => b.kind === \"params\");\n\tif (!block) return [];\n\n\tconst inBlock = tokens.filter(\n\t\t(t) => t.start >= block.body.start && t.start < block.body.end,\n\t);\n\tconst params: DslParam[] = [];\n\n\tfor (let i = 0; i < inBlock.length; i++) {\n\t\tconst name = inBlock[i]!;\n\t\t// One declaration per line — and `^params:\\s*` swallows the newline, so\n\t\t// the header's own line counts: `params: qty: number required` declares\n\t\t// qty exactly as an indented line below would.\n\t\tif ((!name.startsLine && i !== 0) || name.kind !== \"ident\") continue;\n\t\tif (inBlock[i + 1]?.text !== \":\") continue;\n\n\t\tlet j = i + 2;\n\t\tlet isRef = false;\n\t\tif (inBlock[j]?.kind === \"ident\" && inBlock[j]!.text === \"ref\") {\n\t\t\tisRef = true;\n\t\t\tj++;\n\t\t}\n\t\tconst type = inBlock[j];\n\t\tif (!type || type.kind !== \"ident\") continue;\n\t\t// RxParamDecl matches one trimmed line, so the type shares the name's\n\t\t// line. Without this a bare `execute:` swallows the next line's first\n\t\t// word as its type and passes for a declaration.\n\t\tif (type.line !== name.line) continue;\n\n\t\t// A `ref` target may be qualified and hyphenated: `ref fin-ch.invoice`.\n\t\t// The lexer splits on `-` and `.`, so glue back any pieces that are\n\t\t// physically adjacent — a space means the name ended.\n\t\tlet typeEnd = type.end;\n\t\tlet typeText = type.text;\n\t\tif (isRef) {\n\t\t\twhile (\n\t\t\t\tinBlock[j + 1] &&\n\t\t\t\t(inBlock[j + 1]!.text === \"-\" || inBlock[j + 1]!.text === \".\") &&\n\t\t\t\tinBlock[j + 2]?.kind === \"ident\" &&\n\t\t\t\tinBlock[j + 1]!.start === typeEnd &&\n\t\t\t\tinBlock[j + 2]!.start === inBlock[j + 1]!.end\n\t\t\t) {\n\t\t\t\ttypeText += inBlock[j + 1]!.text + inBlock[j + 2]!.text;\n\t\t\t\ttypeEnd = inBlock[j + 2]!.end;\n\t\t\t\tj += 2;\n\t\t\t}\n\t\t}\n\n\t\tlet required = false;\n\t\tlet label: string | undefined;\n\t\tfor (let k = j + 1; k < inBlock.length && !inBlock[k]!.startsLine; k++) {\n\t\t\tconst t = inBlock[k]!;\n\t\t\tif (t.kind === \"ident\" && t.text === \"required\") required = true;\n\t\t\tif (t.kind === \"string\" && label === undefined) label = stringValue(t);\n\t\t}\n\n\t\tparams.push({\n\t\t\tname: name.text,\n\t\t\tnameSpan: { start: name.start, end: name.end },\n\t\t\ttype: typeText,\n\t\t\ttypeSpan: { start: type.start, end: typeEnd },\n\t\t\tisRef,\n\t\t\trequired,\n\t\t\tlabel,\n\t\t});\n\t}\n\n\treturn params;\n}\n","// The DSL's platform globals. Signatures and prose track\n// dforge-mcp/skills/dforge-mcp-author/references/action-dsl.md — that file is\n// the source of truth; re-sync when it changes.\n\nexport interface Builtin {\n\tname: string;\n\tsignature: string;\n\treturns: string;\n\tdoc: string;\n\t/**\n\t * Index of the argument that names an entity, when the built-in takes one.\n\t * Drives entity-code completion and the qualify-your-codes diagnostic.\n\t */\n\tentityArg?: number;\n}\n\nexport const BUILTINS: Builtin[] = [\n\t// Data operations\n\t{\n\t\tname: \"insert\",\n\t\tsignature: \"insert(entity, fields)\",\n\t\treturns: \"object\",\n\t\tentityArg: 0,\n\t\tdoc: \"Insert a new record. Returns the full row including auto-filled columns (PK, audit, number sequences).\",\n\t},\n\t{\n\t\tname: \"select\",\n\t\tsignature: \"select(entity, opts?)\",\n\t\treturns: \"object[]\",\n\t\tentityArg: 0,\n\t\tdoc: \"Structured multi-row read. `opts` = `{columns, filter, orderBy, limit, offset}`. Prefer over `query()` for row-shaped reads.\",\n\t},\n\t{\n\t\tname: \"update\",\n\t\tsignature: \"update(entity, key, fields)\",\n\t\treturns: \"number\",\n\t\tentityArg: 0,\n\t\tdoc: \"Update the row(s) matched by `key`; returns rows affected. A value may be `{ inc: n }` to add to the column's current value — use that for every counter, balance and quantity.\",\n\t},\n\t{\n\t\tname: \"delete\",\n\t\tsignature: \"delete(entity, key)\",\n\t\treturns: \"number\",\n\t\tentityArg: 0,\n\t\tdoc: \"Delete the row(s) matched by `key`; returns rows affected.\",\n\t},\n\t{\n\t\tname: \"query\",\n\t\tsignature: \"query(sql, args?)\",\n\t\treturns: \"object[]\",\n\t\tdoc: \"Execute parameterized SQL with `@argName` placeholders and schema-qualified table names. Escape hatch — prefer `select()` / `update()` / `delete()` when the structured shape fits.\",\n\t},\n\t{\n\t\tname: \"getRecord\",\n\t\tsignature: \"getRecord(entity, key)\",\n\t\treturns: \"object\",\n\t\tentityArg: 0,\n\t\tdoc: \"Fetch a single record by key. **Throws** a localized not-found error when absent.\",\n\t},\n\t{\n\t\tname: \"getRecordOrNull\",\n\t\tsignature: \"getRecordOrNull(entity, key)\",\n\t\treturns: \"object | null\",\n\t\tentityArg: 0,\n\t\tdoc: \"Like `getRecord`, but returns `null` instead of throwing — for an expected absence, guarded with `if (rec == null)`.\",\n\t},\n\t{\n\t\tname: \"preloadRef\",\n\t\tsignature: \"preloadRef(fkColumn)\",\n\t\treturns: \"object\",\n\t\tdoc: \"Load the referenced record for a FK column. Read its fields with `ref.get('field')`.\",\n\t},\n\n\t// Messaging\n\t{\n\t\tname: \"error\",\n\t\tsignature: \"error(message)\",\n\t\treturns: \"never\",\n\t\tdoc: \"Abort the action and show an error. Rolls back all changes.\",\n\t},\n\t{ name: \"warn\", signature: \"warn(message)\", returns: \"void\", doc: \"Show a warning and continue.\" },\n\t{\n\t\tname: \"info\",\n\t\tsignature: \"info(message)\",\n\t\treturns: \"void\",\n\t\tdoc: \"Show an informational message — a receipt for work the action did, not a way to publish a computed value.\",\n\t},\n\t{\n\t\tname: \"exit\",\n\t\tsignature: \"exit(message?, level?)\",\n\t\treturns: \"never\",\n\t\tdoc: \"Stop the script early **without** error, keeping changes made so far. Level `'info'` (default) or `'warn'`. This is the DSL's early return — the block compiles to a bare script, so a `return` outside a function is a syntax error wherever it sits.\",\n\t},\n\t{\n\t\tname: \"notify\",\n\t\tsignature: \"notify(userId, message)\",\n\t\treturns: \"void\",\n\t\tdoc: \"Send an in-app notification to a specific user.\",\n\t},\n\t{\n\t\tname: \"sendEmail\",\n\t\tsignature: \"sendEmail(to, subjectOrTemplate, dataOrBody?)\",\n\t\treturns: \"void\",\n\t\tdoc: \"Queue an outbound email. Three arguments, and the **second** picks the mode: `sendEmail(to, 'order.shipped', { ref: [code] })` sends a template, `sendEmail(to, 'Your order shipped', '<p>…</p>')` sends raw HTML. A second argument with no spaces that contains `.` or `_` is read as a template code — so a raw subject like `'Shipped.'` silently becomes one; give a raw subject spaces. There is no fourth argument.\",\n\t},\n\n\t// External calls\n\t{\n\t\tname: \"callApi\",\n\t\tsignature: \"callApi(url, method, headers?, body?)\",\n\t\treturns: \"string\",\n\t\tdoc: \"HTTP request to an external API; returns the body as a string. Max 10 calls per script, 120s timeout, 5MB response.\",\n\t},\n\t{\n\t\tname: \"callService\",\n\t\tsignature: \"callService(name, args)\",\n\t\treturns: \"any\",\n\t\tdoc: \"Invoke a registered host service.\",\n\t},\n\t{\n\t\tname: \"callProc\",\n\t\tsignature: \"callProc(procName, args)\",\n\t\treturns: \"any\",\n\t\tdoc: \"Call a stored procedure with named parameters.\",\n\t},\n\n\t// Files, settings, extraction\n\t{\n\t\tname: \"getFileBase64\",\n\t\tsignature: \"getFileBase64(fileField)\",\n\t\treturns: \"string\",\n\t\tdoc: \"Read a file from storage as base64. Use with `callApi()` to send files to external APIs. Max 10 MB.\",\n\t},\n\t{\n\t\tname: \"getFileUrl\",\n\t\tsignature: \"getFileUrl(fileField)\",\n\t\treturns: \"string\",\n\t\tdoc: \"Temporary signed download URL (relative path) for a file field — for emails and notifications, not for `callApi()`.\",\n\t},\n\t{ name: \"getFileInfo\", signature: \"getFileInfo(fileField)\", returns: \"object | null\", doc: \"File metadata for a file field.\" },\n\t{\n\t\tname: \"download\",\n\t\tsignature: \"download(url, fileName?)\",\n\t\treturns: \"void\",\n\t\tdoc: \"Set a download URL on the action result; the browser opens it when the action returns. It fetches nothing and stores nothing — the URL must already serve the bytes, e.g. the `/api/temp-file/{token}` a service handed back. To put a remote file INTO storage, fetch it with `callApi()` and write it to a file column.\",\n\t},\n\t{\n\t\tname: \"getSetting\",\n\t\tsignature: \"getSetting(settingCd)\",\n\t\treturns: \"any\",\n\t\tdoc: \"Read a module setting, resolved through the folder chain (current folder → parents → module default).\",\n\t},\n\t{\n\t\tname: \"getSecret\",\n\t\tsignature: \"getSecret(secretCd)\",\n\t\treturns: \"string\",\n\t\tdoc: \"Retrieve a decrypted secret (API key, token). Managed in the admin UI.\",\n\t},\n\t{\n\t\tname: \"ocrExtract\",\n\t\tsignature: \"ocrExtract(fileField, endpointBaseUrl, schema?, opts?)\",\n\t\treturns: \"string (v1) | object (v2)\",\n\t\tdoc: \"Run OCR extraction against a document. **The return type follows the mode, and only `opts.mode` selects it** — a third argument alone never does. Without `opts.mode` (v1) the third argument is forwarded as `hints` and the result is the raw bundle as a JSON **string**: `JSON.parse()` it, or every property read is `undefined`. With `{ mode: 'extract' }` the third argument is a schema object and the result is already parsed — `{ fields, confidence?, unmatched, raw_text, meta }`. `{ mode: 'summary' }` needs no schema and returns `{ summary, raw_text, meta }` parsed. `{ profile: 'module_cd.profile_cd' }` uses a registered extraction profile, implies mode `extract`, and cannot be combined with an inline schema. The OCR host must be on `Dsl:Limits:AllowedHosts`.\",\n\t},\n\t{\n\t\tname: \"detectDocument\",\n\t\tsignature: \"detectDocument(rawText)\",\n\t\treturns: \"object | null\",\n\t\tdoc: \"Score text against reachable extraction profiles; returns the best match `{ profile, docType, score }` or `null`.\",\n\t},\n\t{\n\t\tname: \"applyProfile\",\n\t\tsignature: \"applyProfile(json, profile)\",\n\t\treturns: \"object\",\n\t\tdoc: \"Map already-extracted JSON to target fields and return the mapped object — it never writes, so the `insert()` / `update()` stays yours. `json` is the parsed extractor output (`JSON.parse(ocrExtract(...))`). `profile` must be an **inline object**, `{ map: { target: { from, transform?, pick? } }, lines?: { from, map, key? } }` — passing a profile code throws, as profile-by-code is a later slice. `from` is a path into the extraction; `transform` is one of `firstValid:<basis>`, `lookupRef:<entity.matchField>>returnField>`, `matchCatalog:<same>`, `parseMoney` or `parseDate`. Header targets come back at the top level and the 1:N block under its `key` (default `lines`); a missing source path omits the target. Not the same thing as `ocrExtract`'s registered `opts.profile` code.\",\n\t},\n\n\t// Utilities\n\t{ name: \"now\", signature: \"now()\", returns: \"datetime\", doc: \"Current date/time. Lowercase — this is the execute-block date function.\" },\n\t{ name: \"addDays\", signature: \"addDays(date, n)\", returns: \"date\", doc: \"Add `n` days to a date.\" },\n\t{ name: \"addMinutes\", signature: \"addMinutes(date, n)\", returns: \"datetime\", doc: \"Add `n` minutes.\" },\n\t{ name: \"addSeconds\", signature: \"addSeconds(date, n)\", returns: \"datetime\", doc: \"Add `n` seconds.\" },\n\t{ name: \"currentUserId\", signature: \"currentUserId()\", returns: \"long\", doc: \"The acting user's tenant user ID.\" },\n\t{ name: \"flush\", signature: \"flush()\", returns: \"void\", doc: \"Flush pending writes so a following read sees them.\" },\n\t{ name: \"tryParseJson\", signature: \"tryParseJson(value)\", returns: \"any | null\", doc: \"Parse JSON, returning `null` on failure instead of throwing.\" },\n\t{\n\t\tname: \"nextNumber\",\n\t\tsignature: \"nextNumber(entity)\",\n\t\treturns: \"string\",\n\t\tentityArg: 0,\n\t\tdoc: \"Generate the next value from a number sequence. Usually unnecessary — the platform auto-fills on `insert()`.\",\n\t},\n\t{\n\t\tname: \"entityLink\",\n\t\tsignature: \"entityLink(entityCd, record, description?)\",\n\t\treturns: \"link\",\n\t\tentityArg: 0,\n\t\tdoc: \"Build a clickable link to a record, for an `entitylink` column. Always pass a **qualified** code — `entity_cd` is only unique per module.\",\n\t},\n];\n\nexport const BUILTIN_BY_NAME = new Map(BUILTINS.map((b) => [b.name, b]));\n\n/** Bare identifiers the runtime injects — no parentheses. */\nexport const BUILTIN_VALUES: Record<string, string> = {\n\tuserId: \"The acting user's tenant user ID. A bare identifier — `userId()` is a compile error.\",\n\trecords: \"The selected records, in a `batch` action. Iterate with `for x in records { … }`.\",\n\tparams: \"Declared action parameters — read with `params[name]`.\",\n\told: \"Pre-change values, in a trigger-invoked action — read with `old[field]`. Read-only.\",\n};\n","// Static checks for an action DSL body (`logic/actions/*.dsl`).\n//\n// Every rule here mirrors something the platform only tells you at pack or\n// install time — a slow, tenant-bound round trip. The point is to move that\n// feedback to where the script is written, and to the validator that runs\n// before a pack, from one implementation rather than two.\n//\n// The rules that need to know about the module take it through `DslContext`,\n// which is small on purpose: a module code, the action, and the columns of the\n// entity behind the record context. Anything a host can't resolve it simply\n// omits, and the rules that depend on it stand down. See ./types.\n\nimport { BUILTIN_BY_NAME } from \"./builtins\";\nimport { CONTROL_KEYWORDS, type Token } from \"./lexer\";\nimport { type DslDocument, type Span, blockLabelAt, parseDsl } from \"./parse\";\nimport type { ColumnLookup, DslContext, DslIssue, DslSeverity } from \"./types\";\n\n/**\n * Check a DSL body. Returns [] for a clean script.\n *\n * Issues come back in source-feature order (field reads, params, execution\n * mode, block spelling, built-ins, top-level returns, inline assignments)\n * rather than sorted by position — a host that wants them in file order can\n * sort on `start`.\n */\nexport function checkDsl(text: string, ctx: DslContext = {}): DslIssue[] {\n\tconst parsed = parseDsl(text);\n\tconst out: DslIssue[] = [];\n\tconst positionAt = lineIndexer(text);\n\n\tconst add = (\n\t\tspan: Span,\n\t\tmessage: string,\n\t\tseverity: DslSeverity,\n\t\trule: string,\n\t) => {\n\t\tconst { line, column } = positionAt(span.start);\n\t\tout.push({\n\t\t\trule,\n\t\t\tseverity,\n\t\t\tmessage,\n\t\t\tstart: span.start,\n\t\t\tend: span.end,\n\t\t\tline,\n\t\t\tcolumn,\n\t\t});\n\t};\n\n\tconst action = ctx.action;\n\tconst entity = ctx.currentEntity ?? null;\n\tconst isBatch = (action?.executionMode ?? \"single\") === \"batch\";\n\tconst hasColumn = columnMatcher(entity?.columns);\n\n\t// ── record fields ────────────────────────────────────────────────\n\tfor (const ref of parsed.fieldRefs) {\n\t\t// Neither block is rewritten by TransformLine, so brackets in them are\n\t\t// data rather than field reads: `schema:` is embedded as a JS object\n\t\t// literal, and `params:` is read by RxParamDecl — whose trailing\n\t\t// key=value pairs take a bracketed option list, `options=[cash]`.\n\t\tif (ref.block === \"schema\" || ref.block === \"params\") continue;\n\n\t\t// Single-hop is the DSL's own rewrite (`RxRefNav`), so the rule belongs\n\t\t// to the blocks that go through it. canExecute: reaches the formula\n\t\t// engine verbatim, and a formula walks a chain of any depth —\n\t\t// `[vehicle].[depot].[city_name]` resolves there and is tested.\n\t\tconst isDslBlock = ref.block === \"execute\" || ref.block === \"onBeforeStart\";\n\t\t// The compiler rewrites the first hop and then fails on a surviving\n\t\t// `.[` — so it is the bracket, not the hop count, that marks a second\n\t\t// reference. `[vehicle].plate.length` compiles to\n\t\t// `__ref_vehicle.get('plate').length`: one hop, then JavaScript.\n\t\tconst secondRef = ref.navigation.findIndex((h, idx) => idx > 0 && h.bracketed);\n\t\tif (isDslBlock && secondRef > 0) {\n\t\t\tconst first = ref.navigation[secondRef]!;\n\t\t\tconst last = ref.navigation[ref.navigation.length - 1]!;\n\t\t\tadd(\n\t\t\t\t{ start: first.span.start, end: last.span.end },\n\t\t\t\t`Ref navigation is single-hop in the DSL. Use getRecord() or select() to reach past \"${ref.navigation[0]!.name}\".`,\n\t\t\t\t\"error\",\n\t\t\t\t\"dsl/multi-hop-nav\",\n\t\t\t);\n\t\t}\n\n\t\t// Batch execute: applies no `[field]` rewrite at all, so `[true]` stays\n\t\t// the literal it is — and a keyword is never a column name anyway.\n\t\tif (isBatch && ref.block === \"execute\" && LITERAL_NAMES.has(ref.name))\n\t\t\tcontinue;\n\n\t\tif (!entity) continue;\n\t\tif (entity.columns.size === 0) continue;\n\t\tif (hasColumn(ref.name)) continue;\n\t\t// `var ids = [orderId]` is an array literal, not a field read. Only the\n\t\t// name tells the two apart, so a name bound in this script stands down —\n\t\t// the same fail-open the entity checks above use.\n\t\t//\n\t\t// Only the bare bracket is ambiguous. `r[stauts]` and\n\t\t// `records[0][stauts]` name a column outright — the compiler rewrites\n\t\t// each to `.get('stauts')` with the literal name — so a same-named\n\t\t// local says nothing about them.\n\t\tif (ref.isCurrentRecord && parsed.locals.has(ref.name)) continue;\n\n\t\tadd(\n\t\t\tref.span,\n\t\t\t`\"${ref.name}\" is not a column on ${entity.qualified}. [field] names are checked at pack time — this is a compile error, not an empty read.`,\n\t\t\t\"error\",\n\t\t\t\"dsl/unknown-column\",\n\t\t);\n\t}\n\n\t// `old[field]` names columns of the same entity — RxOldAccess feeds them\n\t// into the very same check — so a typo there is a compile error too.\n\tif (entity && entity.columns.size > 0) {\n\t\tfor (const ref of parsed.globalRefs) {\n\t\t\tif (ref.global !== \"old\") continue;\n\t\t\tif (ref.block !== \"execute\" && ref.block !== \"onBeforeStart\") continue;\n\t\t\tif (hasColumn(ref.property)) continue;\n\t\t\tadd(\n\t\t\t\tref.span,\n\t\t\t\t`\"${ref.property}\" is not a column on ${entity.qualified}. old[field] reads the pre-change value of a column, and the name is checked at pack time.`,\n\t\t\t\t\"error\",\n\t\t\t\t\"dsl/unknown-column\",\n\t\t\t);\n\t\t}\n\t}\n\n\t// ── params ───────────────────────────────────────────────────────\n\t// `ValidateParamUsages` compares with OrdinalIgnoreCase, so `params[Qty]`\n\t// against a declared `qty` compiles — flagging it would be a false error.\n\tconst declared = new Set(parsed.params.map((p) => p.name.toLowerCase()));\n\tconst hasParamsBlock = parsed.blocks.some((b) => b.kind === \"params\");\n\tfor (const ref of parsed.globalRefs) {\n\t\tif (ref.global !== \"params\") continue;\n\t\tif (!hasParamsBlock || declared.has(ref.property.toLowerCase())) continue;\n\t\tadd(\n\t\t\tref.span,\n\t\t\t`\"${ref.property}\" is not declared in the params: block.`,\n\t\t\t\"error\",\n\t\t\t\"dsl/unknown-param\",\n\t\t);\n\t}\n\n\t// ── execution mode ───────────────────────────────────────────────\n\tif (action) {\n\t\tconst mode = action.executionMode ?? \"single\";\n\t\t// `recordsRefs` covers both `records[x]` and the bare `for x in records`,\n\t\t// and comes from the lexer, so the word inside a string or a comment\n\t\t// does not count — nor does a script that binds its own `records`,\n\t\t// which shadows the batch global and says nothing about the mode.\n\t\tconst recordsSpan = parsed.locals.has(\"records\")\n\t\t\t? undefined\n\t\t\t: parsed.recordsRefs[0];\n\t\t// execute: alone. `onBeforeStart:` is compiled by CompilePerRecordBlock\n\t\t// whatever the mode — \"always per-record (no batch form)\" — so a bare\n\t\t// field is exactly how it is meant to be written there.\n\t\t//\n\t\t// Batch mode never applies the `[field]` rewrite at all, which is why\n\t\t// `var ids = [id]` survives as the array literal it looks like. Same\n\t\t// disambiguation as the column rule: a name bound in this script is a\n\t\t// local, not a column.\n\t\tconst bareFields = parsed.fieldRefs.filter(\n\t\t\t(r) =>\n\t\t\t\tr.block === \"execute\" &&\n\t\t\t\tr.isCurrentRecord &&\n\t\t\t\t!parsed.locals.has(r.name) &&\n\t\t\t\t!LITERAL_NAMES.has(r.name),\n\t\t);\n\n\t\tif (mode === \"batch\") {\n\t\t\t// Every one of them: an editor underlines what it is told to, and\n\t\t\t// reporting only the first hides the rest behind a re-check.\n\t\t\tfor (const field of bareFields) {\n\t\t\t\tadd(\n\t\t\t\t\tfield.outerSpan,\n\t\t\t\t\t`Action \"${action.code}\" runs in batch mode, which has no current record. Iterate instead: for x in records { x[${field.name}] }.`,\n\t\t\t\t\t\"error\",\n\t\t\t\t\t\"dsl/batch-bare-field\",\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tif (mode !== \"batch\" && recordsSpan) {\n\t\t\tadd(\n\t\t\t\trecordsSpan,\n\t\t\t\t`\"records\" only exists in batch mode; action \"${action.code}\" runs in \"${mode}\" mode.`,\n\t\t\t\t\"warning\",\n\t\t\t\t\"dsl/records-outside-batch\",\n\t\t\t);\n\t\t}\n\t}\n\n\t// ── block-specific spelling ──────────────────────────────────────\n\t// canExecute is parsed by the formula engine, execute by the JavaScript\n\t// compiler. They share more vocabulary than the docs suggest — NULL and\n\t// lowercase booleans work in both, and shipped modules rely on that — so\n\t// only the operators that genuinely have no formula spelling are flagged.\n\tfor (const token of parsed.tokens) {\n\t\tif (blockOf(parsed, token.start) !== \"canExecute\") continue;\n\t\tif (token.text !== \"&&\" && token.text !== \"||\") continue;\n\t\tadd(\n\t\t\t{ start: token.start, end: token.end },\n\t\t\t`canExecute is a formula, not JavaScript — write ${token.text === \"&&\" ? \"AND\" : \"OR\"}.`,\n\t\t\t\"warning\",\n\t\t\t\"dsl/js-in-formula\",\n\t\t);\n\t}\n\n\t// ── built-in misuse ──────────────────────────────────────────────\n\tfor (const call of parsed.calls) {\n\t\tif (call.name === \"userId\") {\n\t\t\tadd(\n\t\t\t\tcall.nameSpan,\n\t\t\t\t\"userId is a bare identifier — userId() is a compile error.\",\n\t\t\t\t\"error\",\n\t\t\t\t\"dsl/user-id-call\",\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst builtin = BUILTIN_BY_NAME.get(call.name);\n\t\tif (!builtin || builtin.entityArg === undefined) continue;\n\t\tconst arg = call.firstStringArg;\n\t\tif (!arg) continue;\n\n\t\t// A hyphenated module code can't be schema-qualified, so the rule is\n\t\t// skipped there rather than reported as unfixable.\n\t\tif (arg.value.includes(\".\") || ctx.moduleCode?.includes(\"-\")) continue;\n\t\tadd(\n\t\t\targ.span,\n\t\t\t`Qualify the entity code as \"${ctx.moduleCode ? `${ctx.moduleCode}.` : \"<module>.\"}${arg.value}\" — entity_cd is only unique per module, so a bare code can resolve to another module's entity.`,\n\t\t\t\"info\",\n\t\t\t\"dsl/unqualified-entity\",\n\t\t);\n\t}\n\n\t// ── indented headers, and returns outside a function ─────────────\n\t// An indented `params:` inside an object literal is an ordinary key, which\n\t// is the whole reason the compiler anchors headers at column 0 rather than\n\t// trusting the line — so that rule reads brace depth.\n\t//\n\t// `return` reads function scope instead. Both blocks compile to a bare\n\t// script, and Esprima's ParseScript rejects a return outside a function\n\t// wherever it sits: `if (x) { return }` and `if (x) return` fail exactly as\n\t// a return on its own line does.\n\tlet depth = 0;\n\tconst functionDepths: number[] = [];\n\t// Index of the `(` that the most recent `)` closed. Tracked with a stack\n\t// because the nearest open paren is not the matching one: in `if (now()) {`\n\t// it is `now`'s, and in `function f(x = (1)) {` it is the default value's.\n\tconst parenStack: number[] = [];\n\tlet matchingParenOpen = -1;\n\tfor (let i = 0; i < parsed.tokens.length; i++) {\n\t\tconst token = parsed.tokens[i]!;\n\n\t\tif (token.text === \"(\") parenStack.push(i);\n\t\telse if (token.text === \")\") matchingParenOpen = parenStack.pop() ?? -1;\n\n\t\tif (token.text === \"{\") {\n\t\t\tdepth++;\n\t\t\tif (opensFunctionBody(parsed.tokens, i, matchingParenOpen))\n\t\t\t\tfunctionDepths.push(depth);\n\t\t} else if (token.text === \"}\") {\n\t\t\tif (functionDepths[functionDepths.length - 1] === depth)\n\t\t\t\tfunctionDepths.pop();\n\t\t\tdepth = Math.max(0, depth - 1);\n\t\t}\n\n\t\tif (depth === 0 && token.character > 0) {\n\t\t\tconst kind = blockLabelAt(parsed.tokens, i);\n\t\t\t// `execute: number` inside params: declares a param called execute.\n\t\t\t// RxParamDecl takes any `\\w+`, so a block name is a legal param\n\t\t\t// name — and a declaration the parser already read is not a header.\n\t\t\tconst isParamDecl = parsed.params.some(\n\t\t\t\t(p) => p.nameSpan.start === token.start,\n\t\t\t);\n\t\t\tif (kind && !isParamDecl) {\n\t\t\t\tadd(\n\t\t\t\t\t{ start: token.start, end: parsed.tokens[i + 1]!.end },\n\t\t\t\t\t`Block headers start at column 0. Indented, \"${kind}:\" is body text — the compiler never opens the block, and it runs as if empty.`,\n\t\t\t\t\t\"error\",\n\t\t\t\t\t\"dsl/indented-block-header\",\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (token.kind !== \"ident\" || token.text !== \"return\") continue;\n\t\t// `return` is a reserved word, so it is a statement unless it is being\n\t\t// used as a name: `result.return` reads a property, `{ return: 1 }`\n\t\t// declares a key and `{ return() { … } }` declares a method. All three\n\t\t// are legal JavaScript.\n\t\tif (parsed.tokens[i - 1]?.text === \".\") continue;\n\t\tif (parsed.tokens[i + 1]?.text === \":\") continue;\n\t\tif (isMethodName(parsed.tokens, i)) continue;\n\t\tif (functionDepths.length > 0) continue;\n\t\tconst block = blockOf(parsed, token.start);\n\t\tif (block !== \"execute\" && block !== \"onBeforeStart\") continue;\n\t\tadd(\n\t\t\t{ start: token.start, end: token.end },\n\t\t\t`A return outside a function is a syntax error — ${block}: compiles to a bare script. Use exit(message, level) to stop early and keep the changes made so far.`,\n\t\t\t\"error\",\n\t\t\t\"dsl/top-level-return\",\n\t\t);\n\t}\n\n\tout.push(...inlineAssignmentIssues(parsed, positionAt));\n\treturn out;\n}\n\n/**\n * Column matching is case-insensitive at the other end — `EntityColumnLookup`\n * hands the compiler an OrdinalIgnoreCase set — but a host passes us whatever\n * `Set` or `Map` it already holds, and a mixed-case column name is legal.\n *\n * So fold both sides: the names once per check when the lookup can enumerate\n * them (`Set` and `Map` both can), and the reference on the way in. A lookup\n * that can do neither falls back to trying the reference in lower case, which\n * is all that is left to try.\n */\nfunction columnMatcher(columns?: ColumnLookup): (name: string) => boolean {\n\tif (!columns) return () => true;\n\tif (typeof columns.keys !== \"function\")\n\t\treturn (name) => columns.has(name) || columns.has(name.toLowerCase());\n\n\tconst folded = new Set<string>();\n\tfor (const key of columns.keys()) folded.add(key.toLowerCase());\n\treturn (name) => folded.has(name.toLowerCase());\n}\n\n/**\n * Whether the name at `i` heads a method shorthand — `return() { … }`, whose\n * parameter list is followed by a body. `return (x + 1)` is a statement with a\n * parenthesized expression and has no brace after the closing paren, so the\n * two are told apart by what follows the parens rather than by what opens them.\n */\nfunction isMethodName(tokens: Token[], i: number): boolean {\n\tif (tokens[i + 1]?.text !== \"(\") return false;\n\tlet depth = 0;\n\tfor (let j = i + 1; j < tokens.length; j++) {\n\t\tconst text = tokens[j]!.text;\n\t\tif (text === \"(\") depth++;\n\t\telse if (text === \")\") {\n\t\t\tdepth--;\n\t\t\tif (depth === 0) return tokens[j + 1]?.text === \"{\";\n\t\t}\n\t}\n\treturn false;\n}\n\n/**\n * Whether the `{` at `i` opens a function body — where a `return` is legal.\n *\n * `=> {` is one. So is `) {` when the name in front of the matching `(` is not\n * a control keyword: that covers `function (x) {`, `function f(x) {` and the\n * `f() {` method shorthand, while leaving `if (x) {` and `for (…) {` alone.\n */\nfunction opensFunctionBody(\n\ttokens: Token[],\n\ti: number,\n\tmatchingParenOpen: number,\n): boolean {\n\tconst prev = tokens[i - 1];\n\tif (prev?.text === \"=>\") return true;\n\tif (prev?.text !== \")\" || matchingParenOpen < 0) return false;\n\tconst head = tokens[matchingParenOpen - 1];\n\treturn head?.kind === \"ident\" && !CONTROL_KEYWORDS.has(head.text);\n}\n\n/**\n * Keyword literals, which `[…]` can only be holding as array elements. Both\n * spellings: the DSL takes SQL-style `NULL`/`TRUE`/`FALSE` as well as the\n * JavaScript ones, and rewrites them to the latter.\n */\nconst LITERAL_NAMES = new Set([\n\t\"true\",\n\t\"false\",\n\t\"null\",\n\t\"TRUE\",\n\t\"FALSE\",\n\t\"NULL\",\n]);\n\nfunction blockOf(parsed: DslDocument, offset: number) {\n\treturn (\n\t\tparsed.blocks.find((b) => offset >= b.body.start && offset < b.body.end)\n\t\t\t?.kind ?? null\n\t);\n}\n\n/**\n * `if (…) { [field] = x }` on a single line mis-compiles — the assignment is\n * rewritten in place and the setter call is lost. One assignment per line.\n */\nfunction inlineAssignmentIssues(\n\tparsed: DslDocument,\n\tpositionAt: (offset: number) => { line: number; column: number },\n): DslIssue[] {\n\tconst out: DslIssue[] = [];\n\tfor (const ref of parsed.fieldRefs) {\n\t\t// `ref.endIndex` is where the parser stopped: a `.prop` hop is 2 tokens\n\t\t// but a `.[prop]` hop is 4, so the count cannot be derived here.\n\t\tconst assign = parsed.tokens[ref.endIndex + 1];\n\t\tif (!assign || assign.kind !== \"punct\" || assign.text !== \"=\") continue;\n\n\t\t// Walk back over this line only, looking for a brace that opened here.\n\t\tconst line = parsed.tokens[ref.startIndex]!.line;\n\t\tlet openedHere = false;\n\t\tfor (let i = ref.startIndex - 1; i >= 0; i--) {\n\t\t\tconst t = parsed.tokens[i]!;\n\t\t\tif (t.line !== line) break;\n\t\t\tif (t.text === \"{\") {\n\t\t\t\topenedHere = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (!openedHere) continue;\n\n\t\tconst pos = positionAt(ref.outerSpan.start);\n\t\tout.push({\n\t\t\trule: \"dsl/inline-assignment\",\n\t\t\tseverity: \"warning\",\n\t\t\tmessage:\n\t\t\t\t\"An assignment to a record field on the same line as the brace that opens its block mis-compiles. Put the assignment on its own line.\",\n\t\t\tstart: ref.outerSpan.start,\n\t\t\tend: ref.outerSpan.end,\n\t\t\tline: pos.line,\n\t\t\tcolumn: pos.column,\n\t\t});\n\t}\n\treturn out;\n}\n\n/**\n * Offset → 1-indexed line/column, over a line-start table built once per check.\n * Scanning the prefix per issue is O(n) each, and a body with many issues is\n * exactly the one where that shows.\n */\nfunction lineIndexer(text: string): (offset: number) => { line: number; column: number } {\n\tconst starts = [0];\n\tfor (let i = 0; i < text.length; i++) {\n\t\tif (text[i] === \"\\n\") starts.push(i + 1);\n\t}\n\treturn (offset: number) => {\n\t\t// Binary search for the last line start at or before `offset`.\n\t\tlet lo = 0;\n\t\tlet hi = starts.length - 1;\n\t\twhile (lo < hi) {\n\t\t\tconst mid = (lo + hi + 1) >> 1;\n\t\t\tif (starts[mid]! <= offset) lo = mid;\n\t\t\telse hi = mid - 1;\n\t\t}\n\t\treturn { line: lo + 1, column: offset - starts[lo]! + 1 };\n\t};\n}\n"],"mappings":";AA4BA,IAAM,SAA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AI,KAAK,OAAO,SAAS;AACzB,WAAO,KAAK,IAAI;AACf,YAAM,MAAO,KAAK,KAAK,KAAM;AAC7B,UAAI,OAAO,GAAG,KAAM,OAAQ,MAAK;AAAA,UAC5B,MAAK,MAAM;AAAA,IACjB;AACA,WAAO,EAAE,MAAM,KAAK,GAAG,QAAQ,SAAS,OAAO,EAAE,IAAK,EAAE;AAAA,EACzD;AACD;","names":[]}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export { a as ActionDef, A as ActionExecutionMode, b as ActionsFile } from './actions-DvYTrCbP.js';
2
+
1
3
  /** A `{ cd, name }` pair for friendly pickers (view kinds, viz types, …). */
2
4
  interface NamedKind {
3
5
  cd: string;
@@ -204,10 +206,6 @@ declare const fieldTypes: readonly [{
204
206
  readonly maxLen: null;
205
207
  readonly precision: null;
206
208
  readonly useStringInFilter: false;
207
- readonly defParams: {
208
- readonly min: 0;
209
- readonly max: 10000;
210
- };
211
209
  }, {
212
210
  readonly cd: "currency";
213
211
  readonly name: "Currency";
@@ -217,10 +215,6 @@ declare const fieldTypes: readonly [{
217
215
  readonly maxLen: null;
218
216
  readonly precision: 2;
219
217
  readonly useStringInFilter: false;
220
- readonly defParams: {
221
- readonly min: 0;
222
- readonly max: 1000000;
223
- };
224
218
  }, {
225
219
  readonly cd: "percent";
226
220
  readonly name: "Percent";
@@ -230,10 +224,6 @@ declare const fieldTypes: readonly [{
230
224
  readonly maxLen: null;
231
225
  readonly precision: 2;
232
226
  readonly useStringInFilter: false;
233
- readonly defParams: {
234
- readonly min: 0;
235
- readonly max: 100;
236
- };
237
227
  }, {
238
228
  readonly cd: "checkbox";
239
229
  readonly name: "Checkbox";
@@ -1379,68 +1369,9 @@ interface SeedDataFile {
1379
1369
  records: Record<string, unknown>[];
1380
1370
  }
1381
1371
 
1382
- /**
1383
- * Execution mode. 'single' (default) and 'each' run the DSL per selected record;
1384
- * 'batch' runs once with all records exposed as `__records`.
1385
- */
1386
- type ActionExecutionMode = "single" | "each" | "batch";
1387
- /** A single action declaration (value in the `ui/actions.json` map). */
1388
- interface ActionDef {
1389
- /** Human-readable description. */
1390
- description: string;
1391
- /** Button label. */
1392
- label: string;
1393
- /** Bootstrap icon class (e.g. 'bi-telephone-check'). */
1394
- icon: string;
1395
- /** Entity code this action targets. */
1396
- entityCode: string;
1397
- /** Per-record vs. batch execution. */
1398
- executionMode: ActionExecutionMode;
1399
- /** DSL script name (file under `logic/actions/<script>.dsl`). */
1400
- script: string;
1401
- /**
1402
- * Run the whole selection in one transaction, so a failure on any record
1403
- * rolls back the records already processed. **Defaults to `true`** when
1404
- * omitted (`ActionDef.IsTransacted` in the installer is a non-nullable
1405
- * `bool` initialised to `true`), so omit it only when you want atomicity.
1406
- *
1407
- * `false` opens no transaction, and what follows a failure depends on
1408
- * {@link ActionDef.executionMode}: `single` / `each` report it and continue
1409
- * with the next record, so use that for independent per-record work that
1410
- * should process as many records as pass; `batch` is a single script
1411
- * invocation with no loop to continue, so the run simply ends with its
1412
- * earlier writes committed.
1413
- *
1414
- * On a run queued to the background the **rollback** guarantee is lost
1415
- * outright — the worker opens no transaction, so nothing is ever undone. What
1416
- * remains of the flag there depends on the mode: the worker's `single`/`each`
1417
- * loop still reads it for control flow (stop after the first failed record vs.
1418
- * continue), while its `batch` path never reads it at all — one invocation,
1419
- * which ends on failure under either value.
1420
- */
1421
- isTransacted?: boolean;
1422
- /** Display order. */
1423
- orderNum?: number;
1424
- /**
1425
- * @deprecated Not read by the installer — use {@link ActionDef.isAsync}.
1426
- * The module manifest model binds `isAsync` only, so this key is silently
1427
- * ignored and the action installs as synchronous.
1428
- */
1429
- async?: boolean;
1430
- /**
1431
- * Permit background execution. It does not force it: `action.execute`
1432
- * carries its own `async` argument and the server branches on that, so an
1433
- * action with parameters is offered to the user as both "Run" (inline) and
1434
- * "Run in Background". A parameterless `isAsync` action is queued directly.
1435
- */
1436
- isAsync?: boolean;
1437
- }
1438
- /** A `ui/actions.json` file: action code → definition. */
1439
- type ActionsFile = Record<string, ActionDef>;
1440
-
1441
1372
  declare const flagDefs: readonly {
1442
1373
  value: FlagCd;
1443
1374
  label: string;
1444
1375
  }[];
1445
1376
 
1446
- export { AGG_TYPE_LIST, type AccumulationConfig, type ActionDef, type ActionExecutionMode, type ActionsFile, AggType, type AlignType, type BaseDatatypeCd, type CalendarViewConfig, type ColumnDef, type ColumnTypeCd, type ColumnTypeDef, DEP_COLUMN_TYPES, type DataSource, type DataViewDef, type DataViewsFile, type Dataset, type DepColumn, type DepColumnMode, type DepColumnType, type DepEntity, type DepProvenance, type DepProvenanceKind, type DepsFile, type DeriveOptions, type DiagramViewConfig, type DomainDef, type DomainsFile, type EntityDef, type EntityEvent, type EntityReference, type EntityViewColumnDef, type EntityViewDef, FILTER_GROUP_OPERATORS, FILTER_OPERATORS, type FieldDef, type FieldLink, type FieldOption, type FieldTypeCd, type FieldTypeDef, type Filter, type FilterCondition, type FilterGroup, type FilterGroupOperator, type FilterOperator, type FlagCd, type FolderDef, type FolderEntityBinding, type FoldersFile, type JobDef, type JobsFile, type KanbanViewConfig, type LedgerRegistryEntry, type ListLevelConfig, type ListViewConfig, type ManifestAuthor, type ManifestDef, type MenuDef, type MenuItemDef, type MenuItemType, type MenusFile, type ModuleDependency, type ModuleFeature, NUMERIC_TOTAL, type NamedKind, type NumberSequenceDef, type ParamDef, type ParamDefBase, type PeriodConfig, type PrintMargins, type PrintPageSettings, type PrintTemplateDef, type PrintTemplatesFile, type ReportDef, type ReportEntityAttachment, type ReportLayout, type ReportPanel, type ReportQuery, type ReportsFile, type RoleDef, type RolesFile, type SeedDataFile, type SettingBaseDatatype, type SettingDef, type SettingsFile, type SignConfig, type SortClause, type TraitCd, type TraitDef, type TreeGridViewConfig, type TriggerDef, type TriggersFile, type ViewColumn, type ViewType, type VizType, type WebhookPayload, type WebhookSubscription, type WebhooksFile, baseDatatypes, baseToDbDatatype, chartTypes, columnTypes, dataViewKinds, defaultParams, deriveBaseDatatype, deriveDbDatatype, expandTrait, expandTraits, fieldTypeCds, fieldTypes, fieldTypesByColumnType, flagDefs, getColumnType, getFieldType, getIdentityKeys, getLinks, getPrimaryKeys, getTrait, isFieldTypeCd, traits, vizTypes };
1377
+ export { AGG_TYPE_LIST, type AccumulationConfig, AggType, type AlignType, type BaseDatatypeCd, type CalendarViewConfig, type ColumnDef, type ColumnTypeCd, type ColumnTypeDef, DEP_COLUMN_TYPES, type DataSource, type DataViewDef, type DataViewsFile, type Dataset, type DepColumn, type DepColumnMode, type DepColumnType, type DepEntity, type DepProvenance, type DepProvenanceKind, type DepsFile, type DeriveOptions, type DiagramViewConfig, type DomainDef, type DomainsFile, type EntityDef, type EntityEvent, type EntityReference, type EntityViewColumnDef, type EntityViewDef, FILTER_GROUP_OPERATORS, FILTER_OPERATORS, type FieldDef, type FieldLink, type FieldOption, type FieldTypeCd, type FieldTypeDef, type Filter, type FilterCondition, type FilterGroup, type FilterGroupOperator, type FilterOperator, type FlagCd, type FolderDef, type FolderEntityBinding, type FoldersFile, type JobDef, type JobsFile, type KanbanViewConfig, type LedgerRegistryEntry, type ListLevelConfig, type ListViewConfig, type ManifestAuthor, type ManifestDef, type MenuDef, type MenuItemDef, type MenuItemType, type MenusFile, type ModuleDependency, type ModuleFeature, NUMERIC_TOTAL, type NamedKind, type NumberSequenceDef, type ParamDef, type ParamDefBase, type PeriodConfig, type PrintMargins, type PrintPageSettings, type PrintTemplateDef, type PrintTemplatesFile, type ReportDef, type ReportEntityAttachment, type ReportLayout, type ReportPanel, type ReportQuery, type ReportsFile, type RoleDef, type RolesFile, type SeedDataFile, type SettingBaseDatatype, type SettingDef, type SettingsFile, type SignConfig, type SortClause, type TraitCd, type TraitDef, type TreeGridViewConfig, type TriggerDef, type TriggersFile, type ViewColumn, type ViewType, type VizType, type WebhookPayload, type WebhookSubscription, type WebhooksFile, baseDatatypes, baseToDbDatatype, chartTypes, columnTypes, dataViewKinds, defaultParams, deriveBaseDatatype, deriveDbDatatype, expandTrait, expandTraits, fieldTypeCds, fieldTypes, fieldTypesByColumnType, flagDefs, getColumnType, getFieldType, getIdentityKeys, getLinks, getPrimaryKeys, getTrait, isFieldTypeCd, traits, vizTypes };
package/dist/index.js CHANGED
@@ -17,9 +17,9 @@ var fieldTypes = [
17
17
  { cd: "phone", name: "Phone", columnType: "D", baseDatatypeCd: "string", supportedAgg: null, maxLen: null, precision: null, useStringInFilter: true },
18
18
  { cd: "url", name: "URL", columnType: "D", baseDatatypeCd: "string", supportedAgg: null, maxLen: null, precision: null, useStringInFilter: true },
19
19
  { cd: "textarea", name: "Multiline Text", columnType: "D", baseDatatypeCd: "string", supportedAgg: null, maxLen: null, precision: null, useStringInFilter: true },
20
- { cd: "number", name: "Number", columnType: "D", baseDatatypeCd: "number", supportedAgg: "SCAM", maxLen: null, precision: null, useStringInFilter: false, defParams: { min: 0, max: 1e4 } },
21
- { cd: "currency", name: "Currency", columnType: "D", baseDatatypeCd: "number", supportedAgg: "SCAM", maxLen: null, precision: 2, useStringInFilter: false, defParams: { min: 0, max: 1e6 } },
22
- { cd: "percent", name: "Percent", columnType: "D", baseDatatypeCd: "number", supportedAgg: "CAM", maxLen: null, precision: 2, useStringInFilter: false, defParams: { min: 0, max: 100 } },
20
+ { cd: "number", name: "Number", columnType: "D", baseDatatypeCd: "number", supportedAgg: "SCAM", maxLen: null, precision: null, useStringInFilter: false },
21
+ { cd: "currency", name: "Currency", columnType: "D", baseDatatypeCd: "number", supportedAgg: "SCAM", maxLen: null, precision: 2, useStringInFilter: false },
22
+ { cd: "percent", name: "Percent", columnType: "D", baseDatatypeCd: "number", supportedAgg: "CAM", maxLen: null, precision: 2, useStringInFilter: false },
23
23
  { cd: "checkbox", name: "Checkbox", columnType: "D", baseDatatypeCd: "bool", supportedAgg: "C", maxLen: null, precision: null, useStringInFilter: false },
24
24
  { cd: "date", name: "Date", columnType: "D", baseDatatypeCd: "date", supportedAgg: "CM", maxLen: null, precision: null, useStringInFilter: false },
25
25
  { cd: "datetime", name: "Date & Time", columnType: "D", baseDatatypeCd: "timestamp", supportedAgg: "CM", maxLen: null, precision: null, useStringInFilter: false },