@dforge-core/metadata 0.0.35 → 0.0.37

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 CHANGED
@@ -7,6 +7,33 @@ and this package adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.0.37] — 2026-10-12
11
+
12
+ ### Added
13
+
14
+ - **`settings.json` `$constraints`:** `SettingConstraintDef` (`{ type: "check", expression, message? }`),
15
+ the optional `$constraints` map on `SettingsFile` — check constraints across a module's settings,
16
+ written as SQL over setting codes — and `settingDefsOf(file)`, which returns a file's settings
17
+ without it. `settings.schema.json` and `translations.schema.json` describe both.
18
+
19
+ ## [0.0.36] — 2026-10-08
20
+
21
+ ### Added
22
+
23
+ - **Registers, typed and checked:** `RegisterDef` / `RegistersFile` (the authoring shape of
24
+ `registers.json`), `RegisterBindingParams` (an A / L column's `params` bound to a register),
25
+ and the installer's rules as functions every tool can share — `checkRegister` /
26
+ `checkRegisters` for a declaration (per-kind required and refused properties, resource shapes,
27
+ the accounting and totals rules; with a `RegisterEntityLookup`, the entities it names and the
28
+ columns they store) and `checkRegisterBinding` for a binding (qualified and declared register,
29
+ the kind a column type may post to, map keys, unmapped required resources, locked fields, the
30
+ date column being locked, line and account fields, `headerMap` and `skipPostingWhenEmpty`
31
+ rules). Issues carry a JSON path, a stable code and a severity, and every rule fails open where
32
+ the caller can't resolve what is named. Helpers: `registerDimensions`, `registerResources`,
33
+ `registerCarrier`, `registerResourceShape`, `registerLineMode`, `registerRequiredProps`,
34
+ `registerRefusedProps`, `isPlainColumnRef`; constants `REGISTER_KINDS`, `REGISTER_CODE`,
35
+ `REGISTER_COLUMN_NAME`, `REGISTER_TOTALS_PERIODS`.
36
+
10
37
  ## [0.0.35] — 2026-10-07
11
38
 
12
39
  ### Added
package/dist/index.d.ts CHANGED
@@ -1553,8 +1553,233 @@ type SettingDef = (SettingDefBase & {
1553
1553
  baseDatatypeCd?: never;
1554
1554
  params?: never;
1555
1555
  });
1556
- /** A `settings.json` file: setting code → definition. */
1557
- type SettingsFile = Record<string, SettingDef>;
1556
+ /** A check across a module's settings: SQL over setting codes, as an entity check constraint. */
1557
+ interface SettingConstraintDef {
1558
+ type: "check";
1559
+ /** PostgreSQL boolean over setting codes; writing any setting it names re-checks it. */
1560
+ expression: string;
1561
+ message?: string;
1562
+ }
1563
+ /**
1564
+ * A `settings.json` file: setting code → definition, plus the optional `$constraints`. A
1565
+ * setting code cannot start with `$`, but TypeScript cannot exclude it from the index, so
1566
+ * the index admits the constraints map too.
1567
+ */
1568
+ type SettingsFile = {
1569
+ $constraints?: Record<string, SettingConstraintDef>;
1570
+ [settingCd: string]: SettingDef | Record<string, SettingConstraintDef> | undefined;
1571
+ };
1572
+ /** The settings of a file, without its `$constraints`. */
1573
+ declare function settingDefsOf(file: SettingsFile): Record<string, SettingDef>;
1574
+
1575
+ /** The four kinds. Each requires and refuses a fixed set of properties. */
1576
+ type RegisterKind = "balance" | "turnover" | "info" | "accounting";
1577
+ declare const REGISTER_KINDS: readonly RegisterKind[];
1578
+ declare const isRegisterKind: (value: unknown) => value is RegisterKind;
1579
+ /** Register codes: lowercase letters, digits and underscores, starting with a letter. */
1580
+ declare const REGISTER_CODE: RegExp;
1581
+ /** A column name as `registers.json` takes one. */
1582
+ declare const REGISTER_COLUMN_NAME: RegExp;
1583
+ /** How much one cached row of a `totals` cache covers. */
1584
+ type RegisterTotalsPeriod = "day" | "month" | "quarter" | "year";
1585
+ declare const REGISTER_TOTALS_PERIODS: readonly RegisterTotalsPeriod[];
1586
+ /** A measured column of the register: one shared column, or one per side on an accounting register. */
1587
+ interface RegisterResourceDef {
1588
+ /** The column, on the state entity / journal / record entity. Not with `debitField` / `creditField`. */
1589
+ field?: string;
1590
+ /** Debit-side column, on an accounting register. Declared with `creditField`. */
1591
+ debitField?: string;
1592
+ creditField?: string;
1593
+ /** Every binding must map it (default true). False for a resource only some writers supply. */
1594
+ required?: boolean;
1595
+ /** Under `recordChangesOnly`: what the resource compares as before any record is in effect. */
1596
+ absentAs?: number | string | boolean;
1597
+ description?: string;
1598
+ }
1599
+ /** The per-period cache (registers.md §8). */
1600
+ interface RegisterTotalsDef {
1601
+ entity: string;
1602
+ period: RegisterTotalsPeriod;
1603
+ /** Column holding the first date of the period a row covers. */
1604
+ periodField: string;
1605
+ /** Account column; required on an accounting register, refused elsewhere. */
1606
+ accountField?: string;
1607
+ /** Which dimensions the cache is grouped by; accounting only; all of them when omitted. */
1608
+ dimensions?: string[];
1609
+ /** Every resource of the register: `inField` + `outField`, or `debitField` + `creditField` on an accounting register. */
1610
+ resources: Record<string, {
1611
+ inField?: string;
1612
+ outField?: string;
1613
+ debitField?: string;
1614
+ creditField?: string;
1615
+ }>;
1616
+ }
1617
+ /** Where the chart says which analytic each account carries in which slot. */
1618
+ interface RegisterCompositionDef {
1619
+ entity: string;
1620
+ account: string;
1621
+ slot: string;
1622
+ analytic: string;
1623
+ }
1624
+ /** One declaration of `registers.json`. */
1625
+ interface RegisterDef {
1626
+ kind: RegisterKind;
1627
+ label?: string;
1628
+ description?: string;
1629
+ /** State table (`balance`) or record table (`info`). */
1630
+ entity?: string;
1631
+ /** Movement / posting entity (`balance` optional, `turnover` and `accounting` required). */
1632
+ journal?: string;
1633
+ /** Journal column stamped +1 / −1 (`balance`, `turnover`). */
1634
+ journalDirection?: string;
1635
+ /** Journal column holding each movement's date. */
1636
+ journalDate?: string;
1637
+ /** Record-entity column holding when a record takes effect (`info`). */
1638
+ period?: string;
1639
+ /** Record-entity jsonb column the writing document is stamped into (`info`); makes the register subordinate. */
1640
+ recorder?: string;
1641
+ recordChangesOnly?: boolean;
1642
+ /** Chart of accounts (`accounting`). */
1643
+ chart?: string;
1644
+ lineMode?: "classic" | "compound";
1645
+ /** Posting column pointing at the chart (classic). */
1646
+ account?: string;
1647
+ debitAccount?: string;
1648
+ creditAccount?: string;
1649
+ /** Analytic slot columns in slot order (classic). */
1650
+ analyticFields?: string[];
1651
+ debitAnalyticFields?: string[];
1652
+ creditAnalyticFields?: string[];
1653
+ composition?: RegisterCompositionDef;
1654
+ /** 1–8 column names: the key of the register, on its carrier. */
1655
+ dimensions: string[];
1656
+ /** Two-sided dimensions of a compound register, with the column per side. */
1657
+ sideDimensions?: Record<string, {
1658
+ debitField: string;
1659
+ creditField: string;
1660
+ }>;
1661
+ resources: Record<string, RegisterResourceDef>;
1662
+ totals?: RegisterTotalsDef;
1663
+ /** `balance`: may the state go below zero (default false). */
1664
+ allowNegative?: boolean;
1665
+ /** `balance`: create the state row on first movement (default true). */
1666
+ autoCreate?: boolean;
1667
+ }
1668
+ /** `registers.json`: register code → declaration. */
1669
+ type RegistersFile = Record<string, RegisterDef>;
1670
+ /** A map entry: a column of the row read, or on a compound ledger one column per side. */
1671
+ type RegisterMapValue = string | {
1672
+ debit?: string;
1673
+ credit?: string;
1674
+ };
1675
+ /** `params` of an A / L column bound to a register (registers.md §4). */
1676
+ interface RegisterBindingParams {
1677
+ /** `module_cd.register_cd`. */
1678
+ register?: string;
1679
+ /** The bool column recording the posted state, when not the column itself. */
1680
+ stateField?: string;
1681
+ direction?: "increase" | "decrease";
1682
+ /** Per-row direction from a document value, instead of `direction`. */
1683
+ sign?: {
1684
+ field: string;
1685
+ positive?: unknown[];
1686
+ negative?: unknown[];
1687
+ };
1688
+ /** Document column (or path / expression) supplying the journal date. */
1689
+ dateField?: string;
1690
+ dateTrunc?: "day" | "month" | "year";
1691
+ lineEntity?: string;
1692
+ lineField?: string;
1693
+ groupLinesBy?: string[];
1694
+ /** Register dimension or resource name → column of the row read. */
1695
+ map?: Record<string, RegisterMapValue>;
1696
+ /** On a line posting: register name → DOCUMENT column. */
1697
+ headerMap?: Record<string, string>;
1698
+ lockedFields?: string[];
1699
+ lockedLineFields?: string[];
1700
+ skipPostingWhenEmpty?: string[];
1701
+ /** Classic ledger: the line's account column. */
1702
+ accountField?: string;
1703
+ debitAccountField?: string;
1704
+ creditAccountField?: string;
1705
+ periodDimField?: string;
1706
+ /** Analytic kind → line column (classic ledger). */
1707
+ analytics?: Record<string, string>;
1708
+ debitAnalytics?: Record<string, string>;
1709
+ creditAnalytics?: Record<string, string>;
1710
+ movementMapping?: Record<string, string>;
1711
+ /** Inline restatement of a register; refused alongside `register`. */
1712
+ registries?: unknown;
1713
+ }
1714
+
1715
+ type Raw = Record<string, unknown>;
1716
+ /** A declaration's dimension names, only the ones that are strings. */
1717
+ declare const registerDimensions: (def: RegisterDef | Raw) => string[];
1718
+ /** A declaration's resources in file order, each with its definition object. */
1719
+ declare const registerResources: (def: RegisterDef | Raw) => Array<{
1720
+ name: string;
1721
+ def: Raw;
1722
+ }>;
1723
+ /** The entity the dimensions, resources and stamps are columns of. */
1724
+ declare function registerCarrier(def: RegisterDef | Raw): string | undefined;
1725
+ /** How a resource names its column: one shared column, or one per side. */
1726
+ declare const registerResourceShape: (resource: RegisterResourceDef | Raw) => "field" | "split";
1727
+ declare const registerLineMode: (def: RegisterDef | Raw) => "classic" | "compound";
1728
+ declare const registerRefusedProps: (kind: RegisterKind) => readonly string[];
1729
+ declare const registerRequiredProps: (kind: RegisterKind) => readonly string[];
1730
+
1731
+ type IssuePath = Array<string | number>;
1732
+ /** One finding, addressed by a JSON path relative to what was checked. */
1733
+ interface RegisterIssue {
1734
+ path: IssuePath;
1735
+ message: string;
1736
+ /** `error`: install refuses it. `warning`: worth a look. */
1737
+ severity: "error" | "warning";
1738
+ /** Stable id, namespaced `registers/*` for a declaration and `entity/register-*` for a binding. */
1739
+ code: string;
1740
+ }
1741
+
1742
+ /**
1743
+ * What an entity a declaration names looks like, as far as the caller knows.
1744
+ * `columns` is left undefined when they can't be listed (a dependency known
1745
+ * only from its contract), and no column rule runs against it.
1746
+ */
1747
+ interface RegisterEntityInfo {
1748
+ columns?: Iterable<string>;
1749
+ }
1750
+ /**
1751
+ * Resolves an entity code as `registers.json` writes it — bare for the module's
1752
+ * own, `module.entity` for another's. Returns `null` when nothing can be known
1753
+ * (the module named isn't available: the rule stands down) and `undefined` when
1754
+ * the module is known and has no such entity.
1755
+ */
1756
+ type RegisterEntityLookup = (code: string) => RegisterEntityInfo | null | undefined;
1757
+
1758
+ /**
1759
+ * Check one declaration against the schema's per-kind rules and the installer's
1760
+ * — paths relative to the declaration. With a lookup, the entities it names are
1761
+ * checked to exist and the columns it names to be stored on them.
1762
+ */
1763
+ declare function checkRegister(raw: unknown, lookup?: RegisterEntityLookup): RegisterIssue[];
1764
+ /**
1765
+ * Check a whole `registers.json`: every declaration (paths prefixed by its
1766
+ * code), plus the codes themselves and the file's limits.
1767
+ */
1768
+ declare function checkRegisters(file: unknown, lookup?: RegisterEntityLookup): RegisterIssue[];
1769
+
1770
+ /** What a binding is checked against: the parts of a declaration it has to agree with. */
1771
+ type RegisterBindingTarget = Pick<RegisterDef, "kind" | "dimensions" | "resources" | "recorder" | "lineMode" | "sideDimensions">;
1772
+ /** A reference path (`ref.column`), an expression (`=…`) or a quoted constant — not a plain column. */
1773
+ declare const isPlainColumnRef: (value: string) => boolean;
1774
+ /**
1775
+ * Check an A / L column's `params` against the register it binds — paths
1776
+ * relative to `params`. `register` is the resolved declaration, `undefined`
1777
+ * when the module named declares no such register, `null` when that module
1778
+ * can't be seen (every rule that needs the declaration then stands down).
1779
+ */
1780
+ declare function checkRegisterBinding(columnType: "A" | "L", rawParams: unknown, register: RegisterBindingTarget | null | undefined, options?: {
1781
+ moduleCode?: string;
1782
+ }): RegisterIssue[];
1558
1783
 
1559
1784
  /** A single scheduled-job declaration. */
1560
1785
  interface JobDef {
@@ -1791,4 +2016,4 @@ declare const flagDefs: readonly {
1791
2016
  label: string;
1792
2017
  }[];
1793
2018
 
1794
- export { AGG_TYPE_LIST, type AccumulationConfig, AggType, type AlignType, type AuditHistoryLevel, type BaseDatatypeCd, type CalendarViewConfig, type CardFieldDef, type CardFieldEntry, type CardLayout, type CardLayoutDef, type CardLayoutsFile, type CardSection, type CardSetConfig, type CardTabRef, type ColumnDef, type ColumnGroupSection, 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 DiagramDef, type DiagramDetail, type DiagramEntity, type DiagramFile, type DiagramRelation, 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 SeedDataRepeat, type SetSection, type SettingBaseDatatype, type SettingDef, type SettingsFile, type SignConfig, type SortClause, type SpColumnDef, type SpParamDef, type StoredProcedureDef, type StoredProceduresFile, type TabGroupSection, type TraitCd, type TraitDef, type TraitFieldConflict, type TraitsFile, type TranslatedAction, type TranslatedEntity, type TranslatedMenu, type TranslatedOption, type TranslatedReport, type TranslatedWithOptions, type TranslationsFile, 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, traitFieldConflicts, traits, vizTypes };
2019
+ export { AGG_TYPE_LIST, type AccumulationConfig, AggType, type AlignType, type AuditHistoryLevel, type BaseDatatypeCd, type CalendarViewConfig, type CardFieldDef, type CardFieldEntry, type CardLayout, type CardLayoutDef, type CardLayoutsFile, type CardSection, type CardSetConfig, type CardTabRef, type ColumnDef, type ColumnGroupSection, 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 DiagramDef, type DiagramDetail, type DiagramEntity, type DiagramFile, type DiagramRelation, 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, REGISTER_CODE, REGISTER_COLUMN_NAME, REGISTER_KINDS, REGISTER_TOTALS_PERIODS, type RegisterBindingParams, type RegisterBindingTarget, type RegisterCompositionDef, type RegisterDef, type RegisterEntityInfo, type RegisterEntityLookup, type RegisterIssue, type RegisterKind, type RegisterMapValue, type RegisterResourceDef, type RegisterTotalsDef, type RegisterTotalsPeriod, type RegistersFile, type ReportDef, type ReportEntityAttachment, type ReportLayout, type ReportPanel, type ReportQuery, type ReportsFile, type RoleDef, type RolesFile, type SeedDataFile, type SeedDataRepeat, type SetSection, type SettingBaseDatatype, type SettingConstraintDef, type SettingDef, type SettingsFile, type SignConfig, type SortClause, type SpColumnDef, type SpParamDef, type StoredProcedureDef, type StoredProceduresFile, type TabGroupSection, type TraitCd, type TraitDef, type TraitFieldConflict, type TraitsFile, type TranslatedAction, type TranslatedEntity, type TranslatedMenu, type TranslatedOption, type TranslatedReport, type TranslatedWithOptions, type TranslationsFile, type TreeGridViewConfig, type TriggerDef, type TriggersFile, type ViewColumn, type ViewType, type VizType, type WebhookPayload, type WebhookSubscription, type WebhooksFile, baseDatatypes, baseToDbDatatype, chartTypes, checkRegister, checkRegisterBinding, checkRegisters, columnTypes, dataViewKinds, defaultParams, deriveBaseDatatype, deriveDbDatatype, expandTrait, expandTraits, fieldTypeCds, fieldTypes, fieldTypesByColumnType, flagDefs, getColumnType, getFieldType, getIdentityKeys, getLinks, getPrimaryKeys, getTrait, isFieldTypeCd, isPlainColumnRef, isRegisterKind, registerCarrier, registerDimensions, registerLineMode, registerRefusedProps, registerRequiredProps, registerResourceShape, registerResources, settingDefsOf, traitFieldConflicts, traits, vizTypes };