trama-forms 0.0.0-stage → 0.1.0

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.
Files changed (225) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +83 -2
  3. package/dist/core/acceptance.d.ts +15 -0
  4. package/dist/core/acceptance.js +37 -0
  5. package/dist/core/address.d.ts +45 -0
  6. package/dist/core/address.js +68 -0
  7. package/dist/core/authoring-checks.d.ts +39 -0
  8. package/dist/core/authoring-checks.js +1 -0
  9. package/dist/core/authoring-form.d.ts +23 -0
  10. package/dist/core/authoring-form.js +1 -0
  11. package/dist/core/authoring-params.d.ts +37 -0
  12. package/dist/core/authoring-params.js +1 -0
  13. package/dist/core/authoring-relations.d.ts +46 -0
  14. package/dist/core/authoring-relations.js +1 -0
  15. package/dist/core/authoring-rows.d.ts +109 -0
  16. package/dist/core/authoring-rows.js +1 -0
  17. package/dist/core/authoring-values.d.ts +36 -0
  18. package/dist/core/authoring-values.js +1 -0
  19. package/dist/core/authoring.d.ts +117 -0
  20. package/dist/core/authoring.js +1 -0
  21. package/dist/core/baseline.d.ts +12 -0
  22. package/dist/core/baseline.js +66 -0
  23. package/dist/core/candidates.d.ts +26 -0
  24. package/dist/core/candidates.js +155 -0
  25. package/dist/core/collections.d.ts +59 -0
  26. package/dist/core/collections.js +138 -0
  27. package/dist/core/commands.d.ts +15 -0
  28. package/dist/core/commands.js +64 -0
  29. package/dist/core/compile.d.ts +18 -0
  30. package/dist/core/compile.js +60 -0
  31. package/dist/core/compiled.d.ts +34 -0
  32. package/dist/core/compiled.js +12 -0
  33. package/dist/core/config.d.ts +103 -0
  34. package/dist/core/config.js +1 -0
  35. package/dist/core/cycles.d.ts +14 -0
  36. package/dist/core/cycles.js +39 -0
  37. package/dist/core/data.d.ts +40 -0
  38. package/dist/core/data.js +236 -0
  39. package/dist/core/declarations.d.ts +61 -0
  40. package/dist/core/declarations.js +202 -0
  41. package/dist/core/definition.d.ts +54 -0
  42. package/dist/core/definition.js +3 -0
  43. package/dist/core/derived-fields.d.ts +37 -0
  44. package/dist/core/derived-fields.js +121 -0
  45. package/dist/core/derived-scope.d.ts +55 -0
  46. package/dist/core/derived-scope.js +105 -0
  47. package/dist/core/derived.d.ts +76 -0
  48. package/dist/core/derived.js +180 -0
  49. package/dist/core/endpoints.d.ts +94 -0
  50. package/dist/core/endpoints.js +95 -0
  51. package/dist/core/engine-types.d.ts +43 -0
  52. package/dist/core/engine-types.js +1 -0
  53. package/dist/core/engine.d.ts +9 -0
  54. package/dist/core/engine.js +140 -0
  55. package/dist/core/evaluation.d.ts +20 -0
  56. package/dist/core/evaluation.js +62 -0
  57. package/dist/core/external.d.ts +13 -0
  58. package/dist/core/external.js +49 -0
  59. package/dist/core/field-definitions.d.ts +103 -0
  60. package/dist/core/field-definitions.js +20 -0
  61. package/dist/core/field-traits.d.ts +29 -0
  62. package/dist/core/field-traits.js +149 -0
  63. package/dist/core/fields.d.ts +26 -0
  64. package/dist/core/fields.js +89 -0
  65. package/dist/core/forms.d.ts +23 -0
  66. package/dist/core/forms.js +46 -0
  67. package/dist/core/handles.d.ts +56 -0
  68. package/dist/core/handles.js +128 -0
  69. package/dist/core/index.d.ts +13 -0
  70. package/dist/core/index.js +7 -0
  71. package/dist/core/invalidation.d.ts +30 -0
  72. package/dist/core/invalidation.js +161 -0
  73. package/dist/core/issues.d.ts +22 -0
  74. package/dist/core/issues.js +60 -0
  75. package/dist/core/known-keys.d.ts +4 -0
  76. package/dist/core/known-keys.js +22 -0
  77. package/dist/core/lists.d.ts +27 -0
  78. package/dist/core/lists.js +174 -0
  79. package/dist/core/lock.d.ts +4 -0
  80. package/dist/core/lock.js +70 -0
  81. package/dist/core/marking.d.ts +16 -0
  82. package/dist/core/marking.js +28 -0
  83. package/dist/core/marks.d.ts +32 -0
  84. package/dist/core/marks.js +203 -0
  85. package/dist/core/memory.d.ts +79 -0
  86. package/dist/core/memory.js +127 -0
  87. package/dist/core/messages.d.ts +20 -0
  88. package/dist/core/messages.js +46 -0
  89. package/dist/core/multiple.d.ts +12 -0
  90. package/dist/core/multiple.js +123 -0
  91. package/dist/core/notify.d.ts +32 -0
  92. package/dist/core/notify.js +160 -0
  93. package/dist/core/observation.d.ts +7 -0
  94. package/dist/core/observation.js +80 -0
  95. package/dist/core/observe.d.ts +19 -0
  96. package/dist/core/observe.js +59 -0
  97. package/dist/core/operation.d.ts +8 -0
  98. package/dist/core/operation.js +48 -0
  99. package/dist/core/options.d.ts +40 -0
  100. package/dist/core/options.js +32 -0
  101. package/dist/core/outputs.d.ts +58 -0
  102. package/dist/core/outputs.js +149 -0
  103. package/dist/core/param-memory.d.ts +13 -0
  104. package/dist/core/param-memory.js +17 -0
  105. package/dist/core/params.d.ts +37 -0
  106. package/dist/core/params.js +70 -0
  107. package/dist/core/pass.d.ts +6 -0
  108. package/dist/core/pass.js +141 -0
  109. package/dist/core/patches.d.ts +15 -0
  110. package/dist/core/patches.js +106 -0
  111. package/dist/core/prepare.d.ts +19 -0
  112. package/dist/core/prepare.js +105 -0
  113. package/dist/core/prepared.d.ts +10 -0
  114. package/dist/core/prepared.js +14 -0
  115. package/dist/core/program.d.ts +43 -0
  116. package/dist/core/program.js +100 -0
  117. package/dist/core/publication.d.ts +20 -0
  118. package/dist/core/publication.js +56 -0
  119. package/dist/core/published.d.ts +18 -0
  120. package/dist/core/published.js +83 -0
  121. package/dist/core/queries.d.ts +10 -0
  122. package/dist/core/queries.js +148 -0
  123. package/dist/core/query-batch.d.ts +2 -0
  124. package/dist/core/query-batch.js +67 -0
  125. package/dist/core/query-entries.d.ts +78 -0
  126. package/dist/core/query-entries.js +139 -0
  127. package/dist/core/query-response.d.ts +2 -0
  128. package/dist/core/query-response.js +110 -0
  129. package/dist/core/reads.d.ts +30 -0
  130. package/dist/core/reads.js +88 -0
  131. package/dist/core/rebase.d.ts +16 -0
  132. package/dist/core/rebase.js +40 -0
  133. package/dist/core/relations.d.ts +10 -0
  134. package/dist/core/relations.js +84 -0
  135. package/dist/core/remote-fields.d.ts +6 -0
  136. package/dist/core/remote-fields.js +29 -0
  137. package/dist/core/resolution.d.ts +12 -0
  138. package/dist/core/resolution.js +157 -0
  139. package/dist/core/restarts.d.ts +17 -0
  140. package/dist/core/restarts.js +42 -0
  141. package/dist/core/revisions.d.ts +11 -0
  142. package/dist/core/revisions.js +57 -0
  143. package/dist/core/row-arrays.d.ts +12 -0
  144. package/dist/core/row-arrays.js +47 -0
  145. package/dist/core/row-maps.d.ts +16 -0
  146. package/dist/core/row-maps.js +52 -0
  147. package/dist/core/row-states.d.ts +68 -0
  148. package/dist/core/row-states.js +75 -0
  149. package/dist/core/row-types.d.ts +76 -0
  150. package/dist/core/row-types.js +1 -0
  151. package/dist/core/rule-set-config.d.ts +56 -0
  152. package/dist/core/rule-set-config.js +1 -0
  153. package/dist/core/rule-set-types.d.ts +91 -0
  154. package/dist/core/rule-set-types.js +1 -0
  155. package/dist/core/rule-sets.d.ts +15 -0
  156. package/dist/core/rule-sets.js +107 -0
  157. package/dist/core/rules.d.ts +67 -0
  158. package/dist/core/rules.js +144 -0
  159. package/dist/core/saving.d.ts +55 -0
  160. package/dist/core/saving.js +132 -0
  161. package/dist/core/scope-declarations.d.ts +13 -0
  162. package/dist/core/scope-declarations.js +18 -0
  163. package/dist/core/scope-messages.d.ts +9 -0
  164. package/dist/core/scope-messages.js +46 -0
  165. package/dist/core/scope-states.d.ts +50 -0
  166. package/dist/core/scope-states.js +222 -0
  167. package/dist/core/session-external.d.ts +24 -0
  168. package/dist/core/session-external.js +138 -0
  169. package/dist/core/session-lists.d.ts +12 -0
  170. package/dist/core/session-lists.js +60 -0
  171. package/dist/core/session-marks.d.ts +22 -0
  172. package/dist/core/session-marks.js +113 -0
  173. package/dist/core/session-parts.d.ts +26 -0
  174. package/dist/core/session-parts.js +91 -0
  175. package/dist/core/session-rows.d.ts +15 -0
  176. package/dist/core/session-rows.js +62 -0
  177. package/dist/core/session-types.d.ts +112 -0
  178. package/dist/core/session-types.js +1 -0
  179. package/dist/core/session.d.ts +5 -0
  180. package/dist/core/session.js +51 -0
  181. package/dist/core/state-evaluation.d.ts +10 -0
  182. package/dist/core/state-evaluation.js +69 -0
  183. package/dist/core/state-properties.d.ts +30 -0
  184. package/dist/core/state-properties.js +101 -0
  185. package/dist/core/states.d.ts +73 -0
  186. package/dist/core/states.js +180 -0
  187. package/dist/core/steps.d.ts +37 -0
  188. package/dist/core/steps.js +183 -0
  189. package/dist/core/subtype-types.d.ts +67 -0
  190. package/dist/core/subtype-types.js +1 -0
  191. package/dist/core/subtypes.d.ts +19 -0
  192. package/dist/core/subtypes.js +69 -0
  193. package/dist/core/tree.d.ts +44 -0
  194. package/dist/core/tree.js +119 -0
  195. package/dist/core/validation.d.ts +11 -0
  196. package/dist/core/validation.js +42 -0
  197. package/dist/core/views.d.ts +24 -0
  198. package/dist/core/views.js +161 -0
  199. package/dist/react/async.d.ts +7 -0
  200. package/dist/react/async.js +67 -0
  201. package/dist/react/binding.d.ts +15 -0
  202. package/dist/react/binding.js +51 -0
  203. package/dist/react/coverage.d.ts +21 -0
  204. package/dist/react/coverage.js +91 -0
  205. package/dist/react/field.d.ts +60 -0
  206. package/dist/react/field.js +194 -0
  207. package/dist/react/form-state.d.ts +14 -0
  208. package/dist/react/form-state.js +70 -0
  209. package/dist/react/index.d.ts +152 -0
  210. package/dist/react/index.js +6 -0
  211. package/dist/react/opening.d.ts +38 -0
  212. package/dist/react/opening.js +206 -0
  213. package/dist/react/outputs.d.ts +11 -0
  214. package/dist/react/outputs.js +137 -0
  215. package/dist/react/props.d.ts +48 -0
  216. package/dist/react/props.js +1 -0
  217. package/dist/react/query.d.ts +11 -0
  218. package/dist/react/query.js +21 -0
  219. package/dist/react/render.d.ts +49 -0
  220. package/dist/react/render.js +119 -0
  221. package/dist/react/rows.d.ts +2 -0
  222. package/dist/react/rows.js +25 -0
  223. package/dist/react/visible-messages.d.ts +8 -0
  224. package/dist/react/visible-messages.js +16 -0
  225. package/package.json +77 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Alejandro Luman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,84 @@
