@eloxiv/contracts 0.0.0-stage → 0.1.1

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 (537) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +6 -2
  3. package/dist/Agent.d.ts +792 -0
  4. package/dist/Agent.d.ts.map +1 -0
  5. package/dist/Agent.js +610 -0
  6. package/dist/Agent.js.map +1 -0
  7. package/dist/Analytics.d.ts +46 -0
  8. package/dist/Analytics.d.ts.map +1 -0
  9. package/dist/Analytics.js +89 -0
  10. package/dist/Analytics.js.map +1 -0
  11. package/dist/Approval.d.ts +70 -0
  12. package/dist/Approval.d.ts.map +1 -0
  13. package/dist/Approval.js +127 -0
  14. package/dist/Approval.js.map +1 -0
  15. package/dist/Catalog.d.ts +238 -0
  16. package/dist/Catalog.d.ts.map +1 -0
  17. package/dist/Catalog.js +169 -0
  18. package/dist/Catalog.js.map +1 -0
  19. package/dist/Checklist.d.ts +99 -0
  20. package/dist/Checklist.d.ts.map +1 -0
  21. package/dist/Checklist.js +105 -0
  22. package/dist/Checklist.js.map +1 -0
  23. package/dist/Data.d.ts +107 -0
  24. package/dist/Data.d.ts.map +1 -0
  25. package/dist/Data.js +93 -0
  26. package/dist/Data.js.map +1 -0
  27. package/dist/Devices.d.ts +857 -0
  28. package/dist/Devices.d.ts.map +1 -0
  29. package/dist/Devices.js +590 -0
  30. package/dist/Devices.js.map +1 -0
  31. package/dist/Durable.d.ts +406 -0
  32. package/dist/Durable.d.ts.map +1 -0
  33. package/dist/Durable.js +203 -0
  34. package/dist/Durable.js.map +1 -0
  35. package/dist/Errors.d.ts +95 -0
  36. package/dist/Errors.d.ts.map +1 -0
  37. package/dist/Errors.js +72 -0
  38. package/dist/Errors.js.map +1 -0
  39. package/dist/JsonSchema.d.ts +355 -0
  40. package/dist/JsonSchema.d.ts.map +1 -0
  41. package/dist/JsonSchema.js +151 -0
  42. package/dist/JsonSchema.js.map +1 -0
  43. package/dist/Manifest.d.ts +353 -0
  44. package/dist/Manifest.d.ts.map +1 -0
  45. package/dist/Manifest.js +894 -0
  46. package/dist/Manifest.js.map +1 -0
  47. package/dist/Module.d.ts +447 -0
  48. package/dist/Module.d.ts.map +1 -0
  49. package/dist/Module.js +221 -0
  50. package/dist/Module.js.map +1 -0
  51. package/dist/Optimistic.d.ts +192 -0
  52. package/dist/Optimistic.d.ts.map +1 -0
  53. package/dist/Optimistic.js +319 -0
  54. package/dist/Optimistic.js.map +1 -0
  55. package/dist/Projection.d.ts +163 -0
  56. package/dist/Projection.d.ts.map +1 -0
  57. package/dist/Projection.js +158 -0
  58. package/dist/Projection.js.map +1 -0
  59. package/dist/Proposals.d.ts +103 -0
  60. package/dist/Proposals.d.ts.map +1 -0
  61. package/dist/Proposals.js +72 -0
  62. package/dist/Proposals.js.map +1 -0
  63. package/dist/Receipt.d.ts +243 -0
  64. package/dist/Receipt.d.ts.map +1 -0
  65. package/dist/Receipt.js +108 -0
  66. package/dist/Receipt.js.map +1 -0
  67. package/dist/Records.d.ts +297 -0
  68. package/dist/Records.d.ts.map +1 -0
  69. package/dist/Records.js +171 -0
  70. package/dist/Records.js.map +1 -0
  71. package/dist/Render.d.ts +207 -0
  72. package/dist/Render.d.ts.map +1 -0
  73. package/dist/Render.js +502 -0
  74. package/dist/Render.js.map +1 -0
  75. package/dist/Rpc.d.ts +115 -0
  76. package/dist/Rpc.d.ts.map +1 -0
  77. package/dist/Rpc.js +68 -0
  78. package/dist/Rpc.js.map +1 -0
  79. package/dist/SearchLanguages.d.ts +4 -0
  80. package/dist/SearchLanguages.d.ts.map +1 -0
  81. package/dist/SearchLanguages.js +33 -0
  82. package/dist/SearchLanguages.js.map +1 -0
  83. package/dist/Service.d.ts +59 -0
  84. package/dist/Service.d.ts.map +1 -0
  85. package/dist/Service.js +38 -0
  86. package/dist/Service.js.map +1 -0
  87. package/dist/Versions.d.ts +9 -0
  88. package/dist/Versions.d.ts.map +1 -0
  89. package/dist/Versions.js +78 -0
  90. package/dist/Versions.js.map +1 -0
  91. package/dist/contracts/ActionConsent.d.ts +189 -0
  92. package/dist/contracts/ActionConsent.d.ts.map +1 -0
  93. package/dist/contracts/ActionConsent.js +129 -0
  94. package/dist/contracts/ActionConsent.js.map +1 -0
  95. package/dist/contracts/ActionRegistry.d.ts +149 -0
  96. package/dist/contracts/ActionRegistry.d.ts.map +1 -0
  97. package/dist/contracts/ActionRegistry.js +37 -0
  98. package/dist/contracts/ActionRegistry.js.map +1 -0
  99. package/dist/contracts/Actor.d.ts +129 -0
  100. package/dist/contracts/Actor.d.ts.map +1 -0
  101. package/dist/contracts/Actor.js +47 -0
  102. package/dist/contracts/Actor.js.map +1 -0
  103. package/dist/contracts/AgentResources.d.ts +248 -0
  104. package/dist/contracts/AgentResources.d.ts.map +1 -0
  105. package/dist/contracts/AgentResources.js +158 -0
  106. package/dist/contracts/AgentResources.js.map +1 -0
  107. package/dist/contracts/AgentRuntime.d.ts +453 -0
  108. package/dist/contracts/AgentRuntime.d.ts.map +1 -0
  109. package/dist/contracts/AgentRuntime.js +117 -0
  110. package/dist/contracts/AgentRuntime.js.map +1 -0
  111. package/dist/contracts/Approvals.d.ts +303 -0
  112. package/dist/contracts/Approvals.d.ts.map +1 -0
  113. package/dist/contracts/Approvals.js +117 -0
  114. package/dist/contracts/Approvals.js.map +1 -0
  115. package/dist/contracts/Audit.d.ts +510 -0
  116. package/dist/contracts/Audit.d.ts.map +1 -0
  117. package/dist/contracts/Audit.js +139 -0
  118. package/dist/contracts/Audit.js.map +1 -0
  119. package/dist/contracts/CalendarProvider.d.ts +572 -0
  120. package/dist/contracts/CalendarProvider.d.ts.map +1 -0
  121. package/dist/contracts/CalendarProvider.js +203 -0
  122. package/dist/contracts/CalendarProvider.js.map +1 -0
  123. package/dist/contracts/Capability.d.ts +197 -0
  124. package/dist/contracts/Capability.d.ts.map +1 -0
  125. package/dist/contracts/Capability.js +189 -0
  126. package/dist/contracts/Capability.js.map +1 -0
  127. package/dist/contracts/ClientSDK.d.ts +250 -0
  128. package/dist/contracts/ClientSDK.d.ts.map +1 -0
  129. package/dist/contracts/ClientSDK.js +184 -0
  130. package/dist/contracts/ClientSDK.js.map +1 -0
  131. package/dist/contracts/CollabDocument.d.ts +781 -0
  132. package/dist/contracts/CollabDocument.d.ts.map +1 -0
  133. package/dist/contracts/CollabDocument.js +364 -0
  134. package/dist/contracts/CollabDocument.js.map +1 -0
  135. package/dist/contracts/Command.d.ts +183 -0
  136. package/dist/contracts/Command.d.ts.map +1 -0
  137. package/dist/contracts/Command.js +66 -0
  138. package/dist/contracts/Command.js.map +1 -0
  139. package/dist/contracts/Connections.d.ts +612 -0
  140. package/dist/contracts/Connections.d.ts.map +1 -0
  141. package/dist/contracts/Connections.js +323 -0
  142. package/dist/contracts/Connections.js.map +1 -0
  143. package/dist/contracts/ContextAccounting.d.ts +79 -0
  144. package/dist/contracts/ContextAccounting.d.ts.map +1 -0
  145. package/dist/contracts/ContextAccounting.js +32 -0
  146. package/dist/contracts/ContextAccounting.js.map +1 -0
  147. package/dist/contracts/Daemon.d.ts +486 -0
  148. package/dist/contracts/Daemon.d.ts.map +1 -0
  149. package/dist/contracts/Daemon.js +192 -0
  150. package/dist/contracts/Daemon.js.map +1 -0
  151. package/dist/contracts/DbTx.d.ts +149 -0
  152. package/dist/contracts/DbTx.d.ts.map +1 -0
  153. package/dist/contracts/DbTx.js +94 -0
  154. package/dist/contracts/DbTx.js.map +1 -0
  155. package/dist/contracts/Delegation.d.ts +121 -0
  156. package/dist/contracts/Delegation.d.ts.map +1 -0
  157. package/dist/contracts/Delegation.js +76 -0
  158. package/dist/contracts/Delegation.js.map +1 -0
  159. package/dist/contracts/DeviceControl.d.ts +293 -0
  160. package/dist/contracts/DeviceControl.d.ts.map +1 -0
  161. package/dist/contracts/DeviceControl.js +107 -0
  162. package/dist/contracts/DeviceControl.js.map +1 -0
  163. package/dist/contracts/Directory.d.ts +492 -0
  164. package/dist/contracts/Directory.d.ts.map +1 -0
  165. package/dist/contracts/Directory.js +225 -0
  166. package/dist/contracts/Directory.js.map +1 -0
  167. package/dist/contracts/DirectoryProvider.d.ts +214 -0
  168. package/dist/contracts/DirectoryProvider.d.ts.map +1 -0
  169. package/dist/contracts/DirectoryProvider.js +73 -0
  170. package/dist/contracts/DirectoryProvider.js.map +1 -0
  171. package/dist/contracts/DocumentSource.d.ts +190 -0
  172. package/dist/contracts/DocumentSource.d.ts.map +1 -0
  173. package/dist/contracts/DocumentSource.js +64 -0
  174. package/dist/contracts/DocumentSource.js.map +1 -0
  175. package/dist/contracts/Files.d.ts +762 -0
  176. package/dist/contracts/Files.d.ts.map +1 -0
  177. package/dist/contracts/Files.js +339 -0
  178. package/dist/contracts/Files.js.map +1 -0
  179. package/dist/contracts/Flags.d.ts +265 -0
  180. package/dist/contracts/Flags.d.ts.map +1 -0
  181. package/dist/contracts/Flags.js +197 -0
  182. package/dist/contracts/Flags.js.map +1 -0
  183. package/dist/contracts/Host.d.ts +320 -0
  184. package/dist/contracts/Host.d.ts.map +1 -0
  185. package/dist/contracts/Host.js +224 -0
  186. package/dist/contracts/Host.js.map +1 -0
  187. package/dist/contracts/HttpApi.d.ts +102 -0
  188. package/dist/contracts/HttpApi.d.ts.map +1 -0
  189. package/dist/contracts/HttpApi.js +89 -0
  190. package/dist/contracts/HttpApi.js.map +1 -0
  191. package/dist/contracts/Ingestion.d.ts +522 -0
  192. package/dist/contracts/Ingestion.d.ts.map +1 -0
  193. package/dist/contracts/Ingestion.js +275 -0
  194. package/dist/contracts/Ingestion.js.map +1 -0
  195. package/dist/contracts/Ingress.d.ts +132 -0
  196. package/dist/contracts/Ingress.d.ts.map +1 -0
  197. package/dist/contracts/Ingress.js +102 -0
  198. package/dist/contracts/Ingress.js.map +1 -0
  199. package/dist/contracts/Invocation.d.ts +361 -0
  200. package/dist/contracts/Invocation.d.ts.map +1 -0
  201. package/dist/contracts/Invocation.js +104 -0
  202. package/dist/contracts/Invocation.js.map +1 -0
  203. package/dist/contracts/LocalClient.d.ts +888 -0
  204. package/dist/contracts/LocalClient.d.ts.map +1 -0
  205. package/dist/contracts/LocalClient.js +429 -0
  206. package/dist/contracts/LocalClient.js.map +1 -0
  207. package/dist/contracts/Locale.d.ts +162 -0
  208. package/dist/contracts/Locale.d.ts.map +1 -0
  209. package/dist/contracts/Locale.js +123 -0
  210. package/dist/contracts/Locale.js.map +1 -0
  211. package/dist/contracts/MachineIdentity.d.ts +434 -0
  212. package/dist/contracts/MachineIdentity.d.ts.map +1 -0
  213. package/dist/contracts/MachineIdentity.js +223 -0
  214. package/dist/contracts/MachineIdentity.js.map +1 -0
  215. package/dist/contracts/MailProvider.d.ts +791 -0
  216. package/dist/contracts/MailProvider.d.ts.map +1 -0
  217. package/dist/contracts/MailProvider.js +237 -0
  218. package/dist/contracts/MailProvider.js.map +1 -0
  219. package/dist/contracts/Memory.d.ts +62 -0
  220. package/dist/contracts/Memory.d.ts.map +1 -0
  221. package/dist/contracts/Memory.js +43 -0
  222. package/dist/contracts/Memory.js.map +1 -0
  223. package/dist/contracts/Messaging.d.ts +154 -0
  224. package/dist/contracts/Messaging.d.ts.map +1 -0
  225. package/dist/contracts/Messaging.js +97 -0
  226. package/dist/contracts/Messaging.js.map +1 -0
  227. package/dist/contracts/Metering.d.ts +334 -0
  228. package/dist/contracts/Metering.d.ts.map +1 -0
  229. package/dist/contracts/Metering.js +202 -0
  230. package/dist/contracts/Metering.js.map +1 -0
  231. package/dist/contracts/ModelProvider.d.ts +142 -0
  232. package/dist/contracts/ModelProvider.d.ts.map +1 -0
  233. package/dist/contracts/ModelProvider.js +72 -0
  234. package/dist/contracts/ModelProvider.js.map +1 -0
  235. package/dist/contracts/ModuleManifest.d.ts +2519 -0
  236. package/dist/contracts/ModuleManifest.d.ts.map +1 -0
  237. package/dist/contracts/ModuleManifest.js +272 -0
  238. package/dist/contracts/ModuleManifest.js.map +1 -0
  239. package/dist/contracts/NotificationChannel.d.ts +378 -0
  240. package/dist/contracts/NotificationChannel.d.ts.map +1 -0
  241. package/dist/contracts/NotificationChannel.js +136 -0
  242. package/dist/contracts/NotificationChannel.js.map +1 -0
  243. package/dist/contracts/Notifications.d.ts +417 -0
  244. package/dist/contracts/Notifications.d.ts.map +1 -0
  245. package/dist/contracts/Notifications.js +267 -0
  246. package/dist/contracts/Notifications.js.map +1 -0
  247. package/dist/contracts/Outbox.d.ts +469 -0
  248. package/dist/contracts/Outbox.d.ts.map +1 -0
  249. package/dist/contracts/Outbox.js +215 -0
  250. package/dist/contracts/Outbox.js.map +1 -0
  251. package/dist/contracts/Privacy.d.ts +1029 -0
  252. package/dist/contracts/Privacy.d.ts.map +1 -0
  253. package/dist/contracts/Privacy.js +437 -0
  254. package/dist/contracts/Privacy.js.map +1 -0
  255. package/dist/contracts/Progress.d.ts +305 -0
  256. package/dist/contracts/Progress.d.ts.map +1 -0
  257. package/dist/contracts/Progress.js +174 -0
  258. package/dist/contracts/Progress.js.map +1 -0
  259. package/dist/contracts/QuerySurface.d.ts +231 -0
  260. package/dist/contracts/QuerySurface.d.ts.map +1 -0
  261. package/dist/contracts/QuerySurface.js +113 -0
  262. package/dist/contracts/QuerySurface.js.map +1 -0
  263. package/dist/contracts/Readiness.d.ts +105 -0
  264. package/dist/contracts/Readiness.d.ts.map +1 -0
  265. package/dist/contracts/Readiness.js +57 -0
  266. package/dist/contracts/Readiness.js.map +1 -0
  267. package/dist/contracts/Release.d.ts +295 -0
  268. package/dist/contracts/Release.d.ts.map +1 -0
  269. package/dist/contracts/Release.js +175 -0
  270. package/dist/contracts/Release.js.map +1 -0
  271. package/dist/contracts/ResultRendering.d.ts +533 -0
  272. package/dist/contracts/ResultRendering.d.ts.map +1 -0
  273. package/dist/contracts/ResultRendering.js +59 -0
  274. package/dist/contracts/ResultRendering.js.map +1 -0
  275. package/dist/contracts/Sandbox.d.ts +1164 -0
  276. package/dist/contracts/Sandbox.d.ts.map +1 -0
  277. package/dist/contracts/Sandbox.js +550 -0
  278. package/dist/contracts/Sandbox.js.map +1 -0
  279. package/dist/contracts/Scheduler.d.ts +814 -0
  280. package/dist/contracts/Scheduler.d.ts.map +1 -0
  281. package/dist/contracts/Scheduler.js +202 -0
  282. package/dist/contracts/Scheduler.js.map +1 -0
  283. package/dist/contracts/ScreenContext.d.ts +514 -0
  284. package/dist/contracts/ScreenContext.d.ts.map +1 -0
  285. package/dist/contracts/ScreenContext.js +272 -0
  286. package/dist/contracts/ScreenContext.js.map +1 -0
  287. package/dist/contracts/Search.d.ts +308 -0
  288. package/dist/contracts/Search.d.ts.map +1 -0
  289. package/dist/contracts/Search.js +107 -0
  290. package/dist/contracts/Search.js.map +1 -0
  291. package/dist/contracts/Secrets.d.ts +483 -0
  292. package/dist/contracts/Secrets.d.ts.map +1 -0
  293. package/dist/contracts/Secrets.js +136 -0
  294. package/dist/contracts/Secrets.js.map +1 -0
  295. package/dist/contracts/Settings.d.ts +221 -0
  296. package/dist/contracts/Settings.d.ts.map +1 -0
  297. package/dist/contracts/Settings.js +163 -0
  298. package/dist/contracts/Settings.js.map +1 -0
  299. package/dist/contracts/Sharing.d.ts +319 -0
  300. package/dist/contracts/Sharing.d.ts.map +1 -0
  301. package/dist/contracts/Sharing.js +172 -0
  302. package/dist/contracts/Sharing.js.map +1 -0
  303. package/dist/contracts/Slot.d.ts +162 -0
  304. package/dist/contracts/Slot.d.ts.map +1 -0
  305. package/dist/contracts/Slot.js +56 -0
  306. package/dist/contracts/Slot.js.map +1 -0
  307. package/dist/contracts/Space.d.ts +256 -0
  308. package/dist/contracts/Space.d.ts.map +1 -0
  309. package/dist/contracts/Space.js +133 -0
  310. package/dist/contracts/Space.js.map +1 -0
  311. package/dist/contracts/StorageAdapter.d.ts +124 -0
  312. package/dist/contracts/StorageAdapter.d.ts.map +1 -0
  313. package/dist/contracts/StorageAdapter.js +96 -0
  314. package/dist/contracts/StorageAdapter.js.map +1 -0
  315. package/dist/contracts/StorageBackend.d.ts +310 -0
  316. package/dist/contracts/StorageBackend.d.ts.map +1 -0
  317. package/dist/contracts/StorageBackend.js +196 -0
  318. package/dist/contracts/StorageBackend.js.map +1 -0
  319. package/dist/contracts/Sync.d.ts +286 -0
  320. package/dist/contracts/Sync.d.ts.map +1 -0
  321. package/dist/contracts/Sync.js +157 -0
  322. package/dist/contracts/Sync.js.map +1 -0
  323. package/dist/contracts/Telemetry.d.ts +183 -0
  324. package/dist/contracts/Telemetry.d.ts.map +1 -0
  325. package/dist/contracts/Telemetry.js +153 -0
  326. package/dist/contracts/Telemetry.js.map +1 -0
  327. package/dist/contracts/ThemeTokens.d.ts +212 -0
  328. package/dist/contracts/ThemeTokens.d.ts.map +1 -0
  329. package/dist/contracts/ThemeTokens.js +111 -0
  330. package/dist/contracts/ThemeTokens.js.map +1 -0
  331. package/dist/contracts/ToolSource.d.ts +135 -0
  332. package/dist/contracts/ToolSource.d.ts.map +1 -0
  333. package/dist/contracts/ToolSource.js +81 -0
  334. package/dist/contracts/ToolSource.js.map +1 -0
  335. package/dist/contracts/Versioning.d.ts +363 -0
  336. package/dist/contracts/Versioning.d.ts.map +1 -0
  337. package/dist/contracts/Versioning.js +201 -0
  338. package/dist/contracts/Versioning.js.map +1 -0
  339. package/dist/contracts/View.d.ts +232 -0
  340. package/dist/contracts/View.d.ts.map +1 -0
  341. package/dist/contracts/View.js +102 -0
  342. package/dist/contracts/View.js.map +1 -0
  343. package/dist/contracts/WorkItems.d.ts +242 -0
  344. package/dist/contracts/WorkItems.d.ts.map +1 -0
  345. package/dist/contracts/WorkItems.js +126 -0
  346. package/dist/contracts/WorkItems.js.map +1 -0
  347. package/dist/contracts/Workflow.d.ts +191 -0
  348. package/dist/contracts/Workflow.d.ts.map +1 -0
  349. package/dist/contracts/Workflow.js +63 -0
  350. package/dist/contracts/Workflow.js.map +1 -0
  351. package/dist/contracts/index.d.ts +75 -0
  352. package/dist/contracts/index.d.ts.map +1 -0
  353. package/dist/contracts/index.js +196 -0
  354. package/dist/contracts/index.js.map +1 -0
  355. package/dist/devices/module.d.ts +3777 -0
  356. package/dist/devices/module.d.ts.map +1 -0
  357. package/dist/devices/module.js +179 -0
  358. package/dist/devices/module.js.map +1 -0
  359. package/dist/drizzle/Entity.d.ts +148 -0
  360. package/dist/drizzle/Entity.d.ts.map +1 -0
  361. package/dist/drizzle/Entity.js +396 -0
  362. package/dist/drizzle/Entity.js.map +1 -0
  363. package/dist/index.d.ts +20 -0
  364. package/dist/index.d.ts.map +1 -0
  365. package/dist/index.js +20 -0
  366. package/dist/index.js.map +1 -0
  367. package/package.json +48 -3
  368. package/schema/Actor.json +46 -0
  369. package/schema/AuditRecord.json +403 -0
  370. package/schema/DaemonHealth.json +29 -0
  371. package/schema/InvocationError.json +257 -0
  372. package/schema/InvocationReceipt.json +253 -0
  373. package/schema/Lockfile.json +129 -0
  374. package/schema/OutboxEvent.json +36 -0
  375. package/schema/PairingConfirm.json +33 -0
  376. package/schema/PairingResult.json +18 -0
  377. package/schema/PairingStart.json +18 -0
  378. package/schema/ProvenanceEntry.json +110 -0
  379. package/schema/ReplayEnvelope.json +269 -0
  380. package/schema/Surface.json +17 -0
  381. package/schema/codegen/LocalClient.json +1298 -0
  382. package/schema/codegen/Sandbox.json +320 -0
  383. package/schema/contracts/ActionConsent.json +1930 -0
  384. package/schema/contracts/ActionRegistry.json +722 -0
  385. package/schema/contracts/Actor.json +451 -0
  386. package/schema/contracts/AgentResources.json +1400 -0
  387. package/schema/contracts/AgentRuntime.json +4017 -0
  388. package/schema/contracts/Approvals.json +2916 -0
  389. package/schema/contracts/Audit.json +3268 -0
  390. package/schema/contracts/CalendarProvider.json +5557 -0
  391. package/schema/contracts/ClientSDK.json +1400 -0
  392. package/schema/contracts/CollabDocument.json +4012 -0
  393. package/schema/contracts/Command.json +616 -0
  394. package/schema/contracts/Connections.json +6687 -0
  395. package/schema/contracts/ContextAccounting.json +685 -0
  396. package/schema/contracts/Daemon.json +4555 -0
  397. package/schema/contracts/DbTx.json +321 -0
  398. package/schema/contracts/Delegation.json +949 -0
  399. package/schema/contracts/DeviceControl.json +2626 -0
  400. package/schema/contracts/Directory.json +5168 -0
  401. package/schema/contracts/DirectoryProvider.json +2090 -0
  402. package/schema/contracts/DocumentSource.json +2044 -0
  403. package/schema/contracts/Files.json +4122 -0
  404. package/schema/contracts/Flags.json +1202 -0
  405. package/schema/contracts/Host.json +1769 -0
  406. package/schema/contracts/HttpApi.json +1615 -0
  407. package/schema/contracts/Ingestion.json +3211 -0
  408. package/schema/contracts/Ingress.json +819 -0
  409. package/schema/contracts/Invocation.json +2044 -0
  410. package/schema/contracts/LocalClient.json +6657 -0
  411. package/schema/contracts/Locale.json +654 -0
  412. package/schema/contracts/MachineIdentity.json +2303 -0
  413. package/schema/contracts/MailProvider.json +6663 -0
  414. package/schema/contracts/Memory.json +579 -0
  415. package/schema/contracts/Messaging.json +1764 -0
  416. package/schema/contracts/Metering.json +3060 -0
  417. package/schema/contracts/ModelProvider.json +1127 -0
  418. package/schema/contracts/ModuleManifest.json +9449 -0
  419. package/schema/contracts/NotificationChannel.json +986 -0
  420. package/schema/contracts/Notifications.json +4280 -0
  421. package/schema/contracts/Outbox.json +1451 -0
  422. package/schema/contracts/Privacy.json +4354 -0
  423. package/schema/contracts/Progress.json +1524 -0
  424. package/schema/contracts/QuerySurface.json +661 -0
  425. package/schema/contracts/Readiness.json +209 -0
  426. package/schema/contracts/Release.json +805 -0
  427. package/schema/contracts/ResultRendering.json +2859 -0
  428. package/schema/contracts/Sandbox.json +2286 -0
  429. package/schema/contracts/Scheduler.json +6138 -0
  430. package/schema/contracts/ScreenContext.json +1238 -0
  431. package/schema/contracts/Search.json +1058 -0
  432. package/schema/contracts/Secrets.json +2444 -0
  433. package/schema/contracts/Settings.json +654 -0
  434. package/schema/contracts/Sharing.json +2854 -0
  435. package/schema/contracts/Slot.json +537 -0
  436. package/schema/contracts/Space.json +892 -0
  437. package/schema/contracts/StorageAdapter.json +623 -0
  438. package/schema/contracts/StorageBackend.json +2421 -0
  439. package/schema/contracts/Sync.json +894 -0
  440. package/schema/contracts/Telemetry.json +696 -0
  441. package/schema/contracts/ThemeTokens.json +547 -0
  442. package/schema/contracts/ToolSource.json +1333 -0
  443. package/schema/contracts/Versioning.json +1481 -0
  444. package/schema/contracts/View.json +750 -0
  445. package/schema/contracts/WorkItems.json +1731 -0
  446. package/schema/contracts/Workflow.json +1242 -0
  447. package/src/Agent.ts +758 -0
  448. package/src/Analytics.ts +110 -0
  449. package/src/Approval.ts +131 -0
  450. package/src/Catalog.ts +192 -0
  451. package/src/Checklist.ts +162 -0
  452. package/src/Data.ts +109 -0
  453. package/src/Devices.ts +721 -0
  454. package/src/Durable.ts +240 -0
  455. package/src/Errors.ts +111 -0
  456. package/src/JsonSchema.ts +166 -0
  457. package/src/Manifest.ts +1147 -0
  458. package/src/Module.ts +640 -0
  459. package/src/Optimistic.ts +332 -0
  460. package/src/Projection.ts +207 -0
  461. package/src/Proposals.ts +89 -0
  462. package/src/Receipt.ts +125 -0
  463. package/src/Records.ts +197 -0
  464. package/src/Render.ts +515 -0
  465. package/src/Rpc.ts +113 -0
  466. package/src/SearchLanguages.ts +33 -0
  467. package/src/Service.ts +102 -0
  468. package/src/Versions.ts +69 -0
  469. package/src/contracts/ActionConsent.ts +150 -0
  470. package/src/contracts/ActionRegistry.ts +39 -0
  471. package/src/contracts/Actor.ts +53 -0
  472. package/src/contracts/AgentResources.ts +167 -0
  473. package/src/contracts/AgentRuntime.ts +154 -0
  474. package/src/contracts/Approvals.ts +133 -0
  475. package/src/contracts/Audit.ts +160 -0
  476. package/src/contracts/CalendarProvider.ts +241 -0
  477. package/src/contracts/Capability.ts +246 -0
  478. package/src/contracts/ClientSDK.ts +199 -0
  479. package/src/contracts/CollabDocument.ts +420 -0
  480. package/src/contracts/Command.ts +74 -0
  481. package/src/contracts/Connections.ts +360 -0
  482. package/src/contracts/ContextAccounting.ts +35 -0
  483. package/src/contracts/Daemon.ts +247 -0
  484. package/src/contracts/DbTx.ts +110 -0
  485. package/src/contracts/Delegation.ts +91 -0
  486. package/src/contracts/DeviceControl.ts +143 -0
  487. package/src/contracts/Directory.ts +384 -0
  488. package/src/contracts/DirectoryProvider.ts +82 -0
  489. package/src/contracts/DocumentSource.ts +71 -0
  490. package/src/contracts/Files.ts +395 -0
  491. package/src/contracts/Flags.ts +241 -0
  492. package/src/contracts/Host.ts +245 -0
  493. package/src/contracts/HttpApi.ts +100 -0
  494. package/src/contracts/Ingestion.ts +315 -0
  495. package/src/contracts/Ingress.ts +132 -0
  496. package/src/contracts/Invocation.ts +122 -0
  497. package/src/contracts/LocalClient.ts +620 -0
  498. package/src/contracts/Locale.ts +133 -0
  499. package/src/contracts/MachineIdentity.ts +305 -0
  500. package/src/contracts/MailProvider.ts +272 -0
  501. package/src/contracts/Memory.ts +47 -0
  502. package/src/contracts/Messaging.ts +108 -0
  503. package/src/contracts/Metering.ts +231 -0
  504. package/src/contracts/ModelProvider.ts +87 -0
  505. package/src/contracts/ModuleManifest.ts +310 -0
  506. package/src/contracts/NotificationChannel.ts +158 -0
  507. package/src/contracts/Notifications.ts +309 -0
  508. package/src/contracts/Outbox.ts +246 -0
  509. package/src/contracts/Privacy.ts +502 -0
  510. package/src/contracts/Progress.ts +196 -0
  511. package/src/contracts/QuerySurface.ts +134 -0
  512. package/src/contracts/Readiness.ts +67 -0
  513. package/src/contracts/Release.ts +199 -0
  514. package/src/contracts/ResultRendering.ts +65 -0
  515. package/src/contracts/Sandbox.ts +648 -0
  516. package/src/contracts/Scheduler.ts +237 -0
  517. package/src/contracts/ScreenContext.ts +316 -0
  518. package/src/contracts/Search.ts +126 -0
  519. package/src/contracts/Secrets.ts +162 -0
  520. package/src/contracts/Settings.ts +207 -0
  521. package/src/contracts/Sharing.ts +205 -0
  522. package/src/contracts/Slot.ts +61 -0
  523. package/src/contracts/Space.ts +157 -0
  524. package/src/contracts/StorageAdapter.ts +104 -0
  525. package/src/contracts/StorageBackend.ts +220 -0
  526. package/src/contracts/Sync.ts +180 -0
  527. package/src/contracts/Telemetry.ts +177 -0
  528. package/src/contracts/ThemeTokens.ts +136 -0
  529. package/src/contracts/ToolSource.ts +94 -0
  530. package/src/contracts/Versioning.ts +237 -0
  531. package/src/contracts/View.ts +116 -0
  532. package/src/contracts/WorkItems.ts +144 -0
  533. package/src/contracts/Workflow.ts +67 -0
  534. package/src/contracts/index.ts +205 -0
  535. package/src/devices/module.ts +201 -0
  536. package/src/drizzle/Entity.ts +524 -0
  537. package/src/index.ts +19 -0
