@processfocus/runtime-local 0.1.0-next.1 → 0.1.0-next.3

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 (326) hide show
  1. package/README.md +48 -253
  2. package/dist/authentication-server.mjs +52 -84
  3. package/dist/{chunk-fn7b5pxw.js → chunk-04r0t2mb.js} +19364 -34104
  4. package/dist/chunk-727y6qkb.js +156 -0
  5. package/dist/chunk-bg5r4wpv.js +4755 -0
  6. package/dist/chunk-cbd36jq1.js +512 -0
  7. package/dist/chunk-d4ctj079.js +241 -0
  8. package/dist/{chunk-cq9xscgb.js → chunk-r5s2v669.js} +49079 -33564
  9. package/dist/dashboard-source/apps/frontend/app/(protected)/act-on-behalf/actions.ts +12 -12
  10. package/dist/dashboard-source/apps/frontend/app/(protected)/act-on-behalf/delegations-client.tsx +31 -21
  11. package/dist/dashboard-source/apps/frontend/app/(protected)/act-on-behalf/page.tsx +3 -0
  12. package/dist/dashboard-source/apps/frontend/app/(protected)/client-index.tsx +1 -12
  13. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/@modal/(.)[executionId]/client.tsx +1 -1
  14. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/@modal/(.)[executionId]/page.tsx +2 -0
  15. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/@modal/(.)[executionId]/process-state/page.tsx +2 -0
  16. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/@modal/default.tsx +3 -0
  17. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/[executionId]/page.tsx +3 -1
  18. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/[executionId]/process-state/page.tsx +2 -0
  19. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/client-layout.tsx +19 -0
  20. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/default.tsx +6 -0
  21. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/executions-client.tsx +1637 -0
  22. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/layout.tsx +5 -7
  23. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/page.tsx +4 -1589
  24. package/dist/dashboard-source/apps/frontend/app/(protected)/executions/process-state-page-client.tsx +1 -1
  25. package/dist/dashboard-source/apps/frontend/app/(protected)/layout.tsx +41 -33
  26. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/@modal/(.)item/[id]/client.tsx +11 -17
  27. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/@modal/(.)item/[id]/page.tsx +2 -0
  28. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/@modal/default.tsx +3 -0
  29. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/[...listPath]/list-page-client.tsx +153 -16
  30. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/[...listPath]/page.tsx +10 -2
  31. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/components/list-create-form.tsx +29 -13
  32. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/components/list-item-edit-form.tsx +22 -28
  33. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/components/list-item-load-error.tsx +49 -0
  34. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/components/list-schema-form.tsx +28 -0
  35. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/default.tsx +6 -0
  36. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/hooks/metric-control-url-state.ts +7 -16
  37. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/hooks/use-list-deleted-callback.ts +4 -6
  38. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/hooks/use-list-item-detail.ts +45 -142
  39. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/item/[id]/client.tsx +10 -20
  40. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/item/[id]/page.tsx +2 -0
  41. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/layout.tsx +3 -0
  42. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/lib/list-process-dialog.tsx +72 -0
  43. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/lib/list-refresh-provider.tsx +65 -0
  44. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/lib/list-refresh.ts +162 -16
  45. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/utils.tsx +19 -0
  46. package/dist/dashboard-source/apps/frontend/app/(protected)/org-chart/page.tsx +4 -9
  47. package/dist/dashboard-source/apps/frontend/app/(protected)/page.tsx +4 -0
  48. package/dist/dashboard-source/apps/frontend/app/(protected)/passkeys/actions.ts +15 -18
  49. package/dist/dashboard-source/apps/frontend/app/(protected)/passkeys/page.tsx +12 -6
  50. package/dist/dashboard-source/apps/frontend/app/(protected)/passkeys/passkeys-client.tsx +7 -16
  51. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/@modal/(.)start/[...startStepPath]/client.tsx +26 -48
  52. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/@modal/(.)start/[...startStepPath]/page.tsx +4 -7
  53. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/@modal/default.tsx +3 -0
  54. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/client-layout.tsx +28 -0
  55. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/client.tsx +1 -3
  56. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/components/start-process-form.tsx +193 -117
  57. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/default.tsx +6 -0
  58. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/layout.tsx +7 -9
  59. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/page.tsx +3 -0
  60. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/processes-client.tsx +60 -204
  61. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/start/[...startStepPath]/client.tsx +12 -51
  62. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/start/[...startStepPath]/page.tsx +27 -4
  63. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/workflow/[...processPath]/page.tsx +5 -4
  64. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/workflow/[...processPath]/workflow-flow.tsx +0 -5
  65. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/workflow/[...processPath]/workflow-form-preview-sheet.tsx +26 -19
  66. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/[[...tab]]/page.tsx +5 -2
  67. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/cedar-authorize.ts +85 -9
  68. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/cedar-types.ts +12 -1
  69. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/explorer.tsx +66 -4
  70. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/layout.tsx +3 -0
  71. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/cedar/load-handbook.ts +41 -13
  72. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/invitations/[invitationId]/page.tsx +2 -0
  73. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/invitations/invitation-detail-client.tsx +442 -365
  74. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/invitations/new/page.tsx +8 -2
  75. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/invitations/page.tsx +7 -0
  76. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/invitations-table.tsx +61 -43
  77. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/page.tsx +6 -67
  78. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/providers/page.tsx +7 -0
  79. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/roles/page.tsx +7 -0
  80. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/settings-client.tsx +111 -189
  81. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/settings-page.tsx +86 -0
  82. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/users/[userId]/client.tsx +141 -256
  83. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/users/[userId]/page.tsx +2 -0
  84. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/users/[userId]/tokens/page.tsx +2 -0
  85. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/users/page.tsx +7 -0
  86. package/dist/dashboard-source/apps/frontend/app/(protected)/settings/users-table.tsx +6 -4
  87. package/dist/dashboard-source/apps/frontend/app/(protected)/stats/[...statsPath]/page.tsx +3 -0
  88. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/@modal/(.)complete/[...stepPath]/client.tsx +30 -9
  89. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/@modal/(.)complete/[...stepPath]/page.tsx +3 -1
  90. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/@modal/default.tsx +3 -0
  91. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/complete/[...stepPath]/client.tsx +2 -4
  92. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/complete/[...stepPath]/page.tsx +3 -1
  93. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/components/complete-todo-form.tsx +47 -54
  94. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/components/public-completion-correction-form.tsx +37 -54
  95. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/components/todo-form-actions.tsx +1 -1
  96. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/correct/[...stepPath]/page.tsx +3 -1
  97. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/default.tsx +6 -0
  98. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/layout.tsx +3 -0
  99. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/lib/mobile-todo-list.ts +4 -25
  100. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/page.tsx +4 -1315
  101. package/dist/dashboard-source/apps/frontend/app/(protected)/to-dos/to-dos-client.tsx +1282 -0
  102. package/dist/dashboard-source/apps/frontend/app/api/auth/callback/route.ts +81 -65
  103. package/dist/dashboard-source/apps/frontend/app/api/auth/delegation/route.ts +8 -2
  104. package/dist/dashboard-source/apps/frontend/app/api/auth/login/route.ts +0 -1
  105. package/dist/dashboard-source/apps/frontend/app/api/auth/logout/route.ts +10 -5
  106. package/dist/dashboard-source/apps/frontend/app/api/auth/passkey/start/route.ts +1 -3
  107. package/dist/dashboard-source/apps/frontend/app/api/auth/refresh/route.ts +0 -1
  108. package/dist/dashboard-source/apps/frontend/app/api/auth/revalidate-google/route.ts +68 -0
  109. package/dist/dashboard-source/apps/frontend/app/api/auth/switch-role/route.ts +1 -3
  110. package/dist/dashboard-source/apps/frontend/app/api/embed/lookup/route.ts +25 -7
  111. package/dist/dashboard-source/apps/frontend/app/api/embed/submit/route.ts +1 -2
  112. package/dist/dashboard-source/apps/frontend/app/api/public/start/[address]/route.ts +49 -0
  113. package/dist/dashboard-source/apps/frontend/app/api/public/to-dos/lookup/route.ts +4 -3
  114. package/dist/dashboard-source/apps/frontend/app/api/revalidate/route.ts +15 -4
  115. package/dist/dashboard-source/apps/frontend/app/app-shell.tsx +11 -4
  116. package/dist/dashboard-source/apps/frontend/app/cli-auth/route.ts +2 -1
  117. package/dist/dashboard-source/apps/frontend/app/embed/[...startStepPath]/embed-client.tsx +31 -18
  118. package/dist/dashboard-source/apps/frontend/app/embed/[...startStepPath]/page.tsx +5 -1
  119. package/dist/dashboard-source/apps/frontend/app/login/page.tsx +4 -4
  120. package/dist/dashboard-source/apps/frontend/app/login/passkey-button.tsx +11 -6
  121. package/dist/dashboard-source/apps/frontend/app/login/passkey-help/page.tsx +67 -0
  122. package/dist/dashboard-source/apps/frontend/app/mcp/[[...endpoint]]/route.ts +47 -0
  123. package/dist/dashboard-source/apps/frontend/app/public/form/[token]/public-todo-client.tsx +44 -25
  124. package/dist/dashboard-source/apps/frontend/app/public/start/[address]/form/page.tsx +10 -0
  125. package/dist/dashboard-source/apps/frontend/app/public/start/[address]/layout.tsx +32 -0
  126. package/dist/dashboard-source/apps/frontend/app/public/start/[address]/page-client.tsx +319 -0
  127. package/dist/dashboard-source/apps/frontend/app/public/start/[address]/page-content.tsx +41 -0
  128. package/dist/dashboard-source/apps/frontend/app/public/start/[address]/page.tsx +10 -0
  129. package/dist/dashboard-source/apps/frontend/app/public.css +1 -1
  130. package/dist/dashboard-source/apps/frontend/app/register/passkey/register-passkey-client.tsx +17 -0
  131. package/dist/dashboard-source/apps/frontend/components/DashboardSection.tsx +9 -15
  132. package/dist/dashboard-source/apps/frontend/components/Header.tsx +4 -8
  133. package/dist/dashboard-source/apps/frontend/components/anonymous-page-link.tsx +57 -0
  134. package/dist/dashboard-source/apps/frontend/components/anonymous-start-form.tsx +24 -0
  135. package/dist/dashboard-source/apps/frontend/components/app-sidebar.tsx +21 -7
  136. package/dist/dashboard-source/apps/frontend/components/auth-provider.tsx +12 -7
  137. package/dist/dashboard-source/apps/frontend/components/browser-only.tsx +19 -0
  138. package/dist/dashboard-source/apps/frontend/components/config-provider.tsx +0 -1
  139. package/dist/dashboard-source/apps/frontend/components/delegation-expiry.tsx +24 -13
  140. package/dist/dashboard-source/apps/frontend/components/form-dialog-content.tsx +22 -2
  141. package/dist/dashboard-source/apps/frontend/components/journey-timeline.tsx +52 -45
  142. package/dist/dashboard-source/apps/frontend/components/notification-bell.tsx +0 -1
  143. package/dist/dashboard-source/apps/frontend/components/sidebar-lists.tsx +0 -1
  144. package/dist/dashboard-source/apps/frontend/components/token-refresh-scheduler.tsx +38 -11
  145. package/dist/dashboard-source/apps/frontend/components/ui/sidebar.tsx +0 -1
  146. package/dist/dashboard-source/apps/frontend/components/ui/tab-pill.tsx +26 -15
  147. package/dist/dashboard-source/apps/frontend/components/workflow/step-node.tsx +0 -1
  148. package/dist/dashboard-source/apps/frontend/components/workflow/workflow-edge.tsx +5 -0
  149. package/dist/dashboard-source/apps/frontend/hooks/use-form-metadata.ts +21 -10
  150. package/dist/dashboard-source/apps/frontend/hooks/use-process-draft.ts +173 -0
  151. package/dist/dashboard-source/apps/frontend/hooks/use-weekly-execution-stats.ts +1 -3
  152. package/dist/dashboard-source/apps/frontend/lib/anonymous-page-form-values.ts +6 -0
  153. package/dist/dashboard-source/apps/frontend/lib/anonymous-page-server.ts +65 -0
  154. package/dist/dashboard-source/apps/frontend/lib/appsync-events/adapter.ts +9 -3
  155. package/dist/dashboard-source/apps/frontend/lib/appsync-events/client.ts +7 -340
  156. package/dist/dashboard-source/apps/frontend/lib/auth/client-session.ts +2 -0
  157. package/dist/dashboard-source/apps/frontend/lib/auth/delegations.ts +9 -7
  158. package/dist/dashboard-source/apps/frontend/lib/auth/google-revalidation.ts +111 -0
  159. package/dist/dashboard-source/apps/frontend/lib/auth/logout.ts +1 -1
  160. package/dist/dashboard-source/apps/frontend/lib/auth/passkeys.ts +28 -30
  161. package/dist/dashboard-source/apps/frontend/lib/auth/providers.ts +10 -0
  162. package/dist/dashboard-source/apps/frontend/lib/auth/realtime-session-token.ts +1 -0
  163. package/dist/dashboard-source/apps/frontend/lib/auth/reauthentication-state.ts +4 -4
  164. package/dist/dashboard-source/apps/frontend/lib/auth/session-admission.ts +11 -7
  165. package/dist/dashboard-source/apps/frontend/lib/auth/session.ts +27 -10
  166. package/dist/dashboard-source/apps/frontend/lib/auth/ssr-session.ts +76 -9
  167. package/dist/dashboard-source/apps/frontend/lib/auth/verify-passkey.ts +25 -3
  168. package/dist/dashboard-source/apps/frontend/lib/collections/collection-provider-factory.tsx +112 -21
  169. package/dist/dashboard-source/apps/frontend/lib/collections/draft-process-execution.ts +1 -8
  170. package/dist/dashboard-source/apps/frontend/lib/collections/execution.ts +6 -2
  171. package/dist/dashboard-source/apps/frontend/lib/collections/process-collection-provider.tsx +3 -0
  172. package/dist/dashboard-source/apps/frontend/lib/collections/process.ts +8 -2
  173. package/dist/dashboard-source/apps/frontend/lib/collections/replication-factory.ts +16 -4
  174. package/dist/dashboard-source/apps/frontend/lib/collections/todo.ts +1 -1
  175. package/dist/dashboard-source/apps/frontend/lib/effect/navigation.ts +4 -0
  176. package/dist/dashboard-source/apps/frontend/lib/effect/page-runtime.ts +29 -0
  177. package/dist/dashboard-source/apps/frontend/lib/effect/params.ts +18 -12
  178. package/dist/dashboard-source/apps/frontend/lib/effect/run-effect.ts +1 -1
  179. package/dist/dashboard-source/apps/frontend/lib/effect/runtime.ts +19 -23
  180. package/dist/dashboard-source/apps/frontend/lib/effect/services/access-token.ts +9 -12
  181. package/dist/dashboard-source/apps/frontend/lib/effect/services/authorization.ts +12 -12
  182. package/dist/dashboard-source/apps/frontend/lib/effect/services/form-validation.ts +20 -18
  183. package/dist/dashboard-source/apps/frontend/lib/effect/services/graphql.ts +32 -16
  184. package/dist/dashboard-source/apps/frontend/lib/embed-form-server.ts +35 -0
  185. package/dist/dashboard-source/apps/frontend/lib/embed-manifest.ts +10 -103
  186. package/dist/dashboard-source/apps/frontend/lib/forms/invitation.ts +43 -0
  187. package/dist/dashboard-source/apps/frontend/lib/forms/provider-user.ts +64 -0
  188. package/dist/dashboard-source/apps/frontend/lib/frontend-form-loaders.ts +40 -0
  189. package/dist/dashboard-source/apps/frontend/lib/frontend-manifest.ts +1 -33
  190. package/dist/dashboard-source/apps/frontend/lib/generated/gql/gql.ts +123 -33
  191. package/dist/dashboard-source/apps/frontend/lib/generated/gql/graphql.ts +169 -30
  192. package/dist/dashboard-source/apps/frontend/lib/generated/gql/index.ts +1 -0
  193. package/dist/dashboard-source/apps/frontend/lib/graphql/anonymous-page.ts +27 -0
  194. package/dist/dashboard-source/apps/frontend/lib/graphql/dependent-lookup-query.ts +1 -0
  195. package/dist/dashboard-source/apps/frontend/lib/graphql/list-queries.ts +38 -29
  196. package/dist/dashboard-source/apps/frontend/lib/graphql/lookup-provider.tsx +82 -10
  197. package/dist/dashboard-source/apps/frontend/lib/graphql/org-chart-operations.ts +2 -5
  198. package/dist/dashboard-source/apps/frontend/lib/graphql/queries.ts +25 -4
  199. package/dist/dashboard-source/apps/frontend/lib/graphql/server-client.ts +11 -0
  200. package/dist/dashboard-source/apps/frontend/lib/graphql/settings-queries.ts +13 -104
  201. package/dist/dashboard-source/apps/frontend/lib/graphql/user-queries.ts +11 -4
  202. package/dist/dashboard-source/apps/frontend/lib/graphql/workflow-operations.ts +1 -3
  203. package/dist/dashboard-source/apps/frontend/lib/graphql/workflow-queries.ts +1 -0
  204. package/dist/dashboard-source/apps/frontend/lib/list-detail-selection.ts +54 -0
  205. package/dist/dashboard-source/apps/frontend/lib/mcp/executions.ts +110 -0
  206. package/dist/dashboard-source/apps/frontend/lib/mcp/list-writes.ts +395 -0
  207. package/dist/dashboard-source/apps/frontend/lib/mcp/lists.ts +263 -0
  208. package/dist/dashboard-source/apps/frontend/lib/mcp/oauth.ts +900 -0
  209. package/dist/dashboard-source/apps/frontend/lib/mcp/origin.ts +42 -0
  210. package/dist/dashboard-source/apps/frontend/lib/mcp/processes.ts +436 -0
  211. package/dist/dashboard-source/apps/frontend/lib/mcp/read-tool.ts +72 -0
  212. package/dist/dashboard-source/apps/frontend/lib/mcp/result.ts +4 -0
  213. package/dist/dashboard-source/apps/frontend/lib/mcp/server.ts +71 -0
  214. package/dist/dashboard-source/apps/frontend/lib/mcp/store.ts +193 -0
  215. package/dist/dashboard-source/apps/frontend/lib/mcp/todos.ts +237 -0
  216. package/dist/dashboard-source/apps/frontend/lib/notifications/notification-preference.ts +0 -1
  217. package/dist/dashboard-source/apps/frontend/lib/notifications/todo-notification-observer.ts +0 -5
  218. package/dist/dashboard-source/apps/frontend/lib/org-chart-data.ts +0 -2
  219. package/dist/dashboard-source/apps/frontend/lib/org-identity.ts +6 -4
  220. package/dist/dashboard-source/apps/frontend/lib/organisation-form-loaders.ts +4 -0
  221. package/dist/dashboard-source/apps/frontend/lib/public-todo-form-runtime.ts +0 -1
  222. package/dist/dashboard-source/apps/frontend/lib/public-todo-model.ts +39 -139
  223. package/dist/dashboard-source/apps/frontend/lib/public-todo-server.ts +17 -16
  224. package/dist/dashboard-source/apps/frontend/lib/query-client.ts +0 -1
  225. package/dist/dashboard-source/apps/frontend/lib/todo-utils.ts +1 -77
  226. package/dist/dashboard-source/apps/frontend/lib/workflow/layout.ts +3 -7
  227. package/dist/dashboard-source/apps/frontend/next.config.ts +33 -13
  228. package/dist/dashboard-source/apps/frontend/package.json +48 -47
  229. package/dist/dashboard-source/apps/frontend/proxy.ts +72 -14
  230. package/dist/dashboard-source/modules/auth-local-cedar/src/index.ts +0 -3
  231. package/dist/dashboard-source/modules/auth-local-cedar/src/lib/auth-local-cedar.ts +165 -233
  232. package/dist/dashboard-source/modules/auth-local-cedar/src/lib/cedar-reload-notifier.ts +4 -3
  233. package/dist/dashboard-source/modules/auth-local-cedar/src/lib/config-base.ts +111 -75
  234. package/dist/dashboard-source/modules/auth-local-cedar/src/lib/policy-watcher.ts +14 -18
  235. package/dist/dashboard-source/modules/auth-policy/src/index.ts +1 -0
  236. package/dist/dashboard-source/modules/auth-policy/src/lib/auth-policy.ts +19 -37
  237. package/dist/dashboard-source/modules/auth-policy/src/lib/current-principal.ts +33 -29
  238. package/dist/dashboard-source/modules/auth-policy/src/lib/policy-revision.ts +23 -0
  239. package/dist/dashboard-source/modules/auth-policy/src/lib/types.ts +24 -49
  240. package/dist/dashboard-source/modules/auth-session/src/index.ts +4 -0
  241. package/dist/dashboard-source/modules/auth-session/src/lib/project-subscription.ts +13 -0
  242. package/dist/dashboard-source/modules/auth-session/src/lib/realtime-recipient.ts +10 -2
  243. package/dist/dashboard-source/modules/auth-session/src/lib/subjects.ts +82 -8
  244. package/dist/dashboard-source/modules/auth-session/src/lib/workload-access.ts +48 -0
  245. package/dist/dashboard-source/modules/auth-session/src/lib/workload-audit.ts +52 -0
  246. package/dist/dashboard-source/modules/aws-common/src/index.ts +0 -1
  247. package/dist/dashboard-source/modules/effect-json-logger/src/lib/effect-json-logger.ts +6 -9
  248. package/dist/dashboard-source/modules/form/src/hooks/use-local-storage.ts +5 -3
  249. package/dist/dashboard-source/modules/form/src/index.ts +1 -10
  250. package/dist/dashboard-source/modules/form/src/lib/effect-schema-form.tsx +1271 -0
  251. package/dist/dashboard-source/modules/form/src/lib/form-actions.ts +26 -0
  252. package/dist/dashboard-source/modules/form/src/lib/form-prefill.tsx +79 -0
  253. package/dist/dashboard-source/modules/form/src/lib/initial-focus.ts +31 -0
  254. package/dist/dashboard-source/modules/form/src/lib/lookup-context.tsx +18 -0
  255. package/dist/dashboard-source/modules/form/src/lib/plugin-registry.ts +4 -0
  256. package/dist/dashboard-source/modules/form/src/lib/plugin-scripts.ts +26 -0
  257. package/dist/dashboard-source/modules/form/src/lib/registered-plugin-field.tsx +57 -0
  258. package/dist/dashboard-source/modules/form/src/lib/schema-lookup.tsx +124 -0
  259. package/dist/dashboard-source/modules/form/src/lib/schema-typeahead.tsx +522 -0
  260. package/dist/dashboard-source/modules/form/src/lib/validation-logic.ts +172 -0
  261. package/dist/dashboard-source/modules/form-schema/src/index.ts +4 -1
  262. package/dist/dashboard-source/modules/form-schema/src/lib/annotation-helpers.ts +19 -14
  263. package/dist/dashboard-source/modules/form-schema/src/lib/email.ts +13 -11
  264. package/dist/dashboard-source/modules/form-schema/src/lib/field-count.ts +15 -13
  265. package/dist/dashboard-source/modules/form-schema/src/lib/form-annotations.ts +14 -0
  266. package/dist/dashboard-source/modules/form-schema/src/lib/form-presentation.ts +33 -0
  267. package/dist/dashboard-source/modules/form-schema/src/lib/form-schema.ts +186 -80
  268. package/dist/dashboard-source/modules/form-schema/src/lib/number-from-string.ts +26 -0
  269. package/dist/dashboard-source/modules/form-schema/src/lib/phone.ts +8 -7
  270. package/dist/dashboard-source/modules/form-schema/src/lib/public-completion-correction.ts +7 -0
  271. package/dist/dashboard-source/modules/form-schema/src/lib/search-lookup-items.ts +27 -0
  272. package/dist/dashboard-source/modules/form-submission-schema/src/index.ts +5 -0
  273. package/dist/dashboard-source/modules/form-submission-schema/src/lib/executable-rules.ts +379 -0
  274. package/dist/dashboard-source/modules/form-submission-schema/src/lib/form-submission-schema.ts +475 -0
  275. package/dist/dashboard-source/modules/form-submission-schema/src/lib/json-schema.ts +58 -0
  276. package/dist/dashboard-source/modules/form-submission-schema/src/lib/schema-defaults.ts +158 -0
  277. package/dist/dashboard-source/modules/form-submission-schema/src/lib/submission-utils.ts +75 -0
  278. package/dist/dashboard-source/modules/frontend-manifest/src/lib/browser-plugin-artifact.ts +46 -0
  279. package/dist/dashboard-source/modules/frontend-manifest/src/lib/frontend-manifest.ts +37 -30
  280. package/dist/dashboard-source/modules/frontend-plugin-host/src/lib/frontend-plugin-host.ts +9 -1
  281. package/dist/dashboard-source/modules/openauth/src/client.ts +25 -17
  282. package/dist/dashboard-source/modules/openauth/src/util.ts +16 -0
  283. package/dist/dashboard-source/modules/{aws-common/src/lib/project-balance-admission.ts → project-accounting/src/admission.ts} +4 -8
  284. package/dist/dashboard-source/modules/realtime-client/src/appsync-client.ts +377 -0
  285. package/dist/dashboard-source/modules/realtime-client/src/index.ts +5 -0
  286. package/dist/dashboard-source/modules/realtime-client/src/subscription-presence.ts +163 -0
  287. package/dist/dashboard-source/modules/request-time/src/lib/request-time.ts +6 -24
  288. package/dist/dashboard-source/modules/rxdb-collections/generated/execution-schema.json +28 -21
  289. package/dist/dashboard-source/modules/rxdb-collections/src/lib/rxdb-collections.ts +25 -18
  290. package/dist/dashboard-source/modules/rxdb-collections/src/lib/to-rxdb-schema.ts +60 -10
  291. package/dist/dashboard-source/modules/shadcn-components/src/index.ts +18 -2
  292. package/dist/dashboard-source/modules/shadcn-components/src/lib/date-calendar.tsx +93 -0
  293. package/dist/dashboard-source/modules/shadcn-components/src/lib/date-field.tsx +147 -48
  294. package/dist/dashboard-source/modules/shadcn-components/src/lib/date-time-display.tsx +272 -0
  295. package/dist/dashboard-source/modules/shadcn-components/src/lib/local-date-time-input.tsx +108 -0
  296. package/dist/dashboard-source/modules/shadcn-components/src/lib/lookup-field.tsx +237 -351
  297. package/dist/dashboard-source/modules/shadcn-components/src/lib/ui/popover.tsx +2 -1
  298. package/dist/dashboard-source.json +48 -47
  299. package/dist/graphql-server.mjs +245 -200
  300. package/dist/job-worker-supervisor.mjs +262 -0
  301. package/dist/job-worker.mjs +234 -133
  302. package/dist/main.mjs +23 -4
  303. package/dist/prepare-dashboard.mjs +8 -8
  304. package/dist/resources/cedar/policies.cedar +80 -38
  305. package/dist/resources/cedar/schema.cedarschema +39 -21
  306. package/dist/resources/graphql-schema/rxdb.graphql +2 -0
  307. package/dist/resources/graphql-schema/system.graphql +204 -51
  308. package/package.json +64 -62
  309. package/dist/chunk-6b6t8tyq.js +0 -85
  310. package/dist/dashboard-source/apps/frontend/app/(protected)/lists/utils.ts +0 -20
  311. package/dist/dashboard-source/apps/frontend/app/(protected)/processes/components/process-form-actions.tsx +0 -105
  312. package/dist/dashboard-source/apps/frontend/hooks/use-draft-process-save.ts +0 -189
  313. package/dist/dashboard-source/apps/frontend/hooks/use-draft-state.ts +0 -79
  314. package/dist/dashboard-source/apps/frontend/hooks/use-processes-query.ts +0 -56
  315. package/dist/dashboard-source/modules/form/src/lib/ajv-standard-schema.ts +0 -152
  316. package/dist/dashboard-source/modules/form/src/lib/client-components-to-form.tsx +0 -1421
  317. package/dist/dashboard-source/modules/form/src/lib/friendly-validation-message.ts +0 -85
  318. package/dist/dashboard-source/modules/form/src/lib/walker.tsx +0 -1549
  319. package/dist/dashboard-source/modules/form-client-representation/src/lib/client-form-definition.ts +0 -440
  320. package/dist/dashboard-source/modules/form-client-representation/src/lib/plugin-registry.ts +0 -13
  321. package/dist/dashboard-source/modules/form-client-representation/src/lib/types.ts +0 -336
  322. package/dist/dashboard-source/modules/form-rule/src/index.ts +0 -21
  323. package/dist/dashboard-source/modules/form-rule/src/lib/evaluator.ts +0 -531
  324. package/dist/dashboard-source/modules/form-rule/src/lib/paths.ts +0 -102
  325. package/dist/dashboard-source/modules/form-rule/src/lib/types.ts +0 -121
  326. package/dist/dashboard-source/modules/form-schema/src/lib/property-signature.ts +0 -45
