@dforge-core/dforge-mcp 0.1.10 → 0.1.11
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.
- package/CHANGELOG.md +52 -0
- package/dist/server.js +3 -1
- package/package.json +2 -2
- package/resources/docs/conventions.md +1 -1
- package/resources/docs/dsl-reference.md +55 -1
- package/resources/schemas/entity.schema.json +3 -3
- package/skills/dforge-mcp-author/SKILL.md +1 -1
- package/skills/dforge-mcp-author/references/action-dsl.md +104 -5
- package/skills/dforge-mcp-author/references/field-types.md +6 -2
- package/skills/dforge-mcp-author/references/formulas.md +8 -3
- package/skills/dforge-mcp-author/references/jobs.md +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,58 @@ All notable changes to `@dforge-core/dforge-mcp`. This project uses semver-ish
|
|
|
4
4
|
`0.1.0-rc.N` pre-release tags; the published version is set at publish time via
|
|
5
5
|
the release workflow, so committed `package.json` versions are placeholders.
|
|
6
6
|
|
|
7
|
+
## 0.1.11
|
|
8
|
+
|
|
9
|
+
> Release prerequisite: publish `@dforge-core/metadata@0.0.9` first (adds the
|
|
10
|
+
> `avatar`/`markdown` field types to the runtime registry — until then the field
|
|
11
|
+
> tools reject them), then `pnpm install` + `sync-schemas` here.
|
|
12
|
+
|
|
13
|
+
### Skill
|
|
14
|
+
|
|
15
|
+
- **Action DSL: `select()` / `update()` / `delete()` documented.**
|
|
16
|
+
`select('module.entity', {columns, filter, orderBy, limit, offset})` is the
|
|
17
|
+
structured multi-row read: canonical `{c,o,v}`/`{g,i}` filter JSON (same
|
|
18
|
+
operators as data views), one-hop nav paths `'ref.target as alias'` that emit
|
|
19
|
+
LEFT JOINs, **fail-loud** semantics (unknown column/operator/nav path throws —
|
|
20
|
+
unlike UI filters, which drop the condition), and no folder row-filter/column
|
|
21
|
+
security (it hits the table directly; filter nav paths instead of `R`
|
|
22
|
+
columns). `update()`/`delete()` take a scalar PK **or** a `{col: val}` object
|
|
23
|
+
key (string ids coerced to the PK storage type; array and null keys rejected).
|
|
24
|
+
`query()` is repositioned as the escape hatch (aggregates, multi-hop joins,
|
|
25
|
+
CTEs, `FOR UPDATE`). New real example: `comm.dispatch_messages` (cron-scan
|
|
26
|
+
`select()` + scalar-key `update()`). Also documents `exit(message?, level?)` —
|
|
27
|
+
the DSL's early-return — and the rule to always qualify entity codes
|
|
28
|
+
(`update('comm.message', …)`) (`action-dsl.md`, `jobs.md`, `SKILL.md`).
|
|
29
|
+
- **Formula date family completed + SQL-time parity** (`formulas.md`). Adds the
|
|
30
|
+
missing `WEEKDAY`, `DATE`, and period-boundary functions (`STARTMONTH`,
|
|
31
|
+
`ENDMONTH`, `STARTQUARTER`, `ENDQUARTER`, `STARTYEAR`, `ENDYEAR`,
|
|
32
|
+
`STARTNEXTMONTH` — optional arg defaults to today) and corrects
|
|
33
|
+
`DATEADD`/`DATEDIFF` signatures (string-literal units `'DAY'`/`'HOUR'`/
|
|
34
|
+
`'MINUTE'`/`'SECOND'`/`'MONTH'`/`'YEAR'`; `DATEDIFF(d1, d2, unit)` = `d2 − d1`).
|
|
35
|
+
The whole family now evaluates identically client-side and SQL-time (reports,
|
|
36
|
+
filters, sorts) — the server SQL translator gained the full set, so
|
|
37
|
+
`DATEDIFF([due_date], TODAY(), 'DAY')` no longer comes back NULL in reports.
|
|
38
|
+
- **Field types** (`field-types.md`): added `avatar` (initials circle +
|
|
39
|
+
optional photo via `params.imageColumn`), `markdown` (Write/Preview editor,
|
|
40
|
+
distinct from `richtext` WYSIWYG — the alias table previously mapped
|
|
41
|
+
`markdown` → `richtext`, now wrong), and `list` (card-list rendering of a 1:N
|
|
42
|
+
set, sibling of `grid`).
|
|
43
|
+
|
|
44
|
+
### Resources
|
|
45
|
+
|
|
46
|
+
- **`dforge://reference/dsl` (`resources/docs/dsl-reference.md`) caught up with the
|
|
47
|
+
engine**: documents `select()`, `update()`, `delete()` (previously absent — the
|
|
48
|
+
reference stopped at `query()`/`insert()`), plus `entityLink()`, the
|
|
49
|
+
qualify-entity-codes rule, and scalar-vs-object key semantics.
|
|
50
|
+
|
|
51
|
+
### Schema
|
|
52
|
+
|
|
53
|
+
- **`entity.schema.json` re-vendored** (from `@dforge-core/metadata@0.0.9`):
|
|
54
|
+
`fieldTypeCd` enum gains `avatar`, `markdown`, `list`; `refFilter` description
|
|
55
|
+
now documents `@[field]` dynamic placeholders (resolved against the current
|
|
56
|
+
record at option load; an unset placeholder drops the condition, and lookups
|
|
57
|
+
re-resolve options on every open).
|
|
58
|
+
|
|
7
59
|
## 0.1.10
|
|
8
60
|
|
|
9
61
|
### Schema
|
package/dist/server.js
CHANGED
|
@@ -31180,6 +31180,7 @@ var AGG_TYPE_LIST = Object.values(AggType);
|
|
|
31180
31180
|
// node_modules/@dforge-core/metadata/dist/field-types.js
|
|
31181
31181
|
var fieldTypes = [
|
|
31182
31182
|
{ cd: "text", name: "Text", columnType: "D", baseDatatypeCd: "string", supportedAgg: null, maxLen: null, precision: null, useStringInFilter: true },
|
|
31183
|
+
{ cd: "avatar", name: "Avatar Name", columnType: "D", baseDatatypeCd: "string", supportedAgg: null, maxLen: null, precision: null, useStringInFilter: true },
|
|
31183
31184
|
{ cd: "email", name: "Email", columnType: "D", baseDatatypeCd: "string", supportedAgg: null, maxLen: null, precision: null, useStringInFilter: true },
|
|
31184
31185
|
{ cd: "phone", name: "Phone", columnType: "D", baseDatatypeCd: "string", supportedAgg: null, maxLen: null, precision: null, useStringInFilter: true },
|
|
31185
31186
|
{ cd: "url", name: "URL", columnType: "D", baseDatatypeCd: "string", supportedAgg: null, maxLen: null, precision: null, useStringInFilter: true },
|
|
@@ -31198,6 +31199,7 @@ var fieldTypes = [
|
|
|
31198
31199
|
{ cd: "color", name: "Color Picker", columnType: "D", baseDatatypeCd: "string", supportedAgg: null, maxLen: 20, precision: null, useStringInFilter: false },
|
|
31199
31200
|
{ cd: "image", name: "Image", columnType: "D", baseDatatypeCd: "binary", supportedAgg: null, maxLen: null, precision: null, useStringInFilter: false },
|
|
31200
31201
|
{ cd: "file", name: "File", columnType: "D", baseDatatypeCd: "binary", supportedAgg: null, maxLen: null, precision: null, useStringInFilter: false },
|
|
31202
|
+
{ cd: "markdown", name: "Markdown", columnType: "D", baseDatatypeCd: "string", supportedAgg: null, maxLen: null, precision: null, useStringInFilter: true },
|
|
31201
31203
|
{ cd: "richtext", name: "Rich Text Editor", columnType: "D", baseDatatypeCd: "string", supportedAgg: null, maxLen: null, precision: null, useStringInFilter: true },
|
|
31202
31204
|
{ cd: "lookup", name: "Lookup", columnType: "R", baseDatatypeCd: "guid", supportedAgg: "C", maxLen: null, precision: null, useStringInFilter: true },
|
|
31203
31205
|
{ cd: "user", name: "User Picker", columnType: "D", baseDatatypeCd: "cuid", supportedAgg: "C", maxLen: null, precision: null, useStringInFilter: false },
|
|
@@ -31355,7 +31357,7 @@ function expandTraits(traitCds, entityName) {
|
|
|
31355
31357
|
|
|
31356
31358
|
// node_modules/@dforge-core/metadata/dist/derive.js
|
|
31357
31359
|
var NUMERIC_TOTAL = 18;
|
|
31358
|
-
var TEXT_BACKED = /* @__PURE__ */ new Set(["textarea", "richtext", "code"]);
|
|
31360
|
+
var TEXT_BACKED = /* @__PURE__ */ new Set(["textarea", "markdown", "richtext", "code"]);
|
|
31359
31361
|
var DB_DATATYPE_OVERRIDE = {
|
|
31360
31362
|
file: "jsonb",
|
|
31361
31363
|
image: "jsonb"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dforge-core/dforge-mcp",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"description": "MCP server for dForge module authoring. Exposes scaffold/pack/install tools and schema resources so AI agents (Claude Code, Cursor, Zed) can create and ship dForge modules.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/iash44/dForge-core",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@dforge-core/dforge-cli": "^0.2.7",
|
|
35
|
-
"@dforge-core/metadata": "^0.0.
|
|
35
|
+
"@dforge-core/metadata": "^0.0.9",
|
|
36
36
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
37
37
|
"zod": "^4.4.3"
|
|
38
38
|
},
|
|
@@ -562,7 +562,7 @@ Cron-driven action fires. Each entry pairs an existing action (declared in `ui/a
|
|
|
562
562
|
- `schedule` — five fields, minute granularity (sub-minute schedules are rejected at install)
|
|
563
563
|
- `timeout` — required, in seconds, range `(0, 3600]`
|
|
564
564
|
- `timeout > 300` requires `"class": "long_running"` (the standard pool is capped at 300s)
|
|
565
|
-
- Referenced action must NOT use `[field]` or `for x in records` — scheduled fires have no record context. Install fails fast if it does. Use `
|
|
565
|
+
- Referenced action must NOT use `[field]` or `for x in records` — scheduled fires have no record context. Install fails fast if it does. Use `select()` / `insert()` / `update()` for table-level work.
|
|
566
566
|
- Max 50 jobs per module
|
|
567
567
|
- Optional `timeZone` (IANA name) overrides `auth.tenant.time_zone` for that job
|
|
568
568
|
- Use `paused: true` to freeze a job during incidents — admin "Run now" still works while the cron path is silent
|
|
@@ -130,10 +130,13 @@ execute:
|
|
|
130
130
|
|
|
131
131
|
---
|
|
132
132
|
|
|
133
|
-
## Built-in functions
|
|
133
|
+
## Built-in functions
|
|
134
134
|
|
|
135
135
|
All exposed by `ActionScriptEngine.cs` as host globals — no `import` needed.
|
|
136
136
|
|
|
137
|
+
> **Entity codes: always qualify** (`'comm.message'`, not `'message'`) in every data
|
|
138
|
+
> built-in, even inside the owning module.
|
|
139
|
+
|
|
137
140
|
### Database & data
|
|
138
141
|
|
|
139
142
|
#### `query(sql, params?) → array`
|
|
@@ -168,6 +171,46 @@ var po = insert('purchase_order', { supplier_id: params[supplier].supplier_id })
|
|
|
168
171
|
insert('po_line', { po_id: po.purchase_order_id, product_id: [product_id], qty: 1 })
|
|
169
172
|
```
|
|
170
173
|
|
|
174
|
+
#### `select(entityCd, opts?) → array`
|
|
175
|
+
Structured multi-row read — the counterpart to `insert()`/`update()`/`delete()`; prefer
|
|
176
|
+
it over `query()` for row-shaped reads. `opts` (all optional): `columns` (paths; a
|
|
177
|
+
one-hop nav path `'ref.target as alias'` LEFT JOINs the referenced entity; formula
|
|
178
|
+
columns translate to SQL; default = all physical columns), `filter` (canonical
|
|
179
|
+
`{c,o,v}`/`{g,i}` filter JSON, nav paths allowed), `orderBy` (`'-'` prefix =
|
|
180
|
+
descending; default = PK), `limit`, `offset`. **Fail-loud:** an unknown column,
|
|
181
|
+
operator, or nav path throws instead of silently dropping the condition. Hits the
|
|
182
|
+
table directly (no folder row-filter / column security); a plain reference (`R`)
|
|
183
|
+
column can't be selected or string-filtered — use the FK column or a nav path.
|
|
184
|
+
`query()` remains the escape hatch (aggregates, multi-hop joins, CTEs, `FOR UPDATE`).
|
|
185
|
+
|
|
186
|
+
```dsl
|
|
187
|
+
var queued = select('comm.message', {
|
|
188
|
+
columns: ['message_id', 'to_addr', 'to_point.value as point_value', 'subject'],
|
|
189
|
+
filter: { g: 'and', i: [
|
|
190
|
+
{ c: 'status', o: '=', v: 'queued' },
|
|
191
|
+
{ c: 'channel', o: '=', v: 'email' }
|
|
192
|
+
] },
|
|
193
|
+
orderBy: ['message_id'],
|
|
194
|
+
limit: 10
|
|
195
|
+
})
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
#### `update(entityCd, key, fields) → int`
|
|
199
|
+
Update the row(s) matched by `key`; returns rows affected. Refreshes update-phase
|
|
200
|
+
server defaults (audit `last_updated` / `last_updated_by`) and coerces values like
|
|
201
|
+
`insert()`. `key` is a scalar PK (`update('task', 42, {…})`) or an object
|
|
202
|
+
(`{ task_id: 42 }`; multiple entries for a compound key). Scalar string ids are
|
|
203
|
+
coerced to the PK storage type (snowflake-as-string binds `int8`). A null key
|
|
204
|
+
**throws**; array keys are rejected — loop and mutate per id.
|
|
205
|
+
|
|
206
|
+
```dsl
|
|
207
|
+
update('comm.message', msg.message_id, { status: 'sent', sent_at: now() })
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
#### `delete(entityCd, key) → int`
|
|
211
|
+
Delete the row(s) matched by `key`; returns rows affected. Same key shapes and
|
|
212
|
+
rules as `update()`.
|
|
213
|
+
|
|
171
214
|
#### `getRecord(entityCd, key) → record`
|
|
172
215
|
Fetch a single record by key. **Throws** a localized "not found" error if no row
|
|
173
216
|
matches — the safe default for a lookup that should always resolve (e.g. an FK you
|
|
@@ -376,6 +419,17 @@ if (!result.isValid) { error('Validation failed: ' + result.errors[0]) }
|
|
|
376
419
|
|
|
377
420
|
### Utility
|
|
378
421
|
|
|
422
|
+
#### `entityLink(entityCd, record, description?) → link value`
|
|
423
|
+
Build a clickable link to any entity record for storing in an `entitylink` (jsonb)
|
|
424
|
+
column. `record` is a row object (e.g. from `insert()` / `getRecord()`); its PK
|
|
425
|
+
columns are stored as **strings** so snowflake/cuid ids > 2^53 stay exact. Optional
|
|
426
|
+
`description` sets the display text.
|
|
427
|
+
|
|
428
|
+
```dsl
|
|
429
|
+
var task = insert('workspace.task', { title: 'Follow up' })
|
|
430
|
+
insert('workspace.task_note', { link: entityLink('workspace.task', task, task.title) })
|
|
431
|
+
```
|
|
432
|
+
|
|
379
433
|
#### `flush()`
|
|
380
434
|
Commit pending changes mid-script AND broadcast SSE updates to connected clients. **Async / background actions only** — in sync actions, everything commits at the end automatically.
|
|
381
435
|
|
|
@@ -120,10 +120,10 @@
|
|
|
120
120
|
"fieldTypeCd": {
|
|
121
121
|
"type": "string",
|
|
122
122
|
"enum": [
|
|
123
|
-
"text", "email", "phone", "url", "textarea", "number", "currency", "percent",
|
|
123
|
+
"text", "avatar", "email", "phone", "url", "textarea", "number", "currency", "percent",
|
|
124
124
|
"checkbox", "date", "datetime", "time",
|
|
125
125
|
"dropdown", "flags", "tags", "json", "hidden", "color", "image", "file",
|
|
126
|
-
"richtext", "lookup", "user", "grid", "entitylink", "code"
|
|
126
|
+
"markdown", "richtext", "lookup", "user", "grid", "list", "entitylink", "code"
|
|
127
127
|
],
|
|
128
128
|
"description": "UI field type code from field_type table"
|
|
129
129
|
},
|
|
@@ -210,7 +210,7 @@
|
|
|
210
210
|
"description": "On a self-referencing reference column (R column whose link.entity is the owning entity), set true to ALLOW parent/child cycles. When absent the self-reference is treated as an acyclic hierarchy and DB-level guards reject loops. Ignored on non-self-referencing columns."
|
|
211
211
|
},
|
|
212
212
|
"refFilter": {
|
|
213
|
-
"description": "Filter criteria for reference lookups"
|
|
213
|
+
"description": "Filter criteria for reference lookups. Condition values support @[field] placeholders resolved against the current record at lookup time (e.g. {\"c\":\"channel\",\"o\":\"eq\",\"v\":\"@[channel]\"} narrows options to rows matching the record's own channel); a condition whose placeholder is unset is dropped rather than matching nothing."
|
|
214
214
|
}
|
|
215
215
|
},
|
|
216
216
|
"oneOf": [
|
|
@@ -274,7 +274,7 @@ For each trigger, propose: entity + event + (optional) condition formula + targe
|
|
|
274
274
|
Load the "scheduled job" row from the Loading policy table (`dforge://reference/jobs` + `dforge://schema/jobs`).
|
|
275
275
|
|
|
276
276
|
Constraints baked into the tool:
|
|
277
|
-
- Action MUST NOT use record-context (`[field]`) syntax — jobs run as system user with NO current record. Wrap any record-context action in a thin job-friendly action that uses `query()` to fetch the records it needs.
|
|
277
|
+
- Action MUST NOT use record-context (`[field]`) syntax — jobs run as system user with NO current record. Wrap any record-context action in a thin job-friendly action that uses `select()` (or `query()`) to fetch the records it needs.
|
|
278
278
|
- `timeout` is required, ≤ 3600s.
|
|
279
279
|
- If `timeout > 300`, you MUST set `jobClass: 'long_running'`.
|
|
280
280
|
|
|
@@ -106,11 +106,68 @@ var note = params[note] // no quotes around param name in this DSL
|
|
|
106
106
|
| Function | Returns | Description |
|
|
107
107
|
|---|---|---|
|
|
108
108
|
| `insert('entity', { field: value, … })` | Inserted row object | Insert a new record. Returns the full row including auto-filled columns (PK, audit, number sequences). Access returned fields with `result.field_name`. |
|
|
109
|
-
| `
|
|
110
|
-
| `
|
|
109
|
+
| `select('entity', opts?)` | Array of row objects | Structured multi-row read — see "select()" below. `opts` = `{columns, filter, orderBy, limit, offset}`, all optional. Prefer over `query()` for row-shaped reads. |
|
|
110
|
+
| `update('entity', key, { field: value, … })` | Rows affected (number) | Update the row(s) matched by `key`. Refreshes update-phase server defaults (audit `last_updated` / `last_updated_by`) and coerces values like `insert()`. |
|
|
111
|
+
| `delete('entity', key)` | Rows affected (number) | Delete the row(s) matched by `key`. |
|
|
112
|
+
| `query('SQL', { arg: value })` | Array of row objects | Execute parameterized SQL. Use `@argName` placeholders. Schema-qualified table names (`crm.contact`). Access row fields with `row.field_name` or `row['field_name']`. **Escape hatch** — prefer `select()`/`update()`/`delete()` when the structured shape fits. |
|
|
113
|
+
| `getRecord('entity', key)` | Row object | Fetch a single record by key. Access fields with `rec.field_name` (or `rec.get('field_name')`). **Throws** a localized "not found" error if absent. |
|
|
111
114
|
| `getRecordOrNull('entity', key)` | Row object or `null` | Like `getRecord`, but returns `null` instead of throwing when the row is absent — use for an expected-absence lookup, guarded with `if (rec == null)`. |
|
|
112
115
|
| `preloadRef('fk_column')` | Row object | Load the referenced record for a FK column. Access its fields with `ref.get('field')`. |
|
|
113
116
|
|
|
117
|
+
> **Entity codes: always qualify.** Every data built-in (`select`, `insert`, `update`, `delete`,
|
|
118
|
+
> `getRecord`, `nextNumber`) accepts a qualified `module.entity` code — write `update('comm.message', …)`,
|
|
119
|
+
> not `update('message', …)`, even inside the owning module. It reads unambiguously and keeps the
|
|
120
|
+
> script correct if it's ever moved to a bridge module.
|
|
121
|
+
|
|
122
|
+
> **Keys: scalar or object.** In `update()` / `delete()` / `getRecord()` / `getRecordOrNull()`,
|
|
123
|
+
> `key` is either a scalar PK value (`update('task', 42, {…})` — single-column PK only) or an
|
|
124
|
+
> object (`{ task_id: 42 }`; multiple entries for compound keys). Scalar **string** ids are coerced
|
|
125
|
+
> to the PK's storage type, so a snowflake id carried as a string binds as `int8`, not text. A
|
|
126
|
+
> `null` key **throws** (a `col = NULL` predicate can never match), and array keys are rejected —
|
|
127
|
+
> loop and mutate per id instead.
|
|
128
|
+
|
|
129
|
+
### select() — structured multi-row reads
|
|
130
|
+
|
|
131
|
+
The read counterpart to `insert()`/`update()`/`delete()`. Entity codes are metadata-validated,
|
|
132
|
+
values are parameterized and type-coerced per column, and reference navigation replaces
|
|
133
|
+
hand-written LEFT JOINs. A bare `select('entity')` reads every physical column of every row,
|
|
134
|
+
ordered by PK.
|
|
135
|
+
|
|
136
|
+
```javascript
|
|
137
|
+
var queued = select('comm.message', {
|
|
138
|
+
columns: ['message_id', 'to_addr', 'to_point.value as point_value', 'subject'],
|
|
139
|
+
filter: { g: 'and', i: [
|
|
140
|
+
{ c: 'status', o: '=', v: 'queued' },
|
|
141
|
+
{ c: 'channel', o: '=', v: 'email' },
|
|
142
|
+
{ g: 'or', i: [
|
|
143
|
+
{ c: 'to_addr', o: '!null' },
|
|
144
|
+
{ c: 'to_point.value', o: '!null' }
|
|
145
|
+
] }
|
|
146
|
+
] },
|
|
147
|
+
orderBy: ['message_id'],
|
|
148
|
+
limit: 10
|
|
149
|
+
})
|
|
150
|
+
// queued = [{ message_id: 123, to_addr: null, point_value: 'a@b.c', subject: '…' }, …]
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
| Option | Shape | Notes |
|
|
154
|
+
|---|---|---|
|
|
155
|
+
| `columns` | array of strings | Column paths. A one-hop nav path `'ref.target'` LEFT JOINs the referenced entity; `' as alias'` renames the key in the returned rows (avoids bracket-indexed `row['ref.target']` access). Formula columns are translated to SQL. Defaults to all physical columns. |
|
|
156
|
+
| `filter` | object | The platform's canonical filter JSON — `{c, o, v}` conditions inside `{g, i}` groups, same operators as data views (`=`, `!=`, `>`, `in`, `start`, `contains`, `null`, `!null`, `between`, …; see `filters.md`). Nav paths work here too. |
|
|
157
|
+
| `orderBy` | array of strings | Column paths; `'-'` prefix for descending (`['-message_id']`). Defaults to the PK for deterministic results. |
|
|
158
|
+
| `limit` / `offset` | int | Positive / non-negative. |
|
|
159
|
+
|
|
160
|
+
- **Fail-loud:** unlike UI filters (which drop untranslatable conditions with a warning),
|
|
161
|
+
`select()` **throws** on an unknown column, unknown operator, or unresolvable nav path — a
|
|
162
|
+
silently narrowed filter in an action means processing the wrong rows.
|
|
163
|
+
- **Low-level:** like the other data built-ins, `select()` hits the table directly — no folder
|
|
164
|
+
row-filter, column security, or reference display machinery. A plain reference (`R`) column has
|
|
165
|
+
no value here; select its FK column or a nav path (the error message says which). String
|
|
166
|
+
operators on a reference column are rejected for the same reason — filter a nav path like
|
|
167
|
+
`'customer.company_name'` instead.
|
|
168
|
+
- `query()` remains the escape hatch for anything this shape can't express: aggregates, multi-hop
|
|
169
|
+
joins, CTEs, `FOR UPDATE`.
|
|
170
|
+
|
|
114
171
|
### Messaging
|
|
115
172
|
|
|
116
173
|
| Function | Description |
|
|
@@ -118,6 +175,7 @@ var note = params[note] // no quotes around param name in this DSL
|
|
|
118
175
|
| `error('message')` | **Abort** the action and show an error to the user. Rolls back all changes. |
|
|
119
176
|
| `warn('message')` | Show a warning but continue execution. |
|
|
120
177
|
| `info('message')` | Show an informational message. |
|
|
178
|
+
| `exit('message'?, 'level'?)` | **Stop the script early without error** — changes made so far are kept. Level `'info'` (default) or `'warn'` styles the message. This is the DSL's early-return: a bare `return` is not valid at the top level of `execute:`. |
|
|
121
179
|
| `notify(userId, 'message')` | Send an in-app notification to a specific user. First arg is a user ID (typically `[owner_id]` or similar). |
|
|
122
180
|
|
|
123
181
|
### Email
|
|
@@ -315,6 +373,42 @@ execute:
|
|
|
315
373
|
info('Received ' + poLines.length + ' line(s) from PO ' + [po_number])
|
|
316
374
|
```
|
|
317
375
|
|
|
376
|
+
> The two `query()` reads and the raw `query('UPDATE …')` above predate `select()`/`update()` —
|
|
377
|
+
> today each would be a structured call (`select('wms.stock', { filter: … })`,
|
|
378
|
+
> `update('wms.stock', stockId, { quantity: newQty })`).
|
|
379
|
+
|
|
380
|
+
### select() + update() with a scalar key (cron-scan dispatch)
|
|
381
|
+
|
|
382
|
+
From `modules/comm/logic/actions/dispatch_messages.dsl` (a scheduled-job action — no record context):
|
|
383
|
+
|
|
384
|
+
```
|
|
385
|
+
execute:
|
|
386
|
+
var queued = select('comm.message', {
|
|
387
|
+
columns: ['message_id', 'to_addr', 'to_point.value as point_value', 'subject', 'body_html', 'body_text', 'attempt_count'],
|
|
388
|
+
filter: { g: 'and', i: [
|
|
389
|
+
{ c: 'status', o: '=', v: 'queued' },
|
|
390
|
+
{ c: 'channel', o: '=', v: 'email' }
|
|
391
|
+
] },
|
|
392
|
+
orderBy: ['message_id'],
|
|
393
|
+
limit: 10
|
|
394
|
+
})
|
|
395
|
+
|
|
396
|
+
if (queued.length == 0) {
|
|
397
|
+
exit('No queued messages', 'info')
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
for (var i = 0; i < queued.length; i++) {
|
|
401
|
+
var msg = queued[i]
|
|
402
|
+
sendEmail(msg.to_addr || msg.point_value, msg.subject, msg.body_html || msg.body_text || '')
|
|
403
|
+
|
|
404
|
+
update('comm.message', msg.message_id, {
|
|
405
|
+
status: 'sent',
|
|
406
|
+
sent_at: now(),
|
|
407
|
+
attempt_count: (msg.attempt_count || 0) + 1
|
|
408
|
+
})
|
|
409
|
+
}
|
|
410
|
+
```
|
|
411
|
+
|
|
318
412
|
## Execution modes
|
|
319
413
|
|
|
320
414
|
Actions run in one of two modes, declared in `ui/actions.json`:
|
|
@@ -376,10 +470,12 @@ In `ui/actions.json`:
|
|
|
376
470
|
|
|
377
471
|
## SQL in query() — important notes
|
|
378
472
|
|
|
379
|
-
|
|
473
|
+
`query()` is the **escape hatch** — reach for it only when the structured built-ins can't express the read/write (aggregates, multi-hop joins, CTEs, `FOR UPDATE`). For row-shaped work prefer `select()` / `insert()` / `update()` / `delete()`: they validate entity codes against metadata, coerce values per column, and (for `insert`/`update`) maintain auto-fill and audit columns.
|
|
474
|
+
|
|
475
|
+
1. **Table names are schema-qualified** within the module: `crm.contact`, `wms.stock_movement`, `fin.invoice`. Use the module code as the schema prefix. (Module codes with a hyphen, e.g. `crm-fin`, cannot be schema-qualified in raw SQL — another reason to use the structured built-ins, which accept the qualified `module.entity` code.)
|
|
380
476
|
2. **Use `@param` placeholders** for values — NEVER concatenate user input into SQL strings. The engine auto-parameterizes.
|
|
381
477
|
3. **SELECT, INSERT, UPDATE, DELETE all work** via `query()`. For reads, it returns row arrays. For writes, it executes the statement.
|
|
382
|
-
4. **`insert()` is preferred over `query('INSERT ...')
|
|
478
|
+
4. **`insert()` is preferred over `query('INSERT ...')`**, `update()`/`delete()` over `query('UPDATE/DELETE ...')`, and `select()` over `query('SELECT ...')` for module entities — raw SQL skips auto-fill (PKs, audit, number sequences) and metadata validation.
|
|
383
479
|
|
|
384
480
|
## Common mistakes
|
|
385
481
|
|
|
@@ -387,7 +483,10 @@ In `ui/actions.json`:
|
|
|
387
483
|
- Writing `params["note"]` — **also wrong in DSL syntax**. Use `params[note]` without quotes.
|
|
388
484
|
- Writing `update [status] = 'Draft'` (declarative style) — **wrong**. Use `[status] = 'Draft'` (assignment).
|
|
389
485
|
- Writing `insert('entity', field1, value1)` (positional args) — **wrong**. Use `insert('entity', { field: value })` (object).
|
|
390
|
-
- Writing `query('entity', filter)` (filter object) — **wrong**. `query()` takes raw SQL strings with `@param` placeholders.
|
|
486
|
+
- Writing `query('entity', filter)` (filter object) — **wrong**. `query()` takes raw SQL strings with `@param` placeholders. A structured read is `select('entity', { filter: … })`.
|
|
487
|
+
- Passing an **array of ids** as the `key` of `update()`/`delete()` — **rejected**. Loop over the ids and mutate one at a time.
|
|
488
|
+
- Selecting or string-filtering a plain reference (`R`) column in `select()` — **throws**. Use the FK column or a nav path (`'customer.company_name'`).
|
|
489
|
+
- Unqualified entity codes (`update('message', …)`) — works inside the owning module but **always prefer the qualified form** (`update('comm.message', …)`).
|
|
391
490
|
- Forgetting `var` in loops — `for (i = 0; ...)` creates a global. Always `for (var i = 0; ...)`.
|
|
392
491
|
- Using ES6 syntax (`const`, `let`, `=>`, template literals) — **may not work**. Jint supports ES5.1 primarily. Stick to `var`, `function`, string concatenation with `+`.
|
|
393
492
|
- Calling `TODAY()` or `NOW()` (uppercase) inside `execute:` — **wrong**, they're undefined there and install fails with `'TODAY' is not defined`. Use lowercase **`now()`** in `execute:`; `TODAY()`/`NOW()` are formula-only (`canExecute:`, formula columns).
|
|
@@ -15,11 +15,13 @@ Source of truth: `server/database/system-modules/metadata/seed-data/field_types.
|
|
|
15
15
|
| `fieldTypeCd` | `baseDatatypeCd` | Description | Common `dbDatatype` | Params |
|
|
16
16
|
|---|---|---|---|---|
|
|
17
17
|
| `text` | `string` | Single-line text | `varchar` (with `maxLen`) | `maxLen` |
|
|
18
|
+
| `avatar` | `string` | Person/company name rendered as an initials circle; optional photo. | `varchar` | `imageColumn` (an `image` column on the same entity to use as the photo) |
|
|
18
19
|
| `email` | `string` | Email address. Client-side format validation. | `varchar` 250 | — |
|
|
19
20
|
| `phone` | `string` | Phone/telephone. | `varchar` 50 | — |
|
|
20
21
|
| `url` | `string` | Web URL. | `varchar` 500 | — |
|
|
21
22
|
| `textarea` | `string` | Multi-line plain text. | `text` | `defaultLines`, `maxLines` |
|
|
22
|
-
| `
|
|
23
|
+
| `markdown` | `string` | Markdown editor (Write/Preview tabs), rendered sanitized. | `text` | — |
|
|
24
|
+
| `richtext` | `string` | Rich text WYSIWYG editor, stores sanitized HTML. | `text` | — |
|
|
23
25
|
| `code` | `string` | Code editor with syntax highlighting. | `text` | `language` |
|
|
24
26
|
| `dropdown` | `string` | Fixed list of options. | `varchar` | `options: ["a","b",…]` or `[{value,label,icon,color}]` |
|
|
25
27
|
| `flags` | `string` | Multiple checkboxes with letter flags. | `varchar` | `optionSets`, `style: "buttons"` |
|
|
@@ -67,6 +69,7 @@ Source of truth: `server/database/system-modules/metadata/seed-data/field_types.
|
|
|
67
69
|
| `lookup` | `guid` | `R` | Reference to another entity (always paired with a hidden FK column — see SKILL.md "FK+Reference pattern") |
|
|
68
70
|
| `user` | `cuid` | `D` | User picker. Writes a user ID directly, no paired FK needed. |
|
|
69
71
|
| `grid` | `set` | `S` | Detail grid of related records (1:N backwards reference). Used with `link` declaring the relation. |
|
|
72
|
+
| `list` | `set` | `S` | Detail list — same 1:N set as `grid`, rendered as a card list instead of a table. |
|
|
70
73
|
| `entitylink` | `json` | `D` | Polymorphic link to any entity (stores `{entity, id}` pair). Populate from action DSL with the `entityLink('entityCd', record, description?)` built-in (see `action-dsl.md`). |
|
|
71
74
|
|
|
72
75
|
## JSON
|
|
@@ -137,7 +140,8 @@ These are the field type names LLMs tend to invent. **They are all wrong.**
|
|
|
137
140
|
| `picture`, `photo` | `image` |
|
|
138
141
|
| `attachment` | `file` |
|
|
139
142
|
| `multiline` | `textarea` |
|
|
140
|
-
| `
|
|
143
|
+
| `md` | `markdown` |
|
|
144
|
+
| `richText`, `wysiwyg`, `html` | `richtext` |
|
|
141
145
|
| `userPicker` | `user` |
|
|
142
146
|
| `phoneNumber` | `phone` |
|
|
143
147
|
|
|
@@ -70,10 +70,15 @@ FORMAT([created_date], "yyyy-MM-dd")
|
|
|
70
70
|
|
|
71
71
|
- `TODAY()` — current date
|
|
72
72
|
- `NOW()` — current datetime with timezone
|
|
73
|
-
- `YEAR(d)`, `MONTH(d)`, `DAY(d)` — date parts
|
|
73
|
+
- `YEAR(d)`, `MONTH(d)`, `DAY(d)` — date parts (`MONTH` is 1-based)
|
|
74
74
|
- `HOUR(dt)`, `MINUTE(dt)`, `SECOND(dt)` — time parts
|
|
75
|
-
- `
|
|
76
|
-
- `
|
|
75
|
+
- `WEEKDAY(d)` — day of week, `0` = Sunday
|
|
76
|
+
- `DATE(y, m, d)` — build a date from parts; `DATE(v)` casts a value to a date
|
|
77
|
+
- `DATEADD(d, count, unit)` — add time; unit is a **string literal**: `'DAY'`, `'HOUR'`, `'MINUTE'`, `'SECOND'`, `'MONTH'`, `'YEAR'` (plural forms accepted)
|
|
78
|
+
- `DATEDIFF(d1, d2, unit)` — difference `d2 − d1` in the given unit (same unit list). `DAY`/`HOUR`/`MINUTE`/`SECOND` floor the elapsed time; `MONTH`/`YEAR` are calendar-component deltas. E.g. days overdue: `DATEDIFF([due_date], TODAY(), 'DAY')`
|
|
79
|
+
- `STARTMONTH(d?)`, `ENDMONTH(d?)`, `STARTQUARTER(d?)`, `ENDQUARTER(d?)`, `STARTYEAR(d?)`, `ENDYEAR(d?)`, `STARTNEXTMONTH(d?)` — period boundaries; the argument is optional and defaults to today
|
|
80
|
+
|
|
81
|
+
The whole date family evaluates identically **client-side and SQL-time** (reports, filters, sorts on formula columns) — the SQL translator mirrors the client runtime, including `MONTH` 1-based and `WEEKDAY` 0=Sunday. Unit arguments must be string literals; an unknown unit fails loud with the accepted list.
|
|
77
82
|
|
|
78
83
|
### Logical functions
|
|
79
84
|
|
|
@@ -62,7 +62,7 @@ Scheduled actions run with **no record bound**. Specifically:
|
|
|
62
62
|
- `notify()` writes to inbox only (no live SSE in Phase 1)
|
|
63
63
|
- `sendEmail()` raw mode only in Phase 1
|
|
64
64
|
|
|
65
|
-
**Record context is forbidden.** The install pipeline rejects any action whose compiled DSL references `[field]` or `for x in records { … }` — those compile to `__r.` / `__records.` which would `ReferenceError` at fire time. Refactor to operate via `
|
|
65
|
+
**Record context is forbidden.** The install pipeline rejects any action whose compiled DSL references `[field]` or `for x in records { … }` — those compile to `__r.` / `__records.` which would `ReferenceError` at fire time. Refactor to operate via `select()` / `insert()` / `update()`:
|
|
66
66
|
|
|
67
67
|
```
|
|
68
68
|
execute:
|
|
@@ -132,7 +132,7 @@ Full source: [`modules/chore/`](../../../modules/chore/).
|
|
|
132
132
|
## Common mistakes
|
|
133
133
|
|
|
134
134
|
- **Cross-module action reference.** A job in `crm` cannot reference an action in `fin`. Declare a thin `crm.run_fin_thing` action in your own module and bind the job to that.
|
|
135
|
-
- **Record-bound action.** Any `[field]` or `for x in records` in the DSL fails install — the action has no record at fire time. Refactor to `
|
|
135
|
+
- **Record-bound action.** Any `[field]` or `for x in records` in the DSL fails install — the action has no record at fire time. Refactor to `select()`/`insert()`/`update()`.
|
|
136
136
|
- **Missing `timeout`.** Required, no default. Pick 30 s if you don't know; bump when you have evidence.
|
|
137
137
|
- **`timeout > 300` without `class: "long_running"`.** Install fails. Heavy jobs are an explicit opt-in.
|
|
138
138
|
- **Sub-minute cron.** The scheduler ticks every 60 s. Anything finer is dishonest — declare a minute cron.
|