@@ -0,0 +1,1147 @@
1
+ /**
2
+ * The module manifest's declarations beyond entities, actions and events
3
+ * (decisions.md "Kernel contracts"): permission vocabulary, settings, skills,
4
+ * views, slots and contributions, commands, work-item sources (decision 3),
5
+ * entity resolvers and published query views (decision 6). Each is data, with
6
+ * Effect Schema for every value it types, so it emits as JSON Schema
7
+ * (`moduleToJson`) and another language can read and check it.
8
+ *
9
+ * `manifestProblems` checks the declarations of every installed module
10
+ * together: references must resolve (entities, actions, views, slots, query
11
+ * views), ids must be namespaced by their module and unique where they are
12
+ * global, defaults must decode against their schemas, and published query
13
+ * views must be plain `SELECT`s over the module's own schema. The kernel runs it
14
+ * when it builds its registry and refuses to start an app with any problem.
15
+ *
16
+ * Jobs are declared by the Scheduler contract (`jobs`), which adds its own field;
17
+ * `manifestProblems` checks them too: each must invoke an installed action with
18
+ * input that action accepts, on a cron or interval schedule.
19
+ */
20
+ import { Exit, Schema } from "effect"
21
+ import { ApprovalRule, approvalRuleShapeProblems } from "./Approval.ts"
22
+ import { analyticsEventProblems, type AnalyticsEventDeclaration } from "./Analytics.ts"
23
+ import { renderProblems, type RenderDeclaration } from "./Render.ts"
24
+ import { satisfiesRange } from "./Versions.ts"
25
+ import { CatchUp, ScheduleSpec } from "./Durable.ts"
26
+ import type { AnyAction, AnyEntity, AnyModuleContract, EntityCollab } from "./Module.ts"
27
+ import { BestEffortFields } from "./Module.ts"
28
+ import { optimisticProblems } from "./Optimistic.ts"
29
+ import { SEARCH_LANGUAGES } from "./SearchLanguages.ts"
30
+
31
+ // ---------------------------------------------------------------------------
32
+ // Declarations
33
+
34
+ /**
35
+ * A named permission an organisation can grant through roles (decision 1).
36
+ * Policies test it as `principal.permissions.contains("<id>")`; `actions` names
37
+ * the module's actions (or `read`) whose policy the permission is meant for, so
38
+ * an administrator can see what granting it allows.
39
+ */
40
+ export interface PermissionDeclaration {
41
+ readonly description: string
42
+ /** Action names of this module (e.g. `hello.greet`), or `read` for the module's read policy. */
43
+ readonly actions: ReadonlyArray<string>
44
+ }
45
+
46
+ /**
47
+ * A named group of the module's actions as agent tools, which an app can disable for agents
48
+ * (`KernelApp.agentTools.disabledGroups`). Every action is also in its module's own group (the module's name).
49
+ * A disabled group's actions are hidden from agents and refused to every agent-originated call, on every
50
+ * surface; people's calls are governed by policy alone.
51
+ */
52
+ export interface ToolGroupDeclaration {
53
+ readonly description: string
54
+ /** Action names of this module (e.g. `hello.greet`). */
55
+ readonly actions: ReadonlyArray<string>
56
+ }
57
+
58
+ /** Where a setting's value lives: per person, per organisation, per app deployment, or per module installation. */
59
+ export const SettingScope = Schema.Literals(["user", "org", "app", "module"])
60
+ export type SettingScope = typeof SettingScope.Type
61
+
62
+ /** A scoped value with a schema and a default, read by key (the Settings contract). */
63
+ export interface SettingDeclaration<S extends Schema.Top = Schema.Top> {
64
+ readonly description: string
65
+ readonly scope: SettingScope
66
+ readonly schema: S
67
+ /** The default, in its encoded (JSON) form; it must decode against `schema`. */
68
+ readonly default: unknown
69
+ }
70
+
71
+ /**
72
+ * A feature flag (the Flags contract): off or on per person, with a declared default. Organisation
73
+ * administrators target it in their organisation (people, groups, roles, the whole organisation, a percentage
74
+ * rollout); with no targeting it takes its default.
75
+ */
76
+ export interface FlagDeclaration {
77
+ readonly description: string
78
+ /** What the flag evaluates to when no targeting decides it. */
79
+ readonly default: boolean
80
+ /**
81
+ * A lab: each person may turn it on or off for themselves (`flags.optIn`), over what their organisation decided,
82
+ * and back (`flags.clearOptIn`); `flags.labs` lists them. Off by default.
83
+ */
84
+ readonly lab?: boolean | undefined
85
+ }
86
+
87
+ /** An agent skill document the module ships (AgentResources): inline text, or a path relative to the module's directory. */
88
+ export interface SkillDeclaration {
89
+ readonly description: string
90
+ readonly content: { readonly path: string } | { readonly text: string }
91
+ /**
92
+ * The skill's eval cases (`SkillEvals` JSON), relative to the module's directory: prompts, the tool calls a
93
+ * good run makes, assertions on the state it leaves, and the score the skill must reach.
94
+ */
95
+ readonly evals?: { readonly path: string } | undefined
96
+ /**
97
+ * Who the skill is for: the app's agent at run time (`runtime`), coding agents and tooling that build the app
98
+ * (`development`), or both (the default). A development skill is never given to the app's agent: it is not in its
99
+ * skill index, `load_skill` does not find it, and it is not among the app's resources.
100
+ */
101
+ readonly audience?: SkillAudience | undefined
102
+ /**
103
+ * A lab skill: the app's agent is given it only when this flag (one an installed module declares, `<module>.<flag>`,
104
+ * usually a lab, `lab: true`) is on for the person, by their own opt-in or their organisation's targeting.
105
+ */
106
+ readonly requires?: { readonly flag: string } | undefined
107
+ }
108
+
109
+ /** Who a skill is for (`SkillDeclaration.audience`). */
110
+ export type SkillAudience = "runtime" | "development" | "both"
111
+ export const SKILL_AUDIENCES: ReadonlyArray<SkillAudience> = ["runtime", "development", "both"]
112
+
113
+ /** A named shell view the module offers. No UI code: a UI item renders it at `route`. */
114
+ export interface ViewDeclaration {
115
+ readonly title: string
116
+ readonly description?: string | undefined
117
+ /** Shell route, unique across the app, e.g. `/hello`. */
118
+ readonly route: string
119
+ /** What the view shows: one of the module's entities, or one of its published query views. */
120
+ readonly shows: { readonly entity: string } | { readonly queryView: string }
121
+ }
122
+
123
+ /** A named extension point the module exposes; other modules contribute views or commands to it. */
124
+ export interface SlotDeclaration {
125
+ readonly description: string
126
+ readonly accepts: "view" | "command"
127
+ }
128
+
129
+ /** A contribution to a slot (of this or another module): one of this app's views or commands. */
130
+ export type ContributionDeclaration =
131
+ | { readonly slot: string; readonly view: string; readonly order?: number | undefined }
132
+ | { readonly slot: string; readonly command: string; readonly order?: number | undefined }
133
+
134
+ /** A command-palette entry: runs an action or opens a view. */
135
+ export interface CommandDeclaration {
136
+ readonly title: string
137
+ readonly description?: string | undefined
138
+ readonly keywords?: ReadonlyArray<string> | undefined
139
+ readonly run: { readonly action: string } | { readonly view: string }
140
+ }
141
+
142
+ /** The states of a work item in the unified inbox (decision 3). */
143
+ export const WorkItemState = Schema.Literals(["open", "waiting", "done"])
144
+ export type WorkItemState = typeof WorkItemState.Type
145
+
146
+ /**
147
+ * How the module feeds the unified inbox (decision 3): which entity's records
148
+ * are work items, and which fields give their title, state and assignee. The
149
+ * link back to the record is a view; the inbox reads records through the
150
+ * entity's read policy, never the module's tables directly.
151
+ */
152
+ export interface WorkItemSourceDeclaration {
153
+ readonly description: string
154
+ readonly entity: string
155
+ /** The entity field holding the item's title. */
156
+ readonly title: string
157
+ /** The field whose values map to inbox states, or one state for every record. */
158
+ readonly state:
159
+ | { readonly field: string; readonly values: Readonly<Record<string, WorkItemState>> }
160
+ | { readonly constant: WorkItemState }
161
+ /** The field holding the assigned user's id, or `null` when items have no assignee. */
162
+ readonly assignee: string | null
163
+ readonly link: { readonly view: string }
164
+ }
165
+
166
+ /**
167
+ * How another module turns a reference `{ module, entity, id }` to one of this
168
+ * module's records into a title and a link, through the entity's read policy
169
+ * and without reading the module's tables.
170
+ */
171
+ export interface EntityResolverDeclaration {
172
+ /** The entity field holding the record's title. */
173
+ readonly title: string
174
+ readonly link?: { readonly view: string } | undefined
175
+ }
176
+
177
+ /**
178
+ * A read-only SQL view over the module's own tables that the agent's query
179
+ * surface may read (decision 6). Each row is filtered by `entity`'s read
180
+ * policy, so the view must return that entity's primary-key column.
181
+ */
182
+ export interface QueryViewDeclaration {
183
+ readonly description: string
184
+ /** The entity whose read policy filters each row. */
185
+ readonly entity: string
186
+ /** One plain `SELECT` over tables in the module's own schema. */
187
+ readonly sql: string
188
+ /** The view's row: one field per output column, by column name. */
189
+ readonly row: Schema.Struct<Schema.Struct.Fields>
190
+ /** How the rows are shown to people and agents (the ResultRendering contract); checked against `row`. */
191
+ readonly render?: RenderDeclaration | undefined
192
+ }
193
+
194
+ /**
195
+ * What erasure does to a record about a person (the Privacy contract): delete it, set named fields to fixed
196
+ * values (anonymise; every subject field must be among them), or keep it, for a stated reason.
197
+ */
198
+ export type ErasureDeclaration =
199
+ | { readonly kind: "delete" }
200
+ | { readonly kind: "anonymise"; readonly set: Readonly<Record<string, string | number | boolean | null>> }
201
+ | { readonly kind: "retain"; readonly reason: string }
202
+
203
+ /**
204
+ * Records of one entity about a person (the Privacy contract): the fields holding the person's user id (a
205
+ * record is about everyone any of them names), and what erasure does to it. Exports include every such record.
206
+ */
207
+ export interface DataSubjectDeclaration {
208
+ readonly fields: ReadonlyArray<string>
209
+ readonly erase: ErasureDeclaration
210
+ /**
211
+ * What an export holds (default: every record any of `fields` names). `{ fields }` narrows it to records these
212
+ * fields name (a request's subject, not its requester); `false` exports none of them (copies of other exports).
213
+ */
214
+ readonly export?: { readonly fields: ReadonlyArray<string> } | false | undefined
215
+ }
216
+
217
+ /**
218
+ * An entity whose records are about no person (the Privacy contract), and why: with the privacy module installed,
219
+ * every entity is declared in `dataSubjects`, either with the fields naming a person or as this.
220
+ */
221
+ export interface NoDataSubjects {
222
+ readonly none: string
223
+ }
224
+
225
+ /** One entity's entry in `dataSubjects`. */
226
+ export type DataSubjectEntry = DataSubjectDeclaration | NoDataSubjects
227
+
228
+ export const isNoDataSubjects = (entry: DataSubjectEntry): entry is NoDataSubjects => "none" in entry
229
+
230
+ /** The declarations of `dataSubjects` that name a person (by entity), leaving out the entities about nobody. */
231
+ export const dataSubjectDeclarations = (
232
+ entries: Readonly<Record<string, DataSubjectEntry>> | undefined,
233
+ ): Readonly<Record<string, DataSubjectDeclaration>> =>
234
+ Object.fromEntries(
235
+ Object.entries(entries ?? {}).flatMap(([key, entry]) => (isNoDataSubjects(entry) ? [] : [[key, entry] as const])),
236
+ )
237
+
238
+ /** Every declaration a manifest carries besides entities, actions and events. Ids are namespaced by the module. */
239
+ export interface ManifestDeclarations {
240
+ readonly permissions: Readonly<Record<string, PermissionDeclaration>>
241
+ readonly settings: Readonly<Record<string, SettingDeclaration>>
242
+ /** Feature flags (the Flags contract), by id. */
243
+ readonly flags: Readonly<Record<string, FlagDeclaration>>
244
+ readonly skills: Readonly<Record<string, SkillDeclaration>>
245
+ readonly views: Readonly<Record<string, ViewDeclaration>>
246
+ readonly slots: Readonly<Record<string, SlotDeclaration>>
247
+ readonly contributions: Readonly<Record<string, ContributionDeclaration>>
248
+ readonly commands: Readonly<Record<string, CommandDeclaration>>
249
+ readonly workItemSources: Readonly<Record<string, WorkItemSourceDeclaration>>
250
+ /** Keyed by the name of one of the module's entities. */
251
+ readonly entityResolvers: Readonly<Record<string, EntityResolverDeclaration>>
252
+ readonly queryViews: Readonly<Record<string, QueryViewDeclaration>>
253
+ /**
254
+ * Business approval rules (the Approvals contract): which of the app's actions need approval, when, and
255
+ * who may approve. A module may declare rules for any installed action; the app may add its own.
256
+ */
257
+ readonly approvalRules: Readonly<Record<string, ApprovalRule>>
258
+ /** Agent tool groups (`<module>.<name>`): sets of the module's actions an app can disable for agents. */
259
+ readonly toolGroups: Readonly<Record<string, ToolGroupDeclaration>>
260
+ /**
261
+ * Which entities hold records about a person, by entity name, and what erasure does to them (the Privacy
262
+ * contract); `{ none: reason }` for an entity about nobody. With the privacy module installed, every entity must
263
+ * be here: nothing is left out of an export or an erasure by omission.
264
+ */
265
+ readonly dataSubjects: Readonly<Record<string, DataSubjectEntry>>
266
+ /**
267
+ * The product analytics events the module sends (`ctx.analytics.track`), by id (`<module>.<event>`), each with its
268
+ * consent category and typed properties (the Telemetry contract). Only declared events and values leave.
269
+ */
270
+ readonly analyticsEvents: Readonly<Record<string, AnalyticsEventDeclaration>>
271
+ }
272
+
273
+ /**
274
+ * Declarations deleting, on erasure, every record of `entities` that holds a person's user id in any user-typed
275
+ * attribute (by entity key), with `overrides` for the entities that do something else.
276
+ */
277
+ export const deleteRecordsAbout = (
278
+ entities: Readonly<Record<string, AnyEntity>>,
279
+ overrides: Readonly<Record<string, ErasureDeclaration>> = {},
280
+ ): Readonly<Record<string, DataSubjectDeclaration>> =>
281
+ Object.fromEntries(
282
+ Object.entries(entities).flatMap(([key, entity]) => {
283
+ const fields = userFields(entity)
284
+ return fields.length === 0 ? [] : [[key, { fields, erase: overrides[key] ?? { kind: "delete" as const } }]]
285
+ }),
286
+ )
287
+
288
+ /** The fields of an entity whose policy attributes hold a user id (`Eloxiv::User` columns). */
289
+ export const userFields = (entity: AnyEntity): ReadonlyArray<string> =>
290
+ Object.values(entity.policyAttributes).flatMap((a) =>
291
+ a.kind === "column" && a.type === "Entity" && a.entityType === "Eloxiv::User" ? [a.field] : [],
292
+ )
293
+
294
+ /** Field or column names that say they hold a person's id (`authorId`, `owner_id`, `user`, `createdBy`...). */
295
+ const PERSON_NAME =
296
+ /^(?:user|owner|author|creator|created_?by|updated_?by|assignee|customer|member|actor|subject|recipient|sender|requester|requested_?by|approver|reviewer|person|principal)(?:_?ids?)?$|(?:user|person)_?ids?$/iu
297
+
298
+ /** The fields of an entity whose name or column says they hold a person's id, typed or not. */
299
+ export const personNamedFields = (entity: AnyEntity): ReadonlyArray<string> =>
300
+ Object.entries(entity.columns as Readonly<Record<string, string>>).flatMap(([field, column]) =>
301
+ PERSON_NAME.test(field) || PERSON_NAME.test(column) ? [field] : [],
302
+ )
303
+
304
+ /**
305
+ * The privacy module's completeness rule: every entity of `modules` is declared in its module's `dataSubjects`,
306
+ * either with the fields naming a person (every user-typed policy attribute's among them) or as about nobody, which
307
+ * an entity with a user-typed attribute, or a field named for a person, cannot be: nothing about a person is left
308
+ * out of an export or an erasure by omission.
309
+ */
310
+ export const dataSubjectCoverageProblems = (modules: ReadonlyArray<AnyModuleContract>): ReadonlyArray<string> => {
311
+ const problems: Array<string> = []
312
+ for (const module of modules) {
313
+ for (const [key, entity] of Object.entries(module.entities as Record<string, AnyEntity>)) {
314
+ const typed = userFields(entity)
315
+ const declared: DataSubjectEntry | undefined = (module.dataSubjects ?? {})[key]
316
+ if (declared === undefined) {
317
+ problems.push(
318
+ typed.length > 0
319
+ ? `${module.name}: entity ${key} holds user ids (${typed.join(", ")}) but is not declared in dataSubjects (the Privacy contract: say how it is exported and erased)`
320
+ : `${module.name}: entity ${key} is not declared in dataSubjects (the Privacy contract: name the fields that hold a person's id, or declare it { none: reason })`,
321
+ )
322
+ continue
323
+ }
324
+ if (isNoDataSubjects(declared)) {
325
+ const named = [...new Set([...typed, ...personNamedFields(entity)])]
326
+ if (named.length > 0) {
327
+ problems.push(
328
+ `${module.name}: dataSubjects ${key} says it is about nobody, but ${named.join(", ")} hold${named.length === 1 ? "s" : ""} a person's id`,
329
+ )
330
+ }
331
+ continue
332
+ }
333
+ const missing = typed.filter((f) => !declared.fields.includes(f))
334
+ if (missing.length > 0) {
335
+ problems.push(`${module.name}: dataSubjects ${key} leaves out its user fields ${missing.join(", ")}`)
336
+ }
337
+ }
338
+ }
339
+ return problems
340
+ }
341
+
342
+ /** The database view a published query view is created as: `<schema>.qv_<local id>`. */
343
+ export const queryViewName = (id: string): string => `qv_${id.slice(id.indexOf(".") + 1)}`
344
+
345
+ /** The schema holding the query surface's views (QuerySurface): one per published query view. */
346
+ export const QUERY_SURFACE_SCHEMA = "eloxiv_surface"
347
+
348
+ /**
349
+ * The relation name a published query view has on the query surface (QuerySurface): `<module>_<local id>`,
350
+ * the name queries use, unqualified (`hello.greetings` is `hello_greetings`).
351
+ */
352
+ export const queryRelationName = (id: string): string => id.replace(".", "_")
353
+
354
+ /**
355
+ * Is a setting's value schema marked sensitive? Secrets never go in settings (the Secrets contract holds
356
+ * them): a schema annotated `sensitive: true` or `writeOnly: true`, a `password` format, or a `Redacted`
357
+ * value, anywhere inside it.
358
+ */
359
+ export const isSensitiveSchema = (schema: Schema.Top): boolean => {
360
+ const seen = new Set<unknown>()
361
+ const visit = (value: unknown): boolean => {
362
+ if (value === null || typeof value !== "object" || seen.has(value)) return false
363
+ seen.add(value)
364
+ const record = value as Record<string, unknown>
365
+ if (record["sensitive"] === true || record["writeOnly"] === true || record["format"] === "password") return true
366
+ return Object.values(record).some(visit)
367
+ }
368
+ // The schema's AST: annotations anywhere in it, including Effect's `Redacted` declarations.
369
+ const marked = (value: unknown): boolean => {
370
+ if (value === null || typeof value !== "object" || seen.has(value)) return false
371
+ seen.add(value)
372
+ const annotations = (value as { readonly annotations?: Record<string, unknown> }).annotations
373
+ const representation = annotations?.["representation"] as { readonly id?: unknown } | undefined
374
+ if (annotations?.["sensitive"] === true || representation?.id === "effect/schema/Redacted") return true
375
+ return Object.values(value as Record<string, unknown>).some(marked)
376
+ }
377
+ if (marked(schema.ast)) return true
378
+ seen.clear()
379
+ try {
380
+ return visit(Schema.toJsonSchemaDocument(schema))
381
+ } catch {
382
+ // A schema with no JSON form cannot be validated as a setting either; the default check reports it.
383
+ return false
384
+ }
385
+ }
386
+
387
+ // ---------------------------------------------------------------------------
388
+ // Published query views: a conservative check that the SQL is one plain SELECT over one schema
389
+
390
+ type Token =
391
+ | { readonly kind: "word"; readonly text: string; readonly upper: string }
392
+ | { readonly kind: "ident"; readonly text: string }
393
+ | { readonly kind: "string" }
394
+ | { readonly kind: "number" }
395
+ | { readonly kind: "punct"; readonly text: string }
396
+
397
+ const tokenize = (sql: string): ReadonlyArray<Token> | string => {
398
+ const tokens: Array<Token> = []
399
+ let i = 0
400
+ while (i < sql.length) {
401
+ const c = sql[i]!
402
+ if (/\s/.test(c)) {
403
+ i++
404
+ } else if (c === "'") {
405
+ let j = i + 1
406
+ for (;;) {
407
+ if (j >= sql.length) return "an unterminated string literal"
408
+ if (sql[j] === "'") {
409
+ if (sql[j + 1] === "'") j += 2
410
+ else break
411
+ } else j++
412
+ }
413
+ tokens.push({ kind: "string" })
414
+ i = j + 1
415
+ } else if (c === '"') {
416
+ let j = i + 1
417
+ let text = ""
418
+ for (;;) {
419
+ if (j >= sql.length) return "an unterminated quoted identifier"
420
+ if (sql[j] === '"') {
421
+ if (sql[j + 1] === '"') {
422
+ text += '"'
423
+ j += 2
424
+ } else break
425
+ } else text += sql[j++]
426
+ }
427
+ tokens.push({ kind: "ident", text })
428
+ i = j + 1
429
+ } else if (/[A-Za-z_]/.test(c)) {
430
+ let j = i
431
+ while (j < sql.length && /[A-Za-z0-9_]/.test(sql[j]!)) j++
432
+ const text = sql.slice(i, j)
433
+ // E'...', U&'...', B'...' and X'...' literals have their own escape rules: not allowed.
434
+ if (sql[j] === "'" || sql[j] === "&") return `a prefixed literal (${text}'...')`
435
+ tokens.push({ kind: "word", text, upper: text.toUpperCase() })
436
+ i = j
437
+ } else if (/[0-9]/.test(c)) {
438
+ let j = i
439
+ while (j < sql.length && /[0-9.eE]/.test(sql[j]!)) j++
440
+ tokens.push({ kind: "number" })
441
+ i = j
442
+ } else if ((c === "-" && sql[i + 1] === "-") || (c === "/" && sql[i + 1] === "*")) {
443
+ return "a comment"
444
+ } else if (c === "$" || c === "\\" || c === "`") {
445
+ return "a dollar quote, parameter or backslash"
446
+ } else {
447
+ tokens.push({ kind: "punct", text: c })
448
+ i++
449
+ }
450
+ }
451
+ return tokens
452
+ }
453
+
454
+ /** Keywords that make a statement something other than a plain read, or that this check does not admit. */
455
+ const DENIED_KEYWORDS = new Set([
456
+ "INSERT",
457
+ "UPDATE",
458
+ "DELETE",
459
+ "MERGE",
460
+ "INTO",
461
+ "WITH",
462
+ "FOR",
463
+ "CALL",
464
+ "DO",
465
+ "COPY",
466
+ "CREATE",
467
+ "DROP",
468
+ "ALTER",
469
+ "GRANT",
470
+ "REVOKE",
471
+ "TRUNCATE",
472
+ "LOCK",
473
+ "SET",
474
+ "RESET",
475
+ "RETURNING",
476
+ "EXECUTE",
477
+ "PREPARE",
478
+ "LISTEN",
479
+ "NOTIFY",
480
+ "VACUUM",
481
+ "ANALYZE",
482
+ "EXPLAIN",
483
+ "TABLE",
484
+ "ROWS",
485
+ ])
486
+
487
+ /** Functions with side effects, or that run SQL given as text, or read server state: refused by name. */
488
+ const DENIED_FUNCTION =
489
+ /^(pg_|lo_|dblink|txid_|set_config$|current_setting$|nextval$|setval$|currval$|lastval$|ts_stat$|ts_rewrite$|query_to_xml|cursor_to_xml|table_to_xml|schema_to_xml|database_to_xml|xmlparse$)/i
490
+
491
+ /** Clauses after which a comma at the same depth separates from-items. */
492
+ const CLAUSES = new Set([
493
+ "SELECT",
494
+ "FROM",
495
+ "WHERE",
496
+ "GROUP",
497
+ "HAVING",
498
+ "ORDER",
499
+ "LIMIT",
500
+ "OFFSET",
501
+ "FETCH",
502
+ "WINDOW",
503
+ "UNION",
504
+ "INTERSECT",
505
+ "EXCEPT",
506
+ ])
507
+
508
+ /**
509
+ * Why `sql` is not accepted as a published query view over `schema`, or
510
+ * `undefined` if it is. Deliberately conservative (fail closed): one `SELECT`
511
+ * statement, no comments, no CTEs, no locking or `INTO`, every table named as
512
+ * `<schema>.<table>`, subqueries only as `(SELECT ...)` or `(VALUES ...)`, and no
513
+ * schema-qualified or state-changing function calls. Setup checks the created
514
+ * view's real dependencies in Postgres as well.
515
+ */
516
+ export const plainSelectProblem = (sql: string, schema: string): string | undefined => {
517
+ const tokens = tokenize(sql.trim().replace(/;\s*$/, ""))
518
+ if (typeof tokens === "string") return `it holds ${tokens}`
519
+ if (tokens.some((t) => t.kind === "punct" && t.text === ";")) return "it holds more than one statement"
520
+ const first = tokens[0]
521
+ if (first?.kind !== "word" || first.upper !== "SELECT") return "it does not start with SELECT"
522
+ const name = (token: Token | undefined) =>
523
+ token?.kind === "ident" ? token.text : token?.kind === "word" ? token.text.toLowerCase() : undefined
524
+ const clauses: Array<string> = ["SELECT"]
525
+ for (let i = 0; i < tokens.length; i++) {
526
+ const token = tokens[i]!
527
+ const next = tokens[i + 1]
528
+ if (token.kind === "punct" && token.text === "(") clauses.push("")
529
+ if (token.kind === "punct" && token.text === ")") {
530
+ clauses.pop()
531
+ if (clauses.length === 0) return "its parentheses do not balance"
532
+ }
533
+ // `FROM x` also appears inside some function calls (EXTRACT, SUBSTRING, TRIM): only clause-level FROMs,
534
+ // after a SELECT at the same depth, name tables. Anything else is refused.
535
+ const clause = clauses[clauses.length - 1]
536
+ // A quoted name before `(` is a function call this check cannot read the way Postgres resolves it.
537
+ if (token.kind === "ident" && next?.kind === "punct" && next.text === "(") {
538
+ return `it calls a function by a quoted name ("${token.text}")`
539
+ }
540
+ if (token.kind === "word") {
541
+ if (DENIED_KEYWORDS.has(token.upper)) return `it uses ${token.upper}`
542
+ if (next?.kind === "punct" && next.text === "(" && DENIED_FUNCTION.test(token.text)) {
543
+ return `it calls ${token.text}()`
544
+ }
545
+ if (token.upper === "FROM" && clause === "")
546
+ return "it uses FROM outside a SELECT (for example inside a function call)"
547
+ if (CLAUSES.has(token.upper)) clauses[clauses.length - 1] = token.upper
548
+ }
549
+ if (token.kind === "punct" && token.text === "." && next !== undefined) {
550
+ const after = tokens[i + 2]
551
+ if (after?.kind === "punct" && after.text === "(") return `it calls a schema-qualified function (${name(next)})`
552
+ }
553
+ const startsFromItem =
554
+ (token.kind === "word" && (token.upper === "FROM" || token.upper === "JOIN")) ||
555
+ (token.kind === "punct" && token.text === "," && clauses[clauses.length - 1] === "FROM")
556
+ if (!startsFromItem) continue
557
+ let j = i + 1
558
+ while (tokens[j]?.kind === "word" && ["ONLY", "LATERAL"].includes((tokens[j] as { upper: string }).upper)) j++
559
+ const item = tokens[j]
560
+ if (item?.kind === "punct" && item.text === "(") {
561
+ const inner = tokens[j + 1]
562
+ if (inner?.kind !== "word" || (inner.upper !== "SELECT" && inner.upper !== "VALUES")) {
563
+ return "it uses a parenthesised from-item that is not a subquery"
564
+ }
565
+ continue
566
+ }
567
+ const dot = tokens[j + 1]
568
+ const table = tokens[j + 2]
569
+ if (name(item) === undefined || dot?.kind !== "punct" || dot.text !== "." || name(table) === undefined) {
570
+ return `it reads a table not qualified by the module's schema (${name(item) ?? "?"})`
571
+ }
572
+ if (name(item) !== schema) return `it reads ${name(item)}.${name(table)}, outside the module's schema ${schema}`
573
+ const call = tokens[j + 3]
574
+ if (call?.kind === "punct" && call.text === "(") return "it reads from a function"
575
+ }
576
+ if (clauses.length !== 1) return "its parentheses do not balance"
577
+ return undefined
578
+ }
579
+
580
+ /**
581
+ * The names of the entities an action declares it acts on: `writes`, `target` and `actsOn`, without
582
+ * duplicates. Its policy grants access to these entities' tables and to no other.
583
+ */
584
+ export const declaredEntityNames = (action: AnyAction): ReadonlyArray<string> => [
585
+ ...new Set(
586
+ [action.writes, action.target?.entity, ...(action.actsOn ?? [])].filter((n): n is string => n !== undefined),
587
+ ),
588
+ ]
589
+
590
+ // ---------------------------------------------------------------------------
591
+ // Checking the declarations of an app's modules together
592
+
593
+ const LOCAL_ID = /^[a-z][a-zA-Z0-9_-]*(\.[a-z][a-zA-Z0-9_-]*)*$/
594
+ const ROUTE = /^\/([A-Za-z0-9_$-]+(\/[A-Za-z0-9_$-]+)*)?$/
595
+
596
+ const entries = <V>(record: Readonly<Record<string, V>> | undefined): ReadonlyArray<readonly [string, V]> =>
597
+ Object.entries(record ?? {})
598
+
599
+ const isJson = (value: unknown): boolean => {
600
+ try {
601
+ return JSON.stringify(JSON.parse(JSON.stringify(value))) === JSON.stringify(value)
602
+ } catch {
603
+ return false
604
+ }
605
+ }
606
+
607
+ const fieldsOf = (entity: AnyEntity): ReadonlySet<string> => new Set(Object.keys(entity.columns))
608
+
609
+ /** A media type an entity accepts: `type/subtype` or `type/*`. */
610
+ /** The kernel's own Cedar actions on entities: no module action may take their names. */
611
+ export const KERNEL_ENTITY_ACTIONS: ReadonlySet<string> = new Set(["read", "share", "attach", "collaborate"])
612
+
613
+ /** The CollabDocument contract's limits: the defaults, and the most an entity may declare. */
614
+ export const COLLAB_LIMITS = {
615
+ maxBytes: 2 * 1024 * 1024,
616
+ maxBytesCeiling: 16 * 1024 * 1024,
617
+ maxUpdateBytes: 256 * 1024,
618
+ updatesPerMinute: 1200,
619
+ /** The rate window keeps each update's time for a minute: bounded, so its row stays small. */
620
+ updatesPerMinuteCeiling: 6000,
621
+ text: "content",
622
+ } as const
623
+
624
+ /** An entity's collaborative document's limits, with the defaults filled in. */
625
+ export const collabLimits = (collab: EntityCollab) => ({
626
+ maxBytes: collab.maxBytes ?? COLLAB_LIMITS.maxBytes,
627
+ maxUpdateBytes: collab.maxUpdateBytes ?? Math.min(COLLAB_LIMITS.maxUpdateBytes, collab.maxBytes ?? Infinity),
628
+ updatesPerMinute: collab.updatesPerMinute ?? COLLAB_LIMITS.updatesPerMinute,
629
+ text: collab.text ?? COLLAB_LIMITS.text,
630
+ })
631
+
632
+ const isPositiveInteger = (value: unknown) => typeof value === "number" && Number.isSafeInteger(value) && value > 0
633
+
634
+ /** What is wrong with an entity's `collab` declaration. */
635
+ export const collabProblems = (entity: string, collab: EntityCollab): ReadonlyArray<string> => {
636
+ const problems: Array<string> = []
637
+ const limits = collabLimits(collab)
638
+ if (
639
+ collab.maxBytes !== undefined &&
640
+ !(isPositiveInteger(collab.maxBytes) && collab.maxBytes <= COLLAB_LIMITS.maxBytesCeiling)
641
+ ) {
642
+ problems.push(
643
+ `entity ${entity} lets its collaborative document grow to ${collab.maxBytes} bytes (a positive integer, at most ${COLLAB_LIMITS.maxBytesCeiling})`,
644
+ )
645
+ }
646
+ if (
647
+ collab.maxUpdateBytes !== undefined &&
648
+ !(isPositiveInteger(collab.maxUpdateBytes) && collab.maxUpdateBytes <= limits.maxBytes)
649
+ ) {
650
+ problems.push(
651
+ `entity ${entity} accepts collaborative updates of ${collab.maxUpdateBytes} bytes (a positive integer, at most its maxBytes)`,
652
+ )
653
+ }
654
+ if (
655
+ collab.updatesPerMinute !== undefined &&
656
+ !(isPositiveInteger(collab.updatesPerMinute) && collab.updatesPerMinute <= COLLAB_LIMITS.updatesPerMinuteCeiling)
657
+ ) {
658
+ problems.push(
659
+ `entity ${entity} accepts ${collab.updatesPerMinute} collaborative updates a minute (a positive integer, at most ${COLLAB_LIMITS.updatesPerMinuteCeiling})`,
660
+ )
661
+ }
662
+ if (collab.text !== undefined && !/^[A-Za-z_][A-Za-z0-9_-]{0,63}$/u.test(collab.text)) {
663
+ problems.push(`entity ${entity} names ${collab.text} as its collaborative text (letters, digits, _ and -)`)
664
+ }
665
+ return problems
666
+ }
667
+
668
+ export const MEDIA_TYPE_PATTERN = /^[a-z0-9][a-z0-9!#$&^_.+-]*\/(?:\*|[a-z0-9][a-z0-9!#$&^_.+-]*)$/u
669
+
670
+ /**
671
+ * Why `name` cannot name a module, if it cannot. A module's name becomes its database roles
672
+ * (`eloxiv_mod_<name>`, `eloxiv_own_<name>`) and its default schema, so it is a plain lower-case identifier that
673
+ * leaves those roles within PostgreSQL's 63 bytes (52 characters at most), and it is not the kernel's (`eloxiv`,
674
+ * `eloxiv_*`) or PostgreSQL's (`pg_*`).
675
+ */
676
+ export const moduleNameProblem = (name: string): string | undefined => {
677
+ if (!/^[a-z][a-z0-9_]*$/.test(name)) return "must be lower-case letters, digits and '_', starting with a letter"
678
+ if (name.length > 52) return "must be at most 52 characters (its roles' names are limited to 63)"
679
+ if (name === "eloxiv" || name.startsWith("eloxiv_") || name.startsWith("pg_")) {
680
+ return "is reserved (eloxiv, eloxiv_* and pg_* belong to the kernel and PostgreSQL)"
681
+ }
682
+ return undefined
683
+ }
684
+
685
+ /**
686
+ * Every problem with the manifests of `modules` taken together, as readable
687
+ * sentences naming the module and the declaration. Empty when the app is valid.
688
+ */
689
+ export const manifestProblems = (modules: ReadonlyArray<AnyModuleContract>): ReadonlyArray<string> => {
690
+ const problems: Array<string> = []
691
+ const seen = (kind: string, map: Map<string, string>, key: string, owner: string) => {
692
+ const previous = map.get(key)
693
+ if (previous !== undefined) problems.push(`${owner}: ${kind} ${key} is also declared by ${previous}`)
694
+ else map.set(key, owner)
695
+ }
696
+
697
+ // Global names: modules, Cedar namespaces, entity types, tables, actions, view routes.
698
+ const moduleNames = new Map<string, string>()
699
+ const namespaces = new Map<string, string>()
700
+ const cedarTypes = new Map<string, string>()
701
+ const tables = new Map<string, string>()
702
+ const actionNames = new Map<string, string>()
703
+ const actionsByName = new Map<string, AnyAction>()
704
+ const routes = new Map<string, string>()
705
+ const views = new Map<string, ViewDeclaration>()
706
+ const commands = new Map<string, CommandDeclaration>()
707
+ const slots = new Map<string, SlotDeclaration>()
708
+ const surfaceRelations = new Map<string, string>()
709
+ for (const module of modules) {
710
+ const nameProblem = moduleNameProblem(module.name)
711
+ if (nameProblem !== undefined) problems.push(`${module.name}: module name ${nameProblem}`)
712
+ seen("module", moduleNames, module.name, module.name)
713
+ // The kernel records its own migrations, snapshot and audit names under `eloxiv`.
714
+ if (module.name === "eloxiv") problems.push(`eloxiv: the module name eloxiv is the kernel's own`)
715
+ seen("Cedar namespace", namespaces, module.cedarNamespace, module.name)
716
+ for (const entity of Object.values(module.entities as Record<string, AnyEntity>)) {
717
+ seen("entity type", cedarTypes, entity.cedarType, module.name)
718
+ seen("table", tables, `${entity.table.schema}.${entity.table.name}`, module.name)
719
+ }
720
+ for (const action of Object.values(module.actions as Record<string, AnyAction>)) {
721
+ seen("action", actionNames, action.name, module.name)
722
+ actionsByName.set(action.name, action)
723
+ }
724
+ for (const [id, view] of entries(module.views)) {
725
+ views.set(id, view)
726
+ seen("view route", routes, view.route, module.name)
727
+ }
728
+ for (const [id, command] of entries(module.commands)) commands.set(id, command)
729
+ for (const [id, slot] of entries(module.slots)) slots.set(id, slot)
730
+ for (const id of Object.keys(module.queryViews ?? {})) {
731
+ const relation = queryRelationName(id)
732
+ seen("query surface relation", surfaceRelations, relation, module.name)
733
+ if (relation.startsWith("pg_")) {
734
+ problems.push(
735
+ `${module.name}: query view ${id} would be named ${relation} on the query surface, beside the catalog's names`,
736
+ )
737
+ }
738
+ }
739
+ }
740
+
741
+ for (const module of modules) {
742
+ const m = module.name
743
+ const problem = (text: string) => problems.push(`${m}: ${text}`)
744
+ const entities = module.entities as Record<string, AnyEntity>
745
+ const actions = Object.values(module.actions as Record<string, AnyAction>)
746
+ const ownQueryViews = module.queryViews ?? {}
747
+
748
+ const ids = (kind: string, record: Readonly<Record<string, unknown>> | undefined) => {
749
+ for (const id of Object.keys(record ?? {})) {
750
+ if (!id.startsWith(`${m}.`) || !LOCAL_ID.test(id.slice(m.length + 1))) {
751
+ problem(`${kind} id ${id} must be namespaced by its module (${m}.<name>, lower camel or kebab case)`)
752
+ }
753
+ }
754
+ }
755
+ ids("permission", module.permissions)
756
+ ids("setting", module.settings)
757
+ ids("flag", module.flags)
758
+ ids("skill", module.skills)
759
+ ids("view", module.views)
760
+ ids("slot", module.slots)
761
+ ids("contribution", module.contributions)
762
+ ids("command", module.commands)
763
+ ids("work-item source", module.workItemSources)
764
+ ids("query view", module.queryViews)
765
+ ids("approval rule", module.approvalRules)
766
+ ids("tool group", module.toolGroups)
767
+
768
+ for (const [id, group] of entries(module.toolGroups)) {
769
+ if (group.description.trim() === "") problem(`tool group ${id} has no description`)
770
+ if (group.actions.length === 0) problem(`tool group ${id} names no actions`)
771
+ for (const action of group.actions) {
772
+ if (!actions.some((a) => a.name === action)) problem(`tool group ${id} names unknown action ${action}`)
773
+ }
774
+ }
775
+ ids("analytics event", module.analyticsEvents)
776
+ for (const [id, declaration] of entries(module.analyticsEvents)) {
777
+ for (const why of analyticsEventProblems(id, declaration)) problem(why)
778
+ }
779
+
780
+ for (const [id, rule] of entries(module.approvalRules)) {
781
+ for (const shape of approvalRuleShapeProblems(rule)) problem(`approval rule ${id} ${shape}`)
782
+ if (Schema.is(ApprovalRule)(rule) && !actionsByName.has(rule.action)) {
783
+ problem(`approval rule ${id} applies to unknown action ${rule.action}`)
784
+ }
785
+ }
786
+
787
+ for (const entity of Object.values(entities)) {
788
+ if (!entity.cedarType.startsWith(`${module.cedarNamespace}::`)) {
789
+ problem(`entity ${entity.name} has Cedar type ${entity.cedarType}, outside namespace ${module.cedarNamespace}`)
790
+ }
791
+ // A grant is made in, and counts only in, its record's organisation: a shareable record must name one.
792
+ const attributes = Object.values(entity.policyAttributes)
793
+ const orgs = attributes.filter(
794
+ (a) => a.kind === "column" && a.type === "Entity" && a.entityType === "Eloxiv::Org",
795
+ )
796
+ if (attributes.some((a) => a.kind === "sharing") && orgs.length !== 1) {
797
+ problem(
798
+ `entity ${entity.name} has sharing attributes, so it needs exactly one organisation attribute (an Eloxiv::Org column)`,
799
+ )
800
+ }
801
+ // Search's index and files are kept per organisation, read from the record.
802
+ for (const kind of ["search", "files", "collab"] as const) {
803
+ if (entity[kind] !== undefined && orgs.length !== 1) {
804
+ problem(
805
+ `entity ${entity.name} declares ${kind}, so it needs exactly one organisation attribute (an Eloxiv::Org column)`,
806
+ )
807
+ }
808
+ }
809
+ if (entity.search !== undefined) {
810
+ const search = entity.search
811
+ const fields = Object.entries(search.fields ?? {})
812
+ if (fields.length === 0) problem(`entity ${entity.name} declares search over no fields`)
813
+ for (const [field, weight] of fields) {
814
+ if (!fieldsOf(entity).has(field)) problem(`entity ${entity.name} searches unknown field ${field}`)
815
+ if (!["A", "B", "C", "D"].includes(weight)) {
816
+ problem(`entity ${entity.name} gives search field ${field} weight ${weight} (A, B, C or D)`)
817
+ }
818
+ }
819
+ if (search.title !== undefined && !(search.title in (search.fields ?? {}))) {
820
+ problem(`entity ${entity.name} shows ${search.title} as its search title, which it does not search`)
821
+ }
822
+ if (search.language !== undefined && !(SEARCH_LANGUAGES as ReadonlyArray<string>).includes(search.language)) {
823
+ problem(
824
+ `entity ${entity.name} searches in unknown language ${search.language} (${SEARCH_LANGUAGES.join(", ")})`,
825
+ )
826
+ }
827
+ }
828
+ if (entity.collab !== undefined) {
829
+ for (const problemText of collabProblems(entity.name, entity.collab)) problem(problemText)
830
+ }
831
+ if (entity.files !== undefined) {
832
+ const files = entity.files
833
+ if (files.maxBytes !== undefined && !(Number.isSafeInteger(files.maxBytes) && files.maxBytes > 0)) {
834
+ problem(`entity ${entity.name} accepts files of at most ${files.maxBytes} bytes (a positive integer)`)
835
+ }
836
+ for (const type of files.types ?? []) {
837
+ if (!MEDIA_TYPE_PATTERN.test(type)) {
838
+ problem(`entity ${entity.name} accepts files of type ${type}, which is not type/subtype or type/*`)
839
+ }
840
+ }
841
+ }
842
+ }
843
+
844
+ // The action contract: what each action may change.
845
+ for (const action of actions) {
846
+ // `read`, `share`, `attach` and `collaborate` are the kernel's own Cedar actions on entities (reading; sharing
847
+ // and its grants; attaching files; changing a record's collaborative document).
848
+ if (KERNEL_ENTITY_ACTIONS.has(action.cedarAction)) {
849
+ problem(`${action.name}: the Cedar action ${action.cedarAction} is reserved for the kernel`)
850
+ }
851
+ if (action.writes !== undefined && !(action.writes in entities)) {
852
+ problem(`${action.name} writes unknown entity ${action.writes}`)
853
+ }
854
+ const target = action.target
855
+ if (target !== undefined && !(target.entity in entities)) {
856
+ problem(`${action.name} targets unknown entity ${target.entity}`)
857
+ }
858
+ for (const name of action.actsOn ?? []) {
859
+ if (!(name in entities)) problem(`${action.name} acts on unknown entity ${name}`)
860
+ }
861
+ if (action.organisationWide && declaredEntityNames(action).length === 0) {
862
+ problem(`${action.name} is organisation-wide, so it must declare an entity (writes, target or actsOn)`)
863
+ }
864
+ if (action.bestEffort) {
865
+ // Best effort is declared, never inferred: it needs targets to count and an output to report them in.
866
+ const fields = (action.output as { readonly fields?: Record<string, unknown> }).fields ?? {}
867
+ const missing = Object.keys(BestEffortFields).filter((k) => !(k in fields))
868
+ if (target === undefined || missing.length > 0) {
869
+ problem(
870
+ `${action.name} is best effort, so it needs a target and an output with ${Object.keys(BestEffortFields).join(", ")}`,
871
+ )
872
+ }
873
+ }
874
+ if (action.reportsWritten) {
875
+ // What an untargeted write did: it needs no target (a targeted one reports its completion) and an output to
876
+ // report it in.
877
+ const fields = (action.output as { readonly fields?: Record<string, unknown> }).fields ?? {}
878
+ if (target !== undefined || action.writes === undefined || !("written" in fields)) {
879
+ problem(`${action.name} reports what it wrote, so it needs writes, no target and an output with written`)
880
+ }
881
+ }
882
+ for (const text of optimisticProblems(action, entities)) problem(text)
883
+ }
884
+
885
+ // Jobs (the Scheduler contract): the action they invoke, with their input, on their schedule.
886
+ for (const [id, job] of entries(module.jobs)) {
887
+ const where = `job ${m}.${id}`
888
+ if (job.description.trim() === "") problem(`${where} has no description`)
889
+ if (!Schema.is(ScheduleSpec)(job.schedule)) problem(`${where} has a schedule that is neither cron nor interval`)
890
+ if (job.catchUp !== undefined && !Schema.is(CatchUp)(job.catchUp)) {
891
+ problem(`${where} has unknown catch-up policy ${String(job.catchUp)}`)
892
+ }
893
+ if (job.identity !== "system") problem(`${where} has unknown identity ${String(job.identity)}`)
894
+ const action = actionsByName.get(job.action)
895
+ if (action === undefined) problem(`${where} invokes unknown action ${job.action}`)
896
+ else if (!isJson(job.input)) problem(`${where} has input that is not JSON`)
897
+ else {
898
+ // A job whose input its action would refuse fails at startup, not at its first run.
899
+ const decoded = Schema.decodeUnknownExit(action.input as Schema.Codec<unknown, unknown>)(job.input)
900
+ if (Exit.isFailure(decoded)) problem(`${where} has input that ${job.action} refuses`)
901
+ }
902
+ }
903
+
904
+ for (const [id, permission] of entries(module.permissions)) {
905
+ if (permission.description.trim() === "") problem(`permission ${id} has no description`)
906
+ if (permission.actions.length === 0) problem(`permission ${id} names no actions`)
907
+ for (const action of permission.actions) {
908
+ if (!KERNEL_ENTITY_ACTIONS.has(action) && !actions.some((a) => a.name === action)) {
909
+ problem(`permission ${id} names unknown action ${action} (an action of ${m}, read or share)`)
910
+ }
911
+ }
912
+ }
913
+
914
+ for (const [id, setting] of entries(module.settings)) {
915
+ if (!Schema.is(SettingScope)(setting.scope)) problem(`setting ${id} has unknown scope ${String(setting.scope)}`)
916
+ if (!isJson(setting.default)) problem(`setting ${id} has a default that is not JSON`)
917
+ else {
918
+ const decoded = Schema.decodeUnknownExit(setting.schema as Schema.Codec<unknown, unknown>)(setting.default)
919
+ if (Exit.isFailure(decoded)) problem(`setting ${id} has a default that does not decode against its schema`)
920
+ }
921
+ if (isSensitiveSchema(setting.schema)) {
922
+ problem(`setting ${id} is marked sensitive: secrets never go in settings (use the Secrets contract)`)
923
+ }
924
+ }
925
+
926
+ for (const [id, flag] of entries(module.flags)) {
927
+ if (typeof flag.description !== "string" || flag.description.trim() === "")
928
+ problem(`flag ${id} has no description`)
929
+ if (typeof flag.default !== "boolean") problem(`flag ${id} has a default that is not a boolean`)
930
+ }
931
+
932
+ for (const [id, skill] of entries(module.skills)) {
933
+ if (skill.description.trim() === "") problem(`skill ${id} has no description`)
934
+ const content = skill.content as { readonly path?: unknown; readonly text?: unknown }
935
+ if ((content.path === undefined) === (content.text === undefined)) {
936
+ problem(`skill ${id} must give its content as exactly one of path or text`)
937
+ } else if (content.path !== undefined) {
938
+ const path = content.path as string
939
+ if (path === "" || path.startsWith("/") || path.includes("\\") || path.split("/").includes("..")) {
940
+ problem(`skill ${id} has path ${path}, which must stay inside the module's directory`)
941
+ }
942
+ } else if (String(content.text).trim() === "") problem(`skill ${id} has empty text`)
943
+ const audience = (skill as { readonly audience?: unknown }).audience
944
+ if (audience !== undefined && !SKILL_AUDIENCES.includes(audience as SkillAudience)) {
945
+ problem(
946
+ `skill ${id} has audience ${JSON.stringify(audience)}, which is not one of ${SKILL_AUDIENCES.join(", ")}`,
947
+ )
948
+ }
949
+ const evals = (skill as { readonly evals?: { readonly path?: unknown } }).evals
950
+ if (evals !== undefined) {
951
+ const path = typeof evals.path === "string" ? evals.path : ""
952
+ if (path === "" || path.startsWith("/") || path.includes("\\") || path.split("/").includes("..")) {
953
+ problem(`skill ${id} has evals path ${path}, which must stay inside the module's directory`)
954
+ }
955
+ }
956
+ }
957
+
958
+ for (const [id, view] of entries(module.views)) {
959
+ if (!ROUTE.test(view.route)) problem(`view ${id} has route ${view.route}, which is not a shell route (/a/b)`)
960
+ if (view.title.trim() === "") problem(`view ${id} has no title`)
961
+ const shows = view.shows as { readonly entity?: string; readonly queryView?: string }
962
+ if ((shows.entity === undefined) === (shows.queryView === undefined)) {
963
+ problem(`view ${id} must show exactly one entity or query view`)
964
+ } else if (shows.entity !== undefined && !(shows.entity in entities)) {
965
+ problem(`view ${id} shows unknown entity ${shows.entity}`)
966
+ } else if (shows.queryView !== undefined && !(shows.queryView in ownQueryViews)) {
967
+ problem(`view ${id} shows unknown query view ${shows.queryView}`)
968
+ }
969
+ }
970
+
971
+ for (const [id, slot] of entries(module.slots)) {
972
+ if (slot.accepts !== "view" && slot.accepts !== "command") problem(`slot ${id} accepts unknown kind`)
973
+ }
974
+
975
+ for (const [id, contribution] of entries(module.contributions)) {
976
+ const slot = slots.get(contribution.slot)
977
+ const target = contribution as { readonly view?: string; readonly command?: string }
978
+ if (slot === undefined)
979
+ problem(`contribution ${id} contributes to slot ${contribution.slot}, which does not exist`)
980
+ if ((target.view === undefined) === (target.command === undefined)) {
981
+ problem(`contribution ${id} must contribute exactly one view or command`)
982
+ continue
983
+ }
984
+ if (target.view !== undefined && !views.has(target.view)) {
985
+ problem(`contribution ${id} contributes unknown view ${target.view}`)
986
+ }
987
+ if (target.command !== undefined && !commands.has(target.command)) {
988
+ problem(`contribution ${id} contributes unknown command ${target.command}`)
989
+ }
990
+ const kind = target.view !== undefined ? "view" : "command"
991
+ if (slot !== undefined && slot.accepts !== kind) {
992
+ problem(`contribution ${id} contributes a ${kind} to slot ${contribution.slot}, which accepts ${slot.accepts}s`)
993
+ }
994
+ }
995
+
996
+ for (const [id, command] of entries(module.commands)) {
997
+ if (command.title.trim() === "") problem(`command ${id} has no title`)
998
+ const run = command.run as { readonly action?: string; readonly view?: string }
999
+ if ((run.action === undefined) === (run.view === undefined)) {
1000
+ problem(`command ${id} must run exactly one action or view`)
1001
+ } else if (run.action !== undefined && !actionNames.has(run.action)) {
1002
+ problem(`command ${id} runs unknown action ${run.action}`)
1003
+ } else if (run.view !== undefined && !views.has(run.view)) {
1004
+ problem(`command ${id} opens unknown view ${run.view}`)
1005
+ }
1006
+ }
1007
+
1008
+ const needsField = (what: string, entity: AnyEntity, field: string) => {
1009
+ if (!fieldsOf(entity).has(field)) problem(`${what} names unknown field ${field} of ${entity.name}`)
1010
+ }
1011
+ for (const [id, source] of entries(module.workItemSources)) {
1012
+ if (source.description.trim() === "") problem(`work-item source ${id} has no description`)
1013
+ const entity = entities[source.entity]
1014
+ if (entity === undefined) problem(`work-item source ${id} reads unknown entity ${source.entity}`)
1015
+ else {
1016
+ needsField(`work-item source ${id}`, entity, source.title)
1017
+ if (source.assignee !== null) needsField(`work-item source ${id}`, entity, source.assignee)
1018
+ const state = source.state as {
1019
+ readonly field?: string
1020
+ readonly values?: Record<string, unknown>
1021
+ readonly constant?: unknown
1022
+ }
1023
+ if (state.field !== undefined) {
1024
+ needsField(`work-item source ${id}`, entity, state.field)
1025
+ const values = Object.values(state.values ?? {})
1026
+ if (values.length === 0) problem(`work-item source ${id} maps no state values`)
1027
+ for (const value of values) {
1028
+ if (!Schema.is(WorkItemState)(value))
1029
+ problem(`work-item source ${id} maps to unknown state ${String(value)}`)
1030
+ }
1031
+ } else if (!Schema.is(WorkItemState)(state.constant)) {
1032
+ problem(`work-item source ${id} has unknown state ${String(state.constant)}`)
1033
+ }
1034
+ }
1035
+ if (!views.has(source.link.view)) problem(`work-item source ${id} links to unknown view ${source.link.view}`)
1036
+ }
1037
+
1038
+ for (const [name, resolver] of entries(module.entityResolvers)) {
1039
+ const entity = entities[name]
1040
+ if (entity === undefined) {
1041
+ problem(`entity resolver ${name} resolves unknown entity ${name}`)
1042
+ continue
1043
+ }
1044
+ needsField(`entity resolver ${name}`, entity, resolver.title)
1045
+ if (resolver.link !== undefined && !views.has(resolver.link.view)) {
1046
+ problem(`entity resolver ${name} links to unknown view ${resolver.link.view}`)
1047
+ }
1048
+ }
1049
+
1050
+ for (const [id, view] of entries(module.queryViews)) {
1051
+ const local = id.slice(m.length + 1)
1052
+ if (!/^[a-z][a-z0-9_]*$/.test(local)) problem(`query view ${id} needs a lower snake case name after ${m}.`)
1053
+ const entity = entities[view.entity]
1054
+ if (entity === undefined) {
1055
+ problem(`query view ${id} is filtered by unknown entity ${view.entity}`)
1056
+ continue
1057
+ }
1058
+ const why = plainSelectProblem(view.sql, entity.table.schema)
1059
+ if (why !== undefined) {
1060
+ problem(`query view ${id} is not a plain SELECT over schema ${entity.table.schema}: ${why}`)
1061
+ }
1062
+ const fields = (view.row as { readonly fields?: Record<string, unknown> }).fields
1063
+ if (fields === undefined) problem(`query view ${id} must describe its row as a struct`)
1064
+ else {
1065
+ const pk = (entity.columns as Record<string, string>)[entity.primaryKey]!
1066
+ if (!(pk in fields)) {
1067
+ problem(
1068
+ `query view ${id} must return ${entity.name}'s primary key column ${pk}, so its policy can filter rows`,
1069
+ )
1070
+ }
1071
+ }
1072
+ if (view.render !== undefined) {
1073
+ for (const why of renderProblems(view.render, Schema.Array(view.row)))
1074
+ problem(`query view ${id}'s renderer ${why}`)
1075
+ }
1076
+ }
1077
+
1078
+ // Renderers (the ResultRendering contract) must fit the output they render.
1079
+ for (const action of actions) {
1080
+ if (action.render === undefined) continue
1081
+ for (const why of renderProblems(action.render, action.output)) problem(`${action.name}'s renderer ${why}`)
1082
+ }
1083
+
1084
+ // The kernel versions the module works with (the Versioning contract).
1085
+ if (module.kernel !== undefined && satisfiesRange("0.0.0", module.kernel) === undefined) {
1086
+ problem(`kernel range ${module.kernel} cannot be read (use comparators such as >=1.0.0 <2.0.0, ^1.2.0 or ~1.2.0)`)
1087
+ }
1088
+ // Setup compares versions to refuse downgrades: they must be numbers separated by dots.
1089
+ if (!/^v?\d+(?:\.\d+)*(?:-[0-9A-Za-z.-]+)?$/.test(module.version)) {
1090
+ problem(`version ${module.version} is not a version (numbers separated by dots, such as 1.2.0)`)
1091
+ }
1092
+
1093
+ // Data subjects (the Privacy contract): declared entities and fields, a declared erasure.
1094
+ for (const [name, entry] of entries(module.dataSubjects)) {
1095
+ const entity = entities[name]
1096
+ if (entity === undefined) {
1097
+ problem(`dataSubjects ${name} names unknown entity ${name}`)
1098
+ continue
1099
+ }
1100
+ if (isNoDataSubjects(entry)) {
1101
+ if (typeof entry.none !== "string" || entry.none.trim() === "")
1102
+ problem(`dataSubjects ${name} says it is about nobody without a reason`)
1103
+ continue
1104
+ }
1105
+ const declaration = entry
1106
+ if (declaration.fields.length === 0) problem(`dataSubjects ${name} names no fields`)
1107
+ const exported = declaration.export
1108
+ if (exported !== undefined && exported !== false) {
1109
+ for (const field of exported.fields) {
1110
+ if (!declaration.fields.includes(field))
1111
+ problem(`dataSubjects ${name} exports by ${field}, not one of its fields`)
1112
+ }
1113
+ }
1114
+ // Requests are made in an organisation: the kernel finds and erases the person's records there.
1115
+ const orgAttributes = Object.values(entity.policyAttributes).filter(
1116
+ (a) => a.kind === "column" && a.type === "Entity" && a.entityType === "Eloxiv::Org",
1117
+ )
1118
+ if (orgAttributes.length !== 1) {
1119
+ problem(`dataSubjects ${name} needs exactly one organisation attribute (an Eloxiv::Org column) on ${name}`)
1120
+ }
1121
+ for (const field of declaration.fields) needsField(`dataSubjects ${name}`, entity, field)
1122
+ if (declaration.fields.includes(entity.primaryKey)) {
1123
+ problem(
1124
+ `dataSubjects ${name}: the primary key ${entity.primaryKey} cannot hold a person's id (it never changes)`,
1125
+ )
1126
+ }
1127
+ const erase = declaration.erase as { readonly kind?: unknown; readonly set?: unknown; readonly reason?: unknown }
1128
+ if (erase.kind === "anonymise") {
1129
+ const set = (erase.set ?? {}) as Record<string, unknown>
1130
+ for (const field of Object.keys(set)) needsField(`dataSubjects ${name}`, entity, field)
1131
+ if (entity.primaryKey in set)
1132
+ problem(`dataSubjects ${name} cannot anonymise the primary key ${entity.primaryKey}`)
1133
+ const left = declaration.fields.filter((f) => !(f in set))
1134
+ if (left.length > 0) problem(`dataSubjects ${name} anonymises but keeps the person's id in ${left.join(", ")}`)
1135
+ for (const [field, value] of Object.entries(set)) {
1136
+ if (!(value === null || ["string", "number", "boolean"].includes(typeof value))) {
1137
+ problem(`dataSubjects ${name} sets ${field} to a value that is not a string, number, boolean or null`)
1138
+ }
1139
+ }
1140
+ } else if (erase.kind === "retain") {
1141
+ if (typeof erase.reason !== "string" || erase.reason.trim() === "")
1142
+ problem(`dataSubjects ${name} retains records without a reason`)
1143
+ } else if (erase.kind !== "delete") problem(`dataSubjects ${name} has unknown erasure ${String(erase.kind)}`)
1144
+ }
1145
+ }
1146
+ return problems
1147
+ }