@dforge-core/dforge-mcp 0.2.37 → 0.2.38
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 +17 -0
- package/dist/server.js +21 -5
- package/package.json +2 -2
- package/resources/schemas/demo-vars.schema.json +28 -0
- package/resources/schemas/entity.schema.json +1 -1
- package/skills/dforge-mcp-author/SKILL.md +1 -1
- package/skills/dforge-mcp-author/references/conventions.md +15 -0
- package/skills/dforge-mcp-author/references/registers.md +274 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,23 @@ 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.2.38 — 2026-10-12
|
|
8
|
+
|
|
9
|
+
**A register column's `map` may name a debit and a credit column.** On an accounting (`L`) column,
|
|
10
|
+
a resource the register splits by side maps to `{ "debit": "<line column>", "credit": "<line column>" }`;
|
|
11
|
+
install requires it. `dforge://schema/entity` now allows it (metadata 0.0.39). Before this,
|
|
12
|
+
`gl`, `acc-registry` and any module with a two-sided ledger failed schema validation.
|
|
13
|
+
|
|
14
|
+
**A registers reference.** `dforge://reference/registers` covers the register kinds (balance, turnover,
|
|
15
|
+
information, accounting classic and compound), `registers.json`, binding a document from its `A` / `L`
|
|
16
|
+
columns, the DSL and report reads, and the common mistakes.
|
|
17
|
+
|
|
18
|
+
**Demo data is documented.** The conventions reference gains a "Demo data" section: `demo-data/` beside
|
|
19
|
+
`seed-data/`, loaded on request; `$f` formulas, `repeat`, and `vars.json`; the workspace-type gate.
|
|
20
|
+
|
|
21
|
+
**Three schemas are served.** `dforge://schema/registers`, `card-layouts` and `demo-vars` were vendored or
|
|
22
|
+
new but not registered. `demo-vars` is the schema for `demo-data/vars.json` (metadata 0.0.38).
|
|
23
|
+
|
|
7
24
|
## 0.2.37 — 2026-10-12
|
|
8
25
|
|
|
9
26
|
**Author references brought in line with the hand-authoring copy in dForge-core.** Content that
|
package/dist/server.js
CHANGED
|
@@ -31290,7 +31290,7 @@ function buildZedTasks() {
|
|
|
31290
31290
|
var fs = __toESM(require("fs"));
|
|
31291
31291
|
var path = __toESM(require("path"));
|
|
31292
31292
|
|
|
31293
|
-
// node_modules/.pnpm/@dforge-core+metadata@0.0.
|
|
31293
|
+
// node_modules/.pnpm/@dforge-core+metadata@0.0.39/node_modules/@dforge-core/metadata/dist/index.js
|
|
31294
31294
|
var AggType = {
|
|
31295
31295
|
Sum: "sum",
|
|
31296
31296
|
Count: "count",
|
|
@@ -34622,7 +34622,7 @@ var path10 = __toESM(require("path"));
|
|
|
34622
34622
|
var fs7 = __toESM(require("fs"));
|
|
34623
34623
|
var path9 = __toESM(require("path"));
|
|
34624
34624
|
|
|
34625
|
-
// node_modules/.pnpm/@dforge-core+metadata@0.0.
|
|
34625
|
+
// node_modules/.pnpm/@dforge-core+metadata@0.0.39/node_modules/@dforge-core/metadata/dist/dsl/index.js
|
|
34626
34626
|
var PUNCT3 = ["===", "!=="];
|
|
34627
34627
|
var PUNCT2 = [
|
|
34628
34628
|
"==",
|
|
@@ -35549,9 +35549,9 @@ var BUILTINS = [
|
|
|
35549
35549
|
},
|
|
35550
35550
|
// Utilities
|
|
35551
35551
|
{ name: "now", signature: "now()", returns: "datetime", doc: "Current date/time. Lowercase \u2014 this is the execute-block date function." },
|
|
35552
|
-
{ name: "addDays", signature: "addDays(date, n)", returns: "date", doc: "Add `n` days
|
|
35553
|
-
{ name: "addMinutes", signature: "addMinutes(date, n)", returns: "datetime", doc: "Add `n` minutes." },
|
|
35554
|
-
{ name: "addSeconds", signature: "addSeconds(date, n)", returns: "datetime", doc: "Add `n` seconds." },
|
|
35552
|
+
{ name: "addDays", signature: "addDays(date, n)", returns: "date | string", doc: "Add `n` days. Takes a date field, a `Date` or an ISO string; a date field stays a date and a `yyyy-MM-dd` string stays a string. Null stays null; any other value is an error." },
|
|
35553
|
+
{ name: "addMinutes", signature: "addMinutes(date, n)", returns: "datetime", doc: "Add `n` minutes. Takes a date field, a `Date` or an ISO string; the result is a timestamp. Null stays null; any other value is an error." },
|
|
35554
|
+
{ name: "addSeconds", signature: "addSeconds(date, n)", returns: "datetime", doc: "Add `n` seconds. Takes a date field, a `Date` or an ISO string; the result is a timestamp. Null stays null; any other value is an error." },
|
|
35555
35555
|
{ name: "currentUserId", signature: "currentUserId()", returns: "long", doc: "The acting user's tenant user ID." },
|
|
35556
35556
|
{ name: "flush", signature: "flush()", returns: "void", doc: "Flush pending writes so a following read sees them." },
|
|
35557
35557
|
{ name: "tryParseJson", signature: "tryParseJson(value)", returns: "any | null", doc: "Parse JSON, returning `null` on failure instead of throwing." },
|
|
@@ -38891,6 +38891,21 @@ var resources = [
|
|
|
38891
38891
|
"Stored procedures JSON schema",
|
|
38892
38892
|
"JSON Schema for logic/stored_procedures.json \u2014 map of stored-procedure code \u2192 { functionName, schemaName?, params?, columns? }. Required for any report dataset with datasetType 'S': the .sql file under logic/reports/ creates the function, this file registers it as the spCd a dataset binds and the sec_object an sp: right is granted on. functionName names the FUNCTION, never the script."
|
|
38893
38893
|
),
|
|
38894
|
+
schema(
|
|
38895
|
+
"registers",
|
|
38896
|
+
"Registers JSON schema",
|
|
38897
|
+
"JSON Schema for registers.json at the module root \u2014 map of register code \u2192 { kind (balance | turnover | info | accounting), dimensions, resources, journal/entity, totals, ... }. Documents bind to a register from their A / L columns instead of restating it."
|
|
38898
|
+
),
|
|
38899
|
+
schema(
|
|
38900
|
+
"card-layouts",
|
|
38901
|
+
"Card layouts JSON schema",
|
|
38902
|
+
"JSON Schema for ui/card_layouts.json \u2014 layout name \u2192 sections (columnGroup, set, tabGroup). Master/detail is a card layout with a tabGroup of set tabs, not a view type."
|
|
38903
|
+
),
|
|
38904
|
+
schema(
|
|
38905
|
+
"demo-vars",
|
|
38906
|
+
"Demo data variables JSON schema",
|
|
38907
|
+
'JSON Schema for demo-data/vars.json \u2014 a flat map of variable name \u2192 literal or { "$f": formula }. Demo-data formulas read them as @name.'
|
|
38908
|
+
),
|
|
38894
38909
|
{
|
|
38895
38910
|
uri: "dforge://docs/conventions",
|
|
38896
38911
|
name: "dForge module conventions",
|
|
@@ -38934,6 +38949,7 @@ var resources = [
|
|
|
38934
38949
|
mimeType: "text/x-python",
|
|
38935
38950
|
read: () => readSkill("scripts/xlsx_to_model.py")
|
|
38936
38951
|
},
|
|
38952
|
+
reference("registers", "Registers: accumulation (balance / turnover / info) and accounting (classic / compound) registers, registers.json, binding a document from its A / L columns (map, per-side debit/credit objects), and the reads. Load before authoring registers.json or an A / L column."),
|
|
38937
38953
|
reference("data-migration", "Migrating data from a legacy database."),
|
|
38938
38954
|
reference("manifest", "manifest.json shape: moduleId UUID, semver, entities map, locale-keyed translations, security block."),
|
|
38939
38955
|
reference("validation-checklist", "Final pre-pack self-review checklist covering every file type."),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dforge-core/dforge-mcp",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.38",
|
|
4
4
|
"description": "MCP server for dForge module authoring. Exposes 35 scaffold/patch/validate/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",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@dforge-core/dforge-cli": "^0.2.29",
|
|
30
|
-
"@dforge-core/metadata": "^0.0.
|
|
30
|
+
"@dforge-core/metadata": "^0.0.39",
|
|
31
31
|
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
32
32
|
"zod": "^4.4.3"
|
|
33
33
|
},
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"$id": "https://dforge.dev/schemas/demo_vars.schema.json",
|
|
4
|
+
"title": "dForge Demo Data Variables",
|
|
5
|
+
"description": "demo-data/vars.json: the variables demo-data formulas read as @name. A flat map of variable name to value. It is not a data file; the loader skips it, and each module has its own (nothing is shared between modules).",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"propertyNames": {
|
|
8
|
+
"pattern": "^[A-Za-z_][A-Za-z0-9_]*$",
|
|
9
|
+
"description": "A letter or underscore, then letters, digits or underscores. Names are case-insensitive, and a repeat variable of the same name shadows the file's."
|
|
10
|
+
},
|
|
11
|
+
"additionalProperties": {
|
|
12
|
+
"description": "A plain value (string, number, boolean or null) is substituted as a literal. { \"$f\": \"...\" } is a formula expanded where the variable is used, e.g. { \"$f\": \"DATEADD(TODAY(), -30, 'DAY')\" }; it may read other variables with @name (a cycle fails the install) but not [column] values.",
|
|
13
|
+
"oneOf": [
|
|
14
|
+
{ "type": ["string", "number", "boolean", "null"] },
|
|
15
|
+
{
|
|
16
|
+
"type": "object",
|
|
17
|
+
"required": ["$f"],
|
|
18
|
+
"properties": {
|
|
19
|
+
"$f": {
|
|
20
|
+
"type": "string",
|
|
21
|
+
"description": "Formula whose result is the variable's value"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"additionalProperties": false
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -259,7 +259,7 @@
|
|
|
259
259
|
"lineField": { "type": "string", "description": "The line's foreign-key column(s) to the header, comma-separated in the header's key order for a composite key." },
|
|
260
260
|
"stateField": { "type": "string", "description": "The bool column that records the posted state, when it is not the registry column itself. Written only by the register engine." },
|
|
261
261
|
"register": { "type": "string", "description": "The register this column posts to, as 'module_cd.register_cd' (declared in that module's registers.json). Binding to one replaces restating what the register is: the declaration supplies the state entity, dimensions, resources, journal, allowNegative and autoCreate, and this column keeps only what legitimately differs per writer — direction/sign, 'map' and 'dateField'." },
|
|
262
|
-
"map": { "type": "object", "additionalProperties": { "type": "string" }, "description": "Register dimension or resource name -> this document's column carrying it. Every resource the register declares must be mapped (install refuses otherwise); a dimension left out binds to a column of the same name. Only meaningful with 'register'. On an accumulation (A) column a value may be a one-hop reference path, '<reference column>.<target column>', read through the reference at posting time (off the line when the binding posts from lines), or an expression: a string starting with '=' holding an F-column formula over the same row with one-hop reference reads — \"=COALESCE([transit_warehouse_id], [dest_warehouse_id])\"." },
|
|
262
|
+
"map": { "type": "object", "additionalProperties": { "oneOf": [ { "type": "string" }, { "type": "object", "required": ["debit", "credit"], "additionalProperties": false, "properties": { "debit": { "type": "string" }, "credit": { "type": "string" } } } ] }, "description": "Register dimension or resource name -> this document's column carrying it. On an accounting (L) column a resource or dimension the register splits by side maps to { \"debit\": \"<line column>\", \"credit\": \"<line column>\" } instead of one column. Every resource the register declares must be mapped (install refuses otherwise); a dimension left out binds to a column of the same name. Only meaningful with 'register'. On an accumulation (A) column a value may be a one-hop reference path, '<reference column>.<target column>', read through the reference at posting time (off the line when the binding posts from lines), or an expression: a string starting with '=' holding an F-column formula over the same row with one-hop reference reads — \"=COALESCE([transit_warehouse_id], [dest_warehouse_id])\"." },
|
|
263
263
|
"headerMap": { "type": "object", "additionalProperties": { "type": "string" }, "description": "Register dimension or resource name -> this DOCUMENT's column carrying it, for a binding that posts from LINES. A line binding reads every other value off the line, and a dimension that belongs to the document (a dealer, an organisation, a date) cannot be put on the line: a G column is a same-row expression or an aggregate over a child set, so it cannot read a parent. Explicit rather than a fallback, because 'not on the line, try the header' turns a typo into a silent read of an unrelated header column with the same name. Install refuses: a name on neither table, a field also named in 'map', a column also read off the line by 'map', a column that is part of the line's key, a column 'lockedFields' does not freeze (the posting is keyed by it, so it has to hold still while the document is posted), and a RESOURCE unless the register is 'info' (a quantity from the document would be added once per line; an information register's records replace rather than add). A value may be a one-hop reference path off the document, whose reference key column 'lockedFields' must then freeze, or an expression over the document ('=...', see 'map')." },
|
|
264
264
|
"groupLinesBy": { "type": "array", "items": { "type": "string" }, "minItems": 1, "uniqueItems": true, "description": "Line columns whose distinct values each post ONE movement, instead of one per line — a production report posting 'this unit worked today' once per unit with a count of 1. 'map' is then read over a group row: the grouped line columns, every column of the document, and one-hop reads through a reference of either, so an expression may mix the document and the group key. A quoted constant is stamped once per group; a numeric line column mapped to a resource is summed over the group. Install refuses: a binding that posts from the document, an L column, a grouped column the line does not store or 'lockedLineFields' does not freeze, a line column read that is neither grouped nor a summed resource, a non-numeric summed resource, a column both grouped and summed, an ungrouped line resource on an 'info' register, a name both the line and the document carry, and a document column read that 'lockedFields' does not freeze. Accumulation (A) columns only." },
|
|
265
265
|
"dateField": { "type": "string", "description": "This document's date column, supplying the date the register stamps on each journal row. Required once the register declares a 'journalDate' — one writer that supplied none would make every balance read as of a date quietly short, across all writers. On an accumulation (A) column it may be a one-hop reference path, '<reference column>.<target column>', or an expression over the document ('=...', see 'map')." },
|
|
@@ -145,7 +145,7 @@ Load these by URI, one per step, at the step that needs them.
|
|
|
145
145
|
**Per-element references** — `dforge://reference/<name>`:
|
|
146
146
|
`field-types`, `flags`, `column-types`, `column-domains`, `formulas`, `traits`,
|
|
147
147
|
`data-views`, `menus`, `action-dsl`, `filters`, `security`, `reports`,
|
|
148
|
-
`settings`, `jobs`, `number-sequences`, `document-extraction`,
|
|
148
|
+
`settings`, `jobs`, `number-sequences`, `registers`, `document-extraction`,
|
|
149
149
|
`print-templates`, `translations`, `queries`, `schema-import`, `excel-import`,
|
|
150
150
|
`data-migration`, `manifest`, `validation-checklist`, `conventions`.
|
|
151
151
|
|
|
@@ -112,6 +112,21 @@ Use explicit **numeric** PKs in seed data so cross-file references work. The `id
|
|
|
112
112
|
|
|
113
113
|
**Common mistake**: using UUID strings like `"10000000-0000-0000-0000-000000000001"` — **wrong**. The `cuid` datatype is a numeric `int8`, not a UUID string. Seed data PKs must be numbers. Use a numbering scheme that avoids collisions (e.g. 1001-1099 for countries, 2001-2099 for regions, etc.).
|
|
114
114
|
|
|
115
|
+
## Demo data
|
|
116
|
+
|
|
117
|
+
Sample records live in `demo-data/`, not `seed-data/`. `seed-data/` holds reference tables every install needs; `demo-data/` is loaded only on request, so a workspace for real work does not start full of fake customers and invoices.
|
|
118
|
+
|
|
119
|
+
- **Same file shape as seed data** (`entityCode` + `records`, numbered prefixes for FK order, explicit primary keys), and the same schema.
|
|
120
|
+
- **Loaded on request:** `dforge-cli module install … --with-demo-data`, the "Install demo data" checkbox in the install dialogs, or `dforge-cli data demo add` on an installed module. A module's dependencies' demo data loads first. Rows already there are left alone, so repeating is safe.
|
|
121
|
+
- **Workspace type gates it:** a `production` workspace refuses demo data; `staging` or an unset type needs confirmation (`--yes`).
|
|
122
|
+
- **A value can be a formula**, evaluated once at insert: `{ "$f": "DATEADD(TODAY(), -80, 'DAY')" }`. `[column]` reads another column of the same row, and `@name` reads a variable. `TODAY()`, `DATEADD`, `YEAR`, `FORMAT` and `CONCAT` exist. Relative dates keep a scenario intact whatever the install date.
|
|
123
|
+
- **`repeat`** builds several rows from one template, with `@m` in formulas.
|
|
124
|
+
- **`demo-data/vars.json`** declares the variables: a flat `{ "name": value }` map, where a value is a literal or `{ "$f": "formula" }` and may read other variables. It is not a data file; the loader skips it, and each module has its own.
|
|
125
|
+
- **References by text:** a reference column may name its target by its `toString` text instead of a numeric key; no match, or two, is an error.
|
|
126
|
+
- **Not re-evaluated:** a formula runs at insert; an upgrade never recomputes it.
|
|
127
|
+
|
|
128
|
+
Depth: the platform changelog entry "Demo data: its own folder, formulas, and a checkbox at install".
|
|
129
|
+
|
|
115
130
|
## Translations
|
|
116
131
|
|
|
117
132
|
Translation files live in `translations/` and are named after the **IETF locale tag** (`de-DE.json`, `uk-UA.json`, etc.). Filenames are auto-discovered; declare which ones you ship in `manifest.supportedLocales`. English is the default — labels and descriptions live in entity/view JSON, so **don't** create `en.json` or `en-US.json` (they're skipped by the installer).
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
# Registers Reference
|
|
2
|
+
|
|
3
|
+
A **register** is a declared store of movements or values that documents write to by posting, and that the platform reads back with fixed primitives. Declare it once in `registers.json`; documents bind to it from an `A` or `L` column.
|
|
4
|
+
|
|
5
|
+
Lives in: `registers.json` at the module root (a keyed dictionary, like `logic/jobs.json`). Schema: [`docs/schemas/registers.schema.json`](../../../docs/schemas/registers.schema.json); binding params: `registryColumnParams` in [`docs/schemas/entity.schema.json`](../../../docs/schemas/entity.schema.json). Full guide: [`docs/business-logic/registers.md`](../../../docs/business-logic/registers.md). Check with `dforge_module_validate`, then `dforge_module_pack` and `dforge_module_install`.
|
|
6
|
+
|
|
7
|
+
## Register or plain table?
|
|
8
|
+
|
|
9
|
+
| You need | Use |
|
|
10
|
+
|---|---|
|
|
11
|
+
| Running quantity or amount per key, with undo on unpost | `balance` register |
|
|
12
|
+
| "How much moved in a period", no running total | `turnover` register |
|
|
13
|
+
| A value that changes over time, or a keyed lookup, with "value as of a date" | `info` register |
|
|
14
|
+
| Double-entry postings by account, with analytics | `accounting` register |
|
|
15
|
+
| Ordinary master or transactional data nobody aggregates by key | Plain entity |
|
|
16
|
+
| An ad hoc slice by an optional attribute | A report, not a dimension |
|
|
17
|
+
|
|
18
|
+
A register earns its place when something must be guarded or cached by its key: a negative-stock check, a unique slice, a period lock. Posting and unposting are then the platform's job, not a DSL's.
|
|
19
|
+
|
|
20
|
+
## The kinds
|
|
21
|
+
|
|
22
|
+
| `kind` | Keeps | Written by | Read by | Key rules |
|
|
23
|
+
|---|---|---|---|---|
|
|
24
|
+
| `balance` | State row per dimension tuple, plus optional journal | `A` column | `getBalance`, `getTurnover` | Needs `entity`. Set `journal`, `journalDirection`, `journalDate` from the start. `allowNegative` default `false`, `autoCreate` default `true`. |
|
|
25
|
+
| `turnover` | Journal only | `A` column | `getTurnover` | No `entity`, no `allowNegative`/`autoCreate`. `journal`, `journalDirection`, `journalDate` mandatory. `getBalance` refuses it. |
|
|
26
|
+
| `info` | One table of records | `data.set` (independent) or `A` column (subordinate, has `recorder`) | `getSlice` | Needs `entity`, no `journal`. Optional `period`. Independent: unique constraint over dimensions + `period`. Binding needs a `recorder`. |
|
|
27
|
+
| `accounting`, `classic` | Postings, one account per row | `L` column | `getAccountBalance`, `getAccountTurnover`, dataset `R` | `chart`, `account`, `analyticFields`, `composition`. Every resource split `debitField`/`creditField`. No correspondence. |
|
|
28
|
+
| `accounting`, `compound` | Postings, debit and credit account on one row | `L` column | Same, plus `getCorrespondence` | `debitAccount` != `creditAccount`, per-side analytic arrays, optional `sideDimensions`. Resource shared (`field`) or split. Balance check refused. |
|
|
29
|
+
|
|
30
|
+
Every register needs `dimensions` (1-8 columns) and `resources` (1-64). A resource is `required` by default; set `"required": false` when only some writers supply it. A property a kind refuses fails install; it is never ignored.
|
|
31
|
+
|
|
32
|
+
## `registers.json`
|
|
33
|
+
|
|
34
|
+
Register codes: lowercase letters, digits, underscores. A document addresses one as `module_cd.register_cd`. `label` gives it a translatable name.
|
|
35
|
+
|
|
36
|
+
### Balance (`wms-registry.stock`)
|
|
37
|
+
|
|
38
|
+
```json
|
|
39
|
+
{
|
|
40
|
+
"stock": {
|
|
41
|
+
"kind": "balance",
|
|
42
|
+
"label": "Stock on Hand",
|
|
43
|
+
"entity": "stock",
|
|
44
|
+
"journal": "stock_movement",
|
|
45
|
+
"journalDirection": "movement_direction",
|
|
46
|
+
"journalDate": "movement_date",
|
|
47
|
+
"dimensions": ["warehouse_id", "product_id"],
|
|
48
|
+
"resources": { "quantity": { "field": "quantity" } },
|
|
49
|
+
"allowNegative": false,
|
|
50
|
+
"autoCreate": true
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Turnover (`wms-registry.product_flow`)
|
|
56
|
+
|
|
57
|
+
```json
|
|
58
|
+
{
|
|
59
|
+
"product_flow": {
|
|
60
|
+
"kind": "turnover",
|
|
61
|
+
"journal": "product_flow",
|
|
62
|
+
"journalDirection": "flow_direction",
|
|
63
|
+
"journalDate": "flow_date",
|
|
64
|
+
"dimensions": ["warehouse_id", "product_id"],
|
|
65
|
+
"resources": {
|
|
66
|
+
"received": { "field": "received", "required": false },
|
|
67
|
+
"shipped": { "field": "shipped", "required": false }
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Info (`wms-registry.outlet_price`, subordinate)
|
|
74
|
+
|
|
75
|
+
```json
|
|
76
|
+
{
|
|
77
|
+
"outlet_price": {
|
|
78
|
+
"kind": "info",
|
|
79
|
+
"entity": "outlet_price",
|
|
80
|
+
"recorder": "source",
|
|
81
|
+
"period": "effective_from",
|
|
82
|
+
"dimensions": ["warehouse_id", "product_id"],
|
|
83
|
+
"resources": {
|
|
84
|
+
"price": { "field": "price" },
|
|
85
|
+
"currency_cd": { "field": "currency_cd", "required": false }
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
`recorder` is a jsonb column the platform stamps with the writing document. Add `"recordChangesOnly": true` (and `absentAs` per resource) to skip a record equal to the slice already in effect.
|
|
92
|
+
|
|
93
|
+
### Accounting, classic (`acc-registry.gl`)
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"gl": {
|
|
98
|
+
"kind": "accounting",
|
|
99
|
+
"lineMode": "classic",
|
|
100
|
+
"chart": "account",
|
|
101
|
+
"journal": "gl_acc_posting",
|
|
102
|
+
"journalDate": "posted_on",
|
|
103
|
+
"account": "account_id",
|
|
104
|
+
"composition": {
|
|
105
|
+
"entity": "account_analytic",
|
|
106
|
+
"account": "account_id",
|
|
107
|
+
"slot": "slot_no",
|
|
108
|
+
"analytic": "analytic_kind_cd"
|
|
109
|
+
},
|
|
110
|
+
"analyticFields": ["analytic1", "analytic2", "analytic3", "analytic4"],
|
|
111
|
+
"dimensions": ["period_key"],
|
|
112
|
+
"resources": {
|
|
113
|
+
"amount": { "debitField": "debit_amount", "creditField": "credit_amount" }
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
`composition` is where the chart says which analytic kind each account carries in which slot. It is required exactly when slot columns are declared; `"analyticFields": []` needs none. Its entity needs a unique constraint over `(account, slot)`.
|
|
120
|
+
|
|
121
|
+
### Accounting, compound (`acc-registry.gl_corr`)
|
|
122
|
+
|
|
123
|
+
```json
|
|
124
|
+
{
|
|
125
|
+
"gl_corr": {
|
|
126
|
+
"kind": "accounting",
|
|
127
|
+
"lineMode": "compound",
|
|
128
|
+
"chart": "account",
|
|
129
|
+
"journal": "gl_corr_posting",
|
|
130
|
+
"journalDate": "posted_on",
|
|
131
|
+
"debitAccount": "debit_account_id",
|
|
132
|
+
"creditAccount": "credit_account_id",
|
|
133
|
+
"composition": { "entity": "account_analytic", "account": "account_id", "slot": "slot_no", "analytic": "analytic_kind_cd" },
|
|
134
|
+
"debitAnalyticFields": ["dt_analytic1", "dt_analytic2"],
|
|
135
|
+
"creditAnalyticFields": ["ct_analytic1", "ct_analytic2"],
|
|
136
|
+
"dimensions": ["period_key", "organization_id", "currency_cd"],
|
|
137
|
+
"sideDimensions": {
|
|
138
|
+
"currency_cd": { "debitField": "dt_currency_cd", "creditField": "ct_currency_cd" }
|
|
139
|
+
},
|
|
140
|
+
"resources": {
|
|
141
|
+
"amount": { "field": "amount" },
|
|
142
|
+
"currency_amount": { "debitField": "dt_currency_amount", "creditField": "ct_currency_amount" }
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
The slot cap lives in three places that must agree: the posting's slot columns, `analyticFields`, and the chart's check constraint on the composition table. The platform does not parse that check; a mismatch is refused at post time.
|
|
149
|
+
|
|
150
|
+
## Binding a document
|
|
151
|
+
|
|
152
|
+
A register column is a `bool` state column. `A` writes `balance`, `turnover` and `info`; `L` writes `accounting`. Install resolves `register` and refuses an undeclared one.
|
|
153
|
+
|
|
154
|
+
### `A` column (`wms-registry.stock`)
|
|
155
|
+
|
|
156
|
+
```json
|
|
157
|
+
"stock_out": {
|
|
158
|
+
"columnType": "A",
|
|
159
|
+
"dbDatatype": "bool",
|
|
160
|
+
"flags": "V",
|
|
161
|
+
"description": "Stock Out (source)",
|
|
162
|
+
"params": {
|
|
163
|
+
"stateField": "stock_out_state",
|
|
164
|
+
"register": "wms-registry.stock",
|
|
165
|
+
"direction": "decrease",
|
|
166
|
+
"dateField": "transfer_date",
|
|
167
|
+
"map": {
|
|
168
|
+
"warehouse_id": "source_warehouse_id",
|
|
169
|
+
"product_id": "product_id",
|
|
170
|
+
"quantity": "quantity"
|
|
171
|
+
},
|
|
172
|
+
"lockedFields": ["transfer_date", "source_warehouse_id", "product_id", "quantity"]
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
| Param | Meaning |
|
|
178
|
+
|---|---|
|
|
179
|
+
| `register` | `module_cd.register_cd`. Do not combine with inline `registries`. |
|
|
180
|
+
| `direction` | `increase` or `decrease`. Refused on `info`. `sign` decides per row instead. |
|
|
181
|
+
| `dateField` | Document date stamped into `journalDate` or `period`. Required once the register declares either. Must be in `lockedFields`. `dateTrunc` (`day`/`month`/`year`) truncates it. |
|
|
182
|
+
| `map` | Register name to column. A dimension left out binds to the column of the same name. Every required resource must be mapped. |
|
|
183
|
+
| `lineEntity` + `lineField` | Post from lines: one movement per line. Declared per binding. Needs `lockedLineFields`. |
|
|
184
|
+
| `headerMap` | On a line posting, register name to a **document** column. A resource may come from the document only on an `info` register. Every column must be in `lockedFields`. |
|
|
185
|
+
| `groupLinesBy` | One movement per distinct value of these line columns. `map` is read over a group row; numeric resources are summed. |
|
|
186
|
+
| `skipPostingWhenEmpty` | Dimensions whose emptiness means "this row posts nothing". The exception, see below. |
|
|
187
|
+
| `lockedFields` / `lockedLineFields` | Columns frozen while posted. `["*"]` freezes the whole row. |
|
|
188
|
+
| `movementMapping` | Journal attribute column to document or line column. |
|
|
189
|
+
|
|
190
|
+
### `map` value forms
|
|
191
|
+
|
|
192
|
+
| Form | Example | Notes |
|
|
193
|
+
|---|---|---|
|
|
194
|
+
| Column | `"qty"` | The default. |
|
|
195
|
+
| One-hop path | `"product.product_group"` | Root is an `R` column with a `link`. The reference key column must be locked. Two hops refused. |
|
|
196
|
+
| Expression | `"=COALESCE([transit_warehouse_id], [dest_warehouse_id])"` | Leading `=`, `F`-column formula, one-hop `[ref].[col]` reads. Every column read must be locked. |
|
|
197
|
+
| Quoted constant | `"'1'"` | Stamped as is. A resource constant must be a number, outside `info`. |
|
|
198
|
+
| Per-side object | `{ "debit": "dt_currency_cd", "credit": "ct_currency_cd" }` | `L` column only. For a resource or dimension the register splits by side. Both sides named. |
|
|
199
|
+
|
|
200
|
+
The per-side object shape was missing from the entity schema until metadata 0.0.39. Validate with metadata 0.0.39 or later.
|
|
201
|
+
|
|
202
|
+
Paths, expressions, `dateTrunc`, `headerMap`, `groupLinesBy` and `skipPostingWhenEmpty` are `A`-only. An `L` column refuses them.
|
|
203
|
+
|
|
204
|
+
### `L` column (`acc-registry.gl_corr`)
|
|
205
|
+
|
|
206
|
+
```json
|
|
207
|
+
"params": {
|
|
208
|
+
"register": "acc-registry.gl_corr",
|
|
209
|
+
"lineEntity": "gl_corr_line",
|
|
210
|
+
"lineField": "gl_corr_entry_id",
|
|
211
|
+
"debitAccountField": "debit_account_id",
|
|
212
|
+
"creditAccountField": "credit_account_id",
|
|
213
|
+
"dateField": "entry_date",
|
|
214
|
+
"periodDimField": "period_key",
|
|
215
|
+
"map": {
|
|
216
|
+
"organization_id": "organization_id",
|
|
217
|
+
"currency_cd": { "debit": "dt_currency_cd", "credit": "ct_currency_cd" },
|
|
218
|
+
"amount": "amount",
|
|
219
|
+
"currency_amount": { "debit": "dt_currency_amount", "credit": "ct_currency_amount" }
|
|
220
|
+
},
|
|
221
|
+
"debitAnalytics": { "cost_center": "dt_cost_center_id" },
|
|
222
|
+
"creditAnalytics": { "counterparty": "ct_counterparty_id" },
|
|
223
|
+
"lockedFields": ["entry_date", "period_key"],
|
|
224
|
+
"lockedLineFields": ["*"]
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
- Classic uses `accountField` and `analytics`. Compound uses `debitAccountField` + `creditAccountField` and `debitAnalytics` / `creditAnalytics`. Mixing them is refused.
|
|
229
|
+
- `analytics` maps an analytic **kind** to a line column. The chart decides the slot per account, so one line column can land in `analytic1` on one account and `analytic2` on another.
|
|
230
|
+
- `lineEntity` and `lineField` are required. `lockedLineFields` must cover every line column the posting copies, or be `["*"]`.
|
|
231
|
+
- Every register dimension must be mapped, be a same-name line column, or be the `periodDimField` (a shared dimension).
|
|
232
|
+
- `validation.balanced: ["amount"]` checks debits equal credits on classic. It is refused on compound, which balances by construction.
|
|
233
|
+
|
|
234
|
+
## Reads
|
|
235
|
+
|
|
236
|
+
| Read | Kinds | Returns |
|
|
237
|
+
|---|---|---|
|
|
238
|
+
| `getBalance(register, dims?, asOf?)` | `balance` | `{ resource: value }`, zeros when empty |
|
|
239
|
+
| `getTurnover(register, dims, from, to)` | `balance`, `turnover` | `{ resource: { in, out, net } }` |
|
|
240
|
+
| `getSlice(register, dims, onDate?, mode?)` | `info` | Record plus `_period`, or `null`. `mode` is `last` (default) or `first`. |
|
|
241
|
+
| `getAccountBalance(register, account, filter?, asOf?)` | `accounting` | `{ resource: { debit, credit, net } }` |
|
|
242
|
+
| `getAccountTurnover(register, account, filter, from, to)` | `accounting` | Same shape |
|
|
243
|
+
| `getCorrespondence(register, debitAccount, creditAccount, filter, from, to)` | compound | Same shape |
|
|
244
|
+
|
|
245
|
+
```
|
|
246
|
+
execute:
|
|
247
|
+
var onHand = getBalance("wms-registry.stock", { warehouse_id: [warehouse_id], product_id: [product_id] })
|
|
248
|
+
var price = getSlice("wms-registry.outlet_price", { warehouse_id: [warehouse_id], product_id: [product_id] }, [order_date])
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
- A dimension left out is summed over by `getBalance` and `getTurnover`. `getSlice` refuses an omitted dimension.
|
|
252
|
+
- As-of reads and `getTurnover` need a journal with both stamps.
|
|
253
|
+
- A read of the wrong kind is refused, naming the right one.
|
|
254
|
+
- DSL reads are gated by the action's Execute right, not Select on the register tables.
|
|
255
|
+
- **Reports:** a dataset with `"datasetType": "R"` reads an accounting register over an interval. It returns one row per chart account with `opening_*`, `turnover_*` and `closing_*` debit and credit for one resource. See [`reports.md`](reports.md) and [`docs/business-logic/gl-ledger-to-declared-register.md`](../../../docs/business-logic/gl-ledger-to-declared-register.md).
|
|
256
|
+
|
|
257
|
+
## Totals cache
|
|
258
|
+
|
|
259
|
+
`totals` caches the turnover inside each `day`/`month`/`quarter`/`year`, never a closing balance, so a backdated posting touches one row. Declare an `entity` whose PRIMARY KEY is exactly (dimensions, `periodField`), with `inField`/`outField` per resource (`debitField`/`creditField` and an `accountField` on accounting). Posting maintains it; install rebuilds it when its shape changes. Not available on `info`. Details: registers.md section 8.4.
|
|
260
|
+
|
|
261
|
+
## Common mistakes
|
|
262
|
+
|
|
263
|
+
- **Undeclared or unqualified register.** `params.register` must be `module_cd.register_cd` and exist. Install fails, not the first posting.
|
|
264
|
+
- **Unmapped required resource.** Map it, or mark the resource `"required": false` when only some writers supply it.
|
|
265
|
+
- **Empty dimension.** An empty dimension refuses the posting. `skipPostingWhenEmpty` is the exception: it leaves a document posted while some lines moved nothing. Prefer one line table per binding. Use it only when the distinction lives in the data, such as a serial number filled on some rows.
|
|
266
|
+
- **Missing or unlocked `dateField`.** Required once the register has `journalDate` or `period`, and it must be in `lockedFields`.
|
|
267
|
+
- **Key over dimensions.** The journal, a subordinate `info` register's records and an `autoCreate` state table are written by the platform. Each needs **one** surrogate primary key of type `bigint` (`identity`/`cuid`) or `uuid`. A key over dimensions, a multi-column key, a text key and `int4` are refused.
|
|
268
|
+
- **State column narrower than the journal column.** It must hold the journal's value exactly, or unposting cannot take back what posting added.
|
|
269
|
+
- **Two resources from one document column**, or two resources storing into one register column. Refused.
|
|
270
|
+
- **Binding to an independent `info` register.** Refused. Write it with `data.set`, or give it a `recorder`.
|
|
271
|
+
- **Direct writes to register tables.** They are ordinary entities. Withhold `I`/`U`/`D` on state, journal and cache in the module's roles.
|
|
272
|
+
- **`A`/`L` column in an `extends` entity.** An `A` column is allowed (a bridge posts another module's document; the state lives in the bridge's `_ext` table). An `L` column is allowed but not yet tested. See [`register-posting-from-extensions.md`](../../../docs/business-logic/register-posting-from-extensions.md).
|
|
273
|
+
- **`mark-imported` is not `post`.** A document posted in another system is marked with `dforge-cli register mark-imported --entity <e> --state-column <col> --where "<sql>"`. Its state column stays false, and the engine refuses to post or unpost it. Do not set the flag by hand.
|
|
274
|
+
- **Posting a mark-imported document, or unposting a receipt a later shipment consumed** (with `allowNegative: false`), is refused with `REGISTER_NEGATIVE_BALANCE` or an imported-document error.
|