@cosmicdrift/kumiko-framework 0.406.0 → 0.409.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 (209) hide show
  1. package/agents/api/framework-db.md +1 -0
  2. package/agents/api/framework-engine.md +15 -2
  3. package/agents/api/framework-ui-types.md +15 -0
  4. package/agents/api/renderer-web.md +156 -2
  5. package/agents/api/types.md +113 -71
  6. package/agents/api.md +4 -4
  7. package/agents/boot-rules.md +743 -0
  8. package/agents/examples/contact.md +167 -0
  9. package/agents/examples/delivery-notifications.md +34 -1
  10. package/agents/examples/record-detail-layout.md +13 -2
  11. package/agents/examples/search.md +65 -3
  12. package/agents/examples/secrets-demo.md +96 -2
  13. package/agents/examples/tenant-inactivity.md +138 -0
  14. package/agents/examples.md +2 -0
  15. package/agents/features-index.md +4 -0
  16. package/agents/features.md +24 -1
  17. package/agents/widgets.md +12 -1
  18. package/dist/api/export/export-rows.js +1 -0
  19. package/dist/compliance/index.d.ts +1 -1
  20. package/dist/db/event-store-executor-read-where.js +15 -5
  21. package/dist/db/index.d.ts +1 -1
  22. package/dist/db/index.js +1 -1
  23. package/dist/db/migrate-generator.js +3 -1
  24. package/dist/db/queries/event-consumer.js +11 -7
  25. package/dist/db/queries/event-store.d.ts +2 -1
  26. package/dist/db/queries/event-store.js +25 -6
  27. package/dist/db/queries/rls-boot-catalog.js +3 -1
  28. package/dist/db/queries/session-advisory-lock.d.ts +7 -0
  29. package/dist/db/queries/session-advisory-lock.js +23 -0
  30. package/dist/db/query.js +7 -10
  31. package/dist/db/row-level-security-connection.js +4 -2
  32. package/dist/engine/active-membership.js +1 -0
  33. package/dist/engine/boot-validator/access-declarations.js +57 -33
  34. package/dist/engine/boot-validator/action-wiring.js +8 -6
  35. package/dist/engine/boot-validator/agent-effect-rules.d.ts +12 -0
  36. package/dist/engine/boot-validator/agent-effect-rules.js +12 -0
  37. package/dist/engine/boot-validator/agent-effect.d.ts +2 -0
  38. package/dist/engine/boot-validator/agent-effect.js +20 -0
  39. package/dist/engine/boot-validator/boot-context.js +5 -1
  40. package/dist/engine/boot-validator/boot-environment-rules.d.ts +12 -0
  41. package/dist/engine/boot-validator/boot-environment-rules.js +12 -0
  42. package/dist/engine/boot-validator/boot-phases-app.js +5 -1
  43. package/dist/engine/boot-validator/boot-phases.js +3 -1
  44. package/dist/engine/boot-validator/boot-rules.d.ts +2619 -0
  45. package/dist/engine/boot-validator/boot-rules.js +58 -0
  46. package/dist/engine/boot-validator/bundled-lists-table.js +23 -9
  47. package/dist/engine/boot-validator/config-deps.js +71 -23
  48. package/dist/engine/boot-validator/config-edit-action-rules.d.ts +17 -0
  49. package/dist/engine/boot-validator/config-edit-action-rules.js +17 -0
  50. package/dist/engine/boot-validator/config-key-rules.d.ts +117 -0
  51. package/dist/engine/boot-validator/config-key-rules.js +117 -0
  52. package/dist/engine/boot-validator/custom-screen-write-qns.js +6 -2
  53. package/dist/engine/boot-validator/derived-sql-fields-rules.d.ts +77 -0
  54. package/dist/engine/boot-validator/derived-sql-fields-rules.js +77 -0
  55. package/dist/engine/boot-validator/derived-sql-fields.js +53 -17
  56. package/dist/engine/boot-validator/detail-screens.js +10 -4
  57. package/dist/engine/boot-validator/entity-declaration-rules.d.ts +92 -0
  58. package/dist/engine/boot-validator/entity-declaration-rules.js +92 -0
  59. package/dist/engine/boot-validator/entity-handler-access-rules.d.ts +102 -0
  60. package/dist/engine/boot-validator/entity-handler-access-rules.js +102 -0
  61. package/dist/engine/boot-validator/entity-handler.d.ts +0 -7
  62. package/dist/engine/boot-validator/entity-handler.js +259 -355
  63. package/dist/engine/boot-validator/entity-image-variants.d.ts +2 -0
  64. package/dist/engine/boot-validator/entity-image-variants.js +91 -0
  65. package/dist/engine/boot-validator/entity-list-aggregate-options.js +8 -2
  66. package/dist/engine/boot-validator/entity-reference-embedded-rules.d.ts +117 -0
  67. package/dist/engine/boot-validator/entity-reference-embedded-rules.js +117 -0
  68. package/dist/engine/boot-validator/entity-select-image-rules.d.ts +122 -0
  69. package/dist/engine/boot-validator/entity-select-image-rules.js +122 -0
  70. package/dist/engine/boot-validator/entity-select.d.ts +8 -0
  71. package/dist/engine/boot-validator/entity-select.js +197 -0
  72. package/dist/engine/boot-validator/entity-structure-rules.d.ts +107 -0
  73. package/dist/engine/boot-validator/entity-structure-rules.js +107 -0
  74. package/dist/engine/boot-validator/field-conditions-rules.d.ts +92 -0
  75. package/dist/engine/boot-validator/field-conditions-rules.js +92 -0
  76. package/dist/engine/boot-validator/field-conditions.js +67 -22
  77. package/dist/engine/boot-validator/form-derivations-rules.d.ts +77 -0
  78. package/dist/engine/boot-validator/form-derivations-rules.js +77 -0
  79. package/dist/engine/boot-validator/form-derivations.js +52 -18
  80. package/dist/engine/boot-validator/global-tenancy.js +13 -7
  81. package/dist/engine/boot-validator/handler-declaration-rules.d.ts +72 -0
  82. package/dist/engine/boot-validator/handler-declaration-rules.js +72 -0
  83. package/dist/engine/boot-validator/handler-field-references-rules.d.ts +22 -0
  84. package/dist/engine/boot-validator/handler-field-references-rules.js +22 -0
  85. package/dist/engine/boot-validator/handler-field-references.js +14 -6
  86. package/dist/engine/boot-validator/list-bulk-actions-rules.d.ts +42 -0
  87. package/dist/engine/boot-validator/list-bulk-actions-rules.js +42 -0
  88. package/dist/engine/boot-validator/list-bulk-actions.js +29 -11
  89. package/dist/engine/boot-validator/list-column-layout.js +22 -10
  90. package/dist/engine/boot-validator/list-query-rules.d.ts +107 -0
  91. package/dist/engine/boot-validator/list-query-rules.js +107 -0
  92. package/dist/engine/boot-validator/list-table-aggregate-options.js +43 -15
  93. package/dist/engine/boot-validator/list-table-aggregate-query.js +7 -3
  94. package/dist/engine/boot-validator/list-table-aggregate-rules.d.ts +82 -0
  95. package/dist/engine/boot-validator/list-table-aggregate-rules.js +82 -0
  96. package/dist/engine/boot-validator/list-table-export-options.js +19 -7
  97. package/dist/engine/boot-validator/list-table-options.js +33 -13
  98. package/dist/engine/boot-validator/list-table-reject-unknown-keys.js +6 -2
  99. package/dist/engine/boot-validator/list-table-rules.d.ts +132 -0
  100. package/dist/engine/boot-validator/list-table-rules.js +132 -0
  101. package/dist/engine/boot-validator/nav-rules.d.ts +42 -0
  102. package/dist/engine/boot-validator/nav-rules.js +42 -0
  103. package/dist/engine/boot-validator/nav.js +29 -15
  104. package/dist/engine/boot-validator/ownership-rules.d.ts +27 -0
  105. package/dist/engine/boot-validator/ownership-rules.js +27 -0
  106. package/dist/engine/boot-validator/ownership.js +28 -12
  107. package/dist/engine/boot-validator/parent-ref.js +32 -20
  108. package/dist/engine/boot-validator/projection-list-screens.js +76 -35
  109. package/dist/engine/boot-validator/query-output-columns.js +9 -3
  110. package/dist/engine/boot-validator/query-refs.js +20 -10
  111. package/dist/engine/boot-validator/query-rules.d.ts +37 -0
  112. package/dist/engine/boot-validator/query-rules.js +37 -0
  113. package/dist/engine/boot-validator/read-gate.js +14 -10
  114. package/dist/engine/boot-validator/record-owned.js +5 -1
  115. package/dist/engine/boot-validator/related-list-table-rules.js +17 -7
  116. package/dist/engine/boot-validator/screens-actions-rules.d.ts +185 -0
  117. package/dist/engine/boot-validator/screens-actions-rules.js +185 -0
  118. package/dist/engine/boot-validator/screens-actions.js +169 -93
  119. package/dist/engine/boot-validator/screens-dashboard-chart-rules.d.ts +87 -0
  120. package/dist/engine/boot-validator/screens-dashboard-chart-rules.js +87 -0
  121. package/dist/engine/boot-validator/screens-dashboard-rules.d.ts +227 -0
  122. package/dist/engine/boot-validator/screens-dashboard-rules.js +227 -0
  123. package/dist/engine/boot-validator/screens-dashboard.js +222 -85
  124. package/dist/engine/boot-validator/screens-forms-layout-rules.d.ts +122 -0
  125. package/dist/engine/boot-validator/screens-forms-layout-rules.js +122 -0
  126. package/dist/engine/boot-validator/screens-forms-rules.d.ts +152 -0
  127. package/dist/engine/boot-validator/screens-forms-rules.js +152 -0
  128. package/dist/engine/boot-validator/screens-forms.js +240 -112
  129. package/dist/engine/boot-validator/screens-kind-config-edit.js +72 -16
  130. package/dist/engine/boot-validator/screens-kind-entity-edit.js +15 -7
  131. package/dist/engine/boot-validator/screens-kind-entity-list.js +57 -32
  132. package/dist/engine/boot-validator/screens-kind-projection-detail-rules.d.ts +92 -0
  133. package/dist/engine/boot-validator/screens-kind-projection-detail-rules.js +92 -0
  134. package/dist/engine/boot-validator/screens-kind-projection-detail.js +85 -47
  135. package/dist/engine/boot-validator/screens-kind-rules.d.ts +137 -0
  136. package/dist/engine/boot-validator/screens-kind-rules.js +137 -0
  137. package/dist/engine/boot-validator/screens-kind-secret-mint.js +18 -8
  138. package/dist/engine/boot-validator/screens-kind-shared.js +40 -22
  139. package/dist/engine/boot-validator/screens-lists-rules.d.ts +82 -0
  140. package/dist/engine/boot-validator/screens-lists-rules.js +82 -0
  141. package/dist/engine/boot-validator/screens-lists.js +90 -45
  142. package/dist/engine/boot-validator/screens-rules.d.ts +57 -0
  143. package/dist/engine/boot-validator/screens-rules.js +57 -0
  144. package/dist/engine/boot-validator/screens.js +17 -12
  145. package/dist/engine/boot-validator/transaction-phases.js +12 -4
  146. package/dist/engine/boot-validator/transfer-graph.js +17 -11
  147. package/dist/engine/boot-validator/url-prefill-fields.js +9 -5
  148. package/dist/engine/boot-validator/workspaces.js +11 -5
  149. package/dist/engine/boot-validator/zod-shape.js +6 -2
  150. package/dist/engine/entity-handlers.d.ts +1 -0
  151. package/dist/engine/entity-handlers.js +3 -0
  152. package/dist/engine/entity-list-runtime-options.js +23 -29
  153. package/dist/engine/extensions/tenant-data.d.ts +3 -0
  154. package/dist/engine/factories.d.ts +1 -1
  155. package/dist/engine/factories.js +4 -3
  156. package/dist/engine/index.d.ts +4 -2
  157. package/dist/engine/index.js +2 -0
  158. package/dist/engine/project-app-schema-for-roles.js +29 -14
  159. package/dist/engine/registry-facade.js +7 -8
  160. package/dist/engine/registry-validate.js +5 -1
  161. package/dist/engine/soft-delete-cleanup.d.ts +1 -0
  162. package/dist/engine/soft-delete-cleanup.js +5 -0
  163. package/dist/engine/steps/describe-workflow-step-error.js +1 -0
  164. package/dist/es-ops/operations-schema.d.ts +1 -1
  165. package/dist/event-store/ensure-dead-letter-table.d.ts +2 -0
  166. package/dist/event-store/ensure-dead-letter-table.js +10 -0
  167. package/dist/event-store/rebuild-dead-letter.js +2 -8
  168. package/dist/event-store/upcaster-dead-letter.js +2 -8
  169. package/dist/files/copy-pending-file-refs-to-tenant.d.ts +28 -0
  170. package/dist/files/copy-pending-file-refs-to-tenant.js +87 -0
  171. package/dist/files/file-routes.d.ts +1 -1
  172. package/dist/files/file-routes.js +21 -6
  173. package/dist/files/index.d.ts +2 -0
  174. package/dist/files/index.js +1 -0
  175. package/dist/i18n/required-surface-keys.js +1 -0
  176. package/dist/jobs/job-runner-helpers.js +1 -0
  177. package/dist/jobs/job-runner.js +7 -12
  178. package/dist/logging/utils.js +30 -60
  179. package/dist/observability/metrics-handle.js +10 -21
  180. package/dist/pipeline/cascade-handler.js +7 -6
  181. package/dist/pipeline/dispatch-query.js +18 -5
  182. package/dist/pipeline/dispatch-shared.d.ts +1 -0
  183. package/dist/pipeline/dispatch-shared.js +3 -1
  184. package/dist/pipeline/dispatch-write.js +10 -12
  185. package/dist/pipeline/dispatcher.js +12 -14
  186. package/dist/pipeline/event-dispatcher-admin.js +9 -8
  187. package/dist/pipeline/event-dispatcher-delivery.d.ts +19 -1
  188. package/dist/pipeline/event-dispatcher-delivery.js +121 -29
  189. package/dist/pipeline/event-dispatcher.d.ts +5 -1
  190. package/dist/pipeline/event-dispatcher.js +28 -21
  191. package/dist/pipeline/handler-context-phase-denials.js +2 -0
  192. package/dist/pipeline/multi-stream-apply-context.js +12 -20
  193. package/dist/pipeline/system-hooks.d.ts +4 -1
  194. package/dist/pipeline/system-hooks.js +79 -6
  195. package/dist/pipeline/system-identity-switch.js +10 -7
  196. package/dist/search/build-search-snippet.d.ts +9 -0
  197. package/dist/search/build-search-snippet.js +40 -0
  198. package/dist/search/index.d.ts +1 -0
  199. package/dist/search/index.js +1 -0
  200. package/dist/search/meilisearch-adapter.d.ts +32 -0
  201. package/dist/search/meilisearch-adapter.js +153 -56
  202. package/dist/search/meilisearch-chunking.d.ts +21 -0
  203. package/dist/search/meilisearch-chunking.js +96 -0
  204. package/dist/search/reindex-entity.d.ts +1 -0
  205. package/dist/search/reindex-entity.js +97 -52
  206. package/dist/ui-types/index.d.ts +1 -1
  207. package/dist/upgrade-cli.js +3 -14
  208. package/package.json +3 -3
  209. package/src/changes.json +73 -0
