adula 0.0.0 → 2.0.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 (210) hide show
  1. package/LICENSE.md +10 -0
  2. package/README.md +38 -2
  3. package/build/agent/AGENTS.template.md +28 -0
  4. package/build/agent/capabilities.md +60 -0
  5. package/build/agent/skills/adula-frontend-design/SKILL.md +59 -0
  6. package/build/agent/skills/idea-review/SKILL.md +31 -0
  7. package/build/agent/skills/module-review/SKILL.md +22 -0
  8. package/build/agent/skills/perf-review/SKILL.md +24 -0
  9. package/build/agent/skills/schema-review/SKILL.md +22 -0
  10. package/build/agent/skills/security-review/SKILL.md +24 -0
  11. package/build/agent/skills/ui-review/SKILL.md +22 -0
  12. package/build/commands/capabilities.d.ts +10 -0
  13. package/build/commands/capabilities.js +40 -0
  14. package/build/commands/doctor.d.ts +9 -0
  15. package/build/commands/doctor.js +72 -0
  16. package/build/commands/gaps.d.ts +12 -0
  17. package/build/commands/gaps.js +62 -0
  18. package/build/commands/install.d.ts +9 -0
  19. package/build/commands/install.js +105 -0
  20. package/build/commands/main.d.ts +8 -0
  21. package/build/commands/main.js +33 -0
  22. package/build/commands/module_add.d.ts +8 -0
  23. package/build/commands/module_add.js +57 -0
  24. package/build/commands/module_remove.d.ts +10 -0
  25. package/build/commands/module_remove.js +94 -0
  26. package/build/commands/resource.d.ts +8 -0
  27. package/build/commands/resource.js +29 -0
  28. package/build/commands/resource_snapshot.d.ts +15 -0
  29. package/build/commands/resource_snapshot.js +61 -0
  30. package/build/commands/storage_migrate.d.ts +12 -0
  31. package/build/commands/storage_migrate.js +39 -0
  32. package/build/commands/ui.d.ts +11 -0
  33. package/build/commands/ui.js +210 -0
  34. package/build/commands/upgrade.d.ts +15 -0
  35. package/build/commands/upgrade.js +34 -0
  36. package/build/configure.d.ts +2 -0
  37. package/build/configure.js +79 -0
  38. package/build/database/migrations/1770000000000_core.d.ts +5 -0
  39. package/build/database/migrations/1770000000000_core.js +10 -0
  40. package/build/database/migrations/1770000000001_attachments.d.ts +5 -0
  41. package/build/database/migrations/1770000000001_attachments.js +10 -0
  42. package/build/database/migrations/1770000000002_saved_views.d.ts +5 -0
  43. package/build/database/migrations/1770000000002_saved_views.js +10 -0
  44. package/build/database/migrations/1770000000003_user_invitations.d.ts +5 -0
  45. package/build/database/migrations/1770000000003_user_invitations.js +18 -0
  46. package/build/database/migrations/1770000000004_collaboration.d.ts +5 -0
  47. package/build/database/migrations/1770000000004_collaboration.js +10 -0
  48. package/build/database/migrations/1770000000005_assignments.d.ts +5 -0
  49. package/build/database/migrations/1770000000005_assignments.js +10 -0
  50. package/build/database/migrations/1770000000006_messaging.d.ts +5 -0
  51. package/build/database/migrations/1770000000006_messaging.js +10 -0
  52. package/build/database/migrations/1770000000007_webhooks.d.ts +5 -0
  53. package/build/database/migrations/1770000000007_webhooks.js +10 -0
  54. package/build/database/migrations/1770000000008_imports.d.ts +5 -0
  55. package/build/database/migrations/1770000000008_imports.js +10 -0
  56. package/build/database/migrations/1770000000010_workflows.d.ts +5 -0
  57. package/build/database/migrations/1770000000010_workflows.js +10 -0
  58. package/build/database/migrations/1770000000011_managed_assignments.d.ts +5 -0
  59. package/build/database/migrations/1770000000011_managed_assignments.js +10 -0
  60. package/build/database/migrations/1770000000012_role_keys.d.ts +5 -0
  61. package/build/database/migrations/1770000000012_role_keys.js +10 -0
  62. package/build/database/migrations/1770000000013_notification_targets.d.ts +5 -0
  63. package/build/database/migrations/1770000000013_notification_targets.js +10 -0
  64. package/build/database/migrations/1770000000014_upload_grants.d.ts +5 -0
  65. package/build/database/migrations/1770000000014_upload_grants.js +10 -0
  66. package/build/database/migrations/1770000000015_inbound_webhooks.d.ts +5 -0
  67. package/build/database/migrations/1770000000015_inbound_webhooks.js +10 -0
  68. package/build/database/migrations/1770000000016_adulajs_names.d.ts +6 -0
  69. package/build/database/migrations/1770000000016_adulajs_names.js +11 -0
  70. package/build/index.d.ts +80 -0
  71. package/build/index.js +49 -0
  72. package/build/providers/adula_provider.d.ts +6 -0
  73. package/build/providers/adula_provider.js +10 -0
  74. package/build/src/admin/contracts.d.ts +19 -0
  75. package/build/src/admin/contracts.js +115 -0
  76. package/build/src/admin/controller.d.ts +32 -0
  77. package/build/src/admin/controller.js +167 -0
  78. package/build/src/admin/errors.d.ts +5 -0
  79. package/build/src/admin/errors.js +9 -0
  80. package/build/src/admin/presentation.d.ts +28 -0
  81. package/build/src/admin/presentation.js +1 -0
  82. package/build/src/admin/record_title.d.ts +14 -0
  83. package/build/src/admin/record_title.js +50 -0
  84. package/build/src/admin/resource_service.d.ts +376 -0
  85. package/build/src/admin/resource_service.js +1448 -0
  86. package/build/src/attachments/attachment_service.d.ts +100 -0
  87. package/build/src/attachments/attachment_service.js +270 -0
  88. package/build/src/attachments/doctor.d.ts +4 -0
  89. package/build/src/attachments/doctor.js +28 -0
  90. package/build/src/attachments/storage_migrate.d.ts +39 -0
  91. package/build/src/attachments/storage_migrate.js +64 -0
  92. package/build/src/attachments/upload_grants.d.ts +44 -0
  93. package/build/src/attachments/upload_grants.js +105 -0
  94. package/build/src/auth/ability.d.ts +24 -0
  95. package/build/src/auth/ability.js +34 -0
  96. package/build/src/auth/actor_store.d.ts +14 -0
  97. package/build/src/auth/actor_store.js +70 -0
  98. package/build/src/auth/conditions.d.ts +26 -0
  99. package/build/src/auth/conditions.js +117 -0
  100. package/build/src/auth/packed_rules.d.ts +4 -0
  101. package/build/src/auth/packed_rules.js +13 -0
  102. package/build/src/auth/sql.d.ts +11 -0
  103. package/build/src/auth/sql.js +118 -0
  104. package/build/src/collaboration/assignments.d.ts +129 -0
  105. package/build/src/collaboration/assignments.js +333 -0
  106. package/build/src/collaboration/record_collaboration.d.ts +86 -0
  107. package/build/src/collaboration/record_collaboration.js +348 -0
  108. package/build/src/commands/agent_assets.d.ts +7 -0
  109. package/build/src/commands/agent_assets.js +66 -0
  110. package/build/src/commands/capabilities.d.ts +19 -0
  111. package/build/src/commands/capabilities.js +179 -0
  112. package/build/src/commands/doctor.d.ts +42 -0
  113. package/build/src/commands/doctor.js +375 -0
  114. package/build/src/commands/gap_report.d.ts +56 -0
  115. package/build/src/commands/gap_report.js +110 -0
  116. package/build/src/commands/generator.d.ts +1 -0
  117. package/build/src/commands/generator.js +70 -0
  118. package/build/src/commands/snapshot.d.ts +28 -0
  119. package/build/src/commands/snapshot.js +48 -0
  120. package/build/src/commands/source_markers.d.ts +11 -0
  121. package/build/src/commands/source_markers.js +41 -0
  122. package/build/src/core/activity.d.ts +43 -0
  123. package/build/src/core/activity.js +77 -0
  124. package/build/src/core/administration_guard.d.ts +3 -0
  125. package/build/src/core/administration_guard.js +39 -0
  126. package/build/src/core/health.d.ts +42 -0
  127. package/build/src/core/health.js +44 -0
  128. package/build/src/core/mail_test.d.ts +18 -0
  129. package/build/src/core/mail_test.js +88 -0
  130. package/build/src/core/message_templates.d.ts +83 -0
  131. package/build/src/core/message_templates.js +293 -0
  132. package/build/src/core/module_seed.d.ts +15 -0
  133. package/build/src/core/module_seed.js +31 -0
  134. package/build/src/core/notifications.d.ts +42 -0
  135. package/build/src/core/notifications.js +91 -0
  136. package/build/src/core/org_units.d.ts +30 -0
  137. package/build/src/core/org_units.js +123 -0
  138. package/build/src/core/roles.d.ts +98 -0
  139. package/build/src/core/roles.js +447 -0
  140. package/build/src/core/saved_views.d.ts +37 -0
  141. package/build/src/core/saved_views.js +164 -0
  142. package/build/src/core/settings.d.ts +29 -0
  143. package/build/src/core/settings.js +113 -0
  144. package/build/src/core/setup.d.ts +14 -0
  145. package/build/src/core/setup.js +89 -0
  146. package/build/src/core/ui_preferences.d.ts +12 -0
  147. package/build/src/core/ui_preferences.js +30 -0
  148. package/build/src/core/user_invitations.d.ts +23 -0
  149. package/build/src/core/user_invitations.js +144 -0
  150. package/build/src/core/users.d.ts +44 -0
  151. package/build/src/core/users.js +182 -0
  152. package/build/src/database/configure.d.ts +3 -0
  153. package/build/src/database/configure.js +41 -0
  154. package/build/src/database/schema.d.ts +52 -0
  155. package/build/src/database/schema.js +538 -0
  156. package/build/src/eslint/index.d.ts +3 -0
  157. package/build/src/eslint/index.js +90 -0
  158. package/build/src/events/adonis_jobs.d.ts +9 -0
  159. package/build/src/events/adonis_jobs.js +13 -0
  160. package/build/src/events/outbox.d.ts +19 -0
  161. package/build/src/events/outbox.js +33 -0
  162. package/build/src/events/record_mutation.d.ts +24 -0
  163. package/build/src/events/record_mutation.js +62 -0
  164. package/build/src/integrations/imports.d.ts +74 -0
  165. package/build/src/integrations/imports.js +333 -0
  166. package/build/src/integrations/inbound_webhooks.d.ts +94 -0
  167. package/build/src/integrations/inbound_webhooks.js +276 -0
  168. package/build/src/integrations/openapi.d.ts +39 -0
  169. package/build/src/integrations/openapi.js +323 -0
  170. package/build/src/integrations/print.d.ts +37 -0
  171. package/build/src/integrations/print.js +124 -0
  172. package/build/src/integrations/webhooks.d.ts +98 -0
  173. package/build/src/integrations/webhooks.js +298 -0
  174. package/build/src/mcp/tools.d.ts +8 -0
  175. package/build/src/mcp/tools.js +156 -0
  176. package/build/src/org/org_service.d.ts +2 -0
  177. package/build/src/org/org_service.js +16 -0
  178. package/build/src/resource/define_resource.d.ts +5 -0
  179. package/build/src/resource/define_resource.js +68 -0
  180. package/build/src/resource/registry.d.ts +12 -0
  181. package/build/src/resource/registry.js +101 -0
  182. package/build/src/resource/types.d.ts +155 -0
  183. package/build/src/resource/types.js +1 -0
  184. package/build/src/resource/values.d.ts +5 -0
  185. package/build/src/resource/values.js +88 -0
  186. package/build/src/services/backup.d.ts +14 -0
  187. package/build/src/services/backup.js +59 -0
  188. package/build/src/services/settings.d.ts +21 -0
  189. package/build/src/services/settings.js +30 -0
  190. package/build/src/upgrade/legacy.d.ts +27 -0
  191. package/build/src/upgrade/legacy.js +58 -0
  192. package/build/src/upgrade/rename.d.ts +17 -0
  193. package/build/src/upgrade/rename.js +94 -0
  194. package/build/src/version.d.ts +1 -0
  195. package/build/src/version.js +2 -0
  196. package/build/src/workflows/define_workflow.d.ts +124 -0
  197. package/build/src/workflows/define_workflow.js +123 -0
  198. package/build/src/workflows/engine.d.ts +141 -0
  199. package/build/src/workflows/engine.js +752 -0
  200. package/build/stubs/README.md +6 -0
  201. package/build/stubs/controller.stub +8 -0
  202. package/build/stubs/main.d.ts +5 -0
  203. package/build/stubs/main.js +5 -0
  204. package/build/stubs/main.ts +5 -0
  205. package/build/stubs/modules.stub +6 -0
  206. package/build/stubs/resource_contract.stub +1 -0
  207. package/build/stubs/resource_contract.txt +452 -0
  208. package/build/stubs/routes.stub +16 -0
  209. package/build/stubs/service.stub +9 -0
  210. package/package.json +95 -6