@@ -0,0 +1,475 @@
1
+ import { Data, Effect, Result, Schema, SchemaAST } from "effect"
2
+ import {
3
+ type FlattenMarker,
4
+ type ListFieldMarker,
5
+ type ReadOnlyMarker,
6
+ type StructuralOnlyMarker,
7
+ hasFlattenAnnotation,
8
+ hasStructuralOnlyAnnotation,
9
+ isReadOnlyField,
10
+ } from "../../../form-schema/src/index.ts"
11
+
12
+ // Error for field name collisions during flattening
13
+ export class FieldNameCollisionError extends Data.TaggedError(
14
+ "FieldNameCollisionError",
15
+ )<{
16
+ readonly fieldName: string
17
+ readonly wrapperField: string
18
+ }> {
19
+ override get message() {
20
+ return `Field name collision: "${this.wrapperField}" is already present as "${this.fieldName}" in its parent struct`
21
+ }
22
+ }
23
+
24
+ // Error for invalid flatten annotation usage (on non-struct fields)
25
+ export class InvalidFlattenAnnotationError extends Data.TaggedError(
26
+ "InvalidFlattenAnnotationError",
27
+ )<{
28
+ readonly fieldName: string
29
+ readonly astTag: string
30
+ }> {
31
+ override get message() {
32
+ return `Invalid schema: field "${this.fieldName}" has flatten annotation but is not a struct (AST tag: ${this.astTag}). Only use Wrapper() with Schema.Struct().`
33
+ }
34
+ }
35
+
36
+ type UnionToIntersection<U> = (
37
+ U extends unknown
38
+ ? (k: U) => void
39
+ : never
40
+ ) extends (k: infer I) => void
41
+ ? I
42
+ : never
43
+
44
+ type IsExcluded<Field> = Field extends StructuralOnlyMarker | ReadOnlyMarker
45
+ ? true
46
+ : Field extends { readonly schema: infer Inner }
47
+ ? IsExcluded<Inner>
48
+ : Field extends { readonly from: infer From }
49
+ ? IsExcluded<From>
50
+ : Field extends { readonly members: ReadonlyArray<infer Member> }
51
+ ? true extends IsExcluded<Member>
52
+ ? true
53
+ : false
54
+ : false
55
+
56
+ type ProjectedStruct<
57
+ Fields extends Schema.Struct.Fields,
58
+ KeepReadOnly extends boolean,
59
+ > = Schema.Struct<
60
+ (
61
+ KeepReadOnly extends true
62
+ ? FlattenFieldsKeepingReadOnly<Fields>
63
+ : FlattenFields<Fields>
64
+ ) extends infer F extends Schema.Struct.Fields
65
+ ? F
66
+ : never
67
+ >
68
+
69
+ // Preserve wrapper contracts while projecting their contained schemas.
70
+ // Detail arrays recurse like ListField; ordinary submission arrays retain their
71
+ // existing projection.
72
+ type ProjectSchema<
73
+ S extends Schema.Constraint,
74
+ KeepReadOnly extends boolean = false,
75
+ > =
76
+ S extends Schema.Struct<infer Fields>
77
+ ? ProjectedStruct<Fields, KeepReadOnly>
78
+ : S extends ListFieldMarker<infer Items>
79
+ ? Schema.$Array<ProjectedStruct<Items, KeepReadOnly>>
80
+ : S extends Schema.Union<infer Members>
81
+ ? Schema.Union<{
82
+ [K in keyof Members]: ProjectSchema<Members[K], KeepReadOnly>
83
+ }>
84
+ : S extends Schema.optionalKey<infer Inner>
85
+ ? Schema.optionalKey<ProjectSchema<Inner, KeepReadOnly>>
86
+ : S extends Schema.optional<infer Inner>
87
+ ? Schema.optional<ProjectSchema<Inner, KeepReadOnly>>
88
+ : S extends Schema.decodeTo<
89
+ infer To,
90
+ infer From,
91
+ infer RD,
92
+ infer RE
93
+ >
94
+ ? Schema.decodeTo<
95
+ ProjectSchema<To, KeepReadOnly>,
96
+ ProjectSchema<From, KeepReadOnly>,
97
+ RD,
98
+ RE
99
+ >
100
+ : S extends Schema.toType<infer Inner>
101
+ ? Schema.toType<ProjectSchema<Inner, KeepReadOnly>>
102
+ : S extends Schema.toEncoded<infer Inner>
103
+ ? Schema.toEncoded<ProjectSchema<Inner, KeepReadOnly>>
104
+ : KeepReadOnly extends true
105
+ ? S extends Schema.$Array<infer Item>
106
+ ? Schema.$Array<ProjectSchema<Item, KeepReadOnly>>
107
+ : S
108
+ : S
109
+
110
+ type ProjectField<Field extends Schema.Struct.Fields[string]> =
111
+ ProjectSchema<Field>
112
+
113
+ type WrapperFields<Field> = Field extends Schema.Struct<infer Fields> &
114
+ FlattenMarker
115
+ ? FlattenFields<Fields>
116
+ : Field extends Schema.toEncoded<infer Inner>
117
+ ? WrapperFields<Inner> extends infer Fields extends Schema.Struct.Fields
118
+ ? { [K in keyof Fields]: Schema.toEncoded<Fields[K]> }
119
+ : never
120
+ : never
121
+
122
+ // Wrapper fields flatten; ordinary containers keep their keys and optionality.
123
+ export type FlattenFields<Fields extends Schema.Struct.Fields> =
124
+ UnionToIntersection<
125
+ {
126
+ [K in keyof Fields]: IsExcluded<Fields[K]> extends true
127
+ ? never
128
+ : [WrapperFields<Fields[K]>] extends [never]
129
+ ? { [P in K]: ProjectField<Fields[K]> }
130
+ : WrapperFields<Fields[K]>
131
+ }[keyof Fields]
132
+ >
133
+
134
+ type IsStructuralOnly<Field> = Field extends StructuralOnlyMarker
135
+ ? true
136
+ : Field extends { readonly schema: infer Inner }
137
+ ? IsStructuralOnly<Inner>
138
+ : Field extends { readonly from: infer From }
139
+ ? IsStructuralOnly<From>
140
+ : Field extends { readonly members: ReadonlyArray<infer Member> }
141
+ ? true extends IsStructuralOnly<Member>
142
+ ? true
143
+ : false
144
+ : false
145
+
146
+ type WrapperFieldsKeepingReadOnly<Field> = Field extends Schema.Struct<
147
+ infer Fields
148
+ > &
149
+ FlattenMarker
150
+ ? FlattenFieldsKeepingReadOnly<Fields>
151
+ : Field extends Schema.toEncoded<infer Inner>
152
+ ? WrapperFieldsKeepingReadOnly<Inner> extends infer Fields extends
153
+ Schema.Struct.Fields
154
+ ? { [K in keyof Fields]: Schema.toEncoded<Fields[K]> }
155
+ : never
156
+ : never
157
+
158
+ /**
159
+ * Flatten wrapper fields like `FlattenFields`, but keep read-only fields:
160
+ * detail/output data is display-only content that queries still return.
161
+ * Structural-only elements are omitted, matching GraphQL output walking.
162
+ */
163
+ export type FlattenFieldsKeepingReadOnly<Fields extends Schema.Struct.Fields> =
164
+ UnionToIntersection<
165
+ {
166
+ [K in keyof Fields]: IsStructuralOnly<Fields[K]> extends true
167
+ ? never
168
+ : [WrapperFieldsKeepingReadOnly<Fields[K]>] extends [never]
169
+ ? { [P in K]: ProjectSchema<Fields[K], true> }
170
+ : WrapperFieldsKeepingReadOnly<Fields[K]>
171
+ }[keyof Fields]
172
+ >
173
+
174
+ export const isStructSchema = (
175
+ field: Schema.Constraint,
176
+ ): field is Schema.Struct<Schema.Struct.Fields> =>
177
+ field.ast._tag === "Objects" && "fields" in field
178
+
179
+ type FlattenedSubmissionStruct<Fields extends Schema.Struct.Fields> =
180
+ Schema.Struct<
181
+ FlattenFields<Fields> extends infer F extends Schema.Struct.Fields
182
+ ? F
183
+ : never
184
+ >
185
+
186
+ export type SubmissionSchemaError =
187
+ | FieldNameCollisionError
188
+ | InvalidFlattenAnnotationError
189
+
190
+ // Checks whether a field is a flattenable Wrapper struct (errors on invalid annotation).
191
+ const isFlattenableStruct = (
192
+ field: Schema.Constraint,
193
+ fieldName: string,
194
+ ): Effect.Effect<boolean, InvalidFlattenAnnotationError> =>
195
+ Effect.gen(function* () {
196
+ const hasFlatten = hasFlattenAnnotation(field)
197
+ const isStructAst = field.ast._tag === "Objects"
198
+
199
+ // Defensive: if has flatten annotation but isn't a struct, that's a programming error
200
+ if (hasFlatten && !isStructAst) {
201
+ return yield* new InvalidFlattenAnnotationError({
202
+ fieldName,
203
+ astTag: field.ast._tag,
204
+ })
205
+ }
206
+
207
+ return hasFlatten && isStructAst
208
+ })
209
+
210
+ // Creates a submission schema by flattening Wrapper fields while preserving regular nested structs
211
+ export const submissionSchema = <Fields extends Schema.Struct.Fields>(
212
+ schema: Schema.Struct<Fields>,
213
+ ): Effect.Effect<FlattenedSubmissionStruct<Fields>, SubmissionSchemaError> =>
214
+ Effect.gen(function* () {
215
+ const flatFields: Record<string, Schema.Struct.Fields[string]> = {}
216
+
217
+ for (const [key, field] of Object.entries(schema.fields)) {
218
+ const fieldAsAny = field as Schema.Top
219
+
220
+ if (hasStructuralOnlyAnnotation(fieldAsAny)) {
221
+ // Skip structural-only fields (UI-only, not in submission)
222
+ continue
223
+ }
224
+
225
+ if (isReadOnlyField(fieldAsAny)) {
226
+ // Skip read-only fields (display-only, not submittable)
227
+ continue
228
+ }
229
+
230
+ if (yield* isFlattenableStruct(fieldAsAny, String(key))) {
231
+ // This is a Wrapper - recursively flatten it first to handle nested Wrappers
232
+ const recursivelyFlattened = yield* submissionSchema(
233
+ fieldAsAny as Schema.Struct<Schema.Struct.Fields>,
234
+ )
235
+
236
+ // Spread the recursively flattened fields with collision detection
237
+ for (const [nestedKey, nestedValue] of Object.entries(
238
+ recursivelyFlattened.fields,
239
+ )) {
240
+ if (nestedKey in flatFields) {
241
+ return yield* new FieldNameCollisionError({
242
+ fieldName: nestedKey,
243
+ wrapperField: `${key}...${nestedKey}`,
244
+ })
245
+ }
246
+ flatFields[nestedKey] = nestedValue as Schema.Top
247
+ }
248
+ } else {
249
+ if (key in flatFields)
250
+ return yield* new FieldNameCollisionError({
251
+ fieldName: key,
252
+ wrapperField: key,
253
+ })
254
+ // Project nested containers without changing their nesting or array cardinality.
255
+ flatFields[key] = yield* projectField(field)
256
+ }
257
+ }
258
+
259
+ yield* prepareExpansion(schema.ast)
260
+ return Schema.Struct(
261
+ flatFields,
262
+ ) as unknown as FlattenedSubmissionStruct<Fields>
263
+ })
264
+
265
+ /** Rebuild signatures without losing intrinsic defaults, key mappings or codecs. */
266
+ const projectField = (
267
+ field: Schema.Struct.Fields[string],
268
+ ): Effect.Effect<Schema.Struct.Fields[string], SubmissionSchemaError> =>
269
+ Effect.map(projectNested(field.ast), (ast) => Schema.make(ast))
270
+
271
+ const projectNested = (
272
+ ast: SchemaAST.AST,
273
+ ): Effect.Effect<SchemaAST.AST, SubmissionSchemaError> =>
274
+ Effect.gen(function* () {
275
+ const encoding = ast.encoding
276
+ ? yield* Effect.forEach(ast.encoding, (link) =>
277
+ Effect.map(
278
+ projectNested(link.to),
279
+ (to) => new SchemaAST.Link(to, link.transformation),
280
+ ),
281
+ )
282
+ : undefined
283
+ if (ast._tag === "Objects") {
284
+ const properties: SchemaAST.PropertySignature[] = []
285
+ const names = new Set<PropertyKey>()
286
+ for (const property of ast.propertySignatures) {
287
+ const field = Schema.make(property.type)
288
+ if (hasStructuralOnlyAnnotation(field) || isReadOnlyField(field))
289
+ continue
290
+ const flatten = yield* isFlattenableStruct(field, String(property.name))
291
+ const projected = yield* projectNested(property.type)
292
+ const children =
293
+ flatten && projected._tag === "Objects"
294
+ ? projected.propertySignatures
295
+ : [new SchemaAST.PropertySignature(property.name, projected)]
296
+ for (const child of children) {
297
+ if (names.has(child.name))
298
+ return yield* new FieldNameCollisionError({
299
+ fieldName: String(child.name),
300
+ wrapperField: `${String(property.name)}...${String(child.name)}`,
301
+ })
302
+ names.add(child.name)
303
+ properties.push(child)
304
+ }
305
+ }
306
+ return new SchemaAST.Objects(
307
+ properties,
308
+ ast.indexSignatures,
309
+ ast.annotations,
310
+ ast.checks,
311
+ encoding,
312
+ ast.context,
313
+ ast.encodingChecks,
314
+ )
315
+ }
316
+ if (ast._tag === "Union")
317
+ return new SchemaAST.Union(
318
+ yield* Effect.forEach(ast.types, projectNested),
319
+ ast.options,
320
+ ast.annotations,
321
+ ast.checks,
322
+ encoding,
323
+ ast.context,
324
+ ast.encodingChecks,
325
+ )
326
+ if (ast._tag === "Arrays")
327
+ return new SchemaAST.Arrays(
328
+ ast.isMutable,
329
+ yield* Effect.forEach(ast.elements, projectNested),
330
+ yield* Effect.forEach(ast.rest, projectNested),
331
+ ast.annotations,
332
+ ast.checks,
333
+ encoding,
334
+ ast.context,
335
+ ast.encodingChecks,
336
+ )
337
+ return encoding
338
+ ? Object.assign(Object.create(Object.getPrototypeOf(ast)), ast, {
339
+ encoding,
340
+ })
341
+ : ast
342
+ })
343
+
344
+ /**
345
+ * Synchronous boundary for model construction and other non-Effect call sites.
346
+ * Rethrows the original TaggedError on failure (not a FiberFailure wrapper).
347
+ */
348
+ export const submissionSchemaSync = <Fields extends Schema.Struct.Fields>(
349
+ schema: Schema.Struct<Fields>,
350
+ ): FlattenedSubmissionStruct<Fields> => {
351
+ const result = Effect.runSync(Effect.result(submissionSchema(schema)))
352
+ if (Result.isFailure(result)) {
353
+ throw result.failure
354
+ }
355
+ return result.success
356
+ }
357
+
358
+ export const expandSubmissionInput = <Fields extends Schema.Struct.Fields>(
359
+ schema: Schema.Struct<Fields>,
360
+ input: Record<string, unknown>,
361
+ ): Record<string, unknown> => {
362
+ // Accepted schemas are prepared during construction. Direct callers prepare once.
363
+ const prepared =
364
+ expansionCache.get(schema.ast) ??
365
+ Effect.runSync(prepareExpansion(schema.ast))
366
+ return expandStructInput(prepared.ast, input, prepared.members)
367
+ }
368
+
369
+ type UnionMember = {
370
+ readonly ast: SchemaAST.AST
371
+ readonly matches: (input: unknown) => boolean
372
+ }
373
+ type UnionMembers = ReadonlyMap<SchemaAST.AST, ReadonlyArray<UnionMember>>
374
+
375
+ const expansionCache = new WeakMap<
376
+ SchemaAST.AST,
377
+ { readonly ast: SchemaAST.AST; readonly members: UnionMembers }
378
+ >()
379
+
380
+ // Compile encoded union selectors at schema construction, never per submission/row.
381
+ const prepareExpansion = (source: SchemaAST.AST) =>
382
+ Effect.gen(function* () {
383
+ const cached = expansionCache.get(source)
384
+ if (cached) return cached
385
+ // Keep authored annotations: encodedAST drops them when rebuilding codec containers.
386
+ // Traversal follows .from at each codec, so expansion still operates on wire values.
387
+ const ast = SchemaAST.toEncoded(source)
388
+ const members = new Map<SchemaAST.AST, ReadonlyArray<UnionMember>>()
389
+ const visit = (
390
+ node: SchemaAST.AST,
391
+ ): Effect.Effect<void, SubmissionSchemaError> =>
392
+ Effect.gen(function* () {
393
+ if (node._tag === "Union") {
394
+ members.set(
395
+ node,
396
+ yield* Effect.forEach(node.types, (member) =>
397
+ Effect.gen(function* () {
398
+ const projected = yield* projectNested(member)
399
+ yield* visit(member)
400
+ return {
401
+ ast: member,
402
+ matches: Schema.is(Schema.toEncoded(Schema.make(projected))),
403
+ }
404
+ }),
405
+ ),
406
+ )
407
+ } else if (node._tag === "Objects") {
408
+ yield* Effect.forEach(node.propertySignatures, (property) => {
409
+ const field = Schema.make(property.type)
410
+ return hasStructuralOnlyAnnotation(field) || isReadOnlyField(field)
411
+ ? Effect.void
412
+ : visit(property.type)
413
+ })
414
+ } else if (node._tag === "Arrays") {
415
+ yield* Effect.forEach([...node.elements, ...node.rest], (element) =>
416
+ visit(element),
417
+ )
418
+ }
419
+ })
420
+ yield* visit(ast)
421
+ const prepared = { ast, members }
422
+ expansionCache.set(source, prepared)
423
+ return prepared
424
+ })
425
+
426
+ const isInputRecord = (input: unknown): input is Record<string, unknown> =>
427
+ typeof input === "object" && input !== null && !Array.isArray(input)
428
+
429
+ // Expansion rearranges encoded values; it must not run business codecs or defaults.
430
+ const expandNestedInput = (
431
+ ast: SchemaAST.AST,
432
+ input: unknown,
433
+ members: UnionMembers,
434
+ ): unknown => {
435
+ if (ast._tag === "Union") {
436
+ const member = members
437
+ .get(ast)
438
+ ?.find((candidate) => candidate.matches(input))
439
+ return member ? expandNestedInput(member.ast, input, members) : input
440
+ }
441
+ if (ast._tag === "Objects" && isInputRecord(input))
442
+ return expandStructInput(ast, input, members)
443
+ if (ast._tag === "Arrays" && Array.isArray(input))
444
+ return input.map((value, index) => {
445
+ const element = ast.elements[index] ?? ast.rest[0]
446
+ return element ? expandNestedInput(element, value, members) : value
447
+ })
448
+ return input
449
+ }
450
+
451
+ const expandStructInput = (
452
+ ast: SchemaAST.AST,
453
+ input: Record<string, unknown>,
454
+ members: UnionMembers,
455
+ ): Record<string, unknown> => {
456
+ if (ast._tag !== "Objects") return input
457
+ const expanded: Record<string, unknown> = {}
458
+ for (const property of ast.propertySignatures) {
459
+ if (typeof property.name !== "string") continue
460
+ const key = property.name
461
+ const field = Schema.make(property.type)
462
+ if (hasStructuralOnlyAnnotation(field) || isReadOnlyField(field)) continue
463
+ if (hasFlattenAnnotation(field)) {
464
+ expanded[key] = expandNestedInput(property.type, input, members)
465
+ continue
466
+ }
467
+ if (Object.hasOwn(input, key)) {
468
+ expanded[key] = expandNestedInput(property.type, input[key], members)
469
+ continue
470
+ }
471
+ if (!property.type.context?.isOptional && property.type._tag === "Objects")
472
+ expanded[key] = expandStructInput(property.type, {}, members)
473
+ }
474
+ return expanded
475
+ }
@@ -0,0 +1,58 @@
1
+ import { JsonSchema, Schema, SchemaRepresentation } from "effect"
2
+
3
+ /** Keep the v3 JSON-number contract instead of v4's non-finite string codec. */
4
+ const preserveJsonNumbers = (value: unknown): unknown => {
5
+ if (Array.isArray(value)) return value.map(preserveJsonNumbers)
6
+ if (value === null || typeof value !== "object") return value
7
+ const object = value as Record<string, unknown>
8
+ const assertions = object["allOf"]
9
+ if (
10
+ Array.isArray(assertions) &&
11
+ assertions.length === 1 &&
12
+ assertions[0]?.enum
13
+ ) {
14
+ const { allOf: _, ...rest } = object
15
+ return preserveJsonNumbers({ ...rest, ...assertions[0] })
16
+ }
17
+ const alternatives = object["anyOf"]
18
+ if (
19
+ Array.isArray(alternatives) &&
20
+ alternatives.length === 2 &&
21
+ alternatives[0]?.type === "number" &&
22
+ alternatives[1]?.type === "string" &&
23
+ Array.isArray(alternatives[1].enum) &&
24
+ alternatives[1].enum.length === 3 &&
25
+ ["Infinity", "-Infinity", "NaN"].every((value) =>
26
+ alternatives[1].enum.includes(value),
27
+ )
28
+ ) {
29
+ const { anyOf: _, ...rest } = object
30
+ return { ...rest, ...alternatives[0] }
31
+ }
32
+ return Object.fromEntries(
33
+ Object.entries(object).map(([key, item]) => [
34
+ key,
35
+ preserveJsonNumbers(item),
36
+ ]),
37
+ )
38
+ }
39
+
40
+ /** Render the existing draft-07 form contract, including referenced definitions. */
41
+ export const toFormJsonSchema = (
42
+ schema: Schema.Constraint,
43
+ ): JsonSchema.JsonSchema => {
44
+ const document = JsonSchema.toDocumentDraft07(
45
+ // Compile the authored encoded shape directly. Canonical JSON codecs add
46
+ // a Number transformation that drops its checks and annotations.
47
+ SchemaRepresentation.toJsonSchemaDocument(Schema.toRepresentation(schema), {
48
+ onExcessProperty: "error",
49
+ }),
50
+ )
51
+ return preserveJsonNumbers({
52
+ $schema: JsonSchema.META_SCHEMA_URI_DRAFT_07,
53
+ ...document.schema,
54
+ ...(Object.keys(document.definitions).length
55
+ ? { definitions: document.definitions }
56
+ : {}),
57
+ }) as JsonSchema.JsonSchema
58
+ }
@@ -0,0 +1,158 @@
1
+ import { Match, type Schema } from "effect"
2
+ import * as AST from "effect/SchemaAST"
3
+ import {
4
+ FormLookupInput,
5
+ fieldAnnotation,
6
+ hasFlattenAnnotation,
7
+ hasStructuralOnlyAnnotation,
8
+ isReadOnlyField,
9
+ } from "../../../form-schema/src/index.ts"
10
+
11
+ /**
12
+ * Recursively removes readonly modifiers from all properties
13
+ */
14
+ export type DeepWritable<T> = T extends object
15
+ ? { -readonly [K in keyof T]: DeepWritable<T[K]> }
16
+ : T
17
+
18
+ /**
19
+ * Generate type-compatible default values from Effect Schema fields.
20
+ *
21
+ * This creates empty/zero values to satisfy Tanstack Form's type requirements.
22
+ * Values are NOT validated - they're just type-compatible placeholders.
23
+ *
24
+ * Without this we have an uncontrolled input error.
25
+ */
26
+ export const getSchemaDefaults = <Fields extends Schema.Struct.Fields>(
27
+ fields: Fields,
28
+ ): { [K in keyof Fields]: DeepWritable<Schema.Schema.Type<Fields[K]>> } => {
29
+ const result: Record<string, unknown> = {}
30
+
31
+ for (const [key, fieldSchema] of Object.entries(fields)) {
32
+ const schema = fieldSchema as Schema.Codec<unknown, unknown, never, never>
33
+ // Skip structural-only fields (UI-only elements like TextBlock, Divider)
34
+ if (hasStructuralOnlyAnnotation(schema) || isReadOnlyField(schema)) {
35
+ continue
36
+ }
37
+
38
+ if (hasFlattenAnnotation(schema) && schema.ast._tag === "Objects") {
39
+ Object.assign(result, getDefaultsForObjects(schema.ast))
40
+ continue
41
+ }
42
+
43
+ const ast = AST.toEncoded(fieldSchema.ast)
44
+ result[key] = getDefaultForSchema(ast, ast.context?.isOptional)
45
+ }
46
+
47
+ return result as {
48
+ [K in keyof Fields]: DeepWritable<Schema.Schema.Type<Fields[K]>>
49
+ }
50
+ }
51
+
52
+ const getDefaultsForObjects = (
53
+ typeLiteral: AST.Objects,
54
+ ): Record<string, unknown> => {
55
+ const result: Record<string, unknown> = {}
56
+
57
+ for (const prop of typeLiteral.propertySignatures) {
58
+ const key = String(prop.name)
59
+ const fieldSchema = prop.type as AST.AST
60
+ const fieldAsSchema = { ast: fieldSchema } as Schema.Top
61
+
62
+ if (
63
+ hasStructuralOnlyAnnotation(fieldAsSchema) ||
64
+ isReadOnlyField(fieldAsSchema)
65
+ ) {
66
+ continue
67
+ }
68
+
69
+ if (fieldSchema._tag === "Objects") {
70
+ if (hasFlattenAnnotation(fieldAsSchema)) {
71
+ Object.assign(result, getDefaultsForObjects(fieldSchema))
72
+ continue
73
+ }
74
+ }
75
+
76
+ result[key] = getDefaultForSchema(
77
+ fieldSchema,
78
+ prop.type.context?.isOptional,
79
+ )
80
+ }
81
+
82
+ return result
83
+ }
84
+
85
+ const unionMembers = (ast: AST.AST): readonly AST.AST[] =>
86
+ ast._tag === "Union" ? ast.types.flatMap(unionMembers) : [ast]
87
+
88
+ /**
89
+ * Get default value for a single schema AST node
90
+ */
91
+ const getDefaultForSchema = (ast: AST.AST, isOptional = false): unknown => {
92
+ const lookup = fieldAnnotation(ast, FormLookupInput)
93
+ if (
94
+ typeof lookup === "object" &&
95
+ lookup !== null &&
96
+ "mode" in lookup &&
97
+ (lookup.mode === "server" || lookup.mode === "local")
98
+ ) {
99
+ const members = unionMembers(AST.toEncoded(ast))
100
+ if (isOptional || members.some((member) => member._tag === "Undefined"))
101
+ return undefined
102
+ if (members.some((member) => member._tag === "Null")) return null
103
+ }
104
+ const match = Match.type<AST.AST>().pipe(
105
+ Match.tag("String", () => ""),
106
+ Match.tag("Number", () => 0),
107
+ Match.tag("Boolean", () => false),
108
+ Match.tag("Literal", (literal) =>
109
+ isOptional && typeof literal.literal === "string" ? undefined : "",
110
+ ),
111
+ Match.tag("Union", (union) => {
112
+ const members = unionMembers(union)
113
+ if (
114
+ members.some((member) => member._tag === "Boolean") &&
115
+ members.every(
116
+ (member) => member._tag === "Boolean" || member._tag === "Undefined",
117
+ )
118
+ ) {
119
+ return false
120
+ }
121
+ const choices = members.filter(
122
+ (member) => member._tag !== "Undefined" && !(member._tag === "Null"),
123
+ )
124
+ if (
125
+ choices.length > 0 &&
126
+ choices.every(
127
+ (member) =>
128
+ member._tag === "Literal" && typeof member.literal === "string",
129
+ )
130
+ ) {
131
+ if (members.some((member) => member._tag === "Null")) {
132
+ return null
133
+ }
134
+ if (
135
+ isOptional ||
136
+ members.some((member) => member._tag === "Undefined")
137
+ ) {
138
+ return undefined
139
+ }
140
+ }
141
+ return ""
142
+ }),
143
+ Match.tag("Objects", (typeLiteral) => {
144
+ const nestedResult: Record<string, unknown> = {}
145
+ for (const prop of typeLiteral.propertySignatures) {
146
+ nestedResult[String(prop.name)] = getDefaultForSchema(
147
+ prop.type,
148
+ prop.type.context?.isOptional,
149
+ )
150
+ }
151
+ return nestedResult
152
+ }),
153
+ Match.tag("Arrays", () => []),
154
+ Match.orElse(() => ""),
155
+ )
156
+
157
+ return match(AST.toEncoded(ast))
158
+ }