@baseplate-dev/plugin-auth 4.0.3 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (449) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +3 -3
  3. package/dist/auth/core/node.d.ts.map +1 -1
  4. package/dist/auth/core/node.js +2 -1
  5. package/dist/auth/core/node.js.map +1 -1
  6. package/dist/auth/core/schema/plugin-definition.d.ts +2 -12
  7. package/dist/auth/core/schema/plugin-definition.d.ts.map +1 -1
  8. package/dist/auth/core/schema/roles/schema.d.ts +2 -12
  9. package/dist/auth/core/schema/roles/schema.d.ts.map +1 -1
  10. package/dist/auth/core/schema/roles/schema.js +10 -17
  11. package/dist/auth/core/schema/roles/schema.js.map +1 -1
  12. package/dist/auth/plugin.json +1 -1
  13. package/dist/better-auth/constants/model-names.d.ts +8 -0
  14. package/dist/better-auth/constants/model-names.d.ts.map +1 -0
  15. package/dist/better-auth/constants/model-names.js +8 -0
  16. package/dist/better-auth/constants/model-names.js.map +1 -0
  17. package/dist/better-auth/constants/packages.d.ts +4 -0
  18. package/dist/better-auth/constants/packages.d.ts.map +1 -0
  19. package/dist/better-auth/constants/packages.js +4 -0
  20. package/dist/better-auth/constants/packages.js.map +1 -0
  21. package/dist/better-auth/core/common.d.ts.map +1 -0
  22. package/dist/better-auth/core/common.js +17 -0
  23. package/dist/better-auth/core/common.js.map +1 -0
  24. package/dist/better-auth/core/components/better-auth-definition-editor.d.ts +5 -0
  25. package/dist/better-auth/core/components/better-auth-definition-editor.d.ts.map +1 -0
  26. package/dist/{auth0/core/components/auth0-definition-editor.js → better-auth/core/components/better-auth-definition-editor.js} +17 -17
  27. package/dist/better-auth/core/components/better-auth-definition-editor.js.map +1 -0
  28. package/dist/better-auth/core/index.d.ts +2 -0
  29. package/dist/better-auth/core/index.d.ts.map +1 -0
  30. package/dist/better-auth/core/index.js +2 -0
  31. package/dist/better-auth/core/index.js.map +1 -0
  32. package/dist/better-auth/core/node.d.ts.map +1 -0
  33. package/dist/{auth0 → better-auth}/core/node.js +16 -14
  34. package/dist/better-auth/core/node.js.map +1 -0
  35. package/dist/better-auth/core/schema/models.d.ts +3 -0
  36. package/dist/better-auth/core/schema/models.d.ts.map +1 -0
  37. package/dist/better-auth/core/schema/models.js +278 -0
  38. package/dist/better-auth/core/schema/models.js.map +1 -0
  39. package/dist/better-auth/core/schema/plugin-definition.d.ts +5 -0
  40. package/dist/better-auth/core/schema/plugin-definition.d.ts.map +1 -0
  41. package/dist/better-auth/core/schema/plugin-definition.js +4 -0
  42. package/dist/better-auth/core/schema/plugin-definition.js.map +1 -0
  43. package/dist/better-auth/core/web.d.ts.map +1 -0
  44. package/dist/{auth0 → better-auth}/core/web.js +2 -2
  45. package/dist/better-auth/core/web.js.map +1 -0
  46. package/dist/{auth0/generators/fastify/auth0-module/auth0-module.generator.d.ts → better-auth/generators/fastify/better-auth-module/better-auth-module.generator.d.ts} +20 -26
  47. package/dist/better-auth/generators/fastify/better-auth-module/better-auth-module.generator.d.ts.map +1 -0
  48. package/dist/better-auth/generators/fastify/better-auth-module/better-auth-module.generator.js +75 -0
  49. package/dist/better-auth/generators/fastify/better-auth-module/better-auth-module.generator.js.map +1 -0
  50. package/dist/{auth0/generators/fastify/auth0-module → better-auth/generators/fastify/better-auth-module}/generated/index.d.ts +41 -26
  51. package/dist/better-auth/generators/fastify/better-auth-module/generated/index.d.ts.map +1 -0
  52. package/dist/better-auth/generators/fastify/better-auth-module/generated/index.js +11 -0
  53. package/dist/better-auth/generators/fastify/better-auth-module/generated/index.js.map +1 -0
  54. package/dist/better-auth/generators/fastify/better-auth-module/generated/template-paths.d.ts +16 -0
  55. package/dist/better-auth/generators/fastify/better-auth-module/generated/template-paths.d.ts.map +1 -0
  56. package/dist/better-auth/generators/fastify/better-auth-module/generated/template-paths.js +28 -0
  57. package/dist/better-auth/generators/fastify/better-auth-module/generated/template-paths.js.map +1 -0
  58. package/dist/{auth0/generators/fastify/auth0-module → better-auth/generators/fastify/better-auth-module}/generated/template-renderers.d.ts +16 -10
  59. package/dist/better-auth/generators/fastify/better-auth-module/generated/template-renderers.d.ts.map +1 -0
  60. package/dist/{auth0/generators/fastify/auth0-module → better-auth/generators/fastify/better-auth-module}/generated/template-renderers.js +35 -16
  61. package/dist/better-auth/generators/fastify/better-auth-module/generated/template-renderers.js.map +1 -0
  62. package/dist/better-auth/generators/fastify/better-auth-module/generated/ts-import-providers.d.ts +30 -0
  63. package/dist/better-auth/generators/fastify/better-auth-module/generated/ts-import-providers.d.ts.map +1 -0
  64. package/dist/better-auth/generators/fastify/better-auth-module/generated/ts-import-providers.js +37 -0
  65. package/dist/better-auth/generators/fastify/better-auth-module/generated/ts-import-providers.js.map +1 -0
  66. package/dist/{auth0/generators/fastify/auth0-module → better-auth/generators/fastify/better-auth-module}/generated/typed-templates.d.ts +29 -20
  67. package/dist/better-auth/generators/fastify/better-auth-module/generated/typed-templates.d.ts.map +1 -0
  68. package/dist/{auth0/generators/fastify/auth0-module → better-auth/generators/fastify/better-auth-module}/generated/typed-templates.js +37 -9
  69. package/dist/better-auth/generators/fastify/better-auth-module/generated/typed-templates.js.map +1 -0
  70. package/dist/better-auth/generators/fastify/better-auth-module/index.d.ts +4 -0
  71. package/dist/better-auth/generators/fastify/better-auth-module/index.d.ts.map +1 -0
  72. package/dist/better-auth/generators/fastify/better-auth-module/index.js +3 -0
  73. package/dist/better-auth/generators/fastify/better-auth-module/index.js.map +1 -0
  74. package/dist/better-auth/generators/fastify/better-auth-module/templates/module/plugins/better-auth.plugin.ts +31 -0
  75. package/dist/{auth0/generators/fastify/auth0-module → better-auth/generators/fastify/better-auth-module}/templates/module/schema/user-session.queries.ts +1 -1
  76. package/dist/better-auth/generators/fastify/better-auth-module/templates/module/services/auth.ts +62 -0
  77. package/dist/better-auth/generators/fastify/better-auth-module/templates/module/services/user-session.service.ts +72 -0
  78. package/dist/better-auth/generators/fastify/better-auth-module/templates/module/utils/headers.utils.ts +21 -0
  79. package/dist/better-auth/generators/fastify/index.d.ts +2 -0
  80. package/dist/better-auth/generators/fastify/index.d.ts.map +1 -0
  81. package/dist/better-auth/generators/fastify/index.js +2 -0
  82. package/dist/better-auth/generators/fastify/index.js.map +1 -0
  83. package/dist/better-auth/generators/index.d.ts.map +1 -0
  84. package/dist/better-auth/generators/index.js.map +1 -0
  85. package/dist/{auth0/generators/react/auth0-hooks/auth0-hooks.generator.d.ts → better-auth/generators/react/better-auth-hooks/better-auth-hooks.generator.d.ts} +11 -7
  86. package/dist/better-auth/generators/react/better-auth-hooks/better-auth-hooks.generator.d.ts.map +1 -0
  87. package/dist/{auth0/generators/react/auth0-hooks/auth0-hooks.generator.js → better-auth/generators/react/better-auth-hooks/better-auth-hooks.generator.js} +8 -8
  88. package/dist/better-auth/generators/react/better-auth-hooks/better-auth-hooks.generator.js.map +1 -0
  89. package/dist/{auth0/generators/react/auth0-hooks → better-auth/generators/react/better-auth-hooks}/generated/index.d.ts +21 -8
  90. package/dist/better-auth/generators/react/better-auth-hooks/generated/index.d.ts.map +1 -0
  91. package/dist/better-auth/generators/react/better-auth-hooks/generated/index.js +11 -0
  92. package/dist/better-auth/generators/react/better-auth-hooks/generated/index.js.map +1 -0
  93. package/dist/better-auth/generators/react/better-auth-hooks/generated/template-paths.d.ts +14 -0
  94. package/dist/better-auth/generators/react/better-auth-hooks/generated/template-paths.d.ts.map +1 -0
  95. package/dist/{auth0/generators/react/auth0-hooks → better-auth/generators/react/better-auth-hooks}/generated/template-paths.js +9 -7
  96. package/dist/better-auth/generators/react/better-auth-hooks/generated/template-paths.js.map +1 -0
  97. package/dist/better-auth/generators/react/better-auth-hooks/generated/template-renderers.d.ts +27 -0
  98. package/dist/better-auth/generators/react/better-auth-hooks/generated/template-renderers.d.ts.map +1 -0
  99. package/dist/better-auth/generators/react/better-auth-hooks/generated/template-renderers.js +43 -0
  100. package/dist/better-auth/generators/react/better-auth-hooks/generated/template-renderers.js.map +1 -0
  101. package/dist/{auth0/generators/react/auth0-hooks → better-auth/generators/react/better-auth-hooks}/generated/ts-import-providers.d.ts +2 -2
  102. package/dist/better-auth/generators/react/better-auth-hooks/generated/ts-import-providers.d.ts.map +1 -0
  103. package/dist/{auth0/generators/react/auth0-hooks → better-auth/generators/react/better-auth-hooks}/generated/ts-import-providers.js +5 -5
  104. package/dist/better-auth/generators/react/better-auth-hooks/generated/ts-import-providers.js.map +1 -0
  105. package/dist/{auth0/generators/react/auth0-hooks → better-auth/generators/react/better-auth-hooks}/generated/typed-templates.d.ts +21 -3
  106. package/dist/better-auth/generators/react/better-auth-hooks/generated/typed-templates.d.ts.map +1 -0
  107. package/dist/{auth0/generators/react/auth0-hooks → better-auth/generators/react/better-auth-hooks}/generated/typed-templates.js +7 -3
  108. package/dist/better-auth/generators/react/better-auth-hooks/generated/typed-templates.js.map +1 -0
  109. package/dist/better-auth/generators/react/better-auth-hooks/index.d.ts +2 -0
  110. package/dist/better-auth/generators/react/better-auth-hooks/index.d.ts.map +1 -0
  111. package/dist/better-auth/generators/react/better-auth-hooks/index.js +2 -0
  112. package/dist/better-auth/generators/react/better-auth-hooks/index.js.map +1 -0
  113. package/dist/better-auth/generators/react/better-auth-hooks/templates/src/hooks/use-log-out.ts +18 -0
  114. package/dist/better-auth/generators/react/better-auth-hooks/templates/src/hooks/use-session.ts +30 -0
  115. package/dist/{auth0/generators/react/auth0-pages/auth0-pages.generator.d.ts → better-auth/generators/react/better-auth-pages/better-auth-pages.generator.d.ts} +15 -6
  116. package/dist/better-auth/generators/react/better-auth-pages/better-auth-pages.generator.d.ts.map +1 -0
  117. package/dist/{auth0/generators/react/auth0-pages/auth0-pages.generator.js → better-auth/generators/react/better-auth-pages/better-auth-pages.generator.js} +7 -7
  118. package/dist/better-auth/generators/react/better-auth-pages/better-auth-pages.generator.js.map +1 -0
  119. package/dist/{auth0/generators/react/auth0-pages → better-auth/generators/react/better-auth-pages}/generated/index.d.ts +246 -6
  120. package/dist/{auth0/generators/react/auth0-pages → better-auth/generators/react/better-auth-pages}/generated/index.d.ts.map +1 -1
  121. package/dist/better-auth/generators/react/better-auth-pages/generated/index.js +9 -0
  122. package/dist/better-auth/generators/react/better-auth-pages/generated/index.js.map +1 -0
  123. package/dist/better-auth/generators/react/better-auth-pages/generated/template-paths.d.ts +13 -0
  124. package/dist/better-auth/generators/react/better-auth-pages/generated/template-paths.d.ts.map +1 -0
  125. package/dist/better-auth/generators/react/better-auth-pages/generated/template-paths.js +25 -0
  126. package/dist/better-auth/generators/react/better-auth-pages/generated/template-paths.js.map +1 -0
  127. package/dist/{auth0/generators/react/react-auth0 → better-auth/generators/react/better-auth-pages}/generated/template-renderers.d.ts +13 -9
  128. package/dist/better-auth/generators/react/better-auth-pages/generated/template-renderers.d.ts.map +1 -0
  129. package/dist/better-auth/generators/react/better-auth-pages/generated/template-renderers.js +44 -0
  130. package/dist/better-auth/generators/react/better-auth-pages/generated/template-renderers.js.map +1 -0
  131. package/dist/better-auth/generators/react/better-auth-pages/generated/typed-templates.d.ts +895 -0
  132. package/dist/better-auth/generators/react/better-auth-pages/generated/typed-templates.d.ts.map +1 -0
  133. package/dist/better-auth/generators/react/better-auth-pages/generated/typed-templates.js +35 -0
  134. package/dist/better-auth/generators/react/better-auth-pages/generated/typed-templates.js.map +1 -0
  135. package/dist/better-auth/generators/react/better-auth-pages/index.d.ts +2 -0
  136. package/dist/better-auth/generators/react/better-auth-pages/index.d.ts.map +1 -0
  137. package/dist/better-auth/generators/react/better-auth-pages/index.js +2 -0
  138. package/dist/better-auth/generators/react/better-auth-pages/index.js.map +1 -0
  139. package/dist/better-auth/generators/react/better-auth-pages/templates/routes/auth/login.tsx +146 -0
  140. package/dist/better-auth/generators/react/better-auth-pages/templates/routes/auth/register.tsx +162 -0
  141. package/dist/better-auth/generators/react/index.d.ts +4 -0
  142. package/dist/better-auth/generators/react/index.d.ts.map +1 -0
  143. package/dist/better-auth/generators/react/index.js +4 -0
  144. package/dist/better-auth/generators/react/index.js.map +1 -0
  145. package/dist/{auth0/generators/react/react-auth0 → better-auth/generators/react/react-better-auth}/generated/index.d.ts +42 -7
  146. package/dist/{auth0/generators/react/react-auth0 → better-auth/generators/react/react-better-auth}/generated/index.d.ts.map +1 -1
  147. package/dist/better-auth/generators/react/react-better-auth/generated/index.js +11 -0
  148. package/dist/better-auth/generators/react/react-better-auth/generated/index.js.map +1 -0
  149. package/dist/better-auth/generators/react/react-better-auth/generated/template-paths.d.ts +13 -0
  150. package/dist/better-auth/generators/react/react-better-auth/generated/template-paths.d.ts.map +1 -0
  151. package/dist/better-auth/generators/react/react-better-auth/generated/template-paths.js +25 -0
  152. package/dist/better-auth/generators/react/react-better-auth/generated/template-paths.js.map +1 -0
  153. package/dist/{auth0/generators/react/auth0-pages → better-auth/generators/react/react-better-auth}/generated/template-renderers.d.ts +28 -9
  154. package/dist/better-auth/generators/react/react-better-auth/generated/template-renderers.d.ts.map +1 -0
  155. package/dist/better-auth/generators/react/react-better-auth/generated/template-renderers.js +51 -0
  156. package/dist/better-auth/generators/react/react-better-auth/generated/template-renderers.js.map +1 -0
  157. package/dist/better-auth/generators/react/react-better-auth/generated/ts-import-providers.d.ts +21 -0
  158. package/dist/better-auth/generators/react/react-better-auth/generated/ts-import-providers.d.ts.map +1 -0
  159. package/dist/better-auth/generators/react/react-better-auth/generated/ts-import-providers.js +30 -0
  160. package/dist/better-auth/generators/react/react-better-auth/generated/ts-import-providers.js.map +1 -0
  161. package/dist/{auth0/generators/react/react-auth0 → better-auth/generators/react/react-better-auth}/generated/typed-templates.d.ts +16 -2
  162. package/dist/better-auth/generators/react/react-better-auth/generated/typed-templates.d.ts.map +1 -0
  163. package/dist/better-auth/generators/react/react-better-auth/generated/typed-templates.js +33 -0
  164. package/dist/better-auth/generators/react/react-better-auth/generated/typed-templates.js.map +1 -0
  165. package/dist/better-auth/generators/react/react-better-auth/index.d.ts +4 -0
  166. package/dist/better-auth/generators/react/react-better-auth/index.d.ts.map +1 -0
  167. package/dist/better-auth/generators/react/react-better-auth/index.js +3 -0
  168. package/dist/better-auth/generators/react/react-better-auth/index.js.map +1 -0
  169. package/dist/{auth0/generators/react/react-auth0/react-auth0.generator.d.ts → better-auth/generators/react/react-better-auth/react-better-auth.generator.d.ts} +28 -25
  170. package/dist/better-auth/generators/react/react-better-auth/react-better-auth.generator.d.ts.map +1 -0
  171. package/dist/better-auth/generators/react/react-better-auth/react-better-auth.generator.js +74 -0
  172. package/dist/better-auth/generators/react/react-better-auth/react-better-auth.generator.js.map +1 -0
  173. package/dist/better-auth/generators/react/react-better-auth/templates/src/app/auth-loaded-gate.tsx +58 -0
  174. package/dist/better-auth/generators/react/react-better-auth/templates/src/services/auth-client.ts +15 -0
  175. package/dist/better-auth/index.d.ts +3 -0
  176. package/dist/better-auth/index.d.ts.map +1 -0
  177. package/dist/better-auth/index.js +2 -0
  178. package/dist/better-auth/index.js.map +1 -0
  179. package/dist/better-auth/plugin.json +9 -0
  180. package/dist/better-auth/static/icon.svg +10 -0
  181. package/dist/index.d.ts +1 -0
  182. package/dist/local-auth/core/components/local-auth-definition-editor.d.ts.map +1 -1
  183. package/dist/local-auth/core/components/local-auth-definition-editor.js +11 -11
  184. package/dist/local-auth/core/components/local-auth-definition-editor.js.map +1 -1
  185. package/dist/local-auth/core/generators/auth-apollo/auth-apollo.generator.d.ts +2 -2
  186. package/dist/local-auth/core/generators/auth-email-password/auth-email-password.generator.d.ts +4 -4
  187. package/dist/local-auth/core/generators/auth-email-password/templates/module/schema/password-reset.mutations.js +1 -1
  188. package/dist/local-auth/core/generators/auth-email-password/templates/module/schema/password-reset.mutations.js.map +1 -1
  189. package/dist/local-auth/core/generators/auth-email-password/templates/module/schema/password-reset.mutations.ts +1 -1
  190. package/dist/local-auth/core/generators/auth-email-password/templates/module/services/password-reset.service.d.ts +3 -1
  191. package/dist/local-auth/core/generators/auth-email-password/templates/module/services/password-reset.service.d.ts.map +1 -1
  192. package/dist/local-auth/core/generators/auth-email-password/templates/module/services/password-reset.service.js +6 -1
  193. package/dist/local-auth/core/generators/auth-email-password/templates/module/services/password-reset.service.js.map +1 -1
  194. package/dist/local-auth/core/generators/auth-email-password/templates/module/services/password-reset.service.ts +8 -2
  195. package/dist/local-auth/core/generators/auth-module/auth-module.generator.d.ts +1 -0
  196. package/dist/local-auth/core/generators/auth-module/auth-module.generator.d.ts.map +1 -1
  197. package/dist/local-auth/core/generators/auth-module/auth-module.generator.js +14 -3
  198. package/dist/local-auth/core/generators/auth-module/auth-module.generator.js.map +1 -1
  199. package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/login.js +1 -1
  200. package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/login.js.map +1 -1
  201. package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/login.tsx +1 -1
  202. package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/register.js +1 -1
  203. package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/register.js.map +1 -1
  204. package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/register.tsx +1 -1
  205. package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/reset-password.js +34 -15
  206. package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/reset-password.js.map +1 -1
  207. package/dist/local-auth/core/generators/auth-routes/templates/routes/auth_/reset-password.tsx +58 -15
  208. package/dist/local-auth/core/node.d.ts.map +1 -1
  209. package/dist/local-auth/core/node.js +8 -6
  210. package/dist/local-auth/core/node.js.map +1 -1
  211. package/dist/local-auth/core/schema/models.d.ts +2 -4
  212. package/dist/local-auth/core/schema/models.d.ts.map +1 -1
  213. package/dist/local-auth/core/schema/models.js +254 -252
  214. package/dist/local-auth/core/schema/models.js.map +1 -1
  215. package/dist/local-auth/core/schema/plugin-definition.d.ts +2 -2
  216. package/dist/placeholder-auth/core/components/placeholder-auth-definition-editor.d.ts.map +1 -1
  217. package/dist/placeholder-auth/core/components/placeholder-auth-definition-editor.js +11 -11
  218. package/dist/placeholder-auth/core/components/placeholder-auth-definition-editor.js.map +1 -1
  219. package/dist/placeholder-auth/core/schema/models.d.ts +2 -4
  220. package/dist/placeholder-auth/core/schema/models.d.ts.map +1 -1
  221. package/dist/placeholder-auth/core/schema/models.js +30 -28
  222. package/dist/placeholder-auth/core/schema/models.js.map +1 -1
  223. package/dist/web/assets/{__federation_expose_authCoreCommon-Bg2mzE9K.js → __federation_expose_authCoreCommon-CIVhaGqo.js} +3 -3
  224. package/dist/web/assets/{__federation_expose_authCoreCommon-Bg2mzE9K.js.map → __federation_expose_authCoreCommon-CIVhaGqo.js.map} +1 -1
  225. package/dist/web/assets/{__federation_expose_authCoreWeb-DrOVHmj4.js → __federation_expose_authCoreWeb-N-mh42Bs.js} +6 -6
  226. package/dist/web/assets/{__federation_expose_authCoreWeb-DrOVHmj4.js.map → __federation_expose_authCoreWeb-N-mh42Bs.js.map} +1 -1
  227. package/dist/web/assets/__federation_expose_better-authCoreCommon-BIU3Fg7K.js +20 -0
  228. package/dist/web/assets/__federation_expose_better-authCoreCommon-BIU3Fg7K.js.map +1 -0
  229. package/dist/web/assets/__federation_expose_better-authCoreWeb-CMhPrXPA.js +402 -0
  230. package/dist/web/assets/__federation_expose_better-authCoreWeb-CMhPrXPA.js.map +1 -0
  231. package/dist/web/assets/{__federation_expose_local-authAdminCommon-Bzb0P17-.js → __federation_expose_local-authAdminCommon-DvHe9w29.js} +2 -2
  232. package/dist/web/assets/{__federation_expose_local-authAdminCommon-Bzb0P17-.js.map → __federation_expose_local-authAdminCommon-DvHe9w29.js.map} +1 -1
  233. package/dist/web/assets/{__federation_expose_local-authAdminWeb-D_LWcl7j.js → __federation_expose_local-authAdminWeb-CLU9aEy9.js} +2 -2
  234. package/dist/web/assets/{__federation_expose_local-authAdminWeb-D_LWcl7j.js.map → __federation_expose_local-authAdminWeb-CLU9aEy9.js.map} +1 -1
  235. package/dist/web/assets/{__federation_expose_local-authCoreCommon-D6OG-Rz6.js → __federation_expose_local-authCoreCommon-DbuvGG7o.js} +3 -3
  236. package/dist/web/assets/{__federation_expose_local-authCoreCommon-D6OG-Rz6.js.map → __federation_expose_local-authCoreCommon-DbuvGG7o.js.map} +1 -1
  237. package/dist/web/assets/__federation_expose_local-authCoreWeb-BY-mP3uS.js +432 -0
  238. package/dist/web/assets/__federation_expose_local-authCoreWeb-BY-mP3uS.js.map +1 -0
  239. package/dist/web/assets/{__federation_expose_placeholder-authCoreCommon-D7b3GEPP.js → __federation_expose_placeholder-authCoreCommon-BJBCuZvU.js} +3 -3
  240. package/dist/web/assets/{__federation_expose_placeholder-authCoreCommon-D7b3GEPP.js.map → __federation_expose_placeholder-authCoreCommon-BJBCuZvU.js.map} +1 -1
  241. package/dist/web/assets/{__federation_expose_placeholder-authCoreWeb-VZzvid5j.js → __federation_expose_placeholder-authCoreWeb-BaV-Ko2C.js} +61 -53
  242. package/dist/web/assets/__federation_expose_placeholder-authCoreWeb-BaV-Ko2C.js.map +1 -0
  243. package/dist/web/assets/{__federation_fn_import-DfNliZHH.js → __federation_fn_import-BLFDCY-V.js} +2 -2
  244. package/dist/web/assets/{__federation_fn_import-DfNliZHH.js.map → __federation_fn_import-BLFDCY-V.js.map} +1 -1
  245. package/dist/web/assets/__federation_shared_@baseplate-dev/project-builder-lib/{web-BqJ1vSYx.js → web-bRU6KpPk.js} +48 -26
  246. package/dist/web/assets/__federation_shared_@baseplate-dev/project-builder-lib/web-bRU6KpPk.js.map +1 -0
  247. package/dist/web/assets/__federation_shared_@baseplate-dev/{project-builder-lib-qf98MMJC.js → project-builder-lib-CQKLkNsU.js} +5705 -1957
  248. package/dist/web/assets/__federation_shared_@baseplate-dev/project-builder-lib-CQKLkNsU.js.map +1 -0
  249. package/dist/web/assets/__federation_shared_@baseplate-dev/{ui-components-DFkMnXmX.js → ui-components-DhyoEUTy.js} +5886 -1191
  250. package/dist/web/assets/__federation_shared_@baseplate-dev/ui-components-DhyoEUTy.js.map +1 -0
  251. package/dist/web/assets/__federation_shared_@baseplate-dev/{utils-CApJheqk.js → utils-9w-0yxVZ.js} +64 -45
  252. package/dist/web/assets/__federation_shared_@baseplate-dev/utils-9w-0yxVZ.js.map +1 -0
  253. package/dist/web/assets/__federation_shared_@tanstack/{react-router-YQslfDyE.js → react-router-CbExBaoL.js} +2 -2
  254. package/dist/web/assets/__federation_shared_@tanstack/{react-router-YQslfDyE.js.map → react-router-CbExBaoL.js.map} +1 -1
  255. package/dist/web/assets/{__federation_shared_zod-B6wbpZ4f.js → __federation_shared_zod-Do7Aa1b5.js} +3431 -2188
  256. package/dist/web/assets/__federation_shared_zod-Do7Aa1b5.js.map +1 -0
  257. package/dist/web/assets/{get-auth-plugin-definition-CVuj_mvy.js → get-auth-plugin-definition-BL50g0cJ.js} +2 -2
  258. package/dist/web/assets/{get-auth-plugin-definition-CVuj_mvy.js.map → get-auth-plugin-definition-BL50g0cJ.js.map} +1 -1
  259. package/dist/web/assets/{index-B00D4irM.js → index-B_A3cgiy.js} +2 -2
  260. package/dist/web/assets/{index-B00D4irM.js.map → index-B_A3cgiy.js.map} +1 -1
  261. package/dist/web/assets/{index.esm-1qBxxnfu.js → index.esm-BraHxHLB.js} +338 -231
  262. package/dist/web/assets/index.esm-BraHxHLB.js.map +1 -0
  263. package/dist/web/assets/{isEqual-BQtm2LNT.js → isEqual-tnzoadW8.js} +18 -18
  264. package/dist/web/assets/isEqual-tnzoadW8.js.map +1 -0
  265. package/dist/web/assets/mergeWith-VagwCqUi.js +76 -0
  266. package/dist/web/assets/mergeWith-VagwCqUi.js.map +1 -0
  267. package/dist/web/assets/model-utils-BfcjfzCn.js +694 -0
  268. package/dist/web/assets/model-utils-BfcjfzCn.js.map +1 -0
  269. package/dist/web/assets/plugin-definition-CXnKUJ1l.js +20 -0
  270. package/dist/web/assets/plugin-definition-CXnKUJ1l.js.map +1 -0
  271. package/dist/web/assets/{plugin-definition-CcdhC0td.js → plugin-definition-Ckl5hjD1.js} +2 -2
  272. package/dist/web/assets/{plugin-definition-CcdhC0td.js.map → plugin-definition-Ckl5hjD1.js.map} +1 -1
  273. package/dist/web/assets/{plugin-definition-B_hlyPlm.js → plugin-definition-D26rR8AB.js} +2 -2
  274. package/dist/web/assets/{plugin-definition-B_hlyPlm.js.map → plugin-definition-D26rR8AB.js.map} +1 -1
  275. package/dist/web/assets/{plugin-definition-BKCeZ0Ni.js → plugin-definition-DJzXScRp.js} +12 -19
  276. package/dist/web/assets/plugin-definition-DJzXScRp.js.map +1 -0
  277. package/dist/web/assets/{react-Df9ccuow.js → react-CL9M_wyN.js} +2 -2
  278. package/dist/web/assets/{react-Df9ccuow.js.map → react-CL9M_wyN.js.map} +1 -1
  279. package/dist/web/assets/{registries-19UehlAo.js → registries-Tz_dluz3.js} +51 -13
  280. package/dist/web/assets/registries-Tz_dluz3.js.map +1 -0
  281. package/dist/web/assets/remoteEntry.js +14 -14
  282. package/dist/web/assets/{styles-CbPVroCT.js → styles-tkrWV-ZE.js} +4 -4
  283. package/dist/web/assets/{styles-CbPVroCT.js.map → styles-tkrWV-ZE.js.map} +1 -1
  284. package/package.json +17 -17
  285. package/dist/auth0/constants/model-names.d.ts +0 -4
  286. package/dist/auth0/constants/model-names.d.ts.map +0 -1
  287. package/dist/auth0/constants/model-names.js +0 -4
  288. package/dist/auth0/constants/model-names.js.map +0 -1
  289. package/dist/auth0/constants/packages.d.ts +0 -6
  290. package/dist/auth0/constants/packages.d.ts.map +0 -1
  291. package/dist/auth0/constants/packages.js +0 -6
  292. package/dist/auth0/constants/packages.js.map +0 -1
  293. package/dist/auth0/core/common.d.ts.map +0 -1
  294. package/dist/auth0/core/common.js +0 -19
  295. package/dist/auth0/core/common.js.map +0 -1
  296. package/dist/auth0/core/components/auth0-definition-editor.d.ts +0 -5
  297. package/dist/auth0/core/components/auth0-definition-editor.d.ts.map +0 -1
  298. package/dist/auth0/core/components/auth0-definition-editor.js.map +0 -1
  299. package/dist/auth0/core/node.d.ts.map +0 -1
  300. package/dist/auth0/core/node.js.map +0 -1
  301. package/dist/auth0/core/schema/migrations.d.ts +0 -3
  302. package/dist/auth0/core/schema/migrations.d.ts.map +0 -1
  303. package/dist/auth0/core/schema/migrations.js +0 -19
  304. package/dist/auth0/core/schema/migrations.js.map +0 -1
  305. package/dist/auth0/core/schema/models.d.ts +0 -5
  306. package/dist/auth0/core/schema/models.d.ts.map +0 -1
  307. package/dist/auth0/core/schema/models.js +0 -40
  308. package/dist/auth0/core/schema/models.js.map +0 -1
  309. package/dist/auth0/core/schema/plugin-definition.d.ts +0 -5
  310. package/dist/auth0/core/schema/plugin-definition.d.ts.map +0 -1
  311. package/dist/auth0/core/schema/plugin-definition.js +0 -4
  312. package/dist/auth0/core/schema/plugin-definition.js.map +0 -1
  313. package/dist/auth0/core/web.d.ts.map +0 -1
  314. package/dist/auth0/core/web.js.map +0 -1
  315. package/dist/auth0/generators/fastify/auth0-module/auth0-module.generator.d.ts.map +0 -1
  316. package/dist/auth0/generators/fastify/auth0-module/auth0-module.generator.js +0 -114
  317. package/dist/auth0/generators/fastify/auth0-module/auth0-module.generator.js.map +0 -1
  318. package/dist/auth0/generators/fastify/auth0-module/generated/index.d.ts.map +0 -1
  319. package/dist/auth0/generators/fastify/auth0-module/generated/index.js +0 -11
  320. package/dist/auth0/generators/fastify/auth0-module/generated/index.js.map +0 -1
  321. package/dist/auth0/generators/fastify/auth0-module/generated/template-paths.d.ts +0 -14
  322. package/dist/auth0/generators/fastify/auth0-module/generated/template-paths.d.ts.map +0 -1
  323. package/dist/auth0/generators/fastify/auth0-module/generated/template-paths.js +0 -24
  324. package/dist/auth0/generators/fastify/auth0-module/generated/template-paths.js.map +0 -1
  325. package/dist/auth0/generators/fastify/auth0-module/generated/template-renderers.d.ts.map +0 -1
  326. package/dist/auth0/generators/fastify/auth0-module/generated/template-renderers.js.map +0 -1
  327. package/dist/auth0/generators/fastify/auth0-module/generated/ts-import-providers.d.ts +0 -10
  328. package/dist/auth0/generators/fastify/auth0-module/generated/ts-import-providers.d.ts.map +0 -1
  329. package/dist/auth0/generators/fastify/auth0-module/generated/ts-import-providers.js +0 -23
  330. package/dist/auth0/generators/fastify/auth0-module/generated/ts-import-providers.js.map +0 -1
  331. package/dist/auth0/generators/fastify/auth0-module/generated/typed-templates.d.ts.map +0 -1
  332. package/dist/auth0/generators/fastify/auth0-module/generated/typed-templates.js.map +0 -1
  333. package/dist/auth0/generators/fastify/auth0-module/index.d.ts +0 -2
  334. package/dist/auth0/generators/fastify/auth0-module/index.d.ts.map +0 -1
  335. package/dist/auth0/generators/fastify/auth0-module/index.js +0 -2
  336. package/dist/auth0/generators/fastify/auth0-module/index.js.map +0 -1
  337. package/dist/auth0/generators/fastify/auth0-module/templates/module/services/management.ts +0 -22
  338. package/dist/auth0/generators/fastify/auth0-module/templates/module/services/user-session.service.ts +0 -101
  339. package/dist/auth0/generators/fastify/index.d.ts +0 -2
  340. package/dist/auth0/generators/fastify/index.d.ts.map +0 -1
  341. package/dist/auth0/generators/fastify/index.js +0 -2
  342. package/dist/auth0/generators/fastify/index.js.map +0 -1
  343. package/dist/auth0/generators/index.d.ts.map +0 -1
  344. package/dist/auth0/generators/index.js.map +0 -1
  345. package/dist/auth0/generators/react/auth0-apollo/auth0-apollo.generator.d.ts +0 -10
  346. package/dist/auth0/generators/react/auth0-apollo/auth0-apollo.generator.d.ts.map +0 -1
  347. package/dist/auth0/generators/react/auth0-apollo/auth0-apollo.generator.js +0 -41
  348. package/dist/auth0/generators/react/auth0-apollo/auth0-apollo.generator.js.map +0 -1
  349. package/dist/auth0/generators/react/auth0-apollo/index.d.ts +0 -2
  350. package/dist/auth0/generators/react/auth0-apollo/index.d.ts.map +0 -1
  351. package/dist/auth0/generators/react/auth0-apollo/index.js +0 -2
  352. package/dist/auth0/generators/react/auth0-apollo/index.js.map +0 -1
  353. package/dist/auth0/generators/react/auth0-apollo/templates/auth-link.ts +0 -11
  354. package/dist/auth0/generators/react/auth0-hooks/auth0-hooks.generator.d.ts.map +0 -1
  355. package/dist/auth0/generators/react/auth0-hooks/auth0-hooks.generator.js.map +0 -1
  356. package/dist/auth0/generators/react/auth0-hooks/generated/index.d.ts.map +0 -1
  357. package/dist/auth0/generators/react/auth0-hooks/generated/index.js +0 -11
  358. package/dist/auth0/generators/react/auth0-hooks/generated/index.js.map +0 -1
  359. package/dist/auth0/generators/react/auth0-hooks/generated/template-paths.d.ts +0 -14
  360. package/dist/auth0/generators/react/auth0-hooks/generated/template-paths.d.ts.map +0 -1
  361. package/dist/auth0/generators/react/auth0-hooks/generated/template-paths.js.map +0 -1
  362. package/dist/auth0/generators/react/auth0-hooks/generated/template-renderers.d.ts +0 -23
  363. package/dist/auth0/generators/react/auth0-hooks/generated/template-renderers.d.ts.map +0 -1
  364. package/dist/auth0/generators/react/auth0-hooks/generated/template-renderers.js +0 -38
  365. package/dist/auth0/generators/react/auth0-hooks/generated/template-renderers.js.map +0 -1
  366. package/dist/auth0/generators/react/auth0-hooks/generated/ts-import-providers.d.ts.map +0 -1
  367. package/dist/auth0/generators/react/auth0-hooks/generated/ts-import-providers.js.map +0 -1
  368. package/dist/auth0/generators/react/auth0-hooks/generated/typed-templates.d.ts.map +0 -1
  369. package/dist/auth0/generators/react/auth0-hooks/generated/typed-templates.js.map +0 -1
  370. package/dist/auth0/generators/react/auth0-hooks/index.d.ts +0 -2
  371. package/dist/auth0/generators/react/auth0-hooks/index.d.ts.map +0 -1
  372. package/dist/auth0/generators/react/auth0-hooks/index.js +0 -2
  373. package/dist/auth0/generators/react/auth0-hooks/index.js.map +0 -1
  374. package/dist/auth0/generators/react/auth0-hooks/templates/src/hooks/use-log-out.ts +0 -14
  375. package/dist/auth0/generators/react/auth0-hooks/templates/src/hooks/use-session.ts +0 -36
  376. package/dist/auth0/generators/react/auth0-pages/auth0-pages.generator.d.ts.map +0 -1
  377. package/dist/auth0/generators/react/auth0-pages/auth0-pages.generator.js.map +0 -1
  378. package/dist/auth0/generators/react/auth0-pages/generated/index.js +0 -9
  379. package/dist/auth0/generators/react/auth0-pages/generated/index.js.map +0 -1
  380. package/dist/auth0/generators/react/auth0-pages/generated/template-paths.d.ts +0 -12
  381. package/dist/auth0/generators/react/auth0-pages/generated/template-paths.d.ts.map +0 -1
  382. package/dist/auth0/generators/react/auth0-pages/generated/template-paths.js +0 -20
  383. package/dist/auth0/generators/react/auth0-pages/generated/template-paths.js.map +0 -1
  384. package/dist/auth0/generators/react/auth0-pages/generated/template-renderers.d.ts.map +0 -1
  385. package/dist/auth0/generators/react/auth0-pages/generated/template-renderers.js +0 -37
  386. package/dist/auth0/generators/react/auth0-pages/generated/template-renderers.js.map +0 -1
  387. package/dist/auth0/generators/react/auth0-pages/generated/typed-templates.d.ts +0 -433
  388. package/dist/auth0/generators/react/auth0-pages/generated/typed-templates.d.ts.map +0 -1
  389. package/dist/auth0/generators/react/auth0-pages/generated/typed-templates.js +0 -18
  390. package/dist/auth0/generators/react/auth0-pages/generated/typed-templates.js.map +0 -1
  391. package/dist/auth0/generators/react/auth0-pages/index.d.ts +0 -2
  392. package/dist/auth0/generators/react/auth0-pages/index.d.ts.map +0 -1
  393. package/dist/auth0/generators/react/auth0-pages/index.js +0 -2
  394. package/dist/auth0/generators/react/auth0-pages/index.js.map +0 -1
  395. package/dist/auth0/generators/react/auth0-pages/templates/routes/login.tsx +0 -31
  396. package/dist/auth0/generators/react/index.d.ts +0 -5
  397. package/dist/auth0/generators/react/index.d.ts.map +0 -1
  398. package/dist/auth0/generators/react/index.js +0 -5
  399. package/dist/auth0/generators/react/index.js.map +0 -1
  400. package/dist/auth0/generators/react/react-auth0/generated/index.js +0 -9
  401. package/dist/auth0/generators/react/react-auth0/generated/index.js.map +0 -1
  402. package/dist/auth0/generators/react/react-auth0/generated/template-paths.d.ts +0 -12
  403. package/dist/auth0/generators/react/react-auth0/generated/template-paths.d.ts.map +0 -1
  404. package/dist/auth0/generators/react/react-auth0/generated/template-paths.js +0 -22
  405. package/dist/auth0/generators/react/react-auth0/generated/template-paths.js.map +0 -1
  406. package/dist/auth0/generators/react/react-auth0/generated/template-renderers.d.ts.map +0 -1
  407. package/dist/auth0/generators/react/react-auth0/generated/template-renderers.js +0 -39
  408. package/dist/auth0/generators/react/react-auth0/generated/template-renderers.js.map +0 -1
  409. package/dist/auth0/generators/react/react-auth0/generated/typed-templates.d.ts.map +0 -1
  410. package/dist/auth0/generators/react/react-auth0/generated/typed-templates.js +0 -17
  411. package/dist/auth0/generators/react/react-auth0/generated/typed-templates.js.map +0 -1
  412. package/dist/auth0/generators/react/react-auth0/index.d.ts +0 -2
  413. package/dist/auth0/generators/react/react-auth0/index.d.ts.map +0 -1
  414. package/dist/auth0/generators/react/react-auth0/index.js +0 -2
  415. package/dist/auth0/generators/react/react-auth0/index.js.map +0 -1
  416. package/dist/auth0/generators/react/react-auth0/react-auth0.generator.d.ts.map +0 -1
  417. package/dist/auth0/generators/react/react-auth0/react-auth0.generator.js +0 -107
  418. package/dist/auth0/generators/react/react-auth0/react-auth0.generator.js.map +0 -1
  419. package/dist/auth0/generators/react/react-auth0/templates/src/app/auth-loaded-gate.tsx +0 -78
  420. package/dist/auth0/plugin.json +0 -9
  421. package/dist/auth0/static/icon.svg +0 -7
  422. package/dist/web/assets/__federation_expose_auth0CoreCommon-e_GtBIIm.js +0 -40
  423. package/dist/web/assets/__federation_expose_auth0CoreCommon-e_GtBIIm.js.map +0 -1
  424. package/dist/web/assets/__federation_expose_auth0CoreWeb-CTfPylMw.js +0 -158
  425. package/dist/web/assets/__federation_expose_auth0CoreWeb-CTfPylMw.js.map +0 -1
  426. package/dist/web/assets/__federation_expose_local-authCoreWeb-CaR8fx1f.js +0 -424
  427. package/dist/web/assets/__federation_expose_local-authCoreWeb-CaR8fx1f.js.map +0 -1
  428. package/dist/web/assets/__federation_expose_placeholder-authCoreWeb-VZzvid5j.js.map +0 -1
  429. package/dist/web/assets/__federation_shared_@baseplate-dev/project-builder-lib/web-BqJ1vSYx.js.map +0 -1
  430. package/dist/web/assets/__federation_shared_@baseplate-dev/project-builder-lib-qf98MMJC.js.map +0 -1
  431. package/dist/web/assets/__federation_shared_@baseplate-dev/ui-components-DFkMnXmX.js.map +0 -1
  432. package/dist/web/assets/__federation_shared_@baseplate-dev/utils-CApJheqk.js.map +0 -1
  433. package/dist/web/assets/__federation_shared_zod-B6wbpZ4f.js.map +0 -1
  434. package/dist/web/assets/index.esm-1qBxxnfu.js.map +0 -1
  435. package/dist/web/assets/isEqual-BQtm2LNT.js.map +0 -1
  436. package/dist/web/assets/model-merger-59HLmy_J.js +0 -1705
  437. package/dist/web/assets/model-merger-59HLmy_J.js.map +0 -1
  438. package/dist/web/assets/plugin-definition-BKCeZ0Ni.js.map +0 -1
  439. package/dist/web/assets/plugin-definition-Bkx-a_wA.js +0 -16
  440. package/dist/web/assets/plugin-definition-Bkx-a_wA.js.map +0 -1
  441. package/dist/web/assets/registries-19UehlAo.js.map +0 -1
  442. package/dist/web/assets/sortBy-BPH_zRB8.js +0 -34
  443. package/dist/web/assets/sortBy-BPH_zRB8.js.map +0 -1
  444. /package/dist/{auth0 → better-auth}/core/common.d.ts +0 -0
  445. /package/dist/{auth0 → better-auth}/core/node.d.ts +0 -0
  446. /package/dist/{auth0 → better-auth}/core/web.d.ts +0 -0
  447. /package/dist/{auth0 → better-auth}/generators/index.d.ts +0 -0
  448. /package/dist/{auth0 → better-auth}/generators/index.js +0 -0
  449. /package/dist/{auth0/generators/react/auth0-hooks → better-auth/generators/react/better-auth-hooks}/templates/src/hooks/use-required-user-id.ts +0 -0