@@ -0,0 +1,376 @@
1
+ import type { Knex } from 'knex';
2
+ import type { ResourceRegistry } from '../resource/registry.js';
3
+ import type { Action, JsonValue, RecordData, Resource, SerializedRecord } from '../resource/types.js';
4
+ import { type Actor, type AdulaAbility } from '../auth/ability.js';
5
+ import { type Conditions } from '../auth/conditions.js';
6
+ import type { ResourceDescription, ResourceNavigation, ResourceField } from './presentation.js';
7
+ export type AggregateOptions = {
8
+ /** Up to three queryable fields (docStatus and orgUnitId are also accepted). */
9
+ groupBy?: string[];
10
+ /** Count rows per group (default true). */
11
+ count?: boolean;
12
+ /** Integer or money fields to total per group; money totals are decimal strings. */
13
+ sum?: string[];
14
+ /** Equality filters, as in list(). */
15
+ filters?: Record<string, unknown>;
16
+ /** Role-rule style conditions ($eq, $ne, $in, $lt, $gt, $like, "$actor.id"). */
17
+ where?: Conditions;
18
+ search?: string;
19
+ };
20
+ export type AggregateRow = {
21
+ group: Record<string, JsonValue>;
22
+ count?: number;
23
+ sum?: Record<string, string | null>;
24
+ };
25
+ export type ListOptions = {
26
+ limit?: number;
27
+ cursor?: string;
28
+ search?: string;
29
+ sort?: string;
30
+ direction?: 'asc' | 'desc';
31
+ filters?: Record<string, unknown>;
32
+ /** Only records carrying this tag (see RecordCollaboration.setTags). */
33
+ tag?: string;
34
+ estimate?: boolean;
35
+ };
36
+ /**
37
+ * Whether an actor may sort, filter or search by a field. Querying reveals values
38
+ * indirectly, so it needs unconditional view access at the field's level.
39
+ */
40
+ export declare function canQueryField(resource: Resource, actor: Actor, ability: AdulaAbility, key: string): boolean;
41
+ /** Options of ResourceService.systemSave. */
42
+ export type SystemSaveOptions = {
43
+ /** The user recorded as the author: created/updated by, activity and events. */
44
+ actorId: number;
45
+ /** Write inside the module's transaction. */
46
+ trx?: Knex.Transaction;
47
+ /** Why module code wrote the record; stored with the activity entry. */
48
+ reason?: string;
49
+ /** Optimistic lock: when given, it must match the stored version. */
50
+ version?: number;
51
+ /**
52
+ * The person who chose the values, when module code writes a choice made by a user,
53
+ * such as a supervisor reassigning a record. A new value of a user field must then be
54
+ * eligible for them as in a user save; without it, any active member qualifies on
55
+ * unscoped resources.
56
+ */
57
+ chooser?: Actor;
58
+ };
59
+ export declare class ResourceService {
60
+ private db;
61
+ private registry;
62
+ constructor(db: Knex, registry: ResourceRegistry);
63
+ /** The Arabic label of a registered resource, for notifications and titles. */
64
+ label(name: string): string;
65
+ /** Project navigation is derived from registered resources and the current actor. */
66
+ navigation(actor: Actor): ResourceNavigation;
67
+ describe(name: string, actor: Actor): ResourceDescription;
68
+ private permissions;
69
+ private normalizeValues;
70
+ /** Stored attachment ids become summaries for readers; copies keep policy checks on raw rows. */
71
+ private hydrate;
72
+ private hydrateOne;
73
+ private authorizeAction;
74
+ private scopedQuery;
75
+ private columns;
76
+ private find;
77
+ /** A live record regardless of any actor's scope, for system writes. */
78
+ private findAny;
79
+ private requireRecord;
80
+ /**
81
+ * Authorizes one record for collaboration features (comments, tags, assignments...).
82
+ * Scope and conditional rules apply exactly as for show/update.
83
+ */
84
+ access(name: string, id: number, actor: Actor, action?: Action, db?: Knex): Promise<{
85
+ resource: Resource;
86
+ record: RecordData;
87
+ ability: AdulaAbility;
88
+ }>;
89
+ /** Whether a (possibly other) actor may perform an action on a record; never throws for denial. */
90
+ permits(name: string, id: number, actor: Actor, action?: Action): Promise<boolean>;
91
+ list(name: string, actor: Actor, options?: ListOptions): Promise<{
92
+ data: SerializedRecord[];
93
+ permissions: {
94
+ [k: string]: Partial<Record<Action, boolean>>;
95
+ };
96
+ meta: {
97
+ limit: number;
98
+ estimatedTotal: number | undefined;
99
+ nextCursor: string | null;
100
+ };
101
+ related: Record<string, SerializedRecord[]>;
102
+ }>;
103
+ private canQueryField;
104
+ /**
105
+ * Counts and totals over the records the actor may view, grouped by queryable fields,
106
+ * for dashboards. Authorization is list()'s: the same rules, organization scope and
107
+ * soft-delete filter apply, and every grouped, totalled or filtered field must be one
108
+ * the actor may query (E_FIELD_FORBIDDEN otherwise), so no hidden value leaks.
109
+ */
110
+ aggregate(name: string, actor: Actor, options?: AggregateOptions): Promise<{
111
+ rows: AggregateRow[];
112
+ truncated: boolean;
113
+ }>;
114
+ private preload;
115
+ /** Formats record titles of one resource, loading the labels of its title lookups once. */
116
+ private titler;
117
+ /**
118
+ * Titles of records the actor may view, read under the actor's field access (#32).
119
+ * Records the actor cannot view are left out; callers fall back to the record id.
120
+ */
121
+ titles(name: string, ids: readonly number[], actor: Actor): Promise<Map<number, string>>;
122
+ show(name: string, id: number, actor: Actor): Promise<{
123
+ data: SerializedRecord;
124
+ permissions: Partial<Record<Action, boolean>>;
125
+ related: Record<string, SerializedRecord[]>;
126
+ }>;
127
+ relationOptions(name: string, key: string, actor: Actor, options?: {
128
+ id?: number;
129
+ search?: string;
130
+ cursor?: string;
131
+ /** User fields: the organization unit chosen in the form. */
132
+ orgUnitId?: number;
133
+ /** User fields: choices for a list filter instead of a form. */
134
+ purpose?: 'form' | 'filter';
135
+ }): Promise<{
136
+ data: {
137
+ value: string;
138
+ label: string;
139
+ }[];
140
+ nextCursor: string | null;
141
+ }>;
142
+ /**
143
+ * Choices for a user field. A form lists active members of the record's unit or its
144
+ * ancestors (the users the record is visible to through membership); a filter lists
145
+ * active users who share organization scope with the actor. Only names are returned.
146
+ */
147
+ private userOptions;
148
+ /**
149
+ * Active users eligible for a user field: members of the unit at `path` or of one of
150
+ * its ancestors, or (without a path) users sharing organization scope with the actor.
151
+ * A system write on an unscoped resource passes no actor: any active member qualifies.
152
+ */
153
+ private eligibleUsers;
154
+ /** Deferred relation reads re-authorize the parent and each child on every request. */
155
+ children(name: string, id: number, actor: Actor): Promise<Record<string, {
156
+ rows: SerializedRecord[];
157
+ hasMore: boolean;
158
+ }>>;
159
+ /** Inline children of an already authorized parent record. */
160
+ private childrenOf;
161
+ /** Active lookup labels for the lookup fields the actor may read on this resource. */
162
+ lookups(name: string, actor: Actor): Promise<Record<string, {
163
+ value: string;
164
+ label: string;
165
+ }[]>>;
166
+ /** The last 50 recorded mutations of one record, after authorizing the record itself. */
167
+ activity(name: string, id: number, actor: Actor): Promise<{
168
+ id: number;
169
+ action: Action;
170
+ fields: string[];
171
+ actorId: number;
172
+ actorName: string | null;
173
+ /**
174
+ * @deprecated Always null. Kept so project-owned copies of resource-show from
175
+ * earlier releases still compile; they fall back to the actor id.
176
+ */
177
+ actorEmail: string | null;
178
+ createdAt: string;
179
+ }[]>;
180
+ /**
181
+ * Inline children and recent activity of one record, authorized with a single record
182
+ * read (for deferred page props that would otherwise read the record twice).
183
+ */
184
+ details(name: string, id: number, actor: Actor): Promise<{
185
+ children: Record<string, {
186
+ rows: SerializedRecord[];
187
+ hasMore: boolean;
188
+ }>;
189
+ activity: {
190
+ id: number;
191
+ action: Action;
192
+ fields: string[];
193
+ actorId: number;
194
+ actorName: string | null;
195
+ /**
196
+ * @deprecated Always null. Kept so project-owned copies of resource-show from
197
+ * earlier releases still compile; they fall back to the actor id.
198
+ */
199
+ actorEmail: string | null;
200
+ createdAt: string;
201
+ }[];
202
+ }>;
203
+ /** show(), children() and activity() of one record from a single record read. */
204
+ record(name: string, id: number, actor: Actor): Promise<{
205
+ data: SerializedRecord;
206
+ permissions: Partial<Record<Action, boolean>>;
207
+ related: Record<string, SerializedRecord[]>;
208
+ children: Record<string, {
209
+ rows: SerializedRecord[];
210
+ hasMore: boolean;
211
+ }>;
212
+ activity: {
213
+ id: number;
214
+ action: Action;
215
+ fields: string[];
216
+ actorId: number;
217
+ actorName: string | null;
218
+ /**
219
+ * @deprecated Always null. Kept so project-owned copies of resource-show from
220
+ * earlier releases still compile; they fall back to the actor id.
221
+ */
222
+ actorEmail: string | null;
223
+ createdAt: string;
224
+ }[];
225
+ }>;
226
+ private activityOf;
227
+ /**
228
+ * The form description for create (no id) or update. `defaults` pre-fills a create form
229
+ * (#48), for example `?defaults[violation]=13`: only visible form fields are used, a
230
+ * related record must be viewable by the actor and a lookup must be active. Anything else
231
+ * is dropped. Defaults are only initial values; saving validates as usual.
232
+ */
233
+ editor(name: string, actor: Actor, id?: number, request?: {
234
+ defaults?: Record<string, unknown>;
235
+ }): Promise<{
236
+ mode: string;
237
+ name: string;
238
+ label: string;
239
+ recordLabel: string | null;
240
+ fields: ({
241
+ label: import("../resource/types.js").Label;
242
+ column?: string;
243
+ required?: boolean;
244
+ unique?: boolean;
245
+ sortable?: boolean;
246
+ searchable?: boolean;
247
+ filterable?: boolean;
248
+ permissionLevel?: number;
249
+ sequence?: string;
250
+ type: "string" | "text" | "integer" | "money" | "boolean" | "date" | "datetime" | "json";
251
+ key: string;
252
+ } | {
253
+ label: import("../resource/types.js").Label;
254
+ column?: string;
255
+ required?: boolean;
256
+ unique?: boolean;
257
+ sortable?: boolean;
258
+ searchable?: boolean;
259
+ filterable?: boolean;
260
+ permissionLevel?: number;
261
+ sequence?: string;
262
+ type: "attachment";
263
+ accept?: string[] | "any";
264
+ maxSize?: string;
265
+ key: string;
266
+ } | {
267
+ label: import("../resource/types.js").Label;
268
+ column?: string;
269
+ required?: boolean;
270
+ unique?: boolean;
271
+ sortable?: boolean;
272
+ searchable?: boolean;
273
+ filterable?: boolean;
274
+ permissionLevel?: number;
275
+ sequence?: string;
276
+ type: "belongsTo";
277
+ resource: string;
278
+ key: string;
279
+ } | {
280
+ label: import("../resource/types.js").Label;
281
+ column?: string;
282
+ required?: boolean;
283
+ unique?: boolean;
284
+ sortable?: boolean;
285
+ searchable?: boolean;
286
+ filterable?: boolean;
287
+ permissionLevel?: number;
288
+ sequence?: string;
289
+ type: "user";
290
+ key: string;
291
+ } | {
292
+ label: import("../resource/types.js").Label;
293
+ column?: string;
294
+ required?: boolean;
295
+ unique?: boolean;
296
+ sortable?: boolean;
297
+ searchable?: boolean;
298
+ filterable?: boolean;
299
+ permissionLevel?: number;
300
+ sequence?: string;
301
+ type: "hasMany";
302
+ resource: string;
303
+ foreignKey: string;
304
+ inline?: boolean;
305
+ key: string;
306
+ } | {
307
+ label: import("../resource/types.js").Label;
308
+ column?: string;
309
+ required?: boolean;
310
+ unique?: boolean;
311
+ sortable?: boolean;
312
+ searchable?: boolean;
313
+ filterable?: boolean;
314
+ permissionLevel?: number;
315
+ sequence?: string;
316
+ type: "lookup";
317
+ group: string;
318
+ key: string;
319
+ })[];
320
+ /** Initial values of a create form, already checked against the actor's access. */
321
+ defaults: SerializedRecord;
322
+ inline: Record<string, {
323
+ rows: SerializedRecord[];
324
+ hasMore: boolean;
325
+ canCreate: boolean;
326
+ permissions: Record<string, {
327
+ update: boolean;
328
+ delete: boolean;
329
+ }>;
330
+ fields: ResourceField[];
331
+ createFields: string[];
332
+ updateFields: Record<string, string[]>;
333
+ }>;
334
+ options: Record<string, {
335
+ value: string;
336
+ label: string;
337
+ }[]>;
338
+ relationSearch: Record<string, boolean>;
339
+ orgUnits: {
340
+ value: string;
341
+ label: string;
342
+ }[];
343
+ scoped: boolean;
344
+ /** The belongsTo field whose record decides the unit; the form shows no unit picker. */
345
+ scopeFrom: string | null;
346
+ record: SerializedRecord | null;
347
+ }>;
348
+ save(name: string, actor: Actor, input: RecordData, id?: number, transaction?: Knex.Transaction): Promise<SerializedRecord>;
349
+ /**
350
+ * A write decided by module code rather than by a user's role rules: state transitions,
351
+ * snapshots and listener updates. It runs the validator, hooks, lookup, relation and
352
+ * attachment checks, versioning and the audit trail exactly like save(), and skips only
353
+ * the actor's role rules and organization scope. Values may set any stored field except
354
+ * sequences and inline children. Updates merge the given values into the stored record.
355
+ * Returns the full stored record; module code must not send it to users unfiltered.
356
+ */
357
+ systemSave(name: string, values: RecordData, id: number | undefined, options: SystemSaveOptions): Promise<RecordData>;
358
+ /**
359
+ * Moves the records whose scope follows this parent (`scope: { from }`) to the parent's
360
+ * current organization unit, through systemSave. Call it from a listener on the parent's
361
+ * `updated` event, or right after moving the parent. Returns the number of moved records.
362
+ */
363
+ rehome(parentName: string, parentId: number, options: Omit<SystemSaveOptions, 'version'>): Promise<number>;
364
+ private persist;
365
+ private requireVersion;
366
+ /** Inline children share the parent's draft state, organization and update authority. */
367
+ private requireInlineParents;
368
+ transition(name: string, id: number, actor: Actor, action: 'delete' | 'submit' | 'cancel', version?: unknown, transaction?: Knex.Transaction): Promise<SerializedRecord>;
369
+ /**
370
+ * Amend-by-copy: a cancelled document is copied into a new draft that points to
371
+ * it through amended_from_id, together with its inline lines. The original stays
372
+ * cancelled and unchanged; sequence fields receive new numbers.
373
+ */
374
+ amend(name: string, id: number, actor: Actor, transaction?: Knex.Transaction): Promise<SerializedRecord>;
375
+ private audit;
376
+ }