1
- # Temporary Holding Version
1
+ # Trama
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Declarative forms library for modern browsers. A definition declares fields, rules between them, and derived outputs. A session holds the values for an edit, runs the rules on every change, and publishes snapshots. Each entry in `rules` describes a field by its properties. It can specify a value formula, the field's state (disabled or read-only with reasons, hidden, required, label, and placeholder, including for multiple fields at once), and what happens when the field changes. The `form` section locks the whole form except for its exceptions. An async field selects its option from an endpoint in the application's registry, page by page or from a complete list, and the complete option is its value. `trama-forms/core` has no dependencies. `trama-forms/react` adds `Field`, `useFormSession`, outputs, loading with TanStack Query, and a loader that shares its cache, and requires React 19.3 as an optional peer dependency.
4
+
5
+ ```ts
6
+ import { createSession, defineForm, field } from "trama-forms/core";
7
+
8
+ const line = defineForm({
9
+ fields: {
10
+ quantity: field.number({ label: "Quantity", default: 2 }),
11
+ price: field.number({ label: "Price", default: 10 }),
12
+ total: field.number({ label: "Total" }),
13
+ },
14
+ rules: {
15
+ total: { value: ({ quantity, price }) => (quantity ?? 0) * (price ?? 0) },
16
+ },
17
+ });
18
+
19
+ const session = createSession(line);
20
+ session.edit("quantity", 3);
21
+ session.getSnapshot().values; // { quantity: 3, price: 10, total: 30 }
22
+ ```
23
+
24
+ ## Installation
25
+
26
+ ```sh
27
+ npm install trama-forms
28
+ ```
29
+
30
+ The public entries are `trama-forms/core` and `trama-forms/react`, which point to `dist` and never to `src`. `trama-forms/core` has no dependencies. `trama-forms/react` needs React `^19.3.0`, an optional peer dependency that applications using it install themselves. Trama uses the MIT license. See [LICENSE](LICENSE).
31
+
32
+ ## Interactive guide
33
+
34
+ ```sh
35
+ pnpm install --frozen-lockfile
36
+ pnpm run docs:dev
37
+ ```
38
+
39
+ Open http://127.0.0.1:5173. The guide (`docs/site/`) explains fields, sessions, React, loading with TanStack Query, value formulas, events, field state, remote select, outputs, a complete example, the API, and errors and limits. Each example shows the file that runs the demo beside it, with steps to try it. The guide documents only what is implemented.
40
+
41
+ `pnpm run docs:dev` builds Trama, and the guide uses the public entries from `dist`. To rebuild the library while editing `src/`, run `pnpm run build:watch` in another terminal. If a definition changes during HMR, reload the page. `pnpm run docs:site` builds the guide in `.artifacts/site/` and `pnpm run docs:preview` serves it at http://127.0.0.1:4173.
42
+
43
+ ## Development
44
+
45
+ The pnpm version is pinned in `packageManager`, and dependencies are pinned in `pnpm-lock.yaml`. Use Node 26.9.0 (`.node-version`) or later and pnpm 12.4.2. Node is used for development and verification and is outside the runtime contract. There is no guarantee of support for CommonJS, SSR, or older browsers.
46
+
47
+ ```sh
48
+ pnpm run check
49
+ ```
50
+
51
+ `check` builds and type-checks the library, then type-checks the guide, and runs linting, format checks, tests, the guide build, and the generated technical document check, in that order. Run the steps individually with the following commands.
52
+
53
+ ```sh
54
+ pnpm run build
55
+ pnpm run typecheck
56
+ pnpm run lint
57
+ pnpm run format:check
58
+ pnpm test
59
+ ```
60
+
61
+ - **Build.** TypeScript builds the core and the declarations. The build distributes the binding compiled with React Compiler through `oxc-transform-react` 0.145.0, without Babel. The binding uses `react/compiler-runtime`, which ships with React 19. The native compiler is experimental, and its version is pinned alongside `@vitejs/plugin-react` 6.1.1.
62
+ - **Lint and formatting.** [Oxlint](https://oxc.rs/docs/guide/usage/linter/config) with type-aware analysis (`oxlint-tsgolint`) treats the `correctness`, `suspicious`, `pedantic`, and `perf` categories as errors and rejects unused suppressions. [Oxfmt](https://oxc.rs/docs/guide/usage/formatter) formats the code. In `docs/site/`, the `react-perf` rules for new props are disabled because React Compiler memoizes the guide. The Hooks rules remain enabled.
63
+ - **Tests.** `node:test` tests the actual core, React, and TanStack Query with controlled transport, and the definition of the guide's complete example. The package test installs a `.tgz` in an isolated project, runs the core without React, checks the typing of valid and invalid uses, verifies that internal imports are rejected, and builds the guide against the installed package. Artifacts are kept in `.artifacts/package-check/`.
64
+ - **Continuous integration.** GitHub Actions runs `pnpm run check` on every pull request and on every push to `main` (`.github/workflows/ci.yml`).
65
+ - **Releases.** Releases come from `aleluman/trama`. Set the version in `package.json` and push a matching tag, such as `v0.1.1`. The release workflow (`.github/workflows/release.yml`) checks that the tag matches the version, runs `pnpm run check`, and packs the package. If that version is not on npm yet, a separate job publishes the tarball through npm trusted publishing, with provenance. On npmjs.com, the trusted publisher names this repository, the `release.yml` workflow, and the `npm publish` action, and provenance requires the repository to be public. Version 0.1.0 is published by hand, because trusted publishing can only be configured for a package that already exists.
66
+
67
+ ## Project documentation
68
+
69
+ - [Interactive guide](docs/site/) on using the library, with demos. Open it with `pnpm run docs:dev`.
70
+ - The technical document records the current contracts, limits, decisions, and performance. `pnpm run docs:build` generates standalone HTML, and `pnpm run docs:check` checks that it is up to date. [Technical document](docs/technical.html) · [Source](docs/technical/content.html)
71
+ - [CONTEXT.md](CONTEXT.md) is the glossary.
72
+ - [AGENTS.md](AGENTS.md) contains the working rules.
73
+
74
+ ### Architecture decisions
75
+
76
+ - Dependencies and state ownership. [ADR 0001](docs/adr/0001-independent-core.md)
77
+ - Rule authoring by field property. [ADR 0002](docs/adr/0002-property-based-rule-authoring.md)
78
+ - Typed endpoint registry. [ADR 0003](docs/adr/0003-endpoint-registry.md)
79
+ - Lists per view and queries with generations. [ADR 0004](docs/adr/0004-async-lists-and-queries.md)
80
+ - Row identity, per-row values, and targeted invalidation. [ADR 0005](docs/adr/0005-rows-identity-values-invalidation.md)
81
+ - Variants by composing rule sets. [ADR 0006](docs/adr/0006-variants-by-rule-sets.md)
82
+ - Subtypes, values, and limits. [ADR 0007](docs/adr/0007-per-field-presentation.md)
83
+ - Validation, "dirty," and submission. [ADR 0008](docs/adr/0008-validation-dirty-and-submission.md)
84
+ - Direct edits, mode fields, and bidirectional relations. [ADR 0009](docs/adr/0009-direct-edits-mode-fields-and-driver-relations.md)
@@ -0,0 +1,15 @@
1
+ import type { Field } from "./address.js";
2
+ import type { Compiled } from "./compiled.js";
3
+ import { type PreparedRecord, type State } from "./memory.js";
4
+ import type { Given } from "./reads.js";
5
+ import type { Revisions } from "./revisions.js";
6
+ export declare const accept: (compiled: Compiled, given: Given, { current, revisions }: {
7
+ readonly current: State;
8
+ readonly revisions: Revisions;
9
+ }, record: PreparedRecord, writes: ReadonlyMap<Field, unknown>) => {
10
+ baseline: State;
11
+ live: {
12
+ state: State;
13
+ receipt: NonNullable<import("./memory.js").Receipt | undefined>;
14
+ };
15
+ };
@@ -0,0 +1,37 @@
1
+ import { patched } from "./candidates.js";
2
+ import { withoutParams } from "./memory.js";
3
+ import { observed } from "./observation.js";
4
+ import { run, unresolved } from "./operation.js";
5
+ import { holds } from "./tree.js";
6
+ export const accept = (compiled, given, { current, revisions }, record, writes) => {
7
+ const baseline = savedOf(compiled, given, record, writes);
8
+ const { since } = record;
9
+ const live = new Map();
10
+ for (const [address, value] of writes)
11
+ if (!revisions.changedAfter(address, since) &&
12
+ (typeof address === "string" || holds(current.store.collections, address.row)))
13
+ live.set(address, value);
14
+ const change = {
15
+ kind: "change",
16
+ previous: current.store,
17
+ baseline: baseline.store,
18
+ roots: [...live.keys()],
19
+ supplied: (address) => revisions.explicitAfter(address, since),
20
+ };
21
+ const candidate = patched(compiled, current.store, live);
22
+ const { state, receipt } = candidate === undefined
23
+ ? observed(compiled, given, change, current.store, current, unresolved, current)
24
+ : run(compiled, given, change, candidate, current, current);
25
+ return { baseline, live: { state, receipt: receipt } };
26
+ };
27
+ // The prepared state with the canonical values, on its own memory, which the
28
+ // change copies before it writes: a failure leaves the prepared as it was. It
29
+ // derives against the baseline of the prepared, so it rebases nothing.
30
+ const savedOf = (compiled, given, { state }, writes) => {
31
+ const candidate = patched(compiled, state.store, writes);
32
+ if (candidate === undefined)
33
+ return withoutParams(state);
34
+ const roots = [...writes.keys()];
35
+ const change = { kind: "change", previous: state.store, baseline: state.baseline, roots };
36
+ return withoutParams(run(compiled, given, change, candidate, withoutParams(state), state).state);
37
+ };
@@ -0,0 +1,45 @@
1
+ import type { CompiledCollection } from "./collections.js";
2
+ import type { EndpointTable } from "./compiled.js";
3
+ import type { FieldDefinition } from "./fields.js";
4
+ declare const rowKey: unique symbol;
5
+ export type RowKey<N extends string = string> = string & {
6
+ readonly [rowKey]: N;
7
+ };
8
+ export declare const keysGiven: () => number;
9
+ export type Row = {
10
+ readonly key: RowKey;
11
+ readonly seq: number;
12
+ readonly collection: CompiledCollection;
13
+ readonly addresses: Map<string, RowAddress>;
14
+ readonly instances: Map<object, object>;
15
+ };
16
+ export type RowAddress = {
17
+ readonly kind: "row";
18
+ readonly row: Row;
19
+ readonly field: string;
20
+ readonly position: number;
21
+ };
22
+ export type StructureAddress = {
23
+ readonly kind: "structure";
24
+ readonly collection: CompiledCollection;
25
+ };
26
+ export type Address = string | RowAddress | StructureAddress;
27
+ export type Field = string | RowAddress;
28
+ export declare const formScope: Readonly<{
29
+ kind: "form";
30
+ }>;
31
+ export type Own = Row | StructureAddress | typeof formScope;
32
+ export type Destination = Field | Own;
33
+ export declare const isField: (destination: Destination) => destination is Field;
34
+ export declare const isRow: (destination: Destination) => destination is Row;
35
+ export declare const createRow: (collection: CompiledCollection) => Row;
36
+ export declare const rowAddress: (row: Row, field: string) => RowAddress;
37
+ export declare const span: number;
38
+ export declare const definitionAt: (fields: Readonly<Record<string, FieldDefinition>>, address: Field) => FieldDefinition;
39
+ export declare const endpointAt: (endpoints: EndpointTable, address: Field) => import("./endpoints.js").ResolvedEndpoint | undefined;
40
+ export declare const instanceOf: <T extends object>(row: Row, template: object, create: () => T) => T;
41
+ export declare const fieldLabel: (name: string, row?: Row) => string;
42
+ export declare const labelAt: (address: Field) => string;
43
+ export declare const templateLabel: (name: string, collection: string) => string;
44
+ export declare const pathLabel: (address: string | RowAddress) => string;
45
+ export {};
@@ -0,0 +1,68 @@
1
+ // Two copies of the package in the same global share the counter, so a key
2
+ // never names a row of another session. Keys are unique per realm, not across
3
+ // iframes or workers.
4
+ const counter = Symbol.for("trama.rowKeys.1");
5
+ const keys = (globalThis[counter] ??= { next: 0 });
6
+ // The number of keys given so far in the realm, which bounds every sequence.
7
+ export const keysGiven = () => keys.next;
8
+ // What a message from outside the rules is given to: a field, or a scope
9
+ // above the fields, which is a row, a collection, named by the address of its
10
+ // structure, or the form.
11
+ export const formScope = Object.freeze({ kind: "form" });
12
+ export const isField = (destination) => typeof destination === "string" || ("kind" in destination && destination.kind === "row");
13
+ export const isRow = (destination) => typeof destination !== "string" && !("kind" in destination);
14
+ export const createRow = (collection) => {
15
+ const seq = ++keys.next;
16
+ return { key: `r${seq}`, seq, collection, addresses: new Map(), instances: new Map() };
17
+ };
18
+ export const rowAddress = (row, field) => {
19
+ let address = row.addresses.get(field);
20
+ if (address === undefined) {
21
+ const position = rowPosition(row, field);
22
+ address = Object.freeze({ kind: "row", row, field, position });
23
+ row.addresses.set(field, address);
24
+ }
25
+ return address;
26
+ };
27
+ // The traversal of an operation visits the header, field by field in
28
+ // declaration order, then each collection in declaration order, its rows in
29
+ // creation order and their fields in declaration order; each field is right
30
+ // before its event. A position orders that traversal as a number: the field
31
+ // at index i of the header is 2i, its event 2i + 1; a field of a row adds the
32
+ // span of its collection and the sequence of its row times the width of a row.
33
+ // Positions stay exact while every sequence times every width is below the
34
+ // span, which an operation checks before it relies on them.
35
+ export const span = 2 ** 44;
36
+ const rowPosition = (row, field) => (row.collection.index + 1) * span +
37
+ row.seq * row.collection.width +
38
+ row.collection.positions.get(field);
39
+ // The definition of a field and the endpoint of an async field: of the header,
40
+ // or of the rows of its collection.
41
+ export const definitionAt = (fields, address) => (typeof address === "string"
42
+ ? fields[address]
43
+ : address.row.collection.fields[address.field]);
44
+ export const endpointAt = (endpoints, address) => typeof address === "string"
45
+ ? endpoints.get(address)
46
+ : address.row.collection.endpoints.get(address.field);
47
+ // The instance of a template for a row, created once.
48
+ export const instanceOf = (row, template, create) => {
49
+ let instance = row.instances.get(template);
50
+ if (instance === undefined) {
51
+ instance = create();
52
+ row.instances.set(template, instance);
53
+ }
54
+ return instance;
55
+ };
56
+ // How diagnostics name a field: by its name in the header, and with its
57
+ // collection and the key of its row otherwise, never by its position.
58
+ export const fieldLabel = (name, row) => row === undefined
59
+ ? `Field "${name}"`
60
+ : `${templateLabel(name, row.collection.name)} row "${row.key}"`;
61
+ export const labelAt = (address) => typeof address === "string" ? fieldLabel(address) : fieldLabel(address.field, address.row);
62
+ // A field of a collection, as its declaration and the templates of its rules
63
+ // name it: an instance adds the key of its row.
64
+ export const templateLabel = (name, collection) => `Field "${name}" of "${collection}"`;
65
+ // How the path of a cycle names a field.
66
+ export const pathLabel = (address) => typeof address === "string"
67
+ ? address
68
+ : `${address.row.collection.name}["${address.row.key}"].${address.field}`;
@@ -0,0 +1,39 @@
1
+ import type { Fields } from "./definition.js";
2
+ import type { DateDefinition, NumberDefinition, WithPlaceholder } from "./fields.js";
3
+ import type { Limit, StateProperty } from "./state-properties.js";
4
+ export type { Limit };
5
+ export type Keys<T> = T extends unknown ? keyof T : never;
6
+ export type At<T, Q> = T extends unknown ? (Q extends keyof T ? T[Q] : never) : never;
7
+ export type Verdict<M> = [M] extends [never] ? unknown : M;
8
+ export type Reported<V, M> = [M] extends [never] ? unknown : V extends readonly unknown[] ? readonly M[] : M;
9
+ export type Everywhere<V, M> = V extends readonly unknown[] ? readonly M[] & M : M;
10
+ export type Unknown<What extends string, K, Of extends string = ""> = K extends string | number ? `${What} "${K}"${Of} does not exist` : K extends symbol ? `${What} with a symbol key does not exist` : never;
11
+ export type Items<V> = V extends readonly (infer E)[] ? E : V;
12
+ export type Result<V> = V extends (...args: never) => infer R ? R : never;
13
+ export type EmptyReason<R> = [Extract<R, "">] extends [never] ? never : "reasons cannot be empty";
14
+ export type EmptyMessage<P extends string, R> = [Extract<R, "">] extends [never] ? never : `${P} messages cannot be empty`;
15
+ export type MayLack<T> = [T] extends [never] ? true : undefined extends T ? true : false;
16
+ export type Checked<T> = [T][T extends unknown ? 0 : never];
17
+ export type Member<P, K> = NonNullable<At<P, K>>;
18
+ export type EditConflict<E, Label extends string> = E extends unknown ? [Member<E, "onEdit">] extends [never] ? never : [Member<E, "onChange">] extends [never] ? never : `${Label} declares onChange or onEdit, not both` : never;
19
+ type RowPatches<V> = V extends object ? Extract<V[keyof V], object> : never;
20
+ export type EventMessages<F extends Fields, E, K = {}, Of extends string = "", Shape extends string = "events return a patch object or undefined", Sync extends string = "events are synchronous"> = E extends (...args: never) => infer R ? [Extract<R, PromiseLike<unknown>>] extends [never] ? [Exclude<R, object | undefined>] extends [never] ? Unknown<"patch field", Exclude<Keys<Extract<R, object>>, keyof F | keyof K>, Of> | NestedMessages<K, Extract<R, object>> : Shape : Sync : never;
21
+ export type NestedMessages<K, R> = {
22
+ [N in keyof K & Keys<R>]: K[N] extends {
23
+ readonly fields: infer W extends Fields;
24
+ } ? Unknown<"patch field", Exclude<Keys<RowPatches<At<R, N>>>, keyof W>, ` of "${N & string}"`> : never;
25
+ }[keyof K & Keys<R>];
26
+ export type Lacks<F extends Fields, K, Has, What extends string, Of extends string = ""> = K extends keyof F ? F[K] extends Has ? never : `field "${K & string}"${Of} has no ${What}` : never;
27
+ export type LimitMessages<F extends Fields, K, Q, R, Of extends string = ""> = K extends keyof F ? MemberLimit<F[K], K, Q, R, Of> : never;
28
+ type MemberLimit<D, K, Q, R, Of extends string> = D extends NumberDefinition ? Q extends "decimals" ? never : Takes<K, Q, R, number, "a number", Of> : [D, Q] extends [DateDefinition, "min" | "max"] ? Takes<K, Q, R, string, "a date", Of> : `field "${K & string}"${Of} has no ${Q & string}`;
29
+ type Takes<K, Q, R, T, What extends string, Of extends string> = [
30
+ Exclude<R, T | null | undefined>
31
+ ] extends [never] ? never : `field "${K & string}"${Of} ${Q & string} takes ${What} or null`;
32
+ type DestinationMessages<F extends Fields, K, V, Of extends string, S = Extract<V, object>> = [
33
+ Exclude<V, object | undefined>
34
+ ] extends [never] ? Unknown<"state property", Exclude<Keys<S>, StateProperty>> | ("placeholder" extends Keys<S> ? Lacks<F, K, WithPlaceholder, "placeholder", Of> : never) | {
35
+ [Q in Extract<Keys<S>, Limit>]: LimitMessages<F, K, Q, At<S, Q>, Of>;
36
+ }[Extract<Keys<S>, Limit>] | EmptyReason<At<S, "disabled" | "readOnly">> | EmptyMessage<"required", At<S, "required">> | EmptyMessage<"error", At<S, "error">> | EmptyMessage<"warning", At<S, "warning">> : `states field "${K & string}"${Of} takes an object of properties`;
37
+ export type StateMessages<F extends Fields, E, Of extends string = ""> = E extends (...args: never) => infer R ? [Extract<R, PromiseLike<unknown>>] extends [never] ? [Exclude<R, object | undefined>] extends [never] ? Unknown<"states field", Exclude<Keys<Extract<R, object>>, keyof F>, Of> | {
38
+ [K in keyof F & Keys<Extract<R, object>>]: DestinationMessages<F, K, At<Extract<R, object>, K>, Of>;
39
+ }[keyof F & Keys<Extract<R, object>>] : "states return a state patch object or undefined" : "state formulas are synchronous" : never;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ import type { Fields, FieldsIn } from "./definition.js";
2
+ import type { At, Checked, EmptyMessage, EmptyReason, Everywhere, Items, Keys, Member, Reported, Result, Unknown } from "./authoring-checks.js";
3
+ import type { Formula, Many, Reason } from "./authoring.js";
4
+ type Except<F extends Fields, K> = [keyof K] extends [never] ? keyof F & string : (keyof F & string) | {
5
+ readonly [N in keyof K]?: readonly (keyof FieldsIn<K[N]> & string)[] | undefined;
6
+ };
7
+ type Lock<F extends Fields, K, C> = {
8
+ readonly value: Formula<F, K, C, boolean | Reason | undefined>;
9
+ readonly except?: readonly Except<F, K>[] | undefined;
10
+ };
11
+ type FormSection<F extends Fields, K, C> = {
12
+ readonly readOnly?: Many<Lock<F, K, C>> | undefined;
13
+ readonly error?: Many<Formula<F, K, C, Reason | false | undefined>> | undefined;
14
+ readonly warning?: Many<Formula<F, K, C, Reason | false | undefined>> | undefined;
15
+ };
16
+ type LockMessages<E> = E extends unknown ? Unknown<"lock property", Exclude<keyof E, "value" | "except">> | EmptyReason<Result<At<E, "value">>> : never;
17
+ type CheckForm<L> = {
18
+ [Q in Keys<L>]?: Q extends "readOnly" ? Reported<Member<L, Q>, LockMessages<Items<Member<L, Q>>>> : Q extends "error" | "warning" ? Reported<At<L, Q>, EmptyMessage<Q, Result<Items<At<L, Q>>>>> : Everywhere<At<L, Q>, `form property "${Q & string}" does not exist`>;
19
+ };
20
+ export type FormRules<F extends Fields, K, C, L> = FormSection<F, K, C> & CheckForm<Checked<L>> & {
21
+ readonly [Symbol.hasInstance]?: "form must be an object of properties";
22
+ };
23
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,37 @@
1
+ import type { Fields, FieldsIn } from "./definition.js";
2
+ import type { ParamsOf } from "./fields.js";
3
+ import type { Formula, RequiredCollections, RequiredEntries, RequiredRows } from "./authoring.js";
4
+ import type { RemainingEach } from "./authoring-rows.js";
5
+ import type { FieldName, Given, Lists, NameOf, Part } from "./rule-set-types.js";
6
+ export type Left<X, G, Scope extends readonly string[] = ["header"]> = X extends unknown ? [...Scope, NameOf<X>] extends G ? never : X : never;
7
+ type LeftRows<K, N, G> = Left<RequiredRows<FieldsIn<K[N & keyof K]>>, G, ["rows", NameOf<N>]>;
8
+ type RemainingCollections<K, G> = K extends unknown ? {
9
+ [N in keyof K]-?: [LeftRows<K, N, G>] extends [never] ? never : N;
10
+ }[keyof K] : never;
11
+ type Keyed<X, Scope extends readonly unknown[]> = X extends unknown ? [...Scope, NameOf<X>] : never;
12
+ declare const needsParams: unique symbol;
13
+ export type ParamsLeftRules<F extends Fields, K, I> = [
14
+ RequiredEntries<F> | RequiredCollections<K>
15
+ ] extends [never] ? unknown : ParamsMessage<ParamsLeft<F, K, Given<I>>, I> extends infer X ? [X] extends [never] ? unknown : {
16
+ readonly rules: {
17
+ readonly [needsParams]?: X;
18
+ };
19
+ } : never;
20
+ type ParamsLeft<F extends Fields, K, G> = Keyed<Left<RequiredEntries<F>, G>, ["header"]> | {
21
+ [N in RemainingCollections<K, G>]: Keyed<LeftRows<K, N, G>, ["rows", NameOf<N>]>;
22
+ }[RemainingCollections<K, G>];
23
+ type ParamsMessage<X, I> = X extends unknown ? `${FieldName<X>} needs params: ${Why<X, I>}` : never;
24
+ type Why<X, I> = X extends Possibly<I, "loose"> ? 'a list without "as const" may lack the rule set that gives them' : X extends Possibly<I, "fixed"> ? "the rule set that gives them may be absent" : "give them in rules or in a rule set always included";
25
+ type Possibly<I, Where> = Lists<I> extends infer L ? L extends readonly unknown[] ? {
26
+ [J in keyof L]: (J extends `${number}` ? "fixed" : "loose") extends Where ? Part<L[J], "gives"> : never;
27
+ }[number] : never : never;
28
+ export type RemainingLayers<F extends Fields, K, C, M, G> = ([Left<RequiredEntries<F>, G>] extends [
29
+ never
30
+ ] ? unknown : {
31
+ readonly [X in Left<RequiredEntries<F>, G>]: {
32
+ readonly params: Formula<F, K, C, ParamsOf<F[X]> | undefined>;
33
+ };
34
+ }) & ([RemainingCollections<K, G>] extends [never] ? unknown : {
35
+ readonly [N in RemainingCollections<K, G>]: RemainingEach<F, K, C, N & keyof K, M, G>;
36
+ });
37
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,46 @@
1
+ import type { Keys, Member, Unknown } from "./authoring-checks.js";
2
+ import type { RowFormula } from "./authoring-rows.js";
3
+ import type { Formula } from "./authoring.js";
4
+ import type { Fields, FieldsIn } from "./definition.js";
5
+ import type { FieldDefinition, FieldValue } from "./fields.js";
6
+ import type { NameOf } from "./rule-set-types.js";
7
+ export type HeaderRelation<F extends Fields, K, C, X> = {
8
+ readonly default: NameOf<Exclude<keyof F, X>>;
9
+ readonly members: {
10
+ readonly [Y in Exclude<keyof F, X>]?: Formula<F, K, C, FieldValue<F[Y]> | undefined>;
11
+ };
12
+ };
13
+ export type RowRelation<F extends Fields, K, C, N extends keyof K, X> = {
14
+ readonly default: NameOf<Exclude<keyof FieldsIn<K[N]>, X>>;
15
+ readonly members: {
16
+ readonly [Y in Exclude<keyof FieldsIn<K[N]>, X>]?: RowFormula<F, K, C, N, FieldValue<FieldsIn<K[N]>[Y]> | undefined>;
17
+ };
18
+ };
19
+ export type MembersOf<R> = NameOf<Keys<Member<R, "members">>>;
20
+ type Takes = "value" | "onChange" | "onEdit";
21
+ type Declared<E> = {
22
+ [Q in Keys<E> & Takes]: [Member<E, Q>] extends [never] ? never : Q;
23
+ }[Keys<E> & Takes];
24
+ type Taken<P, X, Y extends string, Of extends string> = {
25
+ [Z in Keys<P>]: NameOf<Z> extends Y ? `field "${NameOf<Z>}"${Of} ${Declared<Member<P, Z>>} is taken by the relation of "${NameOf<X>}"` : never;
26
+ }[Keys<P>];
27
+ type Shared<P, X, Y extends string, Of extends string> = {
28
+ [Z in Exclude<Keys<P>, X>]: `field "${Extract<MembersOf<Member<Member<P, Z>, "relation">>, Y>}"${Of} is a member of the relations of "${NameOf<X>}" and "${NameOf<Z>}"`;
29
+ }[Exclude<Keys<P>, X>];
30
+ type Single<U, All = U> = U extends unknown ? [Exclude<All, U>] extends [never] ? true : false : never;
31
+ type Pair<U, All = U> = U extends unknown ? [Exclude<All, U>] extends [never] ? false : Single<Exclude<All, U>> : never;
32
+ type CountMessage<X, Y, Of extends string> = [true] extends [Pair<Y>] ? never : `relation of "${NameOf<X>}"${Of} takes two members`;
33
+ type MemberMessage<R extends Fields, X, Y, Of extends string> = Y extends string ? Y extends NameOf<X> ? `field "${NameOf<X>}"${Of} cannot be a member of its own relation` : Y extends NameOf<keyof R> ? never : `relation member "${Y}" of "${NameOf<X>}"${Of} is not a field` : never;
34
+ type DriverMessage<D extends FieldDefinition, X, Y, Of extends string> = D extends {
35
+ readonly type: "select";
36
+ } ? `relation member "${Exclude<Y, FieldValue<D>> & string}" is not an option of field "${NameOf<X>}"${Of}` | `option "${Exclude<FieldValue<D>, Y | null> & (string | number)}" of field "${NameOf<X>}"${Of} is not a member of its relation` : D extends {
37
+ readonly type: "text";
38
+ } ? "" extends Y ? `field "${NameOf<X>}"${Of} cannot have a member named after the empty text ""` : never : `field "${NameOf<X>}"${Of} drives a relation, it must be a text or a select`;
39
+ export type RelationMessages<R extends Fields, X extends keyof R, P, Of extends string = ""> = P extends unknown ? RelationIn<R, X, Member<Member<P, X>, "relation">, P, Of> : never;
40
+ type RelationIn<R extends Fields, X extends keyof R, V, P, Of extends string> = V extends (...args: never) => unknown ? `relation of "${NameOf<X>}"${Of} takes default and members` : V extends object ? `relation of "${NameOf<X>}"${Of} takes default and members, not "${NameOf<Exclude<Keys<V>, "default" | "members">>}"` | Unknown<"relation property", Extract<Keys<V>, symbol>, Of> | MemberVariants<R, X, V, P, Of> : `relation of "${NameOf<X>}"${Of} takes default and members`;
41
+ type MemberVariants<R extends Fields, X extends keyof R, V, P, Of extends string, M = Member<V, "members">> = M extends unknown ? MemberChecks<R, X, V, P, Of, M> : never;
42
+ type OptionalMembers<M> = {
43
+ [Y in keyof M]-?: undefined extends M[Y] ? NameOf<Y> : never;
44
+ }[keyof M];
45
+ type MemberChecks<R extends Fields, X extends keyof R, V, P, Of extends string, M, Y extends string = NameOf<keyof M>> = Unknown<"relation member", Extract<keyof M, symbol>, Of> | `relation member "${OptionalMembers<M>}" of "${NameOf<X>}"${Of} must have a formula` | `relation default "${Exclude<Member<V, "default">, Y> & string}" of "${NameOf<X>}"${Of} is not a member` | CountMessage<X, Y, Of> | MemberMessage<R, X, Y, Of> | DriverMessage<R[X], X, Y, Of> | Taken<P, X, Y, Of> | Shared<P, X, Y, Of>;
46
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,109 @@
1
+ import type { RowRelation, RelationMessages } from "./authoring-relations.js";
2
+ import type { FieldValue, ParamsOf, RemoteDefinition, WithPlaceholder } from "./fields.js";
3
+ import type { ContextTools, Fields, FieldsIn } from "./definition.js";
4
+ import type { RowKey } from "./address.js";
5
+ import type { PagedKey, ParamsIn, QueryKey, ResultIn } from "./endpoints.js";
6
+ import type { EditConflict, At, EmptyMessage, EmptyReason, EventMessages, Everywhere, Items, Keys, Lacks, Limit, LimitMessages, Member, Reported, Result, StateMessages, Verdict } from "./authoring-checks.js";
7
+ import type { Bound, Formula, Many, Patch, Reason, RequiredRows, StatePatch, ToDefaults, Values } from "./authoring.js";
8
+ import type { Left } from "./authoring-params.js";
9
+ import type { Paged, QueryMessages } from "./authoring-values.js";
10
+ import type { NameOf } from "./rule-set-types.js";
11
+ export type Row<R extends Fields> = {
12
+ readonly [X in keyof R]: FieldValue<R[X]>;
13
+ };
14
+ type Tools<F extends Fields, K, C, N> = {
15
+ readonly values: Values<F, K>;
16
+ readonly key: RowKey<N & string>;
17
+ } & ContextTools<C>;
18
+ export type RowFormula<F extends Fields, K, C, N extends keyof K, T> = (row: Row<FieldsIn<K[N]>>, tools: Tools<F, K, C, N> & {
19
+ readonly peek: {
20
+ readonly row: Row<FieldsIn<K[N]>>;
21
+ readonly values: Values<F, K>;
22
+ };
23
+ }) => T;
24
+ type RowEvent<F extends Fields, K, C, N extends keyof K> = (row: Row<FieldsIn<K[N]>>, tools: Tools<F, K, C, N> & {
25
+ readonly toDefaults: ToDefaults<FieldsIn<K[N]>>;
26
+ readonly before: {
27
+ readonly row: Row<FieldsIn<K[N]>>;
28
+ readonly values: Values<F, K>;
29
+ };
30
+ }) => Patch<FieldsIn<K[N]>> | undefined;
31
+ type RowQueryPatch<F extends Fields, K, C, N extends keyof K, T> = (result: T, tools: {
32
+ readonly row: Row<FieldsIn<K[N]>>;
33
+ } & Tools<F, K, C, N>) => Patch<FieldsIn<K[N]>> | undefined;
34
+ type RowQueryOf<F extends Fields, K, C, N extends keyof K, E extends string, T, P> = {
35
+ readonly endpoint: E;
36
+ readonly patch?: RowQueryPatch<F, K, C, N, T> | undefined;
37
+ readonly forPrepare?: boolean | undefined;
38
+ } & ({} extends P ? {
39
+ readonly params?: RowFormula<F, K, C, N, P | undefined> | undefined;
40
+ } : {
41
+ readonly params: RowFormula<F, K, C, N, P | undefined>;
42
+ });
43
+ type RowQueryRule<F extends Fields, K, C, N extends keyof K, M> = [M] extends [undefined] ? unknown : {
44
+ [E in QueryKey<M>]: RowQueryOf<F, K, C, N, E, ResultIn<M[E]>, ParamsIn<M[E]>>;
45
+ }[QueryKey<M>] | {
46
+ [E in PagedKey<M>]: RowQueryOf<F, K, C, N, E, never, ParamsIn<M[E]>> & Paged<E>;
47
+ }[PagedKey<M>];
48
+ type RowEntry<F extends Fields, K, C, N extends keyof K, X extends keyof FieldsIn<K[N]>, M> = {
49
+ readonly value?: RowFormula<F, K, C, N, FieldValue<FieldsIn<K[N]>[X]> | undefined> | undefined;
50
+ readonly disabled?: Many<RowFormula<F, K, C, N, boolean | Reason | undefined>> | undefined;
51
+ readonly readOnly?: Many<RowFormula<F, K, C, N, boolean | Reason | undefined>> | undefined;
52
+ readonly hidden?: Many<RowFormula<F, K, C, N, boolean | undefined>> | undefined;
53
+ readonly required?: Many<RowFormula<F, K, C, N, boolean | Reason | undefined>> | undefined;
54
+ readonly error?: Many<RowFormula<F, K, C, N, Reason | false | undefined>> | undefined;
55
+ readonly warning?: Many<RowFormula<F, K, C, N, Reason | false | undefined>> | undefined;
56
+ readonly label?: RowFormula<F, K, C, N, string | undefined> | undefined;
57
+ readonly decimals?: RowFormula<F, K, C, N, number | undefined> | undefined;
58
+ readonly min?: RowFormula<F, K, C, N, Bound> | undefined;
59
+ readonly max?: RowFormula<F, K, C, N, Bound> | undefined;
60
+ readonly states?: RowFormula<F, K, C, N, StatePatch<FieldsIn<K[N]>> | undefined> | undefined;
61
+ readonly onChange?: RowEvent<F, K, C, N> | undefined;
62
+ readonly relation?: RowRelation<F, K, C, N, X> | undefined;
63
+ readonly onEdit?: RowEvent<F, K, C, N> | undefined;
64
+ readonly query?: RowQueryRule<F, K, C, N, M> | undefined;
65
+ } & (FieldsIn<K[N]>[X] extends RemoteDefinition ? {
66
+ readonly placeholder?: RowFormula<F, K, C, N, string | undefined> | undefined;
67
+ readonly params?: RowFormula<F, K, C, N, ParamsOf<FieldsIn<K[N]>[X]> | undefined> | undefined;
68
+ } : FieldsIn<K[N]>[X] extends WithPlaceholder ? {
69
+ readonly placeholder?: RowFormula<F, K, C, N, string | undefined> | undefined;
70
+ } : {});
71
+ export type EachRules<F extends Fields, K, C, N extends keyof K, M> = {
72
+ readonly [X in keyof FieldsIn<K[N]>]?: RowEntry<F, K, C, N, X, M> | undefined;
73
+ };
74
+ type Messages<T> = {
75
+ readonly error?: Many<T> | undefined;
76
+ readonly warning?: Many<T> | undefined;
77
+ };
78
+ export type CollectionRules<F extends Fields, K, C, N extends keyof K, M> = {
79
+ readonly each?: EachRules<F, K, C, N, M> | undefined;
80
+ readonly row?: Messages<RowFormula<F, K, C, N, Reason | false | undefined>> | undefined;
81
+ readonly collection?: Messages<Formula<F, K, C, Reason | false | undefined>> | undefined;
82
+ };
83
+ export type RequiredEach<F extends Fields, K, C, N extends keyof K, _M> = {
84
+ readonly each: {
85
+ readonly [X in RequiredRows<FieldsIn<K[N]>>]: FieldsIn<K[N]>[X & keyof FieldsIn<K[N]>] extends RemoteDefinition ? {
86
+ readonly params: RowFormula<F, K, C, N, ParamsOf<FieldsIn<K[N]>[X & keyof FieldsIn<K[N]>]> | undefined>;
87
+ } : {};
88
+ };
89
+ };
90
+ export type RemainingEach<F extends Fields, K, C, N extends keyof K, M, G> = {
91
+ readonly each: {
92
+ readonly [X in keyof RequiredEach<F, K, C, N, M>["each"] as Left<X, G, ["rows", NameOf<N>]>]: RequiredEach<F, K, C, N, M>["each"][X];
93
+ };
94
+ };
95
+ export type CheckCollection<K, N extends keyof K, V, M> = [
96
+ Extract<V, (...args: never) => unknown>
97
+ ] extends [never] ? {
98
+ [Q in Keys<V>]?: Q extends "each" ? CheckEach<FieldsIn<K[N]>, ` of "${N & string}"`, Member<V, Q>, M> | undefined : Q extends "row" | "collection" ? CheckMessages<Member<V, Q>, `${Q} rules of "${N & string}"`> | undefined : Everywhere<At<V, Q>, `rules of collection "${N & string}" take each, row or collection`>;
99
+ } : `rules of collection "${N & string}" must be an object with each, row or collection`;
100
+ export type CheckMessages<V, What extends string> = {
101
+ [Q in Keys<V>]?: Q extends "error" | "warning" ? Reported<At<V, Q>, EmptyMessage<Q, Result<Items<At<V, Q>>>>> : Everywhere<At<V, Q>, `${What} take error or warning`>;
102
+ };
103
+ type CheckEach<R extends Fields, Of extends string, E, M> = {
104
+ [X in Keys<E>]?: X extends keyof R ? [Extract<Member<E, X>, (...args: never) => unknown>] extends [never] ? {
105
+ [Q in Keys<Member<E, X>>]?: CheckRowProperty<R, Of, X, Q, At<Member<E, X>, Q>, M, Member<E, X>, E>;
106
+ } | undefined : `rules of field "${X & string}"${Of} must be an object of properties` : `field "${X & string}"${Of} does not exist`;
107
+ };
108
+ type CheckRowProperty<R extends Fields, Of extends string, X extends keyof R, Q, V, M, E, P> = Q extends "value" | "hidden" | "label" ? unknown : Q extends "disabled" | "readOnly" ? Reported<V, EmptyReason<Result<Items<V>>>> : Q extends "required" | "error" | "warning" ? Reported<V, EmptyMessage<Q, Result<Items<V>>>> : Q extends "placeholder" ? Verdict<Lacks<R, X, WithPlaceholder, "placeholder", Of>> : Q extends Limit ? Verdict<LimitMessages<R, X, Q, Result<V>, Of>> : Q extends "params" ? Verdict<Lacks<R, X, RemoteDefinition, "params", Of>> : Q extends "states" ? Verdict<StateMessages<R, V, Of>> : Q extends "onChange" ? Verdict<EventMessages<R, V, {}, Of>> : Q extends "onEdit" ? Verdict<EventMessages<R, V, {}, Of> | EditConflict<E, `field "${X & string}"${Of}`>> : Q extends "query" ? Verdict<QueryMessages<R, X, V, M, Of>> : Q extends "relation" ? Verdict<RelationMessages<R, X, P, Of>> : Everywhere<V, `rule property "${Q & string}" does not exist`>;
109
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,36 @@
1
+ import type { DeepReadonly } from "./data.js";
2
+ import type { ContextTools, Fields } from "./definition.js";
3
+ import type { PagedKey, ParamsIn, QueryKey, ResultIn } from "./endpoints.js";
4
+ import type { FieldValue } from "./fields.js";
5
+ import type { At, Checked, EventMessages, Keys, MayLack, Unknown, Verdict } from "./authoring-checks.js";
6
+ import type { Formula, Patch, Values } from "./authoring.js";
7
+ type QueryPatch<F extends Fields, K, C, R> = (result: R, tools: {
8
+ readonly values: Values<F, K>;
9
+ } & ContextTools<C>) => Patch<F> | undefined;
10
+ type QueryOf<F extends Fields, K, C, E extends string, R, P> = {
11
+ readonly endpoint: E;
12
+ readonly patch?: QueryPatch<F, K, C, R> | undefined;
13
+ readonly forPrepare?: boolean | undefined;
14
+ } & ({} extends P ? {
15
+ readonly params?: Formula<F, K, C, P | undefined> | undefined;
16
+ } : {
17
+ readonly params: Formula<F, K, C, P | undefined>;
18
+ });
19
+ export type Paged<E extends string> = `query endpoint "${E}" is paged; use a value or list endpoint`;
20
+ export type QueryRule<F extends Fields, K, C, M> = [M] extends [undefined] ? unknown : {
21
+ [E in QueryKey<M>]: QueryOf<F, K, C, E, ResultIn<M[E]>, ParamsIn<M[E]>>;
22
+ }[QueryKey<M>] | {
23
+ [E in PagedKey<M>]: QueryOf<F, K, C, E, never, ParamsIn<M[E]>> & Paged<E>;
24
+ }[PagedKey<M>];
25
+ export type QueryMessages<R extends Fields, X, V, M, Of extends string = ""> = [M] extends [
26
+ undefined
27
+ ] ? [Exclude<V, undefined>] extends [never] ? never : `Field "${X & string}"${Of} query: define the form with the defineForm of createForms` : V extends object ? Unknown<"query property", Exclude<keyof V, "endpoint" | "params" | "patch" | "forPrepare">> | QueryEndpointMessages<R, X, V, M, At<V, "endpoint">, Of> : never;
28
+ type QueryEndpointMessages<R extends Fields, X, V, M, E, Of extends string> = E extends PagedKey<M> ? Paged<E> : E extends QueryKey<M> ? (MayLack<At<V, "patch">> extends true ? Unfit<R, X, M, E, Of> : never) | EventMessages<R, NonNullable<At<V, "patch">>, {}, Of, "query patch returns a patch object or undefined", "query patch is synchronous"> : never;
29
+ type Unfit<R extends Fields, X, M, E extends keyof M & string, Of extends string> = X extends keyof R ? [ResultIn<M[E]>] extends [FieldValue<R[X]> | undefined] ? never : `query result of "${E}" does not fit field "${X & string}"${Of}` : never;
30
+ type DefaultValues<F extends Fields> = {
31
+ readonly [X in keyof F]?: FieldValue<F[X]>;
32
+ };
33
+ type Defaults<F extends Fields, C> = (context: DeepReadonly<C>) => DefaultValues<F>;
34
+ type DefaultsMessages<F extends Fields, X> = X extends (...args: never) => infer R ? [Extract<R, PromiseLike<unknown>>] extends [never] ? [Exclude<R, object>] extends [never] ? Unknown<"defaults field", Exclude<Keys<R>, keyof F>> : "defaults return an object of values" : "defaults are synchronous" : never;
35
+ export type DefaultsRules<F extends Fields, C, X> = Defaults<F, C> & (undefined extends C ? "defaults require a context" : Verdict<DefaultsMessages<F, Checked<X>>>);
36
+ export {};
@@ -0,0 +1 @@
1
+ export {};