@@ -1,1705 +0,0 @@
1
- import { importShared } from './__federation_fn_import-DfNliZHH.js';
2
- import { g as getSymbols, a as isPlainObject, e as eq } from './isEqual-BQtm2LNT.js';
3
-
4
- /**
5
- * Creates a plugin spec with init and use phases.
6
- *
7
- * @example
8
- * ```typescript
9
- * const mySpec = createPluginSpec('core/my-spec', {
10
- * initializer: () => {
11
- * const items = new Map<string, Item>();
12
- * return {
13
- * init: {
14
- * register: (item: Item) => items.set(item.name, item),
15
- * },
16
- * use: () => ({
17
- * get: (name: string) => items.get(name),
18
- * getAll: () => [...items.values()],
19
- * }),
20
- * };
21
- * },
22
- * });
23
- * ```
24
- *
25
- * @param name - Unique identifier for the spec (e.g., 'core/my-spec')
26
- * @param options - Options including the initializer function
27
- * @returns A plugin spec that can be used with SpecStore
28
- */
29
- function createPluginSpec(name, options) {
30
- const { initializer } = options;
31
- return {
32
- type: 'plugin-spec',
33
- name,
34
- initializer,
35
- };
36
- }
37
-
38
- /**
39
- * Plugin context module for tracking the current plugin being initialized.
40
- *
41
- * Uses a simple synchronous context that works on both Node and browser platforms.
42
- * This is safe because plugin initialization is synchronous and single-threaded.
43
- */
44
- // Simple synchronous context - works on both Node and browser
45
- // Safe because plugin initialization is synchronous and single-threaded
46
- let currentPluginContext;
47
- /**
48
- * Runs a function within a plugin context.
49
- *
50
- * This sets the current plugin context for the duration of the function execution,
51
- * allowing nested functions to access the plugin key via `getPluginContext()`.
52
- *
53
- * @param context - The plugin context to set
54
- * @param fn - The function to run within the context
55
- * @returns The result of the function
56
- */
57
- function runInPluginContext(context, fn) {
58
- const prev = currentPluginContext;
59
- currentPluginContext = context;
60
- try {
61
- return fn();
62
- }
63
- finally {
64
- currentPluginContext = prev;
65
- }
66
- }
67
- /**
68
- * Gets the current plugin context if one exists.
69
- *
70
- * @returns The current plugin context, or undefined if not in a plugin context
71
- */
72
- function getPluginContext() {
73
- return currentPluginContext;
74
- }
75
-
76
- const {createFieldMap} = await importShared('@baseplate-dev/utils');
77
- /**
78
- * Creates a field map that automatically tracks which plugin registered each value.
79
- *
80
- * Similar to `createConfigFieldMap` in the sync package, this utility uses the
81
- * current plugin context to track the source of registrations. This enables
82
- * clear error messages when registration conflicts occur.
83
- *
84
- * @example
85
- * ```typescript
86
- * const fieldMap = createPluginFieldMap((t) => ({
87
- * transformers: t.map<string, Transformer>(),
88
- * }));
89
- *
90
- * // When a plugin tries to overwrite a value:
91
- * // Error: Value for key 'myTransformer' has already been set by plugin-auth
92
- * // and cannot be overwritten by plugin-storage
93
- * ```
94
- *
95
- * @param schemaBuilder - A function that builds the field map schema
96
- * @returns A field map with automatic source tracking
97
- */
98
- function createPluginFieldMap(schemaBuilder) {
99
- return createFieldMap(schemaBuilder, {
100
- getDynamicSource: () => getPluginContext()?.pluginKey,
101
- });
102
- }
103
-
104
- /**
105
- * Creates a plugin spec backed by a FieldMap for automatic source tracking.
106
- *
107
- * @param name - Unique identifier for the spec
108
- * @param schemaBuilder - Function that builds the field map schema
109
- * @param options - Optional configuration including custom use interface
110
- */
111
- function createFieldMapSpec(name, schemaBuilder, options) {
112
- return createPluginSpec(name, {
113
- initializer: () => {
114
- const fieldMap = createPluginFieldMap(schemaBuilder);
115
- return {
116
- init: fieldMap,
117
- use: () => {
118
- const values = fieldMap.getValues();
119
- if (options?.use) {
120
- return options.use(values);
121
- }
122
- return values;
123
- },
124
- };
125
- },
126
- });
127
- }
128
-
129
- function isPrimitive(value) {
130
- return value == null || (typeof value !== 'object' && typeof value !== 'function');
131
- }
132
-
133
- function isTypedArray(x) {
134
- return ArrayBuffer.isView(x) && !(x instanceof DataView);
135
- }
136
-
137
- function cloneDeepWithImpl(valueToClone, keyToClone, objectToClone, stack = new Map(), cloneValue = undefined) {
138
- const cloned = cloneValue?.(valueToClone, keyToClone, objectToClone, stack);
139
- if (cloned != null) {
140
- return cloned;
141
- }
142
- if (isPrimitive(valueToClone)) {
143
- return valueToClone;
144
- }
145
- if (stack.has(valueToClone)) {
146
- return stack.get(valueToClone);
147
- }
148
- if (Array.isArray(valueToClone)) {
149
- const result = new Array(valueToClone.length);
150
- stack.set(valueToClone, result);
151
- for (let i = 0; i < valueToClone.length; i++) {
152
- result[i] = cloneDeepWithImpl(valueToClone[i], i, objectToClone, stack, cloneValue);
153
- }
154
- if (Object.hasOwn(valueToClone, 'index')) {
155
- result.index = valueToClone.index;
156
- }
157
- if (Object.hasOwn(valueToClone, 'input')) {
158
- result.input = valueToClone.input;
159
- }
160
- return result;
161
- }
162
- if (valueToClone instanceof Date) {
163
- return new Date(valueToClone.getTime());
164
- }
165
- if (valueToClone instanceof RegExp) {
166
- const result = new RegExp(valueToClone.source, valueToClone.flags);
167
- result.lastIndex = valueToClone.lastIndex;
168
- return result;
169
- }
170
- if (valueToClone instanceof Map) {
171
- const result = new Map();
172
- stack.set(valueToClone, result);
173
- for (const [key, value] of valueToClone) {
174
- result.set(key, cloneDeepWithImpl(value, key, objectToClone, stack, cloneValue));
175
- }
176
- return result;
177
- }
178
- if (valueToClone instanceof Set) {
179
- const result = new Set();
180
- stack.set(valueToClone, result);
181
- for (const value of valueToClone) {
182
- result.add(cloneDeepWithImpl(value, undefined, objectToClone, stack, cloneValue));
183
- }
184
- return result;
185
- }
186
- if (typeof Buffer !== 'undefined' && Buffer.isBuffer(valueToClone)) {
187
- return valueToClone.subarray();
188
- }
189
- if (isTypedArray(valueToClone)) {
190
- const result = new (Object.getPrototypeOf(valueToClone).constructor)(valueToClone.length);
191
- stack.set(valueToClone, result);
192
- for (let i = 0; i < valueToClone.length; i++) {
193
- result[i] = cloneDeepWithImpl(valueToClone[i], i, objectToClone, stack, cloneValue);
194
- }
195
- return result;
196
- }
197
- if (valueToClone instanceof ArrayBuffer ||
198
- (typeof SharedArrayBuffer !== 'undefined' && valueToClone instanceof SharedArrayBuffer)) {
199
- return valueToClone.slice(0);
200
- }
201
- if (valueToClone instanceof DataView) {
202
- const result = new DataView(valueToClone.buffer.slice(0), valueToClone.byteOffset, valueToClone.byteLength);
203
- stack.set(valueToClone, result);
204
- copyProperties(result, valueToClone, objectToClone, stack, cloneValue);
205
- return result;
206
- }
207
- if (typeof File !== 'undefined' && valueToClone instanceof File) {
208
- const result = new File([valueToClone], valueToClone.name, {
209
- type: valueToClone.type,
210
- });
211
- stack.set(valueToClone, result);
212
- copyProperties(result, valueToClone, objectToClone, stack, cloneValue);
213
- return result;
214
- }
215
- if (valueToClone instanceof Blob) {
216
- const result = new Blob([valueToClone], { type: valueToClone.type });
217
- stack.set(valueToClone, result);
218
- copyProperties(result, valueToClone, objectToClone, stack, cloneValue);
219
- return result;
220
- }
221
- if (valueToClone instanceof Error) {
222
- const result = new valueToClone.constructor();
223
- stack.set(valueToClone, result);
224
- result.message = valueToClone.message;
225
- result.name = valueToClone.name;
226
- result.stack = valueToClone.stack;
227
- result.cause = valueToClone.cause;
228
- copyProperties(result, valueToClone, objectToClone, stack, cloneValue);
229
- return result;
230
- }
231
- if (typeof valueToClone === 'object' && valueToClone !== null) {
232
- const result = Object.create(Object.getPrototypeOf(valueToClone));
233
- stack.set(valueToClone, result);
234
- copyProperties(result, valueToClone, objectToClone, stack, cloneValue);
235
- return result;
236
- }
237
- return valueToClone;
238
- }
239
- function copyProperties(target, source, objectToClone = target, stack, cloneValue) {
240
- const keys = [...Object.keys(source), ...getSymbols(source)];
241
- for (let i = 0; i < keys.length; i++) {
242
- const key = keys[i];
243
- const descriptor = Object.getOwnPropertyDescriptor(target, key);
244
- if (descriptor == null || descriptor.writable) {
245
- target[key] = cloneDeepWithImpl(source[key], key, objectToClone, stack, cloneValue);
246
- }
247
- }
248
- }
249
-
250
- function cloneDeep(obj) {
251
- return cloneDeepWithImpl(obj, undefined, obj, new Map(), undefined);
252
- }
253
-
254
- function merge(target, source) {
255
- const sourceKeys = Object.keys(source);
256
- for (let i = 0; i < sourceKeys.length; i++) {
257
- const key = sourceKeys[i];
258
- const sourceValue = source[key];
259
- const targetValue = target[key];
260
- if (Array.isArray(sourceValue)) {
261
- if (Array.isArray(targetValue)) {
262
- target[key] = merge(targetValue, sourceValue);
263
- }
264
- else {
265
- target[key] = merge([], sourceValue);
266
- }
267
- }
268
- else if (isPlainObject(sourceValue)) {
269
- if (isPlainObject(targetValue)) {
270
- target[key] = merge(targetValue, sourceValue);
271
- }
272
- else {
273
- target[key] = merge({}, sourceValue);
274
- }
275
- }
276
- else if (targetValue === undefined || sourceValue !== undefined) {
277
- target[key] = sourceValue;
278
- }
279
- }
280
- return target;
281
- }
282
-
283
- function toMerged(target, source) {
284
- return merge(cloneDeep(target), source);
285
- }
286
-
287
- function isDeepKey(key) {
288
- switch (typeof key) {
289
- case 'number':
290
- case 'symbol': {
291
- return false;
292
- }
293
- case 'string': {
294
- return key.includes('.') || key.includes('[') || key.includes(']');
295
- }
296
- }
297
- }
298
-
299
- function toKey(value) {
300
- if (Object.is(value, -0)) {
301
- return '-0';
302
- }
303
- return value.toString();
304
- }
305
-
306
- function toPath(deepKey) {
307
- const result = [];
308
- const length = deepKey.length;
309
- if (length === 0) {
310
- return result;
311
- }
312
- let index = 0;
313
- let key = '';
314
- let quoteChar = '';
315
- let bracket = false;
316
- if (deepKey.charCodeAt(0) === 46) {
317
- result.push('');
318
- index++;
319
- }
320
- while (index < length) {
321
- const char = deepKey[index];
322
- if (quoteChar) {
323
- if (char === '\\' && index + 1 < length) {
324
- index++;
325
- key += deepKey[index];
326
- }
327
- else if (char === quoteChar) {
328
- quoteChar = '';
329
- }
330
- else {
331
- key += char;
332
- }
333
- }
334
- else if (bracket) {
335
- if (char === '"' || char === "'") {
336
- quoteChar = char;
337
- }
338
- else if (char === ']') {
339
- bracket = false;
340
- result.push(key);
341
- key = '';
342
- }
343
- else {
344
- key += char;
345
- }
346
- }
347
- else {
348
- if (char === '[') {
349
- bracket = true;
350
- if (key) {
351
- result.push(key);
352
- key = '';
353
- }
354
- }
355
- else if (char === '.') {
356
- if (key) {
357
- result.push(key);
358
- key = '';
359
- }
360
- }
361
- else {
362
- key += char;
363
- }
364
- }
365
- index++;
366
- }
367
- if (key) {
368
- result.push(key);
369
- }
370
- return result;
371
- }
372
-
373
- function get(object, path, defaultValue) {
374
- if (object == null) {
375
- return defaultValue;
376
- }
377
- switch (typeof path) {
378
- case 'string': {
379
- const result = object[path];
380
- if (result === undefined) {
381
- if (isDeepKey(path)) {
382
- return get(object, toPath(path), defaultValue);
383
- }
384
- else {
385
- return defaultValue;
386
- }
387
- }
388
- return result;
389
- }
390
- case 'number':
391
- case 'symbol': {
392
- if (typeof path === 'number') {
393
- path = toKey(path);
394
- }
395
- const result = object[path];
396
- if (result === undefined) {
397
- return defaultValue;
398
- }
399
- return result;
400
- }
401
- default: {
402
- if (Array.isArray(path)) {
403
- return getWithPath(object, path, defaultValue);
404
- }
405
- if (Object.is(path?.valueOf(), -0)) {
406
- path = '-0';
407
- }
408
- else {
409
- path = String(path);
410
- }
411
- const result = object[path];
412
- if (result === undefined) {
413
- return defaultValue;
414
- }
415
- return result;
416
- }
417
- }
418
- }
419
- function getWithPath(object, path, defaultValue) {
420
- if (path.length === 0) {
421
- return defaultValue;
422
- }
423
- let current = object;
424
- for (let index = 0; index < path.length; index++) {
425
- if (current == null) {
426
- return defaultValue;
427
- }
428
- current = current[path[index]];
429
- }
430
- if (current === undefined) {
431
- return defaultValue;
432
- }
433
- return current;
434
- }
435
-
436
- function isObject(value) {
437
- return value !== null && (typeof value === 'object' || typeof value === 'function');
438
- }
439
-
440
- function isMatch(target, source) {
441
- if (source === target) {
442
- return true;
443
- }
444
- switch (typeof source) {
445
- case 'object': {
446
- if (source == null) {
447
- return true;
448
- }
449
- const keys = Object.keys(source);
450
- if (target == null) {
451
- return keys.length === 0;
452
- }
453
- if (Array.isArray(source)) {
454
- return isArrayMatch(target, source);
455
- }
456
- if (source instanceof Map) {
457
- return isMapMatch(target, source);
458
- }
459
- if (source instanceof Set) {
460
- return isSetMatch(target, source);
461
- }
462
- for (let i = 0; i < keys.length; i++) {
463
- const key = keys[i];
464
- if (!isPrimitive(target) && !(key in target)) {
465
- return false;
466
- }
467
- if (source[key] === undefined && target[key] !== undefined) {
468
- return false;
469
- }
470
- if (source[key] === null && target[key] !== null) {
471
- return false;
472
- }
473
- if (!isMatch(target[key], source[key])) {
474
- return false;
475
- }
476
- }
477
- return true;
478
- }
479
- case 'function': {
480
- if (Object.keys(source).length > 0) {
481
- return isMatch(target, { ...source });
482
- }
483
- return false;
484
- }
485
- default: {
486
- if (!isObject(target)) {
487
- return eq(target, source);
488
- }
489
- return !source;
490
- }
491
- }
492
- }
493
- function isMapMatch(target, source) {
494
- if (source.size === 0) {
495
- return true;
496
- }
497
- if (!(target instanceof Map)) {
498
- return false;
499
- }
500
- for (const [key, value] of source.entries()) {
501
- if (!isMatch(target.get(key), value)) {
502
- return false;
503
- }
504
- }
505
- return true;
506
- }
507
- function isArrayMatch(target, source) {
508
- if (source.length === 0) {
509
- return true;
510
- }
511
- if (!Array.isArray(target)) {
512
- return false;
513
- }
514
- const countedIndex = new Set();
515
- for (let i = 0; i < source.length; i++) {
516
- const sourceItem = source[i];
517
- const index = target.findIndex((targetItem, index) => {
518
- return isMatch(targetItem, sourceItem) && !countedIndex.has(index);
519
- });
520
- if (index === -1) {
521
- return false;
522
- }
523
- countedIndex.add(index);
524
- }
525
- return true;
526
- }
527
- function isSetMatch(target, source) {
528
- if (source.size === 0) {
529
- return true;
530
- }
531
- if (!(target instanceof Set)) {
532
- return false;
533
- }
534
- return isArrayMatch([...target], [...source]);
535
- }
536
-
537
- const IS_UNSIGNED_INTEGER = /^(?:0|[1-9]\d*)$/;
538
- function isIndex(value, length = Number.MAX_SAFE_INTEGER) {
539
- switch (typeof value) {
540
- case 'number': {
541
- return Number.isInteger(value) && value >= 0 && value < length;
542
- }
543
- case 'symbol': {
544
- return false;
545
- }
546
- case 'string': {
547
- return IS_UNSIGNED_INTEGER.test(value);
548
- }
549
- }
550
- }
551
-
552
- function set(obj, path, value) {
553
- const resolvedPath = Array.isArray(path) ? path : typeof path === 'string' ? toPath(path) : [path];
554
- let current = obj;
555
- for (let i = 0; i < resolvedPath.length - 1; i++) {
556
- const key = resolvedPath[i];
557
- const nextKey = resolvedPath[i + 1];
558
- if (current[key] == null) {
559
- current[key] = isIndex(nextKey) ? [] : {};
560
- }
561
- current = current[key];
562
- }
563
- const lastKey = resolvedPath[resolvedPath.length - 1];
564
- current[lastKey] = value;
565
- return obj;
566
- }
567
-
568
- function mapValues(object, getNewValue) {
569
- const result = {};
570
- const keys = Object.keys(object);
571
- for (let i = 0; i < keys.length; i++) {
572
- const key = keys[i];
573
- const value = object[key];
574
- result[key] = getNewValue(value, key, object);
575
- }
576
- return result;
577
- }
578
-
579
- class DefinitionReferenceMarker {
580
- value;
581
- reference;
582
- constructor(value, reference) {
583
- this.value = value;
584
- this.reference = reference;
585
- }
586
- toString() {
587
- return this.value ?? '';
588
- }
589
- }
590
- /**
591
- * Marker class for expressions during schema parsing.
592
- * Similar to `DefinitionReferenceMarker`, this wraps expression values
593
- * during the Zod parsing phase when `transformReferences` is enabled.
594
- */
595
- class DefinitionExpressionMarker {
596
- value;
597
- expression;
598
- constructor(value, expression) {
599
- this.value = value;
600
- this.expression = expression;
601
- }
602
- toString() {
603
- return String(this.value);
604
- }
605
- }
606
- const REF_ANNOTATIONS_MARKER_SYMBOL = Symbol('refAnnotationsMarker');
607
-
608
- /**
609
- * Creates a new ref context slot for the given entity type.
610
- * Each call creates a unique slot, even for the same entity type.
611
- *
612
- * @param name - A descriptive name for debugging (shows in Symbol description)
613
- * @param entityType - The entity type this slot will be associated with
614
- * @returns A new unique RefContextSlot instance
615
- *
616
- * @example
617
- * ```typescript
618
- * const modelSlot = createRefContextSlot('modelSlot', modelEntityType);
619
- * const anotherModelSlot = createRefContextSlot('anotherModelSlot', modelEntityType);
620
- *
621
- * // These are different slots despite same entity type
622
- * modelSlot.id !== anotherModelSlot.id
623
- * // modelSlot.id.toString() === 'Symbol(modelSlot)'
624
- * ```
625
- */
626
- function createRefContextSlot(name, entityType) {
627
- return {
628
- entityType,
629
- id: Symbol(name),
630
- };
631
- }
632
- /**
633
- * Creates a RefContextSlotMap from a slot definition.
634
- * Used internally by ctx.refContext().
635
- *
636
- * @param slotDefinition - Map of slot names to entity types
637
- * @returns Map of slot names to RefContextSlot instances
638
- */
639
- function createRefContextSlotMap(slotDefinition) {
640
- return Object.fromEntries(Object.entries(slotDefinition).map(([key, entityType]) => [
641
- key,
642
- createRefContextSlot(key, entityType),
643
- ]));
644
- }
645
-
646
- /**
647
- * Strips the DefinitionReferenceMarker and DefinitionExpressionMarker from the value recursively.
648
- * @param value - The value to strip the markers from.
649
- * @returns The value without the markers.
650
- */
651
- function stripRefMarkers(value) {
652
- if (value instanceof DefinitionReferenceMarker) {
653
- return value.value;
654
- }
655
- if (value instanceof DefinitionExpressionMarker) {
656
- return value.value;
657
- }
658
- if (Array.isArray(value)) {
659
- return value.map(stripRefMarkers);
660
- }
661
- if (typeof value === 'object' && value !== null) {
662
- return Object.fromEntries(Object.entries(value).map(([key, childValue]) => [
663
- key,
664
- stripRefMarkers(childValue),
665
- ]));
666
- }
667
- return value;
668
- }
669
-
670
- const {z: z$1} = await importShared('zod');
671
- function extendParserContextWithRefs({ transformReferences, }) {
672
- function modifyAnnotations(value, ctx, modifier) {
673
- if (value === null || value === undefined)
674
- return value;
675
- if (typeof value !== 'object') {
676
- ctx.addIssue({
677
- code: 'invalid_type',
678
- expected: 'object',
679
- message: `Entity must be an object`,
680
- input: value,
681
- });
682
- return value;
683
- }
684
- if (transformReferences) {
685
- const existingAnnotations = REF_ANNOTATIONS_MARKER_SYMBOL in value
686
- ? value[REF_ANNOTATIONS_MARKER_SYMBOL]
687
- : { entities: [], references: [], slots: [] };
688
- return {
689
- ...value,
690
- [REF_ANNOTATIONS_MARKER_SYMBOL]: modifier(existingAnnotations),
691
- };
692
- }
693
- return value;
694
- }
695
- function withRef(reference) {
696
- return z$1.string().transform((value) => {
697
- if (transformReferences && value) {
698
- return new DefinitionReferenceMarker(value, {
699
- path: [],
700
- type: reference.type,
701
- onDelete: reference.onDelete,
702
- parentSlot: reference.parentSlot,
703
- provides: reference.provides,
704
- });
705
- }
706
- return value;
707
- });
708
- }
709
- function withEnt(schema, entity) {
710
- return schema.transform((value, ctx) => {
711
- if (value === null || value === undefined)
712
- return value;
713
- if (transformReferences) {
714
- if (typeof value !== 'object') {
715
- ctx.addIssue({
716
- code: 'invalid_type',
717
- expected: 'object',
718
- message: `Entity must be an object`,
719
- input: value,
720
- });
721
- return value;
722
- }
723
- // Check if the id is valid
724
- const idPath = entity.idPath ?? ['id'];
725
- const id = get(value, idPath);
726
- if (typeof id !== 'string' || !id || !entity.type.isId(id)) {
727
- ctx.addIssue({
728
- code: 'custom',
729
- message: `Unable to find string id field '${entity.idPath?.join('.') ?? 'id'}' in entity ${entity.type.name}`,
730
- input: value,
731
- });
732
- return value;
733
- }
734
- const nameResolver = (() => {
735
- if (entity.getNameResolver) {
736
- return entity.getNameResolver(stripRefMarkers(value));
737
- }
738
- if (!('name' in value) || typeof value.name !== 'string') {
739
- ctx.addIssue({
740
- code: 'custom',
741
- message: `Unable to find string name field in entity ${entity.type.name}`,
742
- input: value,
743
- });
744
- return 'invalid';
745
- }
746
- return value.name;
747
- })();
748
- const newEntity = {
749
- id,
750
- idPath,
751
- path: [],
752
- type: entity.type,
753
- nameResolver,
754
- parentSlot: entity.parentSlot,
755
- provides: entity.provides,
756
- };
757
- return modifyAnnotations(value, ctx, (annotations) => ({
758
- ...annotations,
759
- entities: [...annotations.entities, newEntity],
760
- }));
761
- }
762
- return value;
763
- });
764
- }
765
- /**
766
- * Creates ref context slots for use within a schema definition.
767
- * Slots provide type-safe context for parent-child entity relationships.
768
- *
769
- * @example
770
- * ```typescript
771
- * ctx.refContext(
772
- * { modelSlot: modelEntityType },
773
- * ({ modelSlot }) =>
774
- * ctx.withEnt(schema, {
775
- * type: modelEntityType,
776
- * provides: modelSlot,
777
- * }),
778
- * );
779
- * ```
780
- */
781
- function refContext(slotDefinition, schemaBuilder) {
782
- const slots = createRefContextSlotMap(slotDefinition);
783
- return schemaBuilder(slots).transform((value, ctx) => modifyAnnotations(value, ctx, (annotations) => ({
784
- ...annotations,
785
- slots: [
786
- ...annotations.slots,
787
- ...Object.values(slots).map((slot) => ({
788
- path: [],
789
- slot,
790
- })),
791
- ],
792
- })));
793
- }
794
- /**
795
- * Wraps a value with a ref expression parser for deferred validation.
796
- * The parser handles all parsing, validation, and rename handling.
797
- *
798
- * If the parser declares required slots (via TRequiredSlots), they must be
799
- * provided as the second argument. TypeScript enforces this at compile time.
800
- *
801
- * The parser's `schema` property is used for input validation.
802
- *
803
- * @example
804
- * ```typescript
805
- * // Parser without required slots
806
- * const expressionSchema = ctx.withExpression(simpleParser);
807
- *
808
- * // Parser with required slots (TypeScript enforces the second argument)
809
- * ctx.refContext(
810
- * { modelSlot: modelEntityType },
811
- * ({ modelSlot }) =>
812
- * z.object({
813
- * condition: ctx.withExpression(authorizerParser, { model: modelSlot }),
814
- * })
815
- * );
816
- * ```
817
- */
818
- function withExpression(parser, slots) {
819
- return parser.schema.transform((value) => {
820
- if (transformReferences && value !== undefined) {
821
- return new DefinitionExpressionMarker(value, {
822
- path: [],
823
- value,
824
- parser,
825
- slots,
826
- });
827
- }
828
- return value;
829
- });
830
- }
831
- return {
832
- withRef,
833
- withEnt,
834
- refContext,
835
- withExpression,
836
- };
837
- }
838
-
839
- function isEmpty(value) {
840
- if (value === undefined || value === null) {
841
- return true;
842
- }
843
- if (Array.isArray(value)) {
844
- return value.length === 0;
845
- }
846
- if (typeof value === 'object' &&
847
- Object.getPrototypeOf(value) === Object.prototype) {
848
- return Object.values(value).every((val) => val === undefined);
849
- }
850
- if (typeof value === 'string') {
851
- return value === '';
852
- }
853
- return false;
854
- }
855
- /**
856
- * Extends the parser context with default value handling functionality.
857
- *
858
- * @param options - The schema creator options containing the defaultMode
859
- * @returns An object containing the withDefault method
860
- */
861
- function extendParserContextWithDefaults(options) {
862
- const mode = options.defaultMode ?? 'populate';
863
- return {
864
- withDefault: function withDefault(schema, defaultValue) {
865
- switch (mode) {
866
- case 'populate': {
867
- return schema.prefault(defaultValue).optional();
868
- }
869
- case 'strip': {
870
- // Use transform to remove values matching defaults after validation
871
- return schema
872
- .transform((value) => {
873
- if (value === defaultValue)
874
- return undefined;
875
- if (isEmpty(value)) {
876
- return undefined;
877
- }
878
- return value;
879
- })
880
- .optional();
881
- }
882
- case 'preserve': {
883
- // Return schema with .optional() added
884
- return schema.transform((x) => x).optional();
885
- }
886
- }
887
- },
888
- };
889
- }
890
-
891
- function createDefinitionSchemaParserContext(options) {
892
- return {
893
- ...options,
894
- ...extendParserContextWithRefs(options),
895
- ...extendParserContextWithDefaults(options),
896
- };
897
- }
898
- function definitionSchema(creator) {
899
- return (context) => creator(context);
900
- }
901
- /**
902
- * Creates a schema that requires slots to be passed from parent schemas.
903
- * Used when a schema needs to reference entities from a parent context.
904
- *
905
- * @example
906
- * ```typescript
907
- * // Child schema requiring modelSlot from parent
908
- * export const createModelScalarFieldSchema = definitionSchemaWithSlots(
909
- * { modelSlot: modelEntityType },
910
- * (ctx, { modelSlot }) =>
911
- * ctx.withEnt(schema, {
912
- * type: modelScalarFieldEntityType,
913
- * parentSlot: modelSlot,
914
- * }),
915
- * );
916
- *
917
- * // Called from parent:
918
- * createModelScalarFieldSchema(ctx, { modelSlot: parentModelSlot })
919
- * ```
920
- */
921
- function definitionSchemaWithSlots(slotDefinition, creator) {
922
- const creatorWithSlots = (context, slots) => creator(context, slots);
923
- creatorWithSlots.slotDefinition = slotDefinition;
924
- return creatorWithSlots;
925
- }
926
- /**
927
- * Wraps a schema creator that requires slots with placeholder slots,
928
- * producing a simple schema creator that can be used for validation-only
929
- * contexts (e.g., React Hook Form).
930
- *
931
- * The placeholder slots allow the schema to parse without actual parent context,
932
- * which is useful when you only need schema validation without ref extraction.
933
- *
934
- * @example
935
- * ```typescript
936
- * // Schema that normally requires modelSlot from parent
937
- * const createModelScalarFieldSchema = definitionSchemaWithSlots(
938
- * { modelSlot: modelEntityType },
939
- * (ctx, { modelSlot }) => ctx.withEnt(schema, { parentSlot: modelSlot }),
940
- * );
941
- *
942
- * // For React Hook Form validation, wrap with placeholder slots
943
- * const fieldSchema = withPlaceholderSlots(createModelScalarFieldSchema);
944
- * const zodSchema = fieldSchema(ctx); // No slots needed
945
- * ```
946
- */
947
- function withPlaceholderSlots(schemaCreator) {
948
- return (ctx) => {
949
- const placeholderSlots = createRefContextSlotMap(schemaCreator.slotDefinition);
950
- return schemaCreator(ctx, placeholderSlots);
951
- };
952
- }
953
-
954
- const {randomKey} = await importShared('@baseplate-dev/utils');
955
-
956
- /**
957
- * Definition of an entity type.
958
- */
959
- class DefinitionEntityType {
960
- prefix;
961
- name;
962
- parentType;
963
- /**
964
- * Creates a new entity type.
965
- *
966
- * @param name - The name of the entity type.
967
- * @param prefix - The prefix of the entity type to use in the ID, defaults to the name.
968
- * @param parentType - The type of the parent entity if any
969
- */
970
- constructor(name, prefix, parentType) {
971
- this.name = name;
972
- this.parentType = parentType;
973
- this.prefix = prefix ?? name.split('/').pop() ?? name;
974
- }
975
- /**
976
- * Generates a new ID for the entity type.
977
- *
978
- * @returns The new ID.
979
- */
980
- generateNewId() {
981
- return `${this.prefix}:${randomKey()}`;
982
- }
983
- idFromKey(key) {
984
- if (!key) {
985
- return undefined;
986
- }
987
- return `${this.prefix}:${key}`;
988
- }
989
- keyFromId(id) {
990
- return id.split(':')[1];
991
- }
992
- isId(id) {
993
- return id.startsWith(`${this.prefix}:`);
994
- }
995
- }
996
- function createEntityType(name, options) {
997
- const { parentType, prefix } = options ?? {};
998
- return new DefinitionEntityType(name, prefix, parentType);
999
- }
1000
-
1001
- function omit(obj, keys) {
1002
- const result = { ...obj };
1003
- for (let i = 0; i < keys.length; i++) {
1004
- const key = keys[i];
1005
- delete result[key];
1006
- }
1007
- return result;
1008
- }
1009
-
1010
- const modelEntityType = createEntityType('model');
1011
- const modelScalarFieldEntityType = createEntityType('model-scalar-field', {
1012
- parentType: modelEntityType,
1013
- });
1014
- const modelLocalRelationEntityType = createEntityType('model-local-relation', { parentType: modelEntityType });
1015
- const modelForeignRelationEntityType = createEntityType('model-foreign-relation', { parentType: modelEntityType });
1016
- const modelUniqueConstraintEntityType = createEntityType('model-unique-constraint', { parentType: modelEntityType });
1017
- const modelTransformerEntityType = createEntityType('model-transformer', { parentType: modelEntityType });
1018
- const modelEnumEntityType = createEntityType('model-enum');
1019
- const modelEnumValueEntityType = createEntityType('model-enum-value', {
1020
- parentType: modelEnumEntityType,
1021
- });
1022
-
1023
- const {CASE_VALIDATORS} = await importShared('@baseplate-dev/utils');
1024
-
1025
- const {z} = await importShared('zod');
1026
- const featureEntityType = createEntityType('feature');
1027
- const featureNameSchema = CASE_VALIDATORS.KEBAB_CASE;
1028
- const createFeatureSchema = definitionSchema((ctx) => ctx.withEnt(z.object({
1029
- id: z.string(),
1030
- name: z
1031
- .string()
1032
- .min(1)
1033
- .refine((name) => name
1034
- .split('/')
1035
- .every((part) => featureNameSchema.safeParse(part).success), {
1036
- message: 'Feature name must be lowercase and contain only letters, numbers, and dashes',
1037
- }),
1038
- parentRef: ctx
1039
- .withRef({
1040
- type: featureEntityType,
1041
- onDelete: 'DELETE_PARENT',
1042
- })
1043
- .optional(),
1044
- }), { type: featureEntityType }));
1045
- const createFeaturesSchema = definitionSchema((ctx) => z.array(createFeatureSchema(ctx)).default([]));
1046
-
1047
- function getRootFeatures(projectDefinition) {
1048
- return projectDefinition.features.filter((f) => !f.parentRef);
1049
- }
1050
- function getFeatureById(projectDefinition, featureId) {
1051
- return projectDefinition.features.find((f) => f.id === featureId);
1052
- }
1053
- function getFeatureByIdOrThrow(projectDefinition, featureId) {
1054
- const feature = getFeatureById(projectDefinition, featureId);
1055
- if (!feature) {
1056
- throw new Error(`Could not find feature with ID ${featureId}`);
1057
- }
1058
- return feature;
1059
- }
1060
- function getFeatureChildren(projectDefinition, featureId) {
1061
- return projectDefinition.features.filter((f) => f.parentRef === featureId);
1062
- }
1063
- function getFeatureName(featureConfig) {
1064
- return featureConfig.name.split('/').pop() ?? '';
1065
- }
1066
- function getFeatureNameById(projectDefinition, featureId) {
1067
- const feature = getFeatureByIdOrThrow(projectDefinition, featureId);
1068
- return getFeatureName(feature);
1069
- }
1070
- function getFeaturePathById(projectDefinition, featureId) {
1071
- const feature = getFeatureByIdOrThrow(projectDefinition, featureId);
1072
- return feature.name;
1073
- }
1074
- function validateFeatureName(name) {
1075
- const nameParts = name.split('/');
1076
- return nameParts.every((part) => featureNameSchema.safeParse(part).success);
1077
- }
1078
- function ensureFeatureByNameRecursively(projectDefinition, nameOrId) {
1079
- if (featureEntityType.isId(nameOrId)) {
1080
- return nameOrId;
1081
- }
1082
- const nameParts = nameOrId.split('/');
1083
- let lastName = '';
1084
- let parentRef = undefined;
1085
- for (const part of nameParts) {
1086
- const feature = projectDefinition.features.find((f) => f.name === part && f.parentRef === parentRef);
1087
- const name = [lastName, part].filter(Boolean).join('/');
1088
- if (feature) {
1089
- parentRef = feature.id;
1090
- }
1091
- else {
1092
- const newFeature = {
1093
- id: featureEntityType.generateNewId(),
1094
- name,
1095
- parentRef,
1096
- };
1097
- projectDefinition.features.push(newFeature);
1098
- parentRef = newFeature.id;
1099
- }
1100
- lastName = name;
1101
- }
1102
- if (!parentRef) {
1103
- throw new Error('Failed to create feature');
1104
- }
1105
- return parentRef;
1106
- }
1107
- function getFeatureByName(projectDefinition, name) {
1108
- return projectDefinition.features.find((f) => f.name === name);
1109
- }
1110
- function getFeatureIdByNameOrDefault(projectDefinition, name) {
1111
- return getFeatureByName(projectDefinition, name)?.id ?? name;
1112
- }
1113
- const FeatureUtils = {
1114
- getRootFeatures,
1115
- getFeatureById,
1116
- getFeatureByIdOrThrow,
1117
- getFeatureChildren,
1118
- getFeatureName,
1119
- getFeatureNameById,
1120
- getFeaturePathById,
1121
- validateFeatureName,
1122
- ensureFeatureByNameRecursively,
1123
- getFeatureByName,
1124
- getFeatureIdByNameOrDefault,
1125
- };
1126
-
1127
- const {PASCAL_CASE_REGEX} = await importShared('@baseplate-dev/utils');
1128
-
1129
- function byId(projectDefinition, id) {
1130
- return projectDefinition.models.find((m) => m.id === id);
1131
- }
1132
- function byIdOrThrow(projectDefinition, id) {
1133
- const model = byId(projectDefinition, id);
1134
- if (!model) {
1135
- throw new Error(`Could not find model with ID ${id}`);
1136
- }
1137
- return model;
1138
- }
1139
- function byName(projectDefinition, name) {
1140
- return projectDefinition.models.find((m) => m.name === name);
1141
- }
1142
- function byNameOrThrow(projectDefinition, name) {
1143
- const model = byName(projectDefinition, name);
1144
- if (!model) {
1145
- throw new Error(`Could not find model with name ${name}`);
1146
- }
1147
- return model;
1148
- }
1149
- function getScalarFieldById(model, id) {
1150
- const field = model.model.fields.find((f) => f.id === id);
1151
- if (!field) {
1152
- throw new Error(`Could not find field with ID ${id}`);
1153
- }
1154
- return field;
1155
- }
1156
- function getRelationsToModel(projectDefinition, modelId) {
1157
- return projectDefinition.models.flatMap((m) => m.model.relations
1158
- ?.filter((r) => r.modelRef === modelId)
1159
- .map((r) => ({ model: m, relation: r })) ?? []);
1160
- }
1161
- function getModelsForFeature(projectDefinition, featureId) {
1162
- return projectDefinition.models.filter((m) => m.featureRef === featureId);
1163
- }
1164
- function getModelIdFields(model) {
1165
- return model.model.primaryKeyFieldRefs;
1166
- }
1167
- function hasService(model) {
1168
- return (model.service.create.enabled ||
1169
- model.service.update.enabled ||
1170
- model.service.delete.enabled ||
1171
- model.service.transformers.length > 0);
1172
- }
1173
- function validateModelName(name) {
1174
- return PASCAL_CASE_REGEX.test(name);
1175
- }
1176
- /**
1177
- * Returns the ID of a model by name, or the name if no model is found.
1178
- * @param projectDefinition - The project definition.
1179
- * @param name - The name of the model.
1180
- * @returns The ID of the model, or the name if no model is found.
1181
- */
1182
- function getModelIdByNameOrDefault(projectDefinition, name) {
1183
- return projectDefinition.models.find((m) => m.name === name)?.id ?? name;
1184
- }
1185
- function getPrimaryKeyFields(model) {
1186
- const primaryKeyFields = model.model.primaryKeyFieldRefs;
1187
- return primaryKeyFields.map((id) => getScalarFieldById(model, id));
1188
- }
1189
- const ModelUtils = {
1190
- byId,
1191
- byIdOrThrow,
1192
- byName,
1193
- byNameOrThrow,
1194
- getScalarFieldById,
1195
- getRelationsToModel,
1196
- getModelsForFeature,
1197
- getModelIdFields,
1198
- hasService,
1199
- validateModelName,
1200
- getModelIdByNameOrDefault,
1201
- getPrimaryKeyFields,
1202
- };
1203
-
1204
- /**
1205
- * Allows diffing of arbitrary JSON objects.
1206
- */
1207
- class DefinitionDiffField {
1208
- /**
1209
- * The name of the field to be presented to the user.
1210
- */
1211
- name;
1212
- constructor(name) {
1213
- this.name = name;
1214
- }
1215
- }
1216
- /**
1217
- * A field that is an array of objects with a unique key.
1218
- */
1219
- class DefinitionDiffKeyedArrayField extends DefinitionDiffField {
1220
- getKey;
1221
- options;
1222
- constructor(name, getKey, options = {}) {
1223
- super(name);
1224
- this.getKey = getKey;
1225
- this.options = options;
1226
- }
1227
- diff(current, desired) {
1228
- const currentValue = current ?? [];
1229
- const desiredValue = desired ?? [];
1230
- if (!Array.isArray(currentValue) || !Array.isArray(desiredValue)) {
1231
- throw new TypeError('Current and desired must be arrays');
1232
- }
1233
- const ops = [];
1234
- const { allowRemove, ignoreFields = ['id'] } = this.options;
1235
- const currentByKey = new Map(currentValue.map((item) => [this.getKey(item), item]));
1236
- const desiredByKey = new Map(desiredValue.map((item) => [this.getKey(item), item]));
1237
- for (const [key, desiredItem] of desiredByKey) {
1238
- const currentItem = currentByKey.get(key);
1239
- if (!currentItem) {
1240
- ops.push({ type: 'add', key, item: desiredItem });
1241
- continue;
1242
- }
1243
- if (!isMatch(omit(currentItem, ignoreFields), omit(desiredItem, ignoreFields))) {
1244
- ops.push({ type: 'update', key, item: desiredItem });
1245
- }
1246
- }
1247
- if (allowRemove) {
1248
- for (const [key, currentItem] of currentByKey) {
1249
- if (!desiredByKey.has(key)) {
1250
- ops.push({ type: 'remove', key, item: currentItem });
1251
- }
1252
- }
1253
- }
1254
- return ops;
1255
- }
1256
- apply(current, diff) {
1257
- const patch = diff;
1258
- const currentValue = current ?? [];
1259
- if (!Array.isArray(currentValue)) {
1260
- throw new TypeError('Current must be array');
1261
- }
1262
- const items = [...currentValue];
1263
- for (const { type, key, item } of patch) {
1264
- const index = items.findIndex((i) => this.getKey(i) === key);
1265
- switch (type) {
1266
- case 'add': {
1267
- items.push(item);
1268
- break;
1269
- }
1270
- case 'update': {
1271
- if (index === -1) {
1272
- throw new Error(`Cannot apply patch. Item with key "${key}" not found.`);
1273
- }
1274
- // Preserve existing id if present.
1275
- items[index] = toMerged(items[index], item);
1276
- break;
1277
- }
1278
- case 'remove': {
1279
- if (index !== -1) {
1280
- items.splice(index, 1);
1281
- }
1282
- break;
1283
- }
1284
- }
1285
- }
1286
- return items;
1287
- }
1288
- getActionVerb(isNew) {
1289
- return isNew ? 'created' : 'added or updated';
1290
- }
1291
- }
1292
- /**
1293
- * A field that is a replacement for the entire object or array.
1294
- */
1295
- class DefinitionDiffReplacementField extends DefinitionDiffField {
1296
- diff(current, desired) {
1297
- if (desired === undefined) {
1298
- return [];
1299
- }
1300
- if (!isMatch(current, desired)) {
1301
- return [{ type: 'update', key: '*', item: desired }];
1302
- }
1303
- return [];
1304
- }
1305
- apply(current, diff) {
1306
- if (diff.length === 0)
1307
- return current;
1308
- return diff[0].item;
1309
- }
1310
- getActionVerb(isNew) {
1311
- return isNew ? 'set' : 'replaced';
1312
- }
1313
- }
1314
- /**
1315
- * A field that ensures an array contains certain values.
1316
- * This field type only adds items, never removes them.
1317
- */
1318
- class DefinitionDiffArrayIncludesField extends DefinitionDiffField {
1319
- getKey;
1320
- constructor(name, getKey) {
1321
- super(name);
1322
- this.getKey = getKey;
1323
- }
1324
- diff(current, desired) {
1325
- const currentValue = current ?? [];
1326
- const desiredValue = desired ?? [];
1327
- if (!Array.isArray(currentValue) || !Array.isArray(desiredValue)) {
1328
- throw new TypeError('Current and desired must be arrays');
1329
- }
1330
- const ops = [];
1331
- const currentSet = new Set(this.getKey ? currentValue.map(this.getKey) : currentValue);
1332
- for (const item of desiredValue) {
1333
- const key = this.getKey ? this.getKey(item) : String(item);
1334
- if (!currentSet.has(key)) {
1335
- ops.push({ type: 'add', key, item });
1336
- }
1337
- }
1338
- return ops;
1339
- }
1340
- apply(current, diff) {
1341
- const currentValue = (current ?? []);
1342
- if (!Array.isArray(currentValue)) {
1343
- throw new TypeError('Current must be array');
1344
- }
1345
- const items = [...currentValue];
1346
- for (const { type, item } of diff) {
1347
- if (type === 'add') {
1348
- items.push(item);
1349
- }
1350
- }
1351
- return items;
1352
- }
1353
- getActionVerb(isNew) {
1354
- return isNew ? 'created' : 'added';
1355
- }
1356
- }
1357
- function createDefinitionDiffConfig(config) {
1358
- return config;
1359
- }
1360
- /**
1361
- * Creates a diff between two objects.
1362
- */
1363
- function createDefinitionDiff(current, desired, configuration) {
1364
- const ops = mapValues(configuration, (field, key) => {
1365
- if (!field)
1366
- return [];
1367
- return field.diff(get(current, key), get(desired, key));
1368
- });
1369
- if (Object.values(ops).every((ops) => ops.length === 0)) {
1370
- return undefined;
1371
- }
1372
- return ops;
1373
- }
1374
- /**
1375
- * Applies a diff to an object.
1376
- */
1377
- function applyDefinitionDiff(current, diff, configuration) {
1378
- const clonedCurrent = cloneDeep(current);
1379
- for (const [key, ops] of Object.entries(diff)) {
1380
- if (!ops)
1381
- continue;
1382
- const field = configuration[key];
1383
- const currentValue = get(clonedCurrent, key);
1384
- set(clonedCurrent, key, field.apply(currentValue, ops));
1385
- }
1386
- return clonedCurrent;
1387
- }
1388
-
1389
- /**
1390
- * Computes a unique key for a unique constraint by sorting its field refs.
1391
- *
1392
- * @param constraint - Unique constraint input.
1393
- * @returns A key string.
1394
- */
1395
- function getUniqueConstraintKey(constraint) {
1396
- const fields = constraint.fields.map((f) => f.fieldRef).toSorted();
1397
- return fields.join('|');
1398
- }
1399
- const modelMergerDefinitionDiffConfig = createDefinitionDiffConfig({
1400
- 'model.fields': new DefinitionDiffKeyedArrayField('fields', (f) => f.name),
1401
- 'model.relations': new DefinitionDiffKeyedArrayField('relations', (r) => r.name),
1402
- 'model.uniqueConstraints': new DefinitionDiffKeyedArrayField('unique constraints', (c) => getUniqueConstraintKey(c)),
1403
- 'model.primaryKeyFieldRefs': new DefinitionDiffReplacementField('primary key fields'),
1404
- 'graphql.objectType.enabled': new DefinitionDiffReplacementField('GraphQL object type enabled'),
1405
- 'graphql.objectType.fields': new DefinitionDiffArrayIncludesField('GraphQL object type fields'),
1406
- 'graphql.objectType.localRelations': new DefinitionDiffArrayIncludesField('GraphQL object type local relations'),
1407
- 'graphql.objectType.foreignRelations': new DefinitionDiffArrayIncludesField('GraphQL object type foreign relations'),
1408
- });
1409
- /**
1410
- * Serializes a model merger model input such that all IDs are replaced with
1411
- * names.
1412
- *
1413
- * @param input - The model merger model input.
1414
- * @param definitionContainer - The definition container.
1415
- * @returns The serialized model merger model input.
1416
- */
1417
- function serializeModelMergerModelInput(input, definitionContainer, siblingModels) {
1418
- const siblingModelIds = new Map(siblingModels.map((m) => [m.id, m.name]));
1419
- const siblingModelFieldIdMap = new Map([
1420
- ...input.model.fields.map((f) => [f.id, f.name]),
1421
- ...siblingModels.flatMap((m) => m.model.fields.map((f) => [f.id, f.name])),
1422
- ]);
1423
- const siblingModelRelationIdMap = new Map([
1424
- ...(input.model.relations ?? []).map((r) => [r.id, r.name]),
1425
- ...siblingModels.flatMap((m) => (m.model.relations ?? []).map((r) => [r.id, r.name])),
1426
- ...(input.model.relations ?? []).map((r) => [r.foreignId, r.foreignRelationName]),
1427
- ...siblingModels.flatMap((m) => (m.model.relations ?? []).map((r) => [r.foreignId, r.foreignRelationName])),
1428
- ]);
1429
- const modelFromId = (id) => siblingModelIds.get(id) ?? definitionContainer.nameFromId(id);
1430
- const fieldNameFromId = (id) => siblingModelFieldIdMap.get(id) ?? definitionContainer.nameFromId(id);
1431
- const relationNameFromId = (id) => siblingModelRelationIdMap.get(id) ?? definitionContainer.nameFromId(id);
1432
- return {
1433
- ...input,
1434
- model: {
1435
- ...input.model,
1436
- relations: input.model.relations?.map((r) => ({
1437
- ...r,
1438
- modelRef: modelFromId(r.modelRef),
1439
- references: r.references.map((reference) => ({
1440
- ...reference,
1441
- localRef: fieldNameFromId(reference.localRef),
1442
- foreignRef: fieldNameFromId(reference.foreignRef),
1443
- })),
1444
- })),
1445
- uniqueConstraints: input.model.uniqueConstraints?.map((c) => ({
1446
- ...c,
1447
- fields: c.fields.map((f) => ({
1448
- ...f,
1449
- fieldRef: fieldNameFromId(f.fieldRef),
1450
- })),
1451
- })),
1452
- primaryKeyFieldRefs: input.model.primaryKeyFieldRefs.map(fieldNameFromId),
1453
- },
1454
- graphql: {
1455
- ...input.graphql,
1456
- objectType: {
1457
- ...input.graphql?.objectType,
1458
- fields: input.graphql?.objectType?.fields?.map(fieldNameFromId) ?? [],
1459
- localRelations: input.graphql?.objectType?.localRelations?.map(relationNameFromId) ??
1460
- [],
1461
- foreignRelations: input.graphql?.objectType?.foreignRelations?.map(relationNameFromId) ?? [],
1462
- },
1463
- },
1464
- };
1465
- }
1466
- /**
1467
- * Attaches IDs to the model merger model input.
1468
- *
1469
- * @param input - The model merger model input.
1470
- * @returns The model merger model input with IDs attached.
1471
- */
1472
- function attachIdsToModelMergerModelInput(input) {
1473
- return {
1474
- ...input,
1475
- model: {
1476
- ...input.model,
1477
- fields: input.model.fields.map((f) => ({
1478
- ...f,
1479
- id: f.id ?? modelScalarFieldEntityType.generateNewId(),
1480
- })),
1481
- relations: input.model.relations?.map((r) => ({
1482
- ...r,
1483
- id: r.id ?? modelLocalRelationEntityType.generateNewId(),
1484
- foreignId: r.foreignId ?? modelForeignRelationEntityType.generateNewId(),
1485
- })),
1486
- uniqueConstraints: input.model.uniqueConstraints?.map((c) => ({
1487
- ...c,
1488
- id: c.id ?? modelUniqueConstraintEntityType.generateNewId(),
1489
- })),
1490
- },
1491
- };
1492
- }
1493
- /**
1494
- * Deserializes a model merger model input converting all names to IDs.
1495
- *
1496
- * @param input - The model merger model input.
1497
- * @param resolveForeignFieldRef - A function that resolves the foreign field ref.
1498
- * @returns The deserialized model merger model input.
1499
- */
1500
- function deserializeModelMergerModelInput(input, resolveForeignFieldRef, resolveForeignRelationRef, resolveModelRef) {
1501
- const inputWithIds = attachIdsToModelMergerModelInput(input);
1502
- const resolveLocalFieldName = (name) => {
1503
- const field = inputWithIds.model.fields.find((f) => f.name === name);
1504
- if (!field) {
1505
- throw new Error(`Field ${name} not found`);
1506
- }
1507
- return field.id;
1508
- };
1509
- const resolveLocalRelationName = (name) => {
1510
- const relation = inputWithIds.model.relations?.find((r) => r.name === name);
1511
- if (!relation) {
1512
- throw new Error(`Relation ${name} not found`);
1513
- }
1514
- return relation.id;
1515
- };
1516
- return {
1517
- ...inputWithIds,
1518
- model: {
1519
- ...inputWithIds.model,
1520
- relations: inputWithIds.model.relations?.map((relation) => ({
1521
- ...relation,
1522
- modelRef: resolveModelRef(relation.modelRef),
1523
- references: relation.references.map((reference) => ({
1524
- ...reference,
1525
- localRef: resolveLocalFieldName(reference.localRef),
1526
- foreignRef: resolveForeignFieldRef(relation.modelRef, reference.foreignRef),
1527
- })),
1528
- })),
1529
- uniqueConstraints: inputWithIds.model.uniqueConstraints?.map((constraint) => ({
1530
- ...constraint,
1531
- fields: constraint.fields.map((field) => ({
1532
- ...field,
1533
- fieldRef: resolveLocalFieldName(field.fieldRef),
1534
- })),
1535
- })),
1536
- primaryKeyFieldRefs: inputWithIds.model.primaryKeyFieldRefs.map((fieldRef) => resolveLocalFieldName(fieldRef)),
1537
- },
1538
- graphql: {
1539
- ...inputWithIds.graphql,
1540
- objectType: {
1541
- ...inputWithIds.graphql?.objectType,
1542
- fields: inputWithIds.graphql?.objectType?.fields?.map((fieldRef) => resolveLocalFieldName(fieldRef)) ?? [],
1543
- localRelations: inputWithIds.graphql?.objectType?.localRelations?.map((relationRef) => resolveLocalRelationName(relationRef)) ?? [],
1544
- foreignRelations: inputWithIds.graphql?.objectType?.foreignRelations?.map((relationRef) => resolveForeignRelationRef(relationRef)) ?? [],
1545
- },
1546
- },
1547
- };
1548
- }
1549
- /**
1550
- * Creates a new blank model config input from a name and feature ref.
1551
- *
1552
- * @param name - The name of the model.
1553
- * @param featureRef - The feature ref of the model.
1554
- * @returns The new model config input.
1555
- */
1556
- function createNewModelConfigInput(name, featureRef, id) {
1557
- return {
1558
- id,
1559
- name,
1560
- featureRef,
1561
- model: {
1562
- fields: [],
1563
- primaryKeyFieldRefs: [],
1564
- },
1565
- };
1566
- }
1567
- /**
1568
- * Diff the model definition.
1569
- *
1570
- * @param current - The current model definition or a new model to be created.
1571
- * @param desired - The desired model definition.
1572
- * @param definitionContainer - Project definition container.
1573
- * @param options - Diff options.
1574
- * @returns A diff output or undefined if there are no differences.
1575
- */
1576
- function createModelMergerResult(current, desired, definitionContainer, { siblingModels = [] } = {}) {
1577
- const currentModel = current ??
1578
- createNewModelConfigInput(desired.name, desired.featureRef, modelEntityType.generateNewId());
1579
- // resolves all the names of the current model config input
1580
- const resolvedCurrent = serializeModelMergerModelInput(currentModel, definitionContainer, siblingModels);
1581
- const diff = createDefinitionDiff(resolvedCurrent, desired, modelMergerDefinitionDiffConfig);
1582
- if (!diff) {
1583
- return undefined;
1584
- }
1585
- return {
1586
- isNewModel: !current,
1587
- id: currentModel.id,
1588
- name: currentModel.name,
1589
- featureRef: currentModel.featureRef,
1590
- changes: diff,
1591
- };
1592
- }
1593
- function doesModelMergerResultsHaveChanges(results) {
1594
- return Object.values(results).some((result) => result?.changes);
1595
- }
1596
- /**
1597
- * Creates a model merger result for a set of models.
1598
- *
1599
- * @param current - A map of model IDs
1600
- * @param desired - The desired model definition.
1601
- * @param definitionContainer - Project definition container.
1602
- * @param options - Diff options.
1603
- * @returns A model merger result for a set of models.
1604
- */
1605
- function createModelMergerResults(current, desired, definitionContainer, { siblingModels = [] } = {}) {
1606
- return mapValues(desired, (desired, key) => createModelMergerResult(current[key] && modelEntityType.isId(current[key])
1607
- ? ModelUtils.byIdOrThrow(definitionContainer.definition, current[key])
1608
- : ModelUtils.byName(definitionContainer.definition, current[key] ?? ''), desired, definitionContainer, {
1609
- siblingModels,
1610
- }));
1611
- }
1612
- function applyModelMergerDiff(model, diff, definitionContainer, siblingModels = []) {
1613
- const resolvedCurrent = serializeModelMergerModelInput(model, definitionContainer, siblingModels);
1614
- const patchedCurrent = applyDefinitionDiff(resolvedCurrent, diff, modelMergerDefinitionDiffConfig);
1615
- return {
1616
- ...model,
1617
- ...deserializeModelMergerModelInput(patchedCurrent, (modelId, fieldName) => {
1618
- const siblingModel = siblingModels.find((m) => m.id === modelId || m.name === modelId);
1619
- if (siblingModel) {
1620
- const field = siblingModel.model.fields.find((f) => f.name === fieldName);
1621
- if (!field) {
1622
- throw new Error(`Field ${fieldName} not found in sibling model ${modelId}`);
1623
- }
1624
- return field.id;
1625
- }
1626
- const model = ModelUtils.byName(definitionContainer.definition, modelId) ??
1627
- ModelUtils.byIdOrThrow(definitionContainer.definition, modelId);
1628
- const field = model.model.fields.find((f) => f.name === fieldName);
1629
- if (!field) {
1630
- throw new Error(`Field ${fieldName} not found in model ${model.name}`);
1631
- }
1632
- return field.id;
1633
- }, (relationName) => {
1634
- // Search sibling model first
1635
- let relationId;
1636
- for (const siblingModel of siblingModels) {
1637
- const relation = siblingModel.model.relations?.find((r) => r.foreignRelationName === relationName);
1638
- if (relation) {
1639
- relationId = relation.foreignId;
1640
- break;
1641
- }
1642
- }
1643
- if (relationId) {
1644
- return relationId;
1645
- }
1646
- const relations = ModelUtils.getRelationsToModel(definitionContainer.definition, model.id);
1647
- const relation = relations.find((r) => r.relation.foreignRelationName === relationName &&
1648
- r.relation.modelRef === model.id);
1649
- if (!relation) {
1650
- throw new Error(`Relation ${relationName} not found in model ${model.name}`);
1651
- }
1652
- return relation.relation.foreignId;
1653
- }, (modelRef) => {
1654
- const siblingModel = siblingModels.find((m) => m.id === modelRef || m.name === modelRef);
1655
- if (siblingModel) {
1656
- return siblingModel.id;
1657
- }
1658
- const model = ModelUtils.byName(definitionContainer.definition, modelRef) ??
1659
- ModelUtils.byIdOrThrow(definitionContainer.definition, modelRef);
1660
- return model.id;
1661
- }),
1662
- };
1663
- }
1664
- function applyModelMergerResultInPlace(draftConfig, currentModel, result, definitionContainer, { siblingModels = [] } = {}) {
1665
- const newModel = applyModelMergerDiff(currentModel, result.changes, definitionContainer, siblingModels);
1666
- if (result.isNewModel) {
1667
- draftConfig.models.push(newModel);
1668
- }
1669
- else {
1670
- const index = draftConfig.models.findIndex((m) => m.id === result.id);
1671
- if (index === -1) {
1672
- throw new Error(`Model ${result.id} not found`);
1673
- }
1674
- draftConfig.models[index] = newModel;
1675
- }
1676
- return newModel.id;
1677
- }
1678
- function createAndApplyModelMergerResults(draftConfig, current, desired, definitionContainer, { siblingModels = [] } = {}) {
1679
- const results = createModelMergerResults(current, desired, definitionContainer, { siblingModels });
1680
- const newModels = [];
1681
- const resultIds = {};
1682
- // Apply model mergers in order
1683
- for (const [key, result] of Object.entries(results)) {
1684
- if (result) {
1685
- const model = result.isNewModel
1686
- ? createNewModelConfigInput(result.name, result.featureRef, result.id)
1687
- : ModelUtils.byIdOrThrow(definitionContainer.definition, result.id);
1688
- applyModelMergerResultInPlace(draftConfig, model, result, definitionContainer, {
1689
- siblingModels: newModels,
1690
- });
1691
- const newModel = draftConfig.models.find((m) => m.id === result.id);
1692
- if (newModel) {
1693
- newModels.push(newModel);
1694
- }
1695
- resultIds[key] = model.id;
1696
- }
1697
- else {
1698
- resultIds[key] = desired[key].name;
1699
- }
1700
- }
1701
- return resultIds;
1702
- }
1703
-
1704
- export { createRefContextSlot as A, createRefContextSlotMap as B, DefinitionEntityType as C, DefinitionReferenceMarker as D, withPlaceholderSlots as E, FeatureUtils as F, featureNameSchema as G, createFeatureSchema as H, modelMergerDefinitionDiffConfig as I, createModelMergerResult as J, doesModelMergerResultsHaveChanges as K, createModelMergerResults as L, ModelUtils as M, applyModelMergerDiff as N, applyModelMergerResultInPlace as O, createAndApplyModelMergerResults as P, DefinitionDiffKeyedArrayField as Q, REF_ANNOTATIONS_MARKER_SYMBOL as R, DefinitionDiffReplacementField as S, DefinitionDiffArrayIncludesField as T, createDefinitionDiffConfig as U, createDefinitionDiff as V, applyDefinitionDiff as W, createEntityType as a, DefinitionExpressionMarker as b, createFieldMapSpec as c, definitionSchemaWithSlots as d, createDefinitionSchemaParserContext as e, set as f, get as g, modelEntityType as h, definitionSchema as i, modelEnumValueEntityType as j, modelEnumEntityType as k, featureEntityType as l, mapValues as m, modelForeignRelationEntityType as n, modelLocalRelationEntityType as o, modelScalarFieldEntityType as p, modelTransformerEntityType as q, modelUniqueConstraintEntityType as r, stripRefMarkers as s, runInPluginContext as t, createFeaturesSchema as u, omit as v, cloneDeep as w, getPluginContext as x, createPluginSpec as y, createPluginFieldMap as z };
1705
- //# sourceMappingURL=model-merger-59HLmy_J.js.map