@@ -0,0 +1,197 @@
1
+ import { SELECT_OPTION_TONES } from "@cosmicdrift/kumiko-types/fields";
2
+ import { bootRuleError } from "./boot-rule.js";
3
+ import { ENTITY_SELECT_IMAGE_RULES } from "./entity-select-image-rules.js";
4
+ import { isSelectOptionTone } from "./select-option-tone.js";
5
+ // --- MultiSelect field validation ---
6
+ //
7
+ // options must be non-empty (otherwise the field cannot be used), and
8
+ // default — when set — must be a subset of options. Both conditions would
9
+ // also fail at runtime in the Zod schema; boot validation only provides
10
+ // the earliest clear error messages.
11
+ // Exhaustive over MultiSelectFieldDef["columns"] (the compiler flags a union
12
+ // change); the TS union is gone at runtime for JS/JSON-sourced definitions.
13
+ const CHECKBOX_COLUMN_COUNTS = {
14
+ 1: true,
15
+ 2: true,
16
+ 3: true,
17
+ 4: true,
18
+ };
19
+ function validateCheckboxDisplayOptions(field, fieldName, entityName) {
20
+ if (field.display === "checkboxes") {
21
+ if (field.columns !== undefined && !(field.columns in CHECKBOX_COLUMN_COUNTS)) {
22
+ throw bootRuleError(ENTITY_SELECT_IMAGE_RULES.multiSelectColumnsInvalid, {
23
+ message: `MultiSelect field "${fieldName}" on entity "${entityName}" has invalid columns "${field.columns}" — must be ${Object.keys(CHECKBOX_COLUMN_COUNTS).join(", ")}.`,
24
+ });
25
+ }
26
+ if (field.maxRows !== undefined && (!Number.isInteger(field.maxRows) || field.maxRows < 1)) {
27
+ throw bootRuleError(ENTITY_SELECT_IMAGE_RULES.multiSelectMaxRowsInvalid, {
28
+ message: `MultiSelect field "${fieldName}" on entity "${entityName}" has invalid maxRows "${field.maxRows}" — must be a positive integer.`,
29
+ });
30
+ }
31
+ // skip: checkboxes is the valid display for these options — the checks below only apply to other displays
32
+ return;
33
+ }
34
+ if (field.columns !== undefined) {
35
+ throw bootRuleError(ENTITY_SELECT_IMAGE_RULES.multiSelectColumnsWithoutCheckboxes, {
36
+ message: `MultiSelect field "${fieldName}" on entity "${entityName}" sets columns, which is only valid with display: "checkboxes".`,
37
+ });
38
+ }
39
+ if (field.maxRows !== undefined) {
40
+ throw bootRuleError(ENTITY_SELECT_IMAGE_RULES.multiSelectMaxRowsWithoutCheckboxes, {
41
+ message: `MultiSelect field "${fieldName}" on entity "${entityName}" sets maxRows, which is only valid with display: "checkboxes".`,
42
+ });
43
+ }
44
+ }
45
+ function assertSelectOptionTones(field, path, featureName) {
46
+ const tones = field.type === "select" ? Object.entries(field.optionTones ?? {}) : [];
47
+ for (const [optionValue, tone] of tones) {
48
+ if (!isSelectOptionTone(tone)) {
49
+ throw bootRuleError(ENTITY_SELECT_IMAGE_RULES.selectOptionToneInvalid, {
50
+ message: `[Feature ${featureName}] Entity select field "${path}" optionTones["${optionValue}"] is ` +
51
+ `"${String(tone)}" — expected one of ${SELECT_OPTION_TONES.join(", ")}.`,
52
+ });
53
+ }
54
+ }
55
+ }
56
+ export function validateEntitySelectOptionsQuery(feature) {
57
+ for (const [entityName, entity] of Object.entries(feature.entities ?? {})) {
58
+ for (const [fieldName, field] of Object.entries(entity.fields)) {
59
+ assertNoSelectOptionsQuery(field, `${entityName}.${fieldName}`, feature.name);
60
+ assertSelectOptionTones(field, `${entityName}.${fieldName}`, feature.name);
61
+ if (field.type !== "embedded")
62
+ continue;
63
+ for (const [subName, subField] of Object.entries(field.schema ?? {})) {
64
+ assertNoSelectOptionsQuery(subField, `${entityName}.${fieldName}.${subName}`, feature.name);
65
+ assertSelectOptionTones(subField, `${entityName}.${fieldName}.${subName}`, feature.name);
66
+ }
67
+ }
68
+ }
69
+ }
70
+ function assertNoSelectOptionsQuery(field, path, featureName) {
71
+ // @cast-boundary schema-walk — embedded sub-field types don't declare optionsQuery, an untyped author may still set it
72
+ const { optionsQuery, optionsQueryPayload } = field;
73
+ const declaresOptionsQuery = optionsQuery !== undefined || optionsQueryPayload !== undefined;
74
+ if (field.type === "select" && declaresOptionsQuery) {
75
+ throw bootRuleError(ENTITY_SELECT_IMAGE_RULES.selectOptionsQueryUnsupported, {
76
+ message: `[Feature ${featureName}] Entity select field "${path}" declares optionsQuery — not supported on entity fields because the stored value would not be validated against the query result. Use static options, or a reference field.`,
77
+ });
78
+ }
79
+ }
80
+ // A typo'd availability QN would only surface as a failed query when the form
81
+ // mounts, so it is pinned at boot like the other option queries.
82
+ export function validateEntitySelectAvailabilityQuery(feature, queryHandlers) {
83
+ for (const [entityName, entity] of Object.entries(feature.entities ?? {})) {
84
+ for (const [fieldName, field] of Object.entries(entity.fields)) {
85
+ if ((field.type !== "select" && field.type !== "multiSelect") ||
86
+ field.optionsAvailabilityQuery === undefined)
87
+ continue;
88
+ const query = field.optionsAvailabilityQuery;
89
+ if (query.length === 0 || !queryHandlers.has(query)) {
90
+ throw bootRuleError(ENTITY_SELECT_IMAGE_RULES.selectAvailabilityQueryUnregistered, {
91
+ message: `[Feature ${feature.name}] ${field.type === "select" ? "Select" : "MultiSelect"} field "${fieldName}" on entity "${entityName}" ` +
92
+ `declares optionsAvailabilityQuery "${query}" which is not a registered query-handler. ` +
93
+ `Check the QN spelling (expected "<feature>:query:<short>") and that the handler ` +
94
+ `is declared via r.queryHandler(...).`,
95
+ });
96
+ }
97
+ }
98
+ }
99
+ }
100
+ export function conditionComparisonValues(when) {
101
+ if ("eq" in when)
102
+ return [when.eq];
103
+ if ("ne" in when)
104
+ return [when.ne];
105
+ if ("in" in when)
106
+ return when.in;
107
+ return when.notIn;
108
+ }
109
+ export function validateEntitySelectConditionalOptions(feature) {
110
+ for (const [entityName, entity] of Object.entries(feature.entities ?? {})) {
111
+ for (const [fieldName, field] of Object.entries(entity.fields)) {
112
+ if (field.type !== "select" || field.conditionalOptions === undefined)
113
+ continue;
114
+ const where = `[Feature ${feature.name}] Select field "${fieldName}" on entity "${entityName}"`;
115
+ if (field.optionsQuery !== undefined) {
116
+ throw bootRuleError(ENTITY_SELECT_IMAGE_RULES.conditionalOptionsWithOptionsQuery, {
117
+ message: `${where} combines conditionalOptions with optionsQuery — conditionalOptions filters the static options only. Remove either conditionalOptions or optionsQuery.`,
118
+ });
119
+ }
120
+ const knownOptions = new Set(field.options);
121
+ const ruleOfOption = new Map();
122
+ field.conditionalOptions.forEach((rule, ruleIndex) => {
123
+ const ruleLabel = `conditionalOptions[${ruleIndex}]`;
124
+ if (rule.options.length === 0) {
125
+ throw bootRuleError(ENTITY_SELECT_IMAGE_RULES.conditionalOptionsRuleEmpty, {
126
+ message: `${where} has an empty ${ruleLabel}.options — drop the rule.`,
127
+ });
128
+ }
129
+ for (const option of rule.options) {
130
+ if (!knownOptions.has(option)) {
131
+ throw bootRuleError(ENTITY_SELECT_IMAGE_RULES.conditionalOptionUnknown, {
132
+ message: `${where} lists "${option}" in ${ruleLabel} which is not in options (${field.options.join(", ")}).`,
133
+ });
134
+ }
135
+ const otherRule = ruleOfOption.get(option);
136
+ if (otherRule !== undefined) {
137
+ throw bootRuleError(ENTITY_SELECT_IMAGE_RULES.conditionalOptionDuplicate, {
138
+ message: `${where} lists "${option}" in conditionalOptions[${otherRule}] and ${ruleLabel} — an option may belong to one rule only. Remove the option from one of the rules.`,
139
+ });
140
+ }
141
+ ruleOfOption.set(option, ruleIndex);
142
+ if (option === field.default) {
143
+ throw bootRuleError(ENTITY_SELECT_IMAGE_RULES.conditionalOptionDefault, {
144
+ message: `${where} has default "${option}" inside ${ruleLabel} — the default must be available unconditionally.`,
145
+ });
146
+ }
147
+ }
148
+ const conditionField = rule.when.field;
149
+ if (conditionField === fieldName) {
150
+ throw bootRuleError(ENTITY_SELECT_IMAGE_RULES.conditionalWhenOwnField, {
151
+ message: `${where} has ${ruleLabel}.when on its own field. Make the condition depend on a different field.`,
152
+ });
153
+ }
154
+ if (!(conditionField in entity.fields)) {
155
+ throw bootRuleError(ENTITY_SELECT_IMAGE_RULES.conditionalWhenUnknownField, {
156
+ message: `${where} has ${ruleLabel}.when.field "${conditionField}" which is not a field of the entity. Use an existing field of the entity in when.field.`,
157
+ });
158
+ }
159
+ const conditionFieldDef = entity.fields[conditionField];
160
+ if (conditionFieldDef?.type === "select" || conditionFieldDef?.type === "multiSelect") {
161
+ const conditionOptions = conditionFieldDef.options;
162
+ for (const value of conditionComparisonValues(rule.when)) {
163
+ if (typeof value !== "string" || !conditionOptions.includes(value)) {
164
+ throw bootRuleError(ENTITY_SELECT_IMAGE_RULES.conditionalWhenValueNotOption, {
165
+ message: `${where} has ${ruleLabel}.when value "${String(value)}" which is not an option of "${conditionField}" (${conditionOptions.join(", ")}).`,
166
+ });
167
+ }
168
+ }
169
+ }
170
+ });
171
+ }
172
+ }
173
+ }
174
+ export function validateMultiSelectFields(feature) {
175
+ for (const [entityName, entity] of Object.entries(feature.entities ?? {})) {
176
+ for (const [fieldName, field] of Object.entries(entity.fields)) {
177
+ if (field.type !== "multiSelect")
178
+ continue;
179
+ if (field.options.length === 0) {
180
+ throw bootRuleError(ENTITY_SELECT_IMAGE_RULES.multiSelectOptionsEmpty, {
181
+ message: `MultiSelect field "${fieldName}" on entity "${entityName}" in feature "${feature.name}" has empty options. Add at least one option.`,
182
+ });
183
+ }
184
+ if (field.default !== undefined) {
185
+ const validOptions = new Set(field.options);
186
+ for (const value of field.default) {
187
+ if (!validOptions.has(value)) {
188
+ throw bootRuleError(ENTITY_SELECT_IMAGE_RULES.multiSelectDefaultNotOption, {
189
+ message: `MultiSelect default "${value}" on "${entityName}.${fieldName}" is not a valid option. Valid: ${field.options.join(", ")}`,
190
+ });
191
+ }
192
+ }
193
+ }
194
+ validateCheckboxDisplayOptions(field, fieldName, entityName);
195
+ }
196
+ }
197
+ }
@@ -0,0 +1,107 @@
1
+ export declare const ENTITY_STRUCTURE_RULES: {
2
+ readonly locatedByMissingField: {
3
+ readonly id: "entity/located-by-missing-field";
4
+ readonly summary: "A timestamp locatedBy names a field of the same entity.";
5
+ readonly fix: "Declare the tz field or use createLocatedTimestampField().";
6
+ };
7
+ readonly locatedByNotTz: {
8
+ readonly id: "entity/located-by-not-tz";
9
+ readonly summary: "A timestamp locatedBy points at a tz field.";
10
+ readonly fix: "Point locatedBy at a field of type tz.";
11
+ };
12
+ readonly indexColumnsEmpty: {
13
+ readonly id: "entity-index/columns-empty";
14
+ readonly summary: "An entity index lists at least one column.";
15
+ readonly fix: "Add a column to the index.";
16
+ };
17
+ readonly indexUnknownColumn: {
18
+ readonly id: "entity-index/unknown-column";
19
+ readonly summary: "Every index column is a field of the entity or a base column.";
20
+ readonly fix: "Fix the column name.";
21
+ };
22
+ readonly indexMultiValueColumn: {
23
+ readonly id: "entity-index/multi-value-column";
24
+ readonly summary: "An index does not cover a multi-value field.";
25
+ readonly fix: "Use a single-value field or remove it from the index.";
26
+ };
27
+ readonly indexLongTextColumn: {
28
+ readonly id: "entity-index/long-text-column";
29
+ readonly summary: "An index does not cover a longText field.";
30
+ readonly fix: "Use text if the column needs an index, or use the SearchAdapter.";
31
+ };
32
+ readonly indexTenantIdOnly: {
33
+ readonly id: "entity-index/tenant-id-only";
34
+ readonly summary: "A non-unique index is not on tenantId alone.";
35
+ readonly fix: "Remove the entry; buildEntityTable creates it automatically.";
36
+ };
37
+ readonly indexUniqueEncryptedColumn: {
38
+ readonly id: "entity-index/unique-encrypted-column";
39
+ readonly summary: "A unique index does not cover an encrypted column.";
40
+ readonly fix: "Remove unique or encrypted.";
41
+ };
42
+ readonly encryptedSearchable: {
43
+ readonly id: "entity/encrypted-searchable";
44
+ readonly summary: "An encrypted text field is not searchable.";
45
+ readonly fix: "Drop searchable: true or remove the encryption.";
46
+ };
47
+ readonly encryptedSortable: {
48
+ readonly id: "entity/encrypted-sortable";
49
+ readonly summary: "An encrypted text field is not sortable.";
50
+ readonly fix: "Drop sortable: true or remove the encryption.";
51
+ };
52
+ readonly encryptedFilterable: {
53
+ readonly id: "entity/encrypted-filterable";
54
+ readonly summary: "An encrypted text field is not filterable.";
55
+ readonly fix: "Drop filterable: true or remove the encryption.";
56
+ };
57
+ readonly lockedWhenUnknownField: {
58
+ readonly id: "locked-when/unknown-field";
59
+ readonly summary: "The lockedWhen field is a field of the entity.";
60
+ readonly fix: "Name an existing field.";
61
+ };
62
+ readonly lockedWhenCiphertextField: {
63
+ readonly id: "locked-when/ciphertext-field";
64
+ readonly summary: "The lockedWhen field is plaintext at rest.";
65
+ readonly fix: "Use a plaintext field.";
66
+ };
67
+ readonly lockedWhenReadRestricted: {
68
+ readonly id: "locked-when/read-restricted-field";
69
+ readonly summary: "The lockedWhen field has no read restriction.";
70
+ readonly fix: "Drop field access.read or use another field.";
71
+ };
72
+ readonly transitionUnknownField: {
73
+ readonly id: "transition/unknown-field";
74
+ readonly summary: "Transitions are declared for a field of the entity.";
75
+ readonly fix: "Fix the field name.";
76
+ };
77
+ readonly transitionFieldNotSelect: {
78
+ readonly id: "transition/field-not-select";
79
+ readonly summary: "Transitions are declared for a select field.";
80
+ readonly fix: "Declare transitions on a select field.";
81
+ };
82
+ readonly transitionStateNotOption: {
83
+ readonly id: "transition/state-not-option";
84
+ readonly summary: "Every transition source state is an option of the select field.";
85
+ readonly fix: "Use an existing option.";
86
+ };
87
+ readonly transitionTargetNotOption: {
88
+ readonly id: "transition/target-not-option";
89
+ readonly summary: "Every transition target is an option of the select field.";
90
+ readonly fix: "Use an existing option.";
91
+ };
92
+ readonly extendSchemaCollision: {
93
+ readonly id: "entity/extend-schema-collision";
94
+ readonly summary: "An extendSchema column does not collide with an entity field.";
95
+ readonly fix: "Rename the extension column or the entity field.";
96
+ };
97
+ readonly derivedFieldCollision: {
98
+ readonly id: "entity/derived-field-collision";
99
+ readonly summary: "A derivedFields key does not match a stored field.";
100
+ readonly fix: "Rename the derivedFields key or the stored field.";
101
+ };
102
+ readonly searchableRestrictedRead: {
103
+ readonly id: "entity/searchable-restricted-read";
104
+ readonly summary: "A searchable field has no restricted access.read.";
105
+ readonly fix: 'Drop searchable/find: "fuzzy" or access.read.';
106
+ };
107
+ };
@@ -0,0 +1,107 @@
1
+ export const ENTITY_STRUCTURE_RULES = {
2
+ locatedByMissingField: {
3
+ id: "entity/located-by-missing-field",
4
+ summary: "A timestamp locatedBy names a field of the same entity.",
5
+ fix: "Declare the tz field or use createLocatedTimestampField().",
6
+ },
7
+ locatedByNotTz: {
8
+ id: "entity/located-by-not-tz",
9
+ summary: "A timestamp locatedBy points at a tz field.",
10
+ fix: "Point locatedBy at a field of type tz.",
11
+ },
12
+ indexColumnsEmpty: {
13
+ id: "entity-index/columns-empty",
14
+ summary: "An entity index lists at least one column.",
15
+ fix: "Add a column to the index.",
16
+ },
17
+ indexUnknownColumn: {
18
+ id: "entity-index/unknown-column",
19
+ summary: "Every index column is a field of the entity or a base column.",
20
+ fix: "Fix the column name.",
21
+ },
22
+ indexMultiValueColumn: {
23
+ id: "entity-index/multi-value-column",
24
+ summary: "An index does not cover a multi-value field.",
25
+ fix: "Use a single-value field or remove it from the index.",
26
+ },
27
+ indexLongTextColumn: {
28
+ id: "entity-index/long-text-column",
29
+ summary: "An index does not cover a longText field.",
30
+ fix: "Use text if the column needs an index, or use the SearchAdapter.",
31
+ },
32
+ indexTenantIdOnly: {
33
+ id: "entity-index/tenant-id-only",
34
+ summary: "A non-unique index is not on tenantId alone.",
35
+ fix: "Remove the entry; buildEntityTable creates it automatically.",
36
+ },
37
+ indexUniqueEncryptedColumn: {
38
+ id: "entity-index/unique-encrypted-column",
39
+ summary: "A unique index does not cover an encrypted column.",
40
+ fix: "Remove unique or encrypted.",
41
+ },
42
+ encryptedSearchable: {
43
+ id: "entity/encrypted-searchable",
44
+ summary: "An encrypted text field is not searchable.",
45
+ fix: "Drop searchable: true or remove the encryption.",
46
+ },
47
+ encryptedSortable: {
48
+ id: "entity/encrypted-sortable",
49
+ summary: "An encrypted text field is not sortable.",
50
+ fix: "Drop sortable: true or remove the encryption.",
51
+ },
52
+ encryptedFilterable: {
53
+ id: "entity/encrypted-filterable",
54
+ summary: "An encrypted text field is not filterable.",
55
+ fix: "Drop filterable: true or remove the encryption.",
56
+ },
57
+ lockedWhenUnknownField: {
58
+ id: "locked-when/unknown-field",
59
+ summary: "The lockedWhen field is a field of the entity.",
60
+ fix: "Name an existing field.",
61
+ },
62
+ lockedWhenCiphertextField: {
63
+ id: "locked-when/ciphertext-field",
64
+ summary: "The lockedWhen field is plaintext at rest.",
65
+ fix: "Use a plaintext field.",
66
+ },
67
+ lockedWhenReadRestricted: {
68
+ id: "locked-when/read-restricted-field",
69
+ summary: "The lockedWhen field has no read restriction.",
70
+ fix: "Drop field access.read or use another field.",
71
+ },
72
+ transitionUnknownField: {
73
+ id: "transition/unknown-field",
74
+ summary: "Transitions are declared for a field of the entity.",
75
+ fix: "Fix the field name.",
76
+ },
77
+ transitionFieldNotSelect: {
78
+ id: "transition/field-not-select",
79
+ summary: "Transitions are declared for a select field.",
80
+ fix: "Declare transitions on a select field.",
81
+ },
82
+ transitionStateNotOption: {
83
+ id: "transition/state-not-option",
84
+ summary: "Every transition source state is an option of the select field.",
85
+ fix: "Use an existing option.",
86
+ },
87
+ transitionTargetNotOption: {
88
+ id: "transition/target-not-option",
89
+ summary: "Every transition target is an option of the select field.",
90
+ fix: "Use an existing option.",
91
+ },
92
+ extendSchemaCollision: {
93
+ id: "entity/extend-schema-collision",
94
+ summary: "An extendSchema column does not collide with an entity field.",
95
+ fix: "Rename the extension column or the entity field.",
96
+ },
97
+ derivedFieldCollision: {
98
+ id: "entity/derived-field-collision",
99
+ summary: "A derivedFields key does not match a stored field.",
100
+ fix: "Rename the derivedFields key or the stored field.",
101
+ },
102
+ searchableRestrictedRead: {
103
+ id: "entity/searchable-restricted-read",
104
+ summary: "A searchable field has no restricted access.read.",
105
+ fix: 'Drop searchable/find: "fuzzy" or access.read.',
106
+ },
107
+ };
@@ -0,0 +1,92 @@
1
+ export declare const FIELD_CONDITION_RULES: {
2
+ readonly requiredWithRequiredWhen: {
3
+ readonly id: "field-condition/required-with-required-when";
4
+ readonly summary: "A field does not set required: true together with requiredWhen.";
5
+ readonly fix: "Drop required; requiredWhen covers the conditional case.";
6
+ };
7
+ readonly requiredWithVisibleWhen: {
8
+ readonly id: "field-condition/required-with-visible-when";
9
+ readonly summary: "A field does not set required: true together with visibleWhen.";
10
+ readonly fix: "Drop required and use requiredWhen with the same condition as visibleWhen.";
11
+ };
12
+ readonly comparisonValueNotOption: {
13
+ readonly id: "field-condition/comparison-value-not-option";
14
+ readonly summary: "A condition on a select field compares only against options of that field.";
15
+ readonly fix: "Compare against one of the select field's options.";
16
+ };
17
+ readonly conditionOnOwnField: {
18
+ readonly id: "field-condition/on-own-field";
19
+ readonly summary: "A visibleWhen, requiredWhen or when condition depends on a different field or sibling.";
20
+ readonly fix: "Point the condition's field at another field of the entity (or a sibling sub-field).";
21
+ };
22
+ readonly unknownConditionField: {
23
+ readonly id: "field-condition/unknown-field";
24
+ readonly summary: "A condition's field names a field of the entity or a sub-field of the same row.";
25
+ readonly fix: "Use an existing field of the entity, or a sibling sub-field inside an embedded row.";
26
+ };
27
+ readonly conditionFieldTypeNotComparable: {
28
+ readonly id: "field-condition/field-type-not-comparable";
29
+ readonly summary: "A visibleWhen, requiredWhen or lockedWhen field stores a plain scalar the condition can compare.";
30
+ readonly fix: "Use a text, select, boolean, number or reference field (more types for sub-fields).";
31
+ };
32
+ readonly fileSubFieldSearchable: {
33
+ readonly id: "file-field/sub-field-searchable";
34
+ readonly summary: "A file or image sub-field is not searchable.";
35
+ readonly fix: "Remove searchable from the file sub-field.";
36
+ };
37
+ readonly fileMaxCountInvalid: {
38
+ readonly id: "file-field/max-count-invalid";
39
+ readonly summary: "A file sub-field maxCount is a positive integer.";
40
+ readonly fix: "Set maxCount to a positive integer.";
41
+ };
42
+ readonly fileMaxSizeInvalid: {
43
+ readonly id: "file-field/max-size-invalid";
44
+ readonly summary: "A file sub-field maxSize is a parseable size string.";
45
+ readonly fix: 'Use a size like "10mb" or "500kb".';
46
+ };
47
+ readonly acceptEntryEmpty: {
48
+ readonly id: "file-field/accept-entry-empty";
49
+ readonly summary: "The accept list has no empty entries.";
50
+ readonly fix: 'List file extensions like "pdf".';
51
+ };
52
+ readonly acceptEntryNotBareExtension: {
53
+ readonly id: "file-field/accept-entry-not-bare-extension";
54
+ readonly summary: "Every accept entry is a bare lower-case file extension.";
55
+ readonly fix: 'Use "pdf" instead of ".pdf", a MIME type or a wildcard.';
56
+ };
57
+ readonly optionToneNotAnOption: {
58
+ readonly id: "embedded-field/option-tone-not-an-option";
59
+ readonly summary: "Every optionTones key of a select sub-field is one of its options.";
60
+ readonly fix: "Remove the tone or add the option.";
61
+ };
62
+ readonly derivedSourceNotNumeric: {
63
+ readonly id: "embedded-field/derived-source-not-numeric";
64
+ readonly summary: "A derived cell reads only number, decimal or money sub-fields.";
65
+ readonly fix: "Point from at number, decimal or money sub-fields of the same row.";
66
+ };
67
+ readonly inRangeNeedsThreeSources: {
68
+ readonly id: "embedded-field/in-range-needs-three-sources";
69
+ readonly summary: 'A derived cell with op "inRange" has exactly three sources (value, min, max).';
70
+ readonly fix: "List exactly value, min and max in from.";
71
+ };
72
+ readonly inRangeTargetNotSelect: {
73
+ readonly id: "embedded-field/in-range-target-not-select";
74
+ readonly summary: 'The target of an "inRange" derived cell is a select sub-field with the inside and outside options.';
75
+ readonly fix: "Make the target a select sub-field that lists both the inside and the outside option.";
76
+ };
77
+ readonly derivedTargetNotNumeric: {
78
+ readonly id: "embedded-field/derived-target-not-numeric";
79
+ readonly summary: "The target of a derived cell is a number, decimal or money sub-field.";
80
+ readonly fix: "Change the target sub-field's type to number, decimal or money.";
81
+ };
82
+ readonly derivedWhenReadsDerived: {
83
+ readonly id: "embedded-field/derived-when-reads-derived";
84
+ readonly summary: "A derived cell's when reads a stored sub-field, not another derived cell.";
85
+ readonly fix: "Read a stored sub-field in when.";
86
+ };
87
+ readonly fileSubFieldInDerived: {
88
+ readonly id: "embedded-field/file-sub-field-in-derived";
89
+ readonly summary: "File sub-fields are not used in derived cells or totals.";
90
+ readonly fix: "Remove the file sub-field from derived, totals and totalsMatch.";
91
+ };
92
+ };
@@ -0,0 +1,92 @@
1
+ export const FIELD_CONDITION_RULES = {
2
+ requiredWithRequiredWhen: {
3
+ id: "field-condition/required-with-required-when",
4
+ summary: "A field does not set required: true together with requiredWhen.",
5
+ fix: "Drop required; requiredWhen covers the conditional case.",
6
+ },
7
+ requiredWithVisibleWhen: {
8
+ id: "field-condition/required-with-visible-when",
9
+ summary: "A field does not set required: true together with visibleWhen.",
10
+ fix: "Drop required and use requiredWhen with the same condition as visibleWhen.",
11
+ },
12
+ comparisonValueNotOption: {
13
+ id: "field-condition/comparison-value-not-option",
14
+ summary: "A condition on a select field compares only against options of that field.",
15
+ fix: "Compare against one of the select field's options.",
16
+ },
17
+ conditionOnOwnField: {
18
+ id: "field-condition/on-own-field",
19
+ summary: "A visibleWhen, requiredWhen or when condition depends on a different field or sibling.",
20
+ fix: "Point the condition's field at another field of the entity (or a sibling sub-field).",
21
+ },
22
+ unknownConditionField: {
23
+ id: "field-condition/unknown-field",
24
+ summary: "A condition's field names a field of the entity or a sub-field of the same row.",
25
+ fix: "Use an existing field of the entity, or a sibling sub-field inside an embedded row.",
26
+ },
27
+ conditionFieldTypeNotComparable: {
28
+ id: "field-condition/field-type-not-comparable",
29
+ summary: "A visibleWhen, requiredWhen or lockedWhen field stores a plain scalar the condition can compare.",
30
+ fix: "Use a text, select, boolean, number or reference field (more types for sub-fields).",
31
+ },
32
+ fileSubFieldSearchable: {
33
+ id: "file-field/sub-field-searchable",
34
+ summary: "A file or image sub-field is not searchable.",
35
+ fix: "Remove searchable from the file sub-field.",
36
+ },
37
+ fileMaxCountInvalid: {
38
+ id: "file-field/max-count-invalid",
39
+ summary: "A file sub-field maxCount is a positive integer.",
40
+ fix: "Set maxCount to a positive integer.",
41
+ },
42
+ fileMaxSizeInvalid: {
43
+ id: "file-field/max-size-invalid",
44
+ summary: "A file sub-field maxSize is a parseable size string.",
45
+ fix: 'Use a size like "10mb" or "500kb".',
46
+ },
47
+ acceptEntryEmpty: {
48
+ id: "file-field/accept-entry-empty",
49
+ summary: "The accept list has no empty entries.",
50
+ fix: 'List file extensions like "pdf".',
51
+ },
52
+ acceptEntryNotBareExtension: {
53
+ id: "file-field/accept-entry-not-bare-extension",
54
+ summary: "Every accept entry is a bare lower-case file extension.",
55
+ fix: 'Use "pdf" instead of ".pdf", a MIME type or a wildcard.',
56
+ },
57
+ optionToneNotAnOption: {
58
+ id: "embedded-field/option-tone-not-an-option",
59
+ summary: "Every optionTones key of a select sub-field is one of its options.",
60
+ fix: "Remove the tone or add the option.",
61
+ },
62
+ derivedSourceNotNumeric: {
63
+ id: "embedded-field/derived-source-not-numeric",
64
+ summary: "A derived cell reads only number, decimal or money sub-fields.",
65
+ fix: "Point from at number, decimal or money sub-fields of the same row.",
66
+ },
67
+ inRangeNeedsThreeSources: {
68
+ id: "embedded-field/in-range-needs-three-sources",
69
+ summary: 'A derived cell with op "inRange" has exactly three sources (value, min, max).',
70
+ fix: "List exactly value, min and max in from.",
71
+ },
72
+ inRangeTargetNotSelect: {
73
+ id: "embedded-field/in-range-target-not-select",
74
+ summary: 'The target of an "inRange" derived cell is a select sub-field with the inside and outside options.',
75
+ fix: "Make the target a select sub-field that lists both the inside and the outside option.",
76
+ },
77
+ derivedTargetNotNumeric: {
78
+ id: "embedded-field/derived-target-not-numeric",
79
+ summary: "The target of a derived cell is a number, decimal or money sub-field.",
80
+ fix: "Change the target sub-field's type to number, decimal or money.",
81
+ },
82
+ derivedWhenReadsDerived: {
83
+ id: "embedded-field/derived-when-reads-derived",
84
+ summary: "A derived cell's when reads a stored sub-field, not another derived cell.",
85
+ fix: "Read a stored sub-field in when.",
86
+ },
87
+ fileSubFieldInDerived: {
88
+ id: "embedded-field/file-sub-field-in-derived",
89
+ summary: "File sub-fields are not used in derived cells or totals.",
90
+ fix: "Remove the file sub-field from derived, totals and totalsMatch.",
91
+ },
92
+ };