@nixxie-cms/core 1.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 (658) hide show
  1. package/CHANGELOG.md +3158 -0
  2. package/LICENSE +21 -0
  3. package/README.md +6 -0
  4. package/___internal-do-not-use-will-break-in-patch/admin-ui/id-field-view/dist/nixxie-cms-core-___internal-do-not-use-will-break-in-patch-admin-ui-id-field-view.cjs.d.ts +2 -0
  5. package/___internal-do-not-use-will-break-in-patch/admin-ui/id-field-view/dist/nixxie-cms-core-___internal-do-not-use-will-break-in-patch-admin-ui-id-field-view.cjs.js +244 -0
  6. package/___internal-do-not-use-will-break-in-patch/admin-ui/id-field-view/dist/nixxie-cms-core-___internal-do-not-use-will-break-in-patch-admin-ui-id-field-view.esm.js +235 -0
  7. package/___internal-do-not-use-will-break-in-patch/admin-ui/id-field-view/package.json +4 -0
  8. package/___internal-do-not-use-will-break-in-patch/admin-ui/next-config/package.json +4 -0
  9. package/___internal-do-not-use-will-break-in-patch/admin-ui/pages/App/dist/nixxie-cms-core-___internal-do-not-use-will-break-in-patch-admin-ui-pages-App.cjs.d.ts +2 -0
  10. package/___internal-do-not-use-will-break-in-patch/admin-ui/pages/App/dist/nixxie-cms-core-___internal-do-not-use-will-break-in-patch-admin-ui-pages-App.cjs.js +59 -0
  11. package/___internal-do-not-use-will-break-in-patch/admin-ui/pages/App/dist/nixxie-cms-core-___internal-do-not-use-will-break-in-patch-admin-ui-pages-App.esm.js +55 -0
  12. package/___internal-do-not-use-will-break-in-patch/admin-ui/pages/App/package.json +4 -0
  13. package/___internal-do-not-use-will-break-in-patch/admin-ui/pages/CreateItemPage/dist/nixxie-cms-core-___internal-do-not-use-will-break-in-patch-admin-ui-pages-CreateItemPage.cjs.d.ts +2 -0
  14. package/___internal-do-not-use-will-break-in-patch/admin-ui/pages/CreateItemPage/dist/nixxie-cms-core-___internal-do-not-use-will-break-in-patch-admin-ui-pages-CreateItemPage.cjs.js +116 -0
  15. package/___internal-do-not-use-will-break-in-patch/admin-ui/pages/CreateItemPage/dist/nixxie-cms-core-___internal-do-not-use-will-break-in-patch-admin-ui-pages-CreateItemPage.esm.js +112 -0
  16. package/___internal-do-not-use-will-break-in-patch/admin-ui/pages/CreateItemPage/package.json +4 -0
  17. package/___internal-do-not-use-will-break-in-patch/admin-ui/pages/HomePage/dist/nixxie-cms-core-___internal-do-not-use-will-break-in-patch-admin-ui-pages-HomePage.cjs.d.ts +2 -0
  18. package/___internal-do-not-use-will-break-in-patch/admin-ui/pages/HomePage/dist/nixxie-cms-core-___internal-do-not-use-will-break-in-patch-admin-ui-pages-HomePage.cjs.js +336 -0
  19. package/___internal-do-not-use-will-break-in-patch/admin-ui/pages/HomePage/dist/nixxie-cms-core-___internal-do-not-use-will-break-in-patch-admin-ui-pages-HomePage.esm.js +332 -0
  20. package/___internal-do-not-use-will-break-in-patch/admin-ui/pages/HomePage/package.json +4 -0
  21. package/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ItemPage/dist/nixxie-cms-core-___internal-do-not-use-will-break-in-patch-admin-ui-pages-ItemPage.cjs.d.ts +2 -0
  22. package/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ItemPage/dist/nixxie-cms-core-___internal-do-not-use-will-break-in-patch-admin-ui-pages-ItemPage.cjs.js +463 -0
  23. package/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ItemPage/dist/nixxie-cms-core-___internal-do-not-use-will-break-in-patch-admin-ui-pages-ItemPage.esm.js +455 -0
  24. package/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ItemPage/package.json +4 -0
  25. package/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ListPage/dist/nixxie-cms-core-___internal-do-not-use-will-break-in-patch-admin-ui-pages-ListPage.cjs.d.ts +2 -0
  26. package/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ListPage/dist/nixxie-cms-core-___internal-do-not-use-will-break-in-patch-admin-ui-pages-ListPage.cjs.js +1195 -0
  27. package/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ListPage/dist/nixxie-cms-core-___internal-do-not-use-will-break-in-patch-admin-ui-pages-ListPage.esm.js +1187 -0
  28. package/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ListPage/package.json +4 -0
  29. package/___internal-do-not-use-will-break-in-patch/admin-ui/pages/NoAccessPage/dist/nixxie-cms-core-___internal-do-not-use-will-break-in-patch-admin-ui-pages-NoAccessPage.cjs.d.ts +2 -0
  30. package/___internal-do-not-use-will-break-in-patch/admin-ui/pages/NoAccessPage/dist/nixxie-cms-core-___internal-do-not-use-will-break-in-patch-admin-ui-pages-NoAccessPage.cjs.js +40 -0
  31. package/___internal-do-not-use-will-break-in-patch/admin-ui/pages/NoAccessPage/dist/nixxie-cms-core-___internal-do-not-use-will-break-in-patch-admin-ui-pages-NoAccessPage.esm.js +35 -0
  32. package/___internal-do-not-use-will-break-in-patch/admin-ui/pages/NoAccessPage/package.json +4 -0
  33. package/___internal-do-not-use-will-break-in-patch/artifacts/dist/nixxie-cms-core-___internal-do-not-use-will-break-in-patch-artifacts.cjs.d.ts +2 -0
  34. package/___internal-do-not-use-will-break-in-patch/artifacts/dist/nixxie-cms-core-___internal-do-not-use-will-break-in-patch-artifacts.cjs.js +51 -0
  35. package/___internal-do-not-use-will-break-in-patch/artifacts/dist/nixxie-cms-core-___internal-do-not-use-will-break-in-patch-artifacts.esm.js +38 -0
  36. package/___internal-do-not-use-will-break-in-patch/artifacts/package.json +4 -0
  37. package/access/dist/nixxie-cms-core-access.cjs.d.ts +2 -0
  38. package/access/dist/nixxie-cms-core-access.cjs.js +26 -0
  39. package/access/dist/nixxie-cms-core-access.esm.js +19 -0
  40. package/access/package.json +4 -0
  41. package/admin-ui/apollo/dist/nixxie-cms-core-admin-ui-apollo.cjs.d.ts +2 -0
  42. package/admin-ui/apollo/dist/nixxie-cms-core-admin-ui-apollo.cjs.js +87 -0
  43. package/admin-ui/apollo/dist/nixxie-cms-core-admin-ui-apollo.esm.js +2 -0
  44. package/admin-ui/apollo/package.json +4 -0
  45. package/admin-ui/components/dist/nixxie-cms-core-admin-ui-components.cjs.d.ts +2 -0
  46. package/admin-ui/components/dist/nixxie-cms-core-admin-ui-components.cjs.js +77 -0
  47. package/admin-ui/components/dist/nixxie-cms-core-admin-ui-components.esm.js +58 -0
  48. package/admin-ui/components/package.json +4 -0
  49. package/admin-ui/context/dist/nixxie-cms-core-admin-ui-context.cjs.d.ts +2 -0
  50. package/admin-ui/context/dist/nixxie-cms-core-admin-ui-context.cjs.js +35 -0
  51. package/admin-ui/context/dist/nixxie-cms-core-admin-ui-context.esm.js +23 -0
  52. package/admin-ui/context/package.json +4 -0
  53. package/admin-ui/image/dist/nixxie-cms-core-admin-ui-image.cjs.d.ts +3 -0
  54. package/admin-ui/image/dist/nixxie-cms-core-admin-ui-image.cjs.js +18 -0
  55. package/admin-ui/image/dist/nixxie-cms-core-admin-ui-image.esm.js +2 -0
  56. package/admin-ui/image/package.json +4 -0
  57. package/admin-ui/router/dist/nixxie-cms-core-admin-ui-router.cjs.d.ts +2 -0
  58. package/admin-ui/router/dist/nixxie-cms-core-admin-ui-router.cjs.js +34 -0
  59. package/admin-ui/router/dist/nixxie-cms-core-admin-ui-router.esm.js +12 -0
  60. package/admin-ui/router/package.json +4 -0
  61. package/admin-ui/utils/dist/nixxie-cms-core-admin-ui-utils.cjs.d.ts +2 -0
  62. package/admin-ui/utils/dist/nixxie-cms-core-admin-ui-utils.cjs.js +45 -0
  63. package/admin-ui/utils/dist/nixxie-cms-core-admin-ui-utils.esm.js +22 -0
  64. package/admin-ui/utils/package.json +4 -0
  65. package/bin/cli.js +3 -0
  66. package/context/dist/nixxie-cms-core-context.cjs.d.ts +2 -0
  67. package/context/dist/nixxie-cms-core-context.cjs.js +31 -0
  68. package/context/dist/nixxie-cms-core-context.esm.js +23 -0
  69. package/context/package.json +4 -0
  70. package/dist/CreateItemDialog-33335548.esm.js +55 -0
  71. package/dist/CreateItemDialog-56cf59b7.cjs.js +57 -0
  72. package/dist/Errors-575adfa3.cjs.js +147 -0
  73. package/dist/Errors-bf24759e.esm.js +143 -0
  74. package/dist/Field-47f85161.esm.js +278 -0
  75. package/dist/Field-ed8d7627.cjs.js +287 -0
  76. package/dist/Fields-956d9a14.esm.js +203 -0
  77. package/dist/Fields-e2c28056.cjs.js +206 -0
  78. package/dist/GraphQLErrorNotice-cd74180d.cjs.js +57 -0
  79. package/dist/GraphQLErrorNotice-d9f0931b.esm.js +55 -0
  80. package/dist/NullableFieldWrapper-6ea48af3.esm.js +71 -0
  81. package/dist/NullableFieldWrapper-daa0a080.cjs.js +74 -0
  82. package/dist/PageContainer-27c27f10.cjs.js +1144 -0
  83. package/dist/PageContainer-7db73317.esm.js +1129 -0
  84. package/dist/actionData-64d4c37a.esm.js +28 -0
  85. package/dist/actionData-7858738d.cjs.js +32 -0
  86. package/dist/admin-meta-14c60fec.esm.js +210 -0
  87. package/dist/admin-meta-18d0c276.cjs.js +217 -0
  88. package/dist/admin-meta-graphql-6f7f5331.esm.js +142 -0
  89. package/dist/admin-meta-graphql-c8f926e9.cjs.js +144 -0
  90. package/dist/common-1a350e11.cjs.js +324 -0
  91. package/dist/common-29fc82e6.esm.js +315 -0
  92. package/dist/context-3132c3ed.esm.js +419 -0
  93. package/dist/context-e7a45152.cjs.js +432 -0
  94. package/dist/declarations/src/___internal-do-not-use-will-break-in-patch/admin-ui/id-field-view.d.ts +6 -0
  95. package/dist/declarations/src/___internal-do-not-use-will-break-in-patch/admin-ui/id-field-view.d.ts.map +1 -0
  96. package/dist/declarations/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/App/index.d.ts +10 -0
  97. package/dist/declarations/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/App/index.d.ts.map +1 -0
  98. package/dist/declarations/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/CreateItemPage/index.d.ts +6 -0
  99. package/dist/declarations/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/CreateItemPage/index.d.ts.map +1 -0
  100. package/dist/declarations/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/HomePage/index.d.ts +2 -0
  101. package/dist/declarations/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/HomePage/index.d.ts.map +1 -0
  102. package/dist/declarations/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ItemPage/index.d.ts +6 -0
  103. package/dist/declarations/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ItemPage/index.d.ts.map +1 -0
  104. package/dist/declarations/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ListPage/index.d.ts +12 -0
  105. package/dist/declarations/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ListPage/index.d.ts.map +1 -0
  106. package/dist/declarations/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/NoAccessPage/index.d.ts +7 -0
  107. package/dist/declarations/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/NoAccessPage/index.d.ts.map +1 -0
  108. package/dist/declarations/src/___internal-do-not-use-will-break-in-patch/artifacts.d.ts +6 -0
  109. package/dist/declarations/src/___internal-do-not-use-will-break-in-patch/artifacts.d.ts.map +1 -0
  110. package/dist/declarations/src/access.d.ts +12 -0
  111. package/dist/declarations/src/access.d.ts.map +1 -0
  112. package/dist/declarations/src/admin-ui/apollo.d.ts +8 -0
  113. package/dist/declarations/src/admin-ui/apollo.d.ts.map +1 -0
  114. package/dist/declarations/src/admin-ui/components/CellContainer.d.ts +5 -0
  115. package/dist/declarations/src/admin-ui/components/CellContainer.d.ts.map +1 -0
  116. package/dist/declarations/src/admin-ui/components/CreateItemDialog.d.ts +5 -0
  117. package/dist/declarations/src/admin-ui/components/CreateItemDialog.d.ts.map +1 -0
  118. package/dist/declarations/src/admin-ui/components/Errors.d.ts +28 -0
  119. package/dist/declarations/src/admin-ui/components/Errors.d.ts.map +1 -0
  120. package/dist/declarations/src/admin-ui/components/GraphQLErrorNotice.d.ts +6 -0
  121. package/dist/declarations/src/admin-ui/components/GraphQLErrorNotice.d.ts.map +1 -0
  122. package/dist/declarations/src/admin-ui/components/InlineCode.d.ts +3 -0
  123. package/dist/declarations/src/admin-ui/components/InlineCode.d.ts.map +1 -0
  124. package/dist/declarations/src/admin-ui/components/Logo.d.ts +2 -0
  125. package/dist/declarations/src/admin-ui/components/Logo.d.ts.map +1 -0
  126. package/dist/declarations/src/admin-ui/components/Navigation.d.ts +22 -0
  127. package/dist/declarations/src/admin-ui/components/Navigation.d.ts.map +1 -0
  128. package/dist/declarations/src/admin-ui/components/NullableFieldWrapper.d.ts +33 -0
  129. package/dist/declarations/src/admin-ui/components/NullableFieldWrapper.d.ts.map +1 -0
  130. package/dist/declarations/src/admin-ui/components/PageContainer.d.ts +10 -0
  131. package/dist/declarations/src/admin-ui/components/PageContainer.d.ts.map +1 -0
  132. package/dist/declarations/src/admin-ui/components/index.d.ts +11 -0
  133. package/dist/declarations/src/admin-ui/components/index.d.ts.map +1 -0
  134. package/dist/declarations/src/admin-ui/context.d.ts +50 -0
  135. package/dist/declarations/src/admin-ui/context.d.ts.map +1 -0
  136. package/dist/declarations/src/admin-ui/image.d.ts +3 -0
  137. package/dist/declarations/src/admin-ui/image.d.ts.map +1 -0
  138. package/dist/declarations/src/admin-ui/router.d.ts +15 -0
  139. package/dist/declarations/src/admin-ui/router.d.ts.map +1 -0
  140. package/dist/declarations/src/admin-ui/utils/Fields.d.ts +16 -0
  141. package/dist/declarations/src/admin-ui/utils/Fields.d.ts.map +1 -0
  142. package/dist/declarations/src/admin-ui/utils/filters.d.ts +10 -0
  143. package/dist/declarations/src/admin-ui/utils/filters.d.ts.map +1 -0
  144. package/dist/declarations/src/admin-ui/utils/index.d.ts +8 -0
  145. package/dist/declarations/src/admin-ui/utils/index.d.ts.map +1 -0
  146. package/dist/declarations/src/admin-ui/utils/useCreateItem.d.ts +24 -0
  147. package/dist/declarations/src/admin-ui/utils/useCreateItem.d.ts.map +1 -0
  148. package/dist/declarations/src/admin-ui/utils/utils.d.ts +8 -0
  149. package/dist/declarations/src/admin-ui/utils/utils.d.ts.map +1 -0
  150. package/dist/declarations/src/artifacts.d.ts +14 -0
  151. package/dist/declarations/src/artifacts.d.ts.map +1 -0
  152. package/dist/declarations/src/context.d.ts +2 -0
  153. package/dist/declarations/src/context.d.ts.map +1 -0
  154. package/dist/declarations/src/fields/filters/enum-filter.d.ts +27 -0
  155. package/dist/declarations/src/fields/filters/enum-filter.d.ts.map +1 -0
  156. package/dist/declarations/src/fields/filters/index.d.ts +2 -0
  157. package/dist/declarations/src/fields/filters/index.d.ts.map +1 -0
  158. package/dist/declarations/src/fields/filters/internal.d.ts +21 -0
  159. package/dist/declarations/src/fields/filters/internal.d.ts.map +1 -0
  160. package/dist/declarations/src/fields/filters/providers/mysql.d.ts +182 -0
  161. package/dist/declarations/src/fields/filters/providers/mysql.d.ts.map +1 -0
  162. package/dist/declarations/src/fields/filters/providers/postgresql.d.ts +182 -0
  163. package/dist/declarations/src/fields/filters/providers/postgresql.d.ts.map +1 -0
  164. package/dist/declarations/src/fields/filters/providers/sqlite.d.ts +179 -0
  165. package/dist/declarations/src/fields/filters/providers/sqlite.d.ts.map +1 -0
  166. package/dist/declarations/src/fields/index.d.ts +35 -0
  167. package/dist/declarations/src/fields/index.d.ts.map +1 -0
  168. package/dist/declarations/src/fields/types/bigInt/index.d.ts +20 -0
  169. package/dist/declarations/src/fields/types/bigInt/index.d.ts.map +1 -0
  170. package/dist/declarations/src/fields/types/bigInt/views/index.d.ts +24 -0
  171. package/dist/declarations/src/fields/types/bigInt/views/index.d.ts.map +1 -0
  172. package/dist/declarations/src/fields/types/bytes/index.d.ts +70 -0
  173. package/dist/declarations/src/fields/types/bytes/index.d.ts.map +1 -0
  174. package/dist/declarations/src/fields/types/bytes/views/index.d.ts +24 -0
  175. package/dist/declarations/src/fields/types/bytes/views/index.d.ts.map +1 -0
  176. package/dist/declarations/src/fields/types/calendarDay/index.d.ts +15 -0
  177. package/dist/declarations/src/fields/types/calendarDay/index.d.ts.map +1 -0
  178. package/dist/declarations/src/fields/types/calendarDay/views/index.d.ts +18 -0
  179. package/dist/declarations/src/fields/types/calendarDay/views/index.d.ts.map +1 -0
  180. package/dist/declarations/src/fields/types/checkbox/index.d.ts +11 -0
  181. package/dist/declarations/src/fields/types/checkbox/index.d.ts.map +1 -0
  182. package/dist/declarations/src/fields/types/checkbox/views/index.d.ts +9 -0
  183. package/dist/declarations/src/fields/types/checkbox/views/index.d.ts.map +1 -0
  184. package/dist/declarations/src/fields/types/decimal/index.d.ts +20 -0
  185. package/dist/declarations/src/fields/types/decimal/index.d.ts.map +1 -0
  186. package/dist/declarations/src/fields/types/decimal/views/index.d.ts +22 -0
  187. package/dist/declarations/src/fields/types/decimal/views/index.d.ts.map +1 -0
  188. package/dist/declarations/src/fields/types/file/index.d.ts +34 -0
  189. package/dist/declarations/src/fields/types/file/index.d.ts.map +1 -0
  190. package/dist/declarations/src/fields/types/file/views/Field.d.ts +17 -0
  191. package/dist/declarations/src/fields/types/file/views/Field.d.ts.map +1 -0
  192. package/dist/declarations/src/fields/types/file/views/index.d.ts +29 -0
  193. package/dist/declarations/src/fields/types/file/views/index.d.ts.map +1 -0
  194. package/dist/declarations/src/fields/types/float/index.d.ts +18 -0
  195. package/dist/declarations/src/fields/types/float/index.d.ts.map +1 -0
  196. package/dist/declarations/src/fields/types/float/views/index.d.ts +22 -0
  197. package/dist/declarations/src/fields/types/float/views/index.d.ts.map +1 -0
  198. package/dist/declarations/src/fields/types/image/index.d.ts +34 -0
  199. package/dist/declarations/src/fields/types/image/index.d.ts.map +1 -0
  200. package/dist/declarations/src/fields/types/image/utils.d.ts +2 -0
  201. package/dist/declarations/src/fields/types/image/utils.d.ts.map +1 -0
  202. package/dist/declarations/src/fields/types/image/views/Field.d.ts +4 -0
  203. package/dist/declarations/src/fields/types/image/views/Field.d.ts.map +1 -0
  204. package/dist/declarations/src/fields/types/image/views/index.d.ts +49 -0
  205. package/dist/declarations/src/fields/types/image/views/index.d.ts.map +1 -0
  206. package/dist/declarations/src/fields/types/integer/index.d.ts +20 -0
  207. package/dist/declarations/src/fields/types/integer/index.d.ts.map +1 -0
  208. package/dist/declarations/src/fields/types/integer/views/index.d.ts +23 -0
  209. package/dist/declarations/src/fields/types/integer/views/index.d.ts.map +1 -0
  210. package/dist/declarations/src/fields/types/json/index.d.ts +25 -0
  211. package/dist/declarations/src/fields/types/json/index.d.ts.map +1 -0
  212. package/dist/declarations/src/fields/types/json/views/index.d.ts +9 -0
  213. package/dist/declarations/src/fields/types/json/views/index.d.ts.map +1 -0
  214. package/dist/declarations/src/fields/types/multiselect/index.d.ts +50 -0
  215. package/dist/declarations/src/fields/types/multiselect/index.d.ts.map +1 -0
  216. package/dist/declarations/src/fields/types/multiselect/views/index.d.ts +26 -0
  217. package/dist/declarations/src/fields/types/multiselect/views/index.d.ts.map +1 -0
  218. package/dist/declarations/src/fields/types/password/index.d.ts +49 -0
  219. package/dist/declarations/src/fields/types/password/index.d.ts.map +1 -0
  220. package/dist/declarations/src/fields/types/password/views/index.d.ts +47 -0
  221. package/dist/declarations/src/fields/types/password/views/index.d.ts.map +1 -0
  222. package/dist/declarations/src/fields/types/relationship/index.d.ts +113 -0
  223. package/dist/declarations/src/fields/types/relationship/index.d.ts.map +1 -0
  224. package/dist/declarations/src/fields/types/relationship/views/ComboboxMany.d.ts +26 -0
  225. package/dist/declarations/src/fields/types/relationship/views/ComboboxMany.d.ts.map +1 -0
  226. package/dist/declarations/src/fields/types/relationship/views/ComboboxSingle.d.ts +24 -0
  227. package/dist/declarations/src/fields/types/relationship/views/ComboboxSingle.d.ts.map +1 -0
  228. package/dist/declarations/src/fields/types/relationship/views/index.d.ts +27 -0
  229. package/dist/declarations/src/fields/types/relationship/views/index.d.ts.map +1 -0
  230. package/dist/declarations/src/fields/types/relationship/views/types.d.ts +39 -0
  231. package/dist/declarations/src/fields/types/relationship/views/types.d.ts.map +1 -0
  232. package/dist/declarations/src/fields/types/select/index.d.ts +42 -0
  233. package/dist/declarations/src/fields/types/select/index.d.ts.map +1 -0
  234. package/dist/declarations/src/fields/types/select/views/index.d.ts +32 -0
  235. package/dist/declarations/src/fields/types/select/views/index.d.ts.map +1 -0
  236. package/dist/declarations/src/fields/types/text/index.d.ts +58 -0
  237. package/dist/declarations/src/fields/types/text/index.d.ts.map +1 -0
  238. package/dist/declarations/src/fields/types/text/views/index.d.ts +36 -0
  239. package/dist/declarations/src/fields/types/text/views/index.d.ts.map +1 -0
  240. package/dist/declarations/src/fields/types/timestamp/index.d.ts +19 -0
  241. package/dist/declarations/src/fields/types/timestamp/index.d.ts.map +1 -0
  242. package/dist/declarations/src/fields/types/timestamp/views/index.d.ts +14 -0
  243. package/dist/declarations/src/fields/types/timestamp/views/index.d.ts.map +1 -0
  244. package/dist/declarations/src/fields/types/timestamp/views/utils.d.ts +14 -0
  245. package/dist/declarations/src/fields/types/timestamp/views/utils.d.ts.map +1 -0
  246. package/dist/declarations/src/fields/types/virtual/index.d.ts +40 -0
  247. package/dist/declarations/src/fields/types/virtual/index.d.ts.map +1 -0
  248. package/dist/declarations/src/fields/types/virtual/views/index.d.ts +7 -0
  249. package/dist/declarations/src/fields/types/virtual/views/index.d.ts.map +1 -0
  250. package/dist/declarations/src/graphql-ts.d.ts +5 -0
  251. package/dist/declarations/src/graphql-ts.d.ts.map +1 -0
  252. package/dist/declarations/src/helpers.d.ts +121 -0
  253. package/dist/declarations/src/helpers.d.ts.map +1 -0
  254. package/dist/declarations/src/index.d.ts +6 -0
  255. package/dist/declarations/src/index.d.ts.map +1 -0
  256. package/dist/declarations/src/lib/admin-meta.d.ts +71 -0
  257. package/dist/declarations/src/lib/admin-meta.d.ts.map +1 -0
  258. package/dist/declarations/src/lib/core/access-control.d.ts +39 -0
  259. package/dist/declarations/src/lib/core/access-control.d.ts.map +1 -0
  260. package/dist/declarations/src/lib/core/initialise-lists.d.ts +131 -0
  261. package/dist/declarations/src/lib/core/initialise-lists.d.ts.map +1 -0
  262. package/dist/declarations/src/lib/core/resolve-relationships.d.ts +30 -0
  263. package/dist/declarations/src/lib/core/resolve-relationships.d.ts.map +1 -0
  264. package/dist/declarations/src/lib/core/where-inputs.d.ts +15 -0
  265. package/dist/declarations/src/lib/core/where-inputs.d.ts.map +1 -0
  266. package/dist/declarations/src/lib/express.d.ts +10 -0
  267. package/dist/declarations/src/lib/express.d.ts.map +1 -0
  268. package/dist/declarations/src/lib/migrations.d.ts +13 -0
  269. package/dist/declarations/src/lib/migrations.d.ts.map +1 -0
  270. package/dist/declarations/src/lib/system.d.ts +35 -0
  271. package/dist/declarations/src/lib/system.d.ts.map +1 -0
  272. package/dist/declarations/src/schema.d.ts +40 -0
  273. package/dist/declarations/src/schema.d.ts.map +1 -0
  274. package/dist/declarations/src/scripts/cli.d.ts +11 -0
  275. package/dist/declarations/src/scripts/cli.d.ts.map +1 -0
  276. package/dist/declarations/src/scripts/index.d.ts +2 -0
  277. package/dist/declarations/src/scripts/index.d.ts.map +1 -0
  278. package/dist/declarations/src/scripts/utils.d.ts +7 -0
  279. package/dist/declarations/src/scripts/utils.d.ts.map +1 -0
  280. package/dist/declarations/src/session.d.ts +86 -0
  281. package/dist/declarations/src/session.d.ts.map +1 -0
  282. package/dist/declarations/src/testing.d.ts +2 -0
  283. package/dist/declarations/src/testing.d.ts.map +1 -0
  284. package/dist/declarations/src/types/admin-meta.d.ts +190 -0
  285. package/dist/declarations/src/types/admin-meta.d.ts.map +1 -0
  286. package/dist/declarations/src/types/config/access-control.d.ts +108 -0
  287. package/dist/declarations/src/types/config/access-control.d.ts.map +1 -0
  288. package/dist/declarations/src/types/config/fields.d.ts +67 -0
  289. package/dist/declarations/src/types/config/fields.d.ts.map +1 -0
  290. package/dist/declarations/src/types/config/hooks.d.ts +441 -0
  291. package/dist/declarations/src/types/config/hooks.d.ts.map +1 -0
  292. package/dist/declarations/src/types/config/index.d.ts +283 -0
  293. package/dist/declarations/src/types/config/index.d.ts.map +1 -0
  294. package/dist/declarations/src/types/config/lists.d.ts +430 -0
  295. package/dist/declarations/src/types/config/lists.d.ts.map +1 -0
  296. package/dist/declarations/src/types/context.d.ts +458 -0
  297. package/dist/declarations/src/types/context.d.ts.map +1 -0
  298. package/dist/declarations/src/types/core.d.ts +9 -0
  299. package/dist/declarations/src/types/core.d.ts.map +1 -0
  300. package/dist/declarations/src/types/index.d.ts +9 -0
  301. package/dist/declarations/src/types/index.d.ts.map +1 -0
  302. package/dist/declarations/src/types/next-fields.d.ts +308 -0
  303. package/dist/declarations/src/types/next-fields.d.ts.map +1 -0
  304. package/dist/declarations/src/types/prisma.d.ts +13 -0
  305. package/dist/declarations/src/types/prisma.d.ts.map +1 -0
  306. package/dist/declarations/src/types/schema/g.d.ts +7 -0
  307. package/dist/declarations/src/types/schema/g.d.ts.map +1 -0
  308. package/dist/declarations/src/types/schema/gWithContext.d.ts +12 -0
  309. package/dist/declarations/src/types/schema/gWithContext.d.ts.map +1 -0
  310. package/dist/declarations/src/types/schema/index.d.ts +4 -0
  311. package/dist/declarations/src/types/schema/index.d.ts.map +1 -0
  312. package/dist/declarations/src/types/schema/legacy-alias.d.ts +28 -0
  313. package/dist/declarations/src/types/schema/scalars.d.ts +22 -0
  314. package/dist/declarations/src/types/schema/scalars.d.ts.map +1 -0
  315. package/dist/declarations/src/types/session.d.ts +28 -0
  316. package/dist/declarations/src/types/session.d.ts.map +1 -0
  317. package/dist/declarations/src/types/type-info.d.ts +35 -0
  318. package/dist/declarations/src/types/type-info.d.ts.map +1 -0
  319. package/dist/declarations/src/types/utils.d.ts +78 -0
  320. package/dist/declarations/src/types/utils.d.ts.map +1 -0
  321. package/dist/declarations/types/dist/nixxie-cms-core-types.cjs.d.ts +2 -0
  322. package/dist/express-6743b918.esm.js +476 -0
  323. package/dist/express-e9ed9a7d.cjs.js +495 -0
  324. package/dist/filters-8c8616f9.esm.js +89 -0
  325. package/dist/filters-b3e5eb50.cjs.js +96 -0
  326. package/dist/index-24b78415.esm.js +419 -0
  327. package/dist/index-ac01583b.cjs.js +425 -0
  328. package/dist/migrations-996e66a0.esm.js +76 -0
  329. package/dist/migrations-ab2e0fd4.cjs.js +78 -0
  330. package/dist/next-fields-49c025ef.cjs.js +251 -0
  331. package/dist/next-fields-9bf04ed8.esm.js +241 -0
  332. package/dist/nixxie-cms-core.cjs.d.ts +2 -0
  333. package/dist/nixxie-cms-core.cjs.js +522 -0
  334. package/dist/nixxie-cms-core.esm.js +504 -0
  335. package/dist/non-null-graphql-17b83ddc.cjs.js +72 -0
  336. package/dist/non-null-graphql-5315718c.esm.js +67 -0
  337. package/dist/pick-5fe45878.cjs.js +71 -0
  338. package/dist/pick-b7ef3115.esm.js +68 -0
  339. package/dist/resolve-hooks-17aafd37.esm.js +2026 -0
  340. package/dist/resolve-hooks-66fe8a8e.cjs.js +2043 -0
  341. package/dist/system-48c5f6df.cjs.js +4283 -0
  342. package/dist/system-dfec2f0a.esm.js +4273 -0
  343. package/dist/useCreateItem-1be4987e.cjs.js +160 -0
  344. package/dist/useCreateItem-1f94d252.esm.js +157 -0
  345. package/dist/useFilter-0b5a1ee6.esm.js +118 -0
  346. package/dist/useFilter-1a4e6900.cjs.js +120 -0
  347. package/dist/utils-0cc426c8.esm.js +19 -0
  348. package/dist/utils-1b632a8f.cjs.js +21 -0
  349. package/dist/utils-230cddb1.cjs.js +150 -0
  350. package/dist/utils-5e1d4d28.esm.js +138 -0
  351. package/dist/utils-b031e11c.cjs.js +49 -0
  352. package/dist/utils-e74e3527.cjs.js +87 -0
  353. package/dist/utils-ef2cd0f4.esm.js +80 -0
  354. package/dist/utils-f9556354.esm.js +41 -0
  355. package/fields/dist/nixxie-cms-core-fields.cjs.d.ts +2 -0
  356. package/fields/dist/nixxie-cms-core-fields.cjs.js +1808 -0
  357. package/fields/dist/nixxie-cms-core-fields.esm.js +1785 -0
  358. package/fields/package.json +4 -0
  359. package/fields/types/bigInt/views/dist/nixxie-cms-core-fields-types-bigInt-views.cjs.d.ts +2 -0
  360. package/fields/types/bigInt/views/dist/nixxie-cms-core-fields-types-bigInt-views.cjs.js +258 -0
  361. package/fields/types/bigInt/views/dist/nixxie-cms-core-fields-types-bigInt-views.esm.js +253 -0
  362. package/fields/types/bigInt/views/package.json +4 -0
  363. package/fields/types/bytes/dist/nixxie-cms-core-fields-types-bytes.cjs.d.ts +2 -0
  364. package/fields/types/bytes/dist/nixxie-cms-core-fields-types-bytes.cjs.js +221 -0
  365. package/fields/types/bytes/dist/nixxie-cms-core-fields-types-bytes.esm.js +216 -0
  366. package/fields/types/bytes/package.json +4 -0
  367. package/fields/types/bytes/views/dist/nixxie-cms-core-fields-types-bytes-views.cjs.d.ts +2 -0
  368. package/fields/types/bytes/views/dist/nixxie-cms-core-fields-types-bytes-views.cjs.js +239 -0
  369. package/fields/types/bytes/views/dist/nixxie-cms-core-fields-types-bytes-views.esm.js +234 -0
  370. package/fields/types/bytes/views/package.json +4 -0
  371. package/fields/types/calendarDay/views/dist/nixxie-cms-core-fields-types-calendarDay-views.cjs.d.ts +2 -0
  372. package/fields/types/calendarDay/views/dist/nixxie-cms-core-fields-types-calendarDay-views.cjs.js +147 -0
  373. package/fields/types/calendarDay/views/dist/nixxie-cms-core-fields-types-calendarDay-views.esm.js +141 -0
  374. package/fields/types/calendarDay/views/package.json +4 -0
  375. package/fields/types/checkbox/views/dist/nixxie-cms-core-fields-types-checkbox-views.cjs.d.ts +2 -0
  376. package/fields/types/checkbox/views/dist/nixxie-cms-core-fields-types-checkbox-views.cjs.js +126 -0
  377. package/fields/types/checkbox/views/dist/nixxie-cms-core-fields-types-checkbox-views.esm.js +120 -0
  378. package/fields/types/checkbox/views/package.json +4 -0
  379. package/fields/types/decimal/views/dist/nixxie-cms-core-fields-types-decimal-views.cjs.d.ts +2 -0
  380. package/fields/types/decimal/views/dist/nixxie-cms-core-fields-types-decimal-views.cjs.js +248 -0
  381. package/fields/types/decimal/views/dist/nixxie-cms-core-fields-types-decimal-views.esm.js +239 -0
  382. package/fields/types/decimal/views/package.json +4 -0
  383. package/fields/types/file/utils/package.json +4 -0
  384. package/fields/types/file/views/dist/nixxie-cms-core-fields-types-file-views.cjs.d.ts +2 -0
  385. package/fields/types/file/views/dist/nixxie-cms-core-fields-types-file-views.cjs.js +86 -0
  386. package/fields/types/file/views/dist/nixxie-cms-core-fields-types-file-views.esm.js +81 -0
  387. package/fields/types/file/views/package.json +4 -0
  388. package/fields/types/float/views/dist/nixxie-cms-core-fields-types-float-views.cjs.d.ts +2 -0
  389. package/fields/types/float/views/dist/nixxie-cms-core-fields-types-float-views.cjs.js +237 -0
  390. package/fields/types/float/views/dist/nixxie-cms-core-fields-types-float-views.esm.js +232 -0
  391. package/fields/types/float/views/package.json +4 -0
  392. package/fields/types/image/utils/dist/nixxie-cms-core-fields-types-image-utils.cjs.d.ts +2 -0
  393. package/fields/types/image/utils/dist/nixxie-cms-core-fields-types-image-utils.cjs.js +7 -0
  394. package/fields/types/image/utils/dist/nixxie-cms-core-fields-types-image-utils.esm.js +3 -0
  395. package/fields/types/image/utils/package.json +4 -0
  396. package/fields/types/image/views/dist/nixxie-cms-core-fields-types-image-views.cjs.d.ts +2 -0
  397. package/fields/types/image/views/dist/nixxie-cms-core-fields-types-image-views.cjs.js +361 -0
  398. package/fields/types/image/views/dist/nixxie-cms-core-fields-types-image-views.esm.js +354 -0
  399. package/fields/types/image/views/package.json +4 -0
  400. package/fields/types/integer/views/dist/nixxie-cms-core-fields-types-integer-views.cjs.d.ts +2 -0
  401. package/fields/types/integer/views/dist/nixxie-cms-core-fields-types-integer-views.cjs.js +254 -0
  402. package/fields/types/integer/views/dist/nixxie-cms-core-fields-types-integer-views.esm.js +249 -0
  403. package/fields/types/integer/views/package.json +4 -0
  404. package/fields/types/json/views/dist/nixxie-cms-core-fields-types-json-views.cjs.d.ts +2 -0
  405. package/fields/types/json/views/dist/nixxie-cms-core-fields-types-json-views.cjs.js +83 -0
  406. package/fields/types/json/views/dist/nixxie-cms-core-fields-types-json-views.esm.js +77 -0
  407. package/fields/types/json/views/package.json +4 -0
  408. package/fields/types/multiselect/views/dist/nixxie-cms-core-fields-types-multiselect-views.cjs.d.ts +2 -0
  409. package/fields/types/multiselect/views/dist/nixxie-cms-core-fields-types-multiselect-views.cjs.js +147 -0
  410. package/fields/types/multiselect/views/dist/nixxie-cms-core-fields-types-multiselect-views.esm.js +141 -0
  411. package/fields/types/multiselect/views/package.json +4 -0
  412. package/fields/types/password/dist/nixxie-cms-core-fields-types-password.cjs.d.ts +2 -0
  413. package/fields/types/password/dist/nixxie-cms-core-fields-types-password.cjs.js +206 -0
  414. package/fields/types/password/dist/nixxie-cms-core-fields-types-password.esm.js +196 -0
  415. package/fields/types/password/package.json +4 -0
  416. package/fields/types/password/views/dist/nixxie-cms-core-fields-types-password-views.cjs.d.ts +2 -0
  417. package/fields/types/password/views/dist/nixxie-cms-core-fields-types-password-views.cjs.js +330 -0
  418. package/fields/types/password/views/dist/nixxie-cms-core-fields-types-password-views.esm.js +320 -0
  419. package/fields/types/password/views/package.json +4 -0
  420. package/fields/types/relationship/views/RelationshipSelect/package.json +4 -0
  421. package/fields/types/relationship/views/dist/nixxie-cms-core-fields-types-relationship-views.cjs.d.ts +2 -0
  422. package/fields/types/relationship/views/dist/nixxie-cms-core-fields-types-relationship-views.cjs.js +1213 -0
  423. package/fields/types/relationship/views/dist/nixxie-cms-core-fields-types-relationship-views.esm.js +1201 -0
  424. package/fields/types/relationship/views/package.json +4 -0
  425. package/fields/types/select/views/dist/nixxie-cms-core-fields-types-select-views.cjs.d.ts +2 -0
  426. package/fields/types/select/views/dist/nixxie-cms-core-fields-types-select-views.cjs.js +422 -0
  427. package/fields/types/select/views/dist/nixxie-cms-core-fields-types-select-views.esm.js +416 -0
  428. package/fields/types/select/views/package.json +4 -0
  429. package/fields/types/text/views/dist/nixxie-cms-core-fields-types-text-views.cjs.d.ts +2 -0
  430. package/fields/types/text/views/dist/nixxie-cms-core-fields-types-text-views.cjs.js +316 -0
  431. package/fields/types/text/views/dist/nixxie-cms-core-fields-types-text-views.esm.js +311 -0
  432. package/fields/types/text/views/package.json +4 -0
  433. package/fields/types/timestamp/views/dist/nixxie-cms-core-fields-types-timestamp-views.cjs.d.ts +2 -0
  434. package/fields/types/timestamp/views/dist/nixxie-cms-core-fields-types-timestamp-views.cjs.js +285 -0
  435. package/fields/types/timestamp/views/dist/nixxie-cms-core-fields-types-timestamp-views.esm.js +279 -0
  436. package/fields/types/timestamp/views/package.json +4 -0
  437. package/fields/types/virtual/views/dist/nixxie-cms-core-fields-types-virtual-views.cjs.d.ts +2 -0
  438. package/fields/types/virtual/views/dist/nixxie-cms-core-fields-types-virtual-views.cjs.js +54 -0
  439. package/fields/types/virtual/views/dist/nixxie-cms-core-fields-types-virtual-views.esm.js +48 -0
  440. package/fields/types/virtual/views/package.json +4 -0
  441. package/graphql-ts/dist/nixxie-cms-core-graphql-ts.cjs.d.ts +2 -0
  442. package/graphql-ts/dist/nixxie-cms-core-graphql-ts.cjs.js +45 -0
  443. package/graphql-ts/dist/nixxie-cms-core-graphql-ts.esm.js +2 -0
  444. package/graphql-ts/package.json +4 -0
  445. package/package.json +339 -0
  446. package/schema/package.json +4 -0
  447. package/scripts/cli/dist/nixxie-cms-core-scripts-cli.cjs.d.ts +2 -0
  448. package/scripts/cli/dist/nixxie-cms-core-scripts-cli.cjs.js +1607 -0
  449. package/scripts/cli/dist/nixxie-cms-core-scripts-cli.esm.js +1586 -0
  450. package/scripts/cli/package.json +4 -0
  451. package/scripts/dist/nixxie-cms-core-scripts.cjs.d.ts +2 -0
  452. package/scripts/dist/nixxie-cms-core-scripts.cjs.js +73 -0
  453. package/scripts/dist/nixxie-cms-core-scripts.esm.js +71 -0
  454. package/scripts/package.json +4 -0
  455. package/session/dist/nixxie-cms-core-session.cjs.d.ts +2 -0
  456. package/session/dist/nixxie-cms-core-session.cjs.js +157 -0
  457. package/session/dist/nixxie-cms-core-session.esm.js +129 -0
  458. package/session/package.json +4 -0
  459. package/src/___internal-do-not-use-will-break-in-patch/admin-ui/id-field-view.tsx +167 -0
  460. package/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/App/index.tsx +22 -0
  461. package/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/CreateItemPage/index.tsx +71 -0
  462. package/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/HomePage/index.tsx +333 -0
  463. package/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ItemPage/common.tsx +358 -0
  464. package/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ItemPage/index.tsx +483 -0
  465. package/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ListPage/FilterAdd.tsx +221 -0
  466. package/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ListPage/PaginationControls.tsx +170 -0
  467. package/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ListPage/Tag.tsx +72 -0
  468. package/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ListPage/index.tsx +1006 -0
  469. package/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/NoAccessPage/index.tsx +24 -0
  470. package/src/___internal-do-not-use-will-break-in-patch/artifacts.ts +5 -0
  471. package/src/access.ts +25 -0
  472. package/src/admin-ui/admin-meta-graphql.ts +168 -0
  473. package/src/admin-ui/apollo.tsx +35 -0
  474. package/src/admin-ui/components/CellContainer.tsx +6 -0
  475. package/src/admin-ui/components/CommandPalette.tsx +431 -0
  476. package/src/admin-ui/components/Container.tsx +14 -0
  477. package/src/admin-ui/components/CreateButtonLink.tsx +46 -0
  478. package/src/admin-ui/components/CreateItemDialog.tsx +56 -0
  479. package/src/admin-ui/components/EmptyState.tsx +52 -0
  480. package/src/admin-ui/components/Errors.tsx +130 -0
  481. package/src/admin-ui/components/GraphQLErrorNotice.tsx +78 -0
  482. package/src/admin-ui/components/InlineCode.tsx +17 -0
  483. package/src/admin-ui/components/Logo.tsx +70 -0
  484. package/src/admin-ui/components/Navigation.tsx +385 -0
  485. package/src/admin-ui/components/NullableFieldWrapper.tsx +72 -0
  486. package/src/admin-ui/components/PageContainer.tsx +310 -0
  487. package/src/admin-ui/components/WelcomeDialog.tsx +119 -0
  488. package/src/admin-ui/components/index.ts +23 -0
  489. package/src/admin-ui/context.tsx +338 -0
  490. package/src/admin-ui/image.tsx +2 -0
  491. package/src/admin-ui/index.tsx +1 -0
  492. package/src/admin-ui/router.tsx +24 -0
  493. package/src/admin-ui/system/generateAdminUI.ts +155 -0
  494. package/src/admin-ui/system/index.ts +1 -0
  495. package/src/admin-ui/templates/app.ts +60 -0
  496. package/src/admin-ui/templates/create-item.ts +5 -0
  497. package/src/admin-ui/templates/home.ts +2 -0
  498. package/src/admin-ui/templates/index.ts +53 -0
  499. package/src/admin-ui/templates/item.tsx +5 -0
  500. package/src/admin-ui/templates/list.tsx +5 -0
  501. package/src/admin-ui/templates/next-config.ts +16 -0
  502. package/src/admin-ui/templates/no-access.ts +7 -0
  503. package/src/admin-ui/utils/Fields.tsx +241 -0
  504. package/src/admin-ui/utils/actionData.ts +36 -0
  505. package/src/admin-ui/utils/filters.ts +148 -0
  506. package/src/admin-ui/utils/index.ts +10 -0
  507. package/src/admin-ui/utils/pick.ts +12 -0
  508. package/src/admin-ui/utils/useCreateItem.ts +171 -0
  509. package/src/admin-ui/utils/usePreventNavigation.tsx +31 -0
  510. package/src/admin-ui/utils/utils.tsx +127 -0
  511. package/src/artifacts.ts +110 -0
  512. package/src/context.ts +1 -0
  513. package/src/fields/filters/enum-filter.ts +77 -0
  514. package/src/fields/filters/index.ts +1 -0
  515. package/src/fields/filters/internal.ts +89 -0
  516. package/src/fields/filters/providers/mysql.ts +450 -0
  517. package/src/fields/filters/providers/postgresql.ts +448 -0
  518. package/src/fields/filters/providers/sqlite.ts +442 -0
  519. package/src/fields/index.ts +34 -0
  520. package/src/fields/non-null-graphql.ts +115 -0
  521. package/src/fields/resolve-hooks.ts +61 -0
  522. package/src/fields/types/bigInt/index.ts +181 -0
  523. package/src/fields/types/bigInt/views/index.tsx +254 -0
  524. package/src/fields/types/bytes/index.ts +275 -0
  525. package/src/fields/types/bytes/views/index.tsx +190 -0
  526. package/src/fields/types/calendarDay/index.ts +194 -0
  527. package/src/fields/types/calendarDay/views/index.tsx +144 -0
  528. package/src/fields/types/checkbox/index.ts +76 -0
  529. package/src/fields/types/checkbox/views/index.tsx +97 -0
  530. package/src/fields/types/decimal/index.ts +182 -0
  531. package/src/fields/types/decimal/views/index.tsx +215 -0
  532. package/src/fields/types/file/index.ts +168 -0
  533. package/src/fields/types/file/views/Field.tsx +300 -0
  534. package/src/fields/types/file/views/index.tsx +74 -0
  535. package/src/fields/types/float/index.ts +133 -0
  536. package/src/fields/types/float/views/index.tsx +215 -0
  537. package/src/fields/types/image/index.ts +244 -0
  538. package/src/fields/types/image/internal-utils.ts +58 -0
  539. package/src/fields/types/image/utils.ts +1 -0
  540. package/src/fields/types/image/views/Field.tsx +295 -0
  541. package/src/fields/types/image/views/index.tsx +92 -0
  542. package/src/fields/types/integer/index.ts +156 -0
  543. package/src/fields/types/integer/views/index.tsx +255 -0
  544. package/src/fields/types/json/index.ts +77 -0
  545. package/src/fields/types/json/views/index.tsx +76 -0
  546. package/src/fields/types/multiselect/index.ts +212 -0
  547. package/src/fields/types/multiselect/views/index.tsx +151 -0
  548. package/src/fields/types/password/index.ts +241 -0
  549. package/src/fields/types/password/views/index.tsx +342 -0
  550. package/src/fields/types/relationship/index.ts +381 -0
  551. package/src/fields/types/relationship/views/ComboboxMany.tsx +110 -0
  552. package/src/fields/types/relationship/views/ComboboxSingle.tsx +115 -0
  553. package/src/fields/types/relationship/views/ContextualActions.tsx +139 -0
  554. package/src/fields/types/relationship/views/RelationshipTable.tsx +190 -0
  555. package/src/fields/types/relationship/views/index.tsx +492 -0
  556. package/src/fields/types/relationship/views/types.ts +46 -0
  557. package/src/fields/types/relationship/views/useApolloQuery.ts +185 -0
  558. package/src/fields/types/relationship/views/useFilter.tsx +109 -0
  559. package/src/fields/types/select/index.ts +226 -0
  560. package/src/fields/types/select/views/SegmentedControl.tsx +83 -0
  561. package/src/fields/types/select/views/index.tsx +318 -0
  562. package/src/fields/types/text/index.ts +207 -0
  563. package/src/fields/types/text/views/index.tsx +273 -0
  564. package/src/fields/types/timestamp/index.ts +116 -0
  565. package/src/fields/types/timestamp/views/__tests__/index.tsx +68 -0
  566. package/src/fields/types/timestamp/views/__tests__/utils.tsx +16 -0
  567. package/src/fields/types/timestamp/views/index.tsx +262 -0
  568. package/src/fields/types/timestamp/views/utils.ts +22 -0
  569. package/src/fields/types/virtual/index.ts +108 -0
  570. package/src/fields/types/virtual/views/index.tsx +53 -0
  571. package/src/graphql-ts.ts +32 -0
  572. package/src/helpers.ts +316 -0
  573. package/src/index.ts +20 -0
  574. package/src/lib/admin-meta-graphql.ts +407 -0
  575. package/src/lib/admin-meta.ts +369 -0
  576. package/src/lib/coerceAndValidateForGraphQLInput.ts +29 -0
  577. package/src/lib/context/api.ts +99 -0
  578. package/src/lib/context/createContext.ts +161 -0
  579. package/src/lib/context/graphql.ts +300 -0
  580. package/src/lib/core/access-control.ts +434 -0
  581. package/src/lib/core/field-assertions.ts +118 -0
  582. package/src/lib/core/filter-order-access.ts +48 -0
  583. package/src/lib/core/graphql-errors.ts +76 -0
  584. package/src/lib/core/hooks.ts +111 -0
  585. package/src/lib/core/initialise-lists.ts +1097 -0
  586. package/src/lib/core/mutations/index.ts +917 -0
  587. package/src/lib/core/mutations/nested-mutation-many-input-resolvers.ts +145 -0
  588. package/src/lib/core/mutations/nested-mutation-one-input-resolvers.ts +71 -0
  589. package/src/lib/core/prisma-schema-printer.ts +256 -0
  590. package/src/lib/core/queries/index.ts +66 -0
  591. package/src/lib/core/queries/output-field.ts +178 -0
  592. package/src/lib/core/queries/resolvers.ts +258 -0
  593. package/src/lib/core/resolve-relationships.ts +303 -0
  594. package/src/lib/core/utils.ts +56 -0
  595. package/src/lib/core/where-inputs.ts +130 -0
  596. package/src/lib/express.ts +109 -0
  597. package/src/lib/graphql.ts +83 -0
  598. package/src/lib/id-field.ts +214 -0
  599. package/src/lib/middleware.ts +68 -0
  600. package/src/lib/migrations.ts +90 -0
  601. package/src/lib/otel.ts +43 -0
  602. package/src/lib/prompts.ts +29 -0
  603. package/src/lib/system.ts +207 -0
  604. package/src/lib/telemetry.ts +342 -0
  605. package/src/lib/typescript-schema-printer.ts +227 -0
  606. package/src/lib/utils.ts +21 -0
  607. package/src/pkg-dir.ts +6 -0
  608. package/src/schema.ts +233 -0
  609. package/src/scripts/build.ts +64 -0
  610. package/src/scripts/cli.ts +124 -0
  611. package/src/scripts/dev.ts +452 -0
  612. package/src/scripts/esbuild.ts +120 -0
  613. package/src/scripts/index.ts +20 -0
  614. package/src/scripts/migrate.ts +214 -0
  615. package/src/scripts/prisma.ts +49 -0
  616. package/src/scripts/start.ts +76 -0
  617. package/src/scripts/telemetry.ts +37 -0
  618. package/src/scripts/utils.ts +22 -0
  619. package/src/session.ts +168 -0
  620. package/src/testing.ts +23 -0
  621. package/src/types/admin-meta.ts +218 -0
  622. package/src/types/config/access-control.ts +186 -0
  623. package/src/types/config/fields.ts +96 -0
  624. package/src/types/config/hooks.ts +529 -0
  625. package/src/types/config/index.ts +333 -0
  626. package/src/types/config/lists.ts +565 -0
  627. package/src/types/context.ts +530 -0
  628. package/src/types/core.ts +16 -0
  629. package/src/types/index.ts +8 -0
  630. package/src/types/next-fields.ts +499 -0
  631. package/src/types/prisma.ts +16 -0
  632. package/src/types/schema/g.ts +5 -0
  633. package/src/types/schema/gWithContext.ts +20 -0
  634. package/src/types/schema/index.ts +4 -0
  635. package/src/types/schema/legacy-alias.d.ts +28 -0
  636. package/src/types/schema/legacy-alias.js +1 -0
  637. package/src/types/schema/scalars.ts +220 -0
  638. package/src/types/session.ts +26 -0
  639. package/src/types/telemetry.ts +51 -0
  640. package/src/types/type-info.ts +38 -0
  641. package/src/types/type-tests.ts +21 -0
  642. package/src/types/utils.ts +108 -0
  643. package/static/admin-error.html +53 -0
  644. package/static/dev-loading.html +146 -0
  645. package/static/favicon.ico +0 -0
  646. package/static/favicon.svg +4 -0
  647. package/system/package.json +4 -0
  648. package/testing/dist/nixxie-cms-core-testing.cjs.d.ts +2 -0
  649. package/testing/dist/nixxie-cms-core-testing.cjs.js +29 -0
  650. package/testing/dist/nixxie-cms-core-testing.esm.js +21 -0
  651. package/testing/package.json +4 -0
  652. package/tests/conditional-filters.test.ts +326 -0
  653. package/tests/telemetry.test.ts +361 -0
  654. package/tsconfig.json +20 -0
  655. package/types/dist/nixxie-cms-core-types.cjs.d.ts +2 -0
  656. package/types/dist/nixxie-cms-core-types.cjs.js +29 -0
  657. package/types/dist/nixxie-cms-core-types.esm.js +9 -0
  658. package/types/package.json +4 -0
@@ -0,0 +1,4283 @@
1
+ 'use strict';
2
+
3
+ var node_crypto = require('node:crypto');
4
+ var path = require('node:path');
5
+ var adminMeta$1 = require('./admin-meta-18d0c276.cjs.js');
6
+ var graphql = require('graphql');
7
+ var schema = require('@graphql-ts/schema');
8
+ var resolveHooks = require('./resolve-hooks-66fe8a8e.cjs.js');
9
+ var utils$1 = require('./utils-e74e3527.cjs.js');
10
+ var nextFields = require('./next-fields-49c025ef.cjs.js');
11
+ require('@graphql-ts/extend');
12
+ var utils$2 = require('./utils-1b632a8f.cjs.js');
13
+ var access_dist_nixxieCmsCoreAccess = require('../access/dist/nixxie-cms-core-access.cjs.js');
14
+ var values = require('graphql/execution/values');
15
+ var utils = require('./utils-b031e11c.cjs.js');
16
+ require('pluralize');
17
+ var cacheControlTypes = require('@apollo/cache-control-types');
18
+ var DataLoader = require('dataloader');
19
+ var _classPrivateFieldInitSpec = require('@babel/runtime/helpers/classPrivateFieldInitSpec');
20
+ var _classPrivateFieldGet = require('@babel/runtime/helpers/classPrivateFieldGet2');
21
+ var _classPrivateFieldSet = require('@babel/runtime/helpers/classPrivateFieldSet2');
22
+ var api = require('@opentelemetry/api');
23
+
24
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
25
+
26
+ var path__default = /*#__PURE__*/_interopDefault(path);
27
+ var DataLoader__default = /*#__PURE__*/_interopDefault(DataLoader);
28
+
29
+ function getNamedOrListTypeNodeForType(type) {
30
+ if (type instanceof graphql.GraphQLList) {
31
+ return {
32
+ kind: graphql.Kind.LIST_TYPE,
33
+ type: getTypeNodeForType(type.ofType)
34
+ };
35
+ }
36
+ return {
37
+ kind: graphql.Kind.NAMED_TYPE,
38
+ name: {
39
+ kind: graphql.Kind.NAME,
40
+ value: type.name
41
+ }
42
+ };
43
+ }
44
+ function getTypeNodeForType(type) {
45
+ if (type instanceof graphql.GraphQLNonNull) {
46
+ return {
47
+ kind: graphql.Kind.NON_NULL_TYPE,
48
+ type: getNamedOrListTypeNodeForType(type.ofType)
49
+ };
50
+ }
51
+ return getNamedOrListTypeNodeForType(type);
52
+ }
53
+ function getVariablesForGraphQLField(field) {
54
+ const variableDefinitions = field.args.map(arg => {
55
+ var _ref;
56
+ return {
57
+ kind: graphql.Kind.VARIABLE_DEFINITION,
58
+ type: getTypeNodeForType(arg.type),
59
+ variable: {
60
+ kind: graphql.Kind.VARIABLE,
61
+ name: {
62
+ kind: graphql.Kind.NAME,
63
+ value: arg.name
64
+ }
65
+ },
66
+ defaultValue: arg.defaultValue === undefined ? undefined : (_ref = graphql.astFromValue(arg.defaultValue, arg.type)) !== null && _ref !== void 0 ? _ref : undefined
67
+ };
68
+ });
69
+ const argumentNodes = field.args.map(arg => ({
70
+ kind: graphql.Kind.ARGUMENT,
71
+ name: {
72
+ kind: graphql.Kind.NAME,
73
+ value: arg.name
74
+ },
75
+ value: {
76
+ kind: graphql.Kind.VARIABLE,
77
+ name: {
78
+ kind: graphql.Kind.NAME,
79
+ value: arg.name
80
+ }
81
+ }
82
+ }));
83
+ return {
84
+ variableDefinitions,
85
+ argumentNodes
86
+ };
87
+ }
88
+ function getRootTypeName(type) {
89
+ if (type instanceof graphql.GraphQLNonNull) {
90
+ return getRootTypeName(type.ofType);
91
+ }
92
+ if (type instanceof graphql.GraphQLList) {
93
+ return getRootTypeName(type.ofType);
94
+ }
95
+ return type.name;
96
+ }
97
+ const rawField = 'raw';
98
+ const RawScalar = new graphql.GraphQLScalarType({
99
+ name: 'RawThingPlsDontRelyOnThisAnywhere'
100
+ });
101
+ const ReturnRawValueObjectType = new graphql.GraphQLObjectType({
102
+ name: 'ReturnRawValue',
103
+ fields: {
104
+ [rawField]: {
105
+ type: RawScalar,
106
+ resolve(source) {
107
+ return source;
108
+ }
109
+ }
110
+ }
111
+ });
112
+ function argsToArgsConfig(args) {
113
+ return Object.fromEntries(args.map(arg => {
114
+ const argConfig = {
115
+ astNode: arg.astNode,
116
+ defaultValue: arg.defaultValue,
117
+ deprecationReason: arg.deprecationReason,
118
+ description: arg.description,
119
+ extensions: arg.extensions,
120
+ type: arg.type
121
+ };
122
+ return [arg.name, argConfig];
123
+ }));
124
+ }
125
+ // note the GraphQLNonNull and GraphQLList constructors are incorrectly
126
+ // not generic over their inner type which is why we have to use as
127
+ // (the classes are generic but not the constructors)
128
+ function getTypeForField(originalType) {
129
+ if (originalType instanceof graphql.GraphQLNonNull) {
130
+ return new graphql.GraphQLNonNull(getTypeForField(originalType.ofType));
131
+ }
132
+ if (originalType instanceof graphql.GraphQLList) {
133
+ return new graphql.GraphQLList(getTypeForField(originalType.ofType));
134
+ }
135
+ return ReturnRawValueObjectType;
136
+ }
137
+ function getSourceGivenOutputType(originalType, value) {
138
+ if (originalType instanceof graphql.GraphQLNonNull) {
139
+ return getSourceGivenOutputType(originalType.ofType, value);
140
+ }
141
+ if (value === null) return null;
142
+ if (originalType instanceof graphql.GraphQLList) {
143
+ return value.map(x => getSourceGivenOutputType(originalType.ofType, x));
144
+ }
145
+ return value[rawField];
146
+ }
147
+ function makeContextDbFn(field) {
148
+ const {
149
+ argumentNodes,
150
+ variableDefinitions
151
+ } = getVariablesForGraphQLField(field);
152
+ const document = {
153
+ kind: graphql.Kind.DOCUMENT,
154
+ definitions: [{
155
+ kind: graphql.Kind.OPERATION_DEFINITION,
156
+ operation: graphql.OperationTypeNode.QUERY,
157
+ selectionSet: {
158
+ kind: graphql.Kind.SELECTION_SET,
159
+ selections: [{
160
+ kind: graphql.Kind.FIELD,
161
+ name: {
162
+ kind: graphql.Kind.NAME,
163
+ value: field.name
164
+ },
165
+ arguments: argumentNodes,
166
+ selectionSet: {
167
+ kind: graphql.Kind.SELECTION_SET,
168
+ selections: [{
169
+ kind: graphql.Kind.FIELD,
170
+ name: {
171
+ kind: graphql.Kind.NAME,
172
+ value: rawField
173
+ }
174
+ }]
175
+ }
176
+ }]
177
+ },
178
+ variableDefinitions
179
+ }]
180
+ };
181
+ const type = getTypeForField(field.type);
182
+ const fieldConfig = {
183
+ args: argsToArgsConfig(field.args),
184
+ astNode: undefined,
185
+ deprecationReason: field.deprecationReason,
186
+ description: field.description,
187
+ extensions: field.extensions,
188
+ resolve: field.resolve,
189
+ subscribe: field.subscribe,
190
+ type
191
+ };
192
+
193
+ // we construct a schema as we need return a different type than the one in the base GraphQL schema
194
+ const schema = new graphql.GraphQLSchema({
195
+ query: new graphql.GraphQLObjectType({
196
+ name: 'Query',
197
+ fields: {
198
+ [field.name]: fieldConfig
199
+ }
200
+ }),
201
+ assumeValid: true
202
+ });
203
+ return async (args, context, rootValue = {}) => {
204
+ var _result$errors;
205
+ const result = await graphql.execute({
206
+ schema,
207
+ document,
208
+ contextValue: context,
209
+ variableValues: args,
210
+ rootValue
211
+ });
212
+ if ((_result$errors = result.errors) !== null && _result$errors !== void 0 && _result$errors.length) {
213
+ throw result.errors[0];
214
+ }
215
+ return getSourceGivenOutputType(type, result.data[field.name]);
216
+ };
217
+ }
218
+ function makeContextQueryFn(schema, operation, field) {
219
+ const {
220
+ argumentNodes,
221
+ variableDefinitions
222
+ } = getVariablesForGraphQLField(field);
223
+ const rootName = getRootTypeName(field.type);
224
+ const exec = async (args, query, context) => {
225
+ var _result$errors2;
226
+ const selectionSet = graphql.parse(`fragment x on ${rootName} {${query}}`).definitions[0].selectionSet;
227
+ const document = {
228
+ kind: graphql.Kind.DOCUMENT,
229
+ definitions: [{
230
+ kind: graphql.Kind.OPERATION_DEFINITION,
231
+ // OperationTypeNode is an ts enum where the values are 'query' | 'mutation' | 'subscription'
232
+ operation: operation,
233
+ selectionSet: {
234
+ kind: graphql.Kind.SELECTION_SET,
235
+ selections: [{
236
+ kind: graphql.Kind.FIELD,
237
+ name: {
238
+ kind: graphql.Kind.NAME,
239
+ value: field.name
240
+ },
241
+ arguments: argumentNodes,
242
+ selectionSet: selectionSet
243
+ }]
244
+ },
245
+ variableDefinitions
246
+ }]
247
+ };
248
+ const validationErrors = graphql.validate(schema, document);
249
+ if (validationErrors.length > 0) {
250
+ throw validationErrors[0];
251
+ }
252
+ const result = await graphql.execute({
253
+ schema,
254
+ document,
255
+ contextValue: context,
256
+ variableValues: Object.fromEntries(
257
+ // GraphQL for some reason decides to make undefined values in args
258
+ // skip defaulting for some reason
259
+ // this ofc doesn't technically fully fix it (bc nested things)
260
+ // but for the cases where we care, it does
261
+ Object.entries(args).filter(([, val]) => val !== undefined)),
262
+ rootValue: {}
263
+ });
264
+ if ((_result$errors2 = result.errors) !== null && _result$errors2 !== void 0 && _result$errors2.length) {
265
+ throw result.errors[0];
266
+ }
267
+ return result.data[field.name];
268
+ };
269
+ return (_args = {}, context) => {
270
+ const {
271
+ query,
272
+ ...args
273
+ } = _args;
274
+ return exec(args, query !== null && query !== void 0 ? query : 'id', context);
275
+ };
276
+ }
277
+
278
+ function getQueryFactory(list, schema) {
279
+ const queryType = schema.getQueryType();
280
+ const mutationType = schema.getMutationType();
281
+ function f(operation, fieldName) {
282
+ const rootType = operation === 'query' ? queryType : mutationType;
283
+ const field = rootType.getFields()[fieldName];
284
+ if (field) return makeContextQueryFn(schema, operation, field);
285
+
286
+ // if omitted
287
+ return () => {
288
+ throw new Error(`This ${operation} is not supported by the GraphQL schema: ${fieldName}()`);
289
+ };
290
+ }
291
+ const {
292
+ listQueryCountName,
293
+ whereInputName
294
+ } = list.graphql.names;
295
+ const fcache = {
296
+ findOne: f('query', list.graphql.names.itemQueryName),
297
+ findMany: f('query', list.graphql.names.listQueryName),
298
+ count: async (args = {}, context) => {
299
+ const {
300
+ where = {}
301
+ } = args;
302
+ const {
303
+ count
304
+ } = await context.graphql.run({
305
+ query: `query ($where: ${whereInputName}!) { count: ${listQueryCountName}(where: $where) }`,
306
+ variables: {
307
+ where
308
+ }
309
+ });
310
+ return count;
311
+ },
312
+ createOne: f('mutation', list.graphql.names.createMutationName),
313
+ createMany: f('mutation', list.graphql.names.createManyMutationName),
314
+ updateOne: f('mutation', list.graphql.names.updateMutationName),
315
+ updateMany: f('mutation', list.graphql.names.updateManyMutationName),
316
+ deleteOne: f('mutation', list.graphql.names.deleteMutationName),
317
+ deleteMany: f('mutation', list.graphql.names.deleteManyMutationName)
318
+ };
319
+ return context => {
320
+ return {
321
+ findOne: args => fcache.findOne(args, context),
322
+ findMany: args => fcache.findMany(args, context),
323
+ count: args => fcache.count(args, context),
324
+ createOne: args => fcache.createOne(args, context),
325
+ createMany: args => fcache.createMany(args, context),
326
+ updateOne: args => fcache.updateOne(args, context),
327
+ updateMany: args => fcache.updateMany(args, context),
328
+ deleteOne: args => fcache.deleteOne(args, context),
329
+ deleteMany: args => fcache.deleteMany(args, context)
330
+ };
331
+ };
332
+ }
333
+ function getDbFactory(list, schema) {
334
+ const queryType = schema.getQueryType();
335
+ const mutationType = schema.getMutationType();
336
+ function f(operation, fieldName) {
337
+ const rootType = operation === 'query' ? queryType : mutationType;
338
+ const field = rootType.getFields()[fieldName];
339
+ if (field) return makeContextDbFn(field);
340
+
341
+ // if omitted
342
+ return () => {
343
+ throw new Error(`This ${operation} is not supported by the GraphQL schema: ${fieldName}()`);
344
+ };
345
+ }
346
+ const fcache = {
347
+ findOne: f('query', list.graphql.names.itemQueryName),
348
+ findMany: f('query', list.graphql.names.listQueryName),
349
+ count: f('query', list.graphql.names.listQueryCountName),
350
+ createOne: f('mutation', list.graphql.names.createMutationName),
351
+ createMany: f('mutation', list.graphql.names.createManyMutationName),
352
+ updateOne: f('mutation', list.graphql.names.updateMutationName),
353
+ updateMany: f('mutation', list.graphql.names.updateManyMutationName),
354
+ deleteOne: f('mutation', list.graphql.names.deleteMutationName),
355
+ deleteMany: f('mutation', list.graphql.names.deleteManyMutationName)
356
+ };
357
+ return context => {
358
+ return {
359
+ findOne: args => fcache.findOne(args, context),
360
+ findMany: args => fcache.findMany(args, context),
361
+ count: args => fcache.count(args, context),
362
+ createOne: args => fcache.createOne(args, context),
363
+ createMany: args => fcache.createMany(args, context),
364
+ updateOne: args => fcache.updateOne(args, context),
365
+ updateMany: args => fcache.updateMany(args, context),
366
+ deleteOne: args => fcache.deleteOne(args, context),
367
+ deleteMany: args => fcache.deleteMany(args, context)
368
+ };
369
+ };
370
+ }
371
+
372
+ function createContext({
373
+ config,
374
+ lists,
375
+ graphQLSchemas,
376
+ prismaClient,
377
+ prismaTypes
378
+ }) {
379
+ const dbFactories = {};
380
+ for (const [listKey, list] of Object.entries(lists)) {
381
+ dbFactories[listKey] = getDbFactory(list, graphQLSchemas.public);
382
+ }
383
+ const dbFactoriesInternal = {};
384
+ for (const [listKey, list] of Object.entries(lists)) {
385
+ dbFactoriesInternal[listKey] = getDbFactory(list, graphQLSchemas.internal);
386
+ }
387
+ const queryFactories = {};
388
+ for (const [listKey, list] of Object.entries(lists)) {
389
+ queryFactories[listKey] = getQueryFactory(list, graphQLSchemas.public);
390
+ }
391
+ const queryFactoriesInternal = {};
392
+ for (const [listKey, list] of Object.entries(lists)) {
393
+ queryFactoriesInternal[listKey] = getQueryFactory(list, graphQLSchemas.internal);
394
+ }
395
+ const construct = ({
396
+ prisma,
397
+ req,
398
+ res,
399
+ session,
400
+ internal,
401
+ sudo
402
+ }) => {
403
+ var _config$email, _config$jobs, _config$cache, _config$audit, _config$webhooks, _config$rateLimit, _config$health;
404
+ const schema = internal ? graphQLSchemas.internal : graphQLSchemas.public;
405
+ const rawGraphQL = async ({
406
+ query,
407
+ variables
408
+ }) => {
409
+ const source = typeof query === 'string' ? query : graphql.print(query);
410
+ return await graphql.graphql({
411
+ schema,
412
+ source,
413
+ contextValue: context,
414
+ variableValues: variables
415
+ });
416
+ };
417
+ const runGraphQL = async ({
418
+ query,
419
+ variables
420
+ }) => {
421
+ var _result$errors;
422
+ const result = await rawGraphQL({
423
+ query,
424
+ variables
425
+ });
426
+ if ((_result$errors = result.errors) !== null && _result$errors !== void 0 && _result$errors.length) throw result.errors[0];
427
+ return result.data;
428
+ };
429
+ const context = {
430
+ prisma,
431
+ db: {},
432
+ query: {},
433
+ graphql: {
434
+ raw: rawGraphQL,
435
+ run: runGraphQL,
436
+ schema
437
+ },
438
+ services: {
439
+ email: (_config$email = config.email) !== null && _config$email !== void 0 ? _config$email : null,
440
+ jobs: (_config$jobs = config.jobs) !== null && _config$jobs !== void 0 ? _config$jobs : null,
441
+ cache: (_config$cache = config.cache) !== null && _config$cache !== void 0 ? _config$cache : null,
442
+ audit: (_config$audit = config.audit) !== null && _config$audit !== void 0 ? _config$audit : null,
443
+ webhooks: (_config$webhooks = config.webhooks) !== null && _config$webhooks !== void 0 ? _config$webhooks : null,
444
+ rateLimit: (_config$rateLimit = config.rateLimit) !== null && _config$rateLimit !== void 0 ? _config$rateLimit : null,
445
+ health: (_config$health = config.health) !== null && _config$health !== void 0 ? _config$health : null
446
+ },
447
+ transaction: async (f, opts) => {
448
+ return await prisma.$transaction(async prisma_ => {
449
+ const newContext = construct({
450
+ prisma: prisma_,
451
+ req,
452
+ res,
453
+ session,
454
+ internal,
455
+ sudo
456
+ });
457
+ return await f(newContext);
458
+ }, opts);
459
+ },
460
+ req,
461
+ res,
462
+ sessionStrategy: config.session,
463
+ ...(session ? {
464
+ session
465
+ } : {}),
466
+ withRequest: async (newReq, newRes) => {
467
+ var _await$config$session, _config$session;
468
+ const newContext = construct({
469
+ prisma,
470
+ req: newReq,
471
+ res: newRes,
472
+ session,
473
+ internal,
474
+ sudo
475
+ });
476
+ return newContext.withSession((_await$config$session = await ((_config$session = config.session) === null || _config$session === void 0 ? void 0 : _config$session.get({
477
+ context: newContext
478
+ }))) !== null && _await$config$session !== void 0 ? _await$config$session : undefined);
479
+ },
480
+ withSession: session => {
481
+ return construct({
482
+ prisma,
483
+ req,
484
+ res,
485
+ session,
486
+ internal,
487
+ sudo
488
+ });
489
+ },
490
+ // privilege escalation
491
+ internal: () => construct({
492
+ prisma,
493
+ req,
494
+ res,
495
+ session,
496
+ internal: true,
497
+ sudo
498
+ }),
499
+ sudo: () => construct({
500
+ prisma,
501
+ req,
502
+ res,
503
+ session,
504
+ internal: true,
505
+ sudo: true
506
+ }),
507
+ __internal: {
508
+ sudo,
509
+ lists,
510
+ prisma: {
511
+ ...prismaTypes
512
+ }
513
+ }
514
+ };
515
+ const _dbFactories = internal ? dbFactoriesInternal : dbFactories;
516
+ const _queryFactories = internal ? queryFactoriesInternal : queryFactories;
517
+ for (const listKey of Object.keys(lists)) {
518
+ context.db[listKey] = _dbFactories[listKey](context);
519
+ context.query[listKey] = _queryFactories[listKey](context);
520
+ }
521
+ return context;
522
+ };
523
+ return construct({
524
+ prisma: prismaClient,
525
+ internal: false,
526
+ sudo: false
527
+ });
528
+ }
529
+
530
+ const argName = 'where';
531
+ function coerceAndValidateForGraphQLInput(schema, type, value) {
532
+ const variableDefintions = [{
533
+ kind: graphql.Kind.VARIABLE_DEFINITION,
534
+ type: getTypeNodeForType(type),
535
+ variable: {
536
+ kind: graphql.Kind.VARIABLE,
537
+ name: {
538
+ kind: graphql.Kind.NAME,
539
+ value: argName
540
+ }
541
+ }
542
+ }];
543
+ const coercedVariableValues = values.getVariableValues(schema, variableDefintions, {
544
+ [argName]: value
545
+ });
546
+ if (coercedVariableValues.errors) {
547
+ return {
548
+ kind: 'error',
549
+ error: coercedVariableValues.errors[0]
550
+ };
551
+ }
552
+ return {
553
+ kind: 'valid',
554
+ value: coercedVariableValues.coerced[argName]
555
+ };
556
+ }
557
+
558
+ async function resolveUniqueWhereInput(inputFilter, list, context) {
559
+ const where = {};
560
+ for (const key in inputFilter) {
561
+ const value = inputFilter[key];
562
+ const resolver = list.fields[key].input.uniqueWhere.resolve;
563
+ if (resolver !== undefined) {
564
+ where[key] = await resolver(value, context);
565
+ } else {
566
+ where[key] = value;
567
+ }
568
+ }
569
+ return where;
570
+ }
571
+ async function resolveWhereInput(inputFilter, list, context) {
572
+ return {
573
+ AND: await Promise.all(Object.entries(inputFilter).map(async ([key, value]) => {
574
+ if (key === 'OR' || key === 'AND' || key === 'NOT') {
575
+ return {
576
+ [key]: await Promise.all(value.map(value => resolveWhereInput(value, list, context)))
577
+ };
578
+ }
579
+
580
+ // we know if there are filters in the input object with the key of a field,
581
+ // the field must have defined a where input so this non null assertion is okay
582
+ const field = list.fields[key];
583
+ const {
584
+ dbField
585
+ } = field;
586
+ const resolve = field.input.where.resolve;
587
+ const ret = resolve ? await resolve(value, context, (() => {
588
+ if (dbField.kind !== 'relation') {
589
+ return undefined;
590
+ }
591
+ const foreignList = dbField.list;
592
+ const whereResolver = filter => resolveWhereInput(filter, list.lists[foreignList], context);
593
+ if (dbField.mode === 'many') {
594
+ return async () => {
595
+ if (value === null) {
596
+ throw resolveHooks.userInputError('A many relation filter cannot be set to null');
597
+ }
598
+ return Object.fromEntries(await Promise.all(Object.entries(value).map(async ([key, val]) => {
599
+ if (val === null) {
600
+ throw resolveHooks.userInputError(`The key "${key}" in a many relation filter cannot be set to null`);
601
+ }
602
+ return [key, await whereResolver(val)];
603
+ })));
604
+ };
605
+ }
606
+ return value => {
607
+ if (value === null) return null;
608
+ return whereResolver(value);
609
+ };
610
+ })()) : value;
611
+ if (ret === null) {
612
+ if (dbField.kind === 'multi') {
613
+ // Note: no built-in field types support multi valued database fields *and* filtering.
614
+ // This code path is only relevent to custom fields which fit that criteria.
615
+ throw new Error('multi db fields cannot return null from where input resolvers');
616
+ }
617
+ return {
618
+ [key]: null
619
+ };
620
+ }
621
+ return handleOperators(key, dbField, ret);
622
+ }))
623
+ };
624
+ }
625
+ function handleOperators(fieldKey, dbField, {
626
+ AND,
627
+ OR,
628
+ NOT,
629
+ ...rest
630
+ }) {
631
+ return {
632
+ AND: AND === null || AND === void 0 ? void 0 : AND.map(value => handleOperators(fieldKey, dbField, value)),
633
+ OR: OR === null || OR === void 0 ? void 0 : OR.map(value => handleOperators(fieldKey, dbField, value)),
634
+ NOT: NOT === null || NOT === void 0 ? void 0 : NOT.map(value => handleOperators(fieldKey, dbField, value)),
635
+ ...nestWithAppropiateField(fieldKey, dbField, rest)
636
+ };
637
+ }
638
+ function nestWithAppropiateField(fieldKey, dbField, value) {
639
+ if (dbField.kind === 'multi') {
640
+ return Object.fromEntries(Object.entries(value).map(([key, val]) => [utils.getDBFieldKeyForFieldOnMultiField(fieldKey, key), val]));
641
+ }
642
+ return {
643
+ [fieldKey]: value
644
+ };
645
+ }
646
+
647
+ function cannotForItem(operation, list) {
648
+ if (operation === 'create') return `You cannot ${operation} that ${list.graphql.names.outputTypeName}`;
649
+ return `You cannot ${operation} that ${list.graphql.names.outputTypeName} - it may not exist`;
650
+ }
651
+ function cannotActionForItem(action, list) {
652
+ return `You cannot execute action "${action.actionKey}" for that ${list.graphql.names.outputTypeName}`;
653
+ }
654
+ function cannotForItemFields(operation, list, fieldsDenied) {
655
+ return `You cannot ${operation} that ${list.graphql.names.outputTypeName} - you cannot ${operation} the fields ${resolveHooks.formatKeys(fieldsDenied)}`;
656
+ }
657
+ async function getOperationFieldAccess(item, list, fieldKey, context, operation) {
658
+ if (context.__internal.sudo) return true;
659
+ const {
660
+ listKey
661
+ } = list;
662
+ let result;
663
+ try {
664
+ result = await list.fields[fieldKey].access.read({
665
+ operation: 'read',
666
+ session: context.session,
667
+ listKey,
668
+ fieldKey,
669
+ context,
670
+ item
671
+ });
672
+ } catch (error) {
673
+ throw resolveHooks.extensionError('Access control', [{
674
+ error,
675
+ tag: `${list.listKey}.${fieldKey}.access.${operation}`
676
+ }]);
677
+ }
678
+ if (typeof result !== 'boolean') {
679
+ throw resolveHooks.accessReturnError([{
680
+ tag: `${listKey}.access.operation.${operation}`,
681
+ returned: typeof result
682
+ }]);
683
+ }
684
+ return result;
685
+ }
686
+ async function getOperationAccess(list, context, operation) {
687
+ if (context.__internal.sudo) return true;
688
+ const {
689
+ listKey
690
+ } = list;
691
+ let result;
692
+ try {
693
+ if (operation === 'query') {
694
+ result = await list.access.operation.query({
695
+ operation,
696
+ session: context.session,
697
+ listKey,
698
+ context
699
+ });
700
+ } else if (operation === 'create') {
701
+ result = await list.access.operation.create({
702
+ operation,
703
+ session: context.session,
704
+ listKey,
705
+ context
706
+ });
707
+ } else if (operation === 'update') {
708
+ result = await list.access.operation.update({
709
+ operation,
710
+ session: context.session,
711
+ listKey,
712
+ context
713
+ });
714
+ } else if (operation === 'delete') {
715
+ result = await list.access.operation.delete({
716
+ operation,
717
+ session: context.session,
718
+ listKey,
719
+ context
720
+ });
721
+ }
722
+ } catch (error) {
723
+ throw resolveHooks.extensionError('Access control', [{
724
+ error,
725
+ tag: `${listKey}.access.operation.${operation}`
726
+ }]);
727
+ }
728
+ if (typeof result !== 'boolean') {
729
+ throw resolveHooks.accessReturnError([{
730
+ tag: `${listKey}.access.operation.${operation}`,
731
+ returned: typeof result
732
+ }]);
733
+ }
734
+ return result;
735
+ }
736
+ async function getAccessFilters(list, context, operation) {
737
+ if (context.__internal.sudo) return true;
738
+ try {
739
+ let filters;
740
+ if (operation === 'query') {
741
+ filters = await list.access.filter.query({
742
+ operation,
743
+ session: context.session,
744
+ listKey: list.listKey,
745
+ context
746
+ });
747
+ } else if (operation === 'update') {
748
+ filters = await list.access.filter.update({
749
+ operation,
750
+ session: context.session,
751
+ listKey: list.listKey,
752
+ context
753
+ });
754
+ } else if (operation === 'delete') {
755
+ filters = await list.access.filter.delete({
756
+ operation,
757
+ session: context.session,
758
+ listKey: list.listKey,
759
+ context
760
+ });
761
+ }
762
+ if (typeof filters === 'boolean') return filters;
763
+ if (!filters) return false; // shouldn't happen, but, Typescript
764
+
765
+ const schema = context.sudo().graphql.schema;
766
+ const whereInput = graphql.assertInputObjectType(schema.getType(list.graphql.names.whereInputName));
767
+ const result = coerceAndValidateForGraphQLInput(schema, whereInput, filters);
768
+ if (result.kind === 'valid') return result.value;
769
+ throw result.error;
770
+ } catch (error) {
771
+ throw resolveHooks.extensionError('Access control', [{
772
+ error,
773
+ tag: `${list.listKey}.access.filter.${operation}`
774
+ }]);
775
+ }
776
+ }
777
+ async function enforceListLevelAccessControl(context, operation, list, inputData, item) {
778
+ if (context.__internal.sudo) return;
779
+ let accepted; // should be boolean, but dont trust, it might accidentally be a filter
780
+ try {
781
+ // apply access.item.* controls
782
+ if (operation === 'create') {
783
+ const itemAccessControl = list.access.item[operation];
784
+ accepted = await itemAccessControl({
785
+ operation,
786
+ session: context.session,
787
+ listKey: list.listKey,
788
+ context,
789
+ inputData
790
+ });
791
+ } else if (operation === 'update' && item !== undefined) {
792
+ const itemAccessControl = list.access.item[operation];
793
+ accepted = await itemAccessControl({
794
+ operation,
795
+ session: context.session,
796
+ listKey: list.listKey,
797
+ context,
798
+ item,
799
+ inputData
800
+ });
801
+ } else if (operation === 'delete' && item !== undefined) {
802
+ const itemAccessControl = list.access.item[operation];
803
+ accepted = await itemAccessControl({
804
+ operation,
805
+ session: context.session,
806
+ listKey: list.listKey,
807
+ context,
808
+ item
809
+ });
810
+ }
811
+ } catch (error) {
812
+ throw resolveHooks.extensionError('Access control', [{
813
+ error,
814
+ tag: `${list.listKey}.access.item.${operation}`
815
+ }]);
816
+ }
817
+
818
+ // short circuit the safe path
819
+ if (accepted === true) return;
820
+ if (typeof accepted !== 'boolean') {
821
+ throw resolveHooks.accessReturnError([{
822
+ tag: `${list.listKey}.access.item.${operation}`,
823
+ returned: typeof accepted
824
+ }]);
825
+ }
826
+ throw resolveHooks.accessDeniedError(cannotForItem(operation, list));
827
+ }
828
+ async function enforceFieldLevelAccessControl(context, operation, list, inputData, item) {
829
+ if (context.__internal.sudo) return;
830
+ const nonBooleans = [];
831
+ const fieldsDenied = [];
832
+ const accessErrors = [];
833
+ await Promise.allSettled(Object.keys(inputData).map(async fieldKey => {
834
+ let accepted; // should be boolean, but dont trust
835
+ try {
836
+ // apply fields.[fieldKey].access.* controls
837
+ if (operation === 'create') {
838
+ const fieldAccessControl = list.fields[fieldKey].access[operation];
839
+ accepted = await fieldAccessControl({
840
+ operation,
841
+ session: context.session,
842
+ listKey: list.listKey,
843
+ fieldKey,
844
+ context,
845
+ inputData: inputData // FIXME
846
+ });
847
+ } else if (operation === 'update' && item !== undefined) {
848
+ const fieldAccessControl = list.fields[fieldKey].access[operation];
849
+ accepted = await fieldAccessControl({
850
+ operation,
851
+ session: context.session,
852
+ listKey: list.listKey,
853
+ fieldKey,
854
+ context,
855
+ item,
856
+ inputData
857
+ });
858
+ }
859
+ } catch (error) {
860
+ accessErrors.push({
861
+ error,
862
+ tag: `${list.listKey}.${fieldKey}.access.${operation}`
863
+ });
864
+ return;
865
+ }
866
+
867
+ // short circuit the safe path
868
+ if (accepted === true) return;
869
+ fieldsDenied.push(fieldKey);
870
+
871
+ // wrong type?
872
+ if (typeof accepted !== 'boolean') {
873
+ nonBooleans.push({
874
+ tag: `${list.listKey}.${fieldKey}.access.${operation}`,
875
+ returned: typeof accepted
876
+ });
877
+ }
878
+ }));
879
+ if (nonBooleans.length) {
880
+ throw resolveHooks.accessReturnError(nonBooleans);
881
+ }
882
+ if (accessErrors.length) {
883
+ throw resolveHooks.extensionError('Access control', accessErrors);
884
+ }
885
+ if (fieldsDenied.length) {
886
+ throw resolveHooks.accessDeniedError(cannotForItemFields(operation, list, fieldsDenied));
887
+ }
888
+ }
889
+ function parseFieldAccessControl(access) {
890
+ var _access$read, _access$create, _access$update;
891
+ if (typeof access === 'function') {
892
+ return {
893
+ read: access,
894
+ create: access,
895
+ update: access
896
+ };
897
+ }
898
+ return {
899
+ read: (_access$read = access === null || access === void 0 ? void 0 : access.read) !== null && _access$read !== void 0 ? _access$read : access_dist_nixxieCmsCoreAccess.allowAll,
900
+ create: (_access$create = access === null || access === void 0 ? void 0 : access.create) !== null && _access$create !== void 0 ? _access$create : access_dist_nixxieCmsCoreAccess.allowAll,
901
+ update: (_access$update = access === null || access === void 0 ? void 0 : access.update) !== null && _access$update !== void 0 ? _access$update : access_dist_nixxieCmsCoreAccess.allowAll
902
+ };
903
+ }
904
+ function parseListAccessControl(access) {
905
+ var _filter$query, _filter$update, _filter$delete, _item$create, _item$update, _item$delete;
906
+ if (typeof access === 'function') {
907
+ return {
908
+ operation: {
909
+ query: access,
910
+ create: access,
911
+ update: access,
912
+ delete: access
913
+ },
914
+ filter: {
915
+ query: access_dist_nixxieCmsCoreAccess.allowAll,
916
+ update: access_dist_nixxieCmsCoreAccess.allowAll,
917
+ delete: access_dist_nixxieCmsCoreAccess.allowAll
918
+ },
919
+ item: {
920
+ create: access_dist_nixxieCmsCoreAccess.allowAll,
921
+ update: access_dist_nixxieCmsCoreAccess.allowAll,
922
+ delete: access_dist_nixxieCmsCoreAccess.allowAll
923
+ }
924
+ };
925
+ }
926
+ let {
927
+ operation,
928
+ filter,
929
+ item
930
+ } = access;
931
+ if (typeof operation === 'function') {
932
+ operation = {
933
+ query: operation,
934
+ create: operation,
935
+ update: operation,
936
+ delete: operation
937
+ };
938
+ }
939
+ return {
940
+ operation: {
941
+ query: operation.query,
942
+ create: operation.create,
943
+ update: operation.update,
944
+ delete: operation.delete
945
+ },
946
+ filter: {
947
+ query: (_filter$query = filter === null || filter === void 0 ? void 0 : filter.query) !== null && _filter$query !== void 0 ? _filter$query : access_dist_nixxieCmsCoreAccess.allowAll,
948
+ // create: not supported
949
+ update: (_filter$update = filter === null || filter === void 0 ? void 0 : filter.update) !== null && _filter$update !== void 0 ? _filter$update : access_dist_nixxieCmsCoreAccess.allowAll,
950
+ delete: (_filter$delete = filter === null || filter === void 0 ? void 0 : filter.delete) !== null && _filter$delete !== void 0 ? _filter$delete : access_dist_nixxieCmsCoreAccess.allowAll
951
+ },
952
+ item: {
953
+ // query: not supported
954
+ create: (_item$create = item === null || item === void 0 ? void 0 : item.create) !== null && _item$create !== void 0 ? _item$create : access_dist_nixxieCmsCoreAccess.allowAll,
955
+ update: (_item$update = item === null || item === void 0 ? void 0 : item.update) !== null && _item$update !== void 0 ? _item$update : access_dist_nixxieCmsCoreAccess.allowAll,
956
+ delete: (_item$delete = item === null || item === void 0 ? void 0 : item.delete) !== null && _item$delete !== void 0 ? _item$delete : access_dist_nixxieCmsCoreAccess.allowAll
957
+ }
958
+ };
959
+ }
960
+ async function checkUniqueItemExists(uniqueInput, foreignList, context, operation) {
961
+ // Validate and resolve the input filter
962
+ const uniqueWhere = await resolveUniqueWhereInput(uniqueInput, foreignList, context);
963
+
964
+ // Check whether the item exists (from this users POV).
965
+ try {
966
+ const item = await context.db[foreignList.listKey].findOne({
967
+ where: uniqueInput
968
+ });
969
+ if (item !== null) return uniqueWhere;
970
+ } catch (err) {}
971
+ throw resolveHooks.accessDeniedError(cannotForItem(operation, foreignList));
972
+ }
973
+
974
+ function assertFieldsValid(list) {
975
+ assertNoConflictingExtraOutputFields(list);
976
+ assertIdFieldGraphQLTypesCorrect(list);
977
+ assertNoFieldKeysThatConflictWithFilterCombinators(list);
978
+ assertUniqueWhereInputsValid(list);
979
+ assertFieldsIsNonNullAllowed(list);
980
+ }
981
+ function assertFieldsIsNonNullAllowed(list) {
982
+ for (const [fieldKey, field] of Object.entries(list.fields)) {
983
+ if (field.access.read !== access_dist_nixxieCmsCoreAccess.allowAll) {
984
+ if (field.graphql.isNonNull.read) {
985
+ throw new Error(`The field at ${list.listKey}.${fieldKey} sets graphql.isNonNull.read: true, and has 'read' field access control, this is not allowed.\n` + `Either disable graphql.read.isNonNull, or disable 'read' field access control.`);
986
+ }
987
+ }
988
+ }
989
+ }
990
+ function assertUniqueWhereInputsValid(list) {
991
+ for (const [fieldKey, {
992
+ dbField,
993
+ input
994
+ }] of Object.entries(list.fields)) {
995
+ if (input !== null && input !== void 0 && input.uniqueWhere) {
996
+ if (dbField.kind !== 'scalar' && dbField.kind !== 'enum' && dbField.kind !== 'relation') {
997
+ throw new Error(`Only scalar db fields can provide a uniqueWhere input currently but the field at ${list.listKey}.${fieldKey} specifies a uniqueWhere input`);
998
+ }
999
+ if (dbField.kind !== 'relation' && dbField.index !== 'unique' && fieldKey !== 'id') {
1000
+ throw new Error(`Fields must have a unique index or be the idField to specify a uniqueWhere input but the field at ${list.listKey}.${fieldKey} specifies a uniqueWhere input without a unique index`);
1001
+ }
1002
+ }
1003
+ }
1004
+ }
1005
+ function assertNoFieldKeysThatConflictWithFilterCombinators(list) {
1006
+ for (const fieldKey of Object.keys(list.fields)) {
1007
+ if (fieldKey === 'AND' || fieldKey === 'OR' || fieldKey === 'NOT') {
1008
+ throw new Error(`Fields cannot be named ${fieldKey} but there is a field named ${fieldKey} on ${list.listKey}`);
1009
+ }
1010
+ }
1011
+ }
1012
+ function assertNoConflictingExtraOutputFields(list) {
1013
+ const fieldKeys = new Set(Object.keys(list.fields));
1014
+ const alreadyFoundFields = {};
1015
+ for (const [fieldKey, field] of Object.entries(list.fields)) {
1016
+ if (field.extraOutputFields) {
1017
+ for (const outputTypeFieldName of Object.keys(field.extraOutputFields)) {
1018
+ // note that this and the case handled below are fundamentally the same thing but i want different errors for each of them
1019
+ if (fieldKeys.has(outputTypeFieldName)) {
1020
+ throw new Error(`The field ${fieldKey} on the ${list.listKey} list defines an extra GraphQL output field named ${outputTypeFieldName} which conflicts with the Nixxie field type named ${outputTypeFieldName} on the same list`);
1021
+ }
1022
+ const alreadyFoundField = alreadyFoundFields[outputTypeFieldName];
1023
+ if (alreadyFoundField !== undefined) {
1024
+ throw new Error(`The field ${fieldKey} on the ${list.listKey} list defines an extra GraphQL output field named ${outputTypeFieldName} which conflicts with the Nixxie field type named ${alreadyFoundField} which also defines an extra GraphQL output field named ${outputTypeFieldName}`);
1025
+ }
1026
+ alreadyFoundFields[outputTypeFieldName] = fieldKey;
1027
+ }
1028
+ }
1029
+ }
1030
+ }
1031
+ function assertIdFieldGraphQLTypesCorrect(list) {
1032
+ var _idField$input;
1033
+ const idField = list.fields.id;
1034
+ if (((_idField$input = idField.input) === null || _idField$input === void 0 ? void 0 : _idField$input.uniqueWhere) === undefined) {
1035
+ throw new Error(`The idField on a list must define a uniqueWhere GraphQL input with the ID GraphQL scalar type but the idField for ${list.listKey} does not define one`);
1036
+ }
1037
+ if (idField.input.uniqueWhere.arg.type !== nextFields.g.ID) {
1038
+ throw new Error(`The idField on a list must define a uniqueWhere GraphQL input with the ID GraphQL scalar type but the idField for ${list.listKey} defines the type ${idField.input.uniqueWhere.arg.type.toString()}`);
1039
+ }
1040
+ // we may want to loosen these constraints in the future
1041
+ if (idField.input.create !== undefined) {
1042
+ throw new Error(`The idField on a list must not define a create GraphQL input but the idField for ${list.listKey} does define one`);
1043
+ }
1044
+ if (idField.input.update !== undefined) {
1045
+ throw new Error(`The idField on a list must not define an update GraphQL input but the idField for ${list.listKey} does define one`);
1046
+ }
1047
+ if (idField.graphql.isEnabled.read === false) {
1048
+ throw new Error(`The idField on a list must not have graphql.isEnabled.read be set to false but ${list.listKey} does`);
1049
+ }
1050
+ if (!(idField.output.type instanceof schema.GNonNull) || idField.output.type.ofType !== nextFields.g.ID) {
1051
+ throw new Error(`The idField on a list must define a GraphQL output field with a non-nullable ID GraphQL scalar type but the idField for ${list.listKey} defines the type ${idField.output.type.toString()}`);
1052
+ }
1053
+ }
1054
+
1055
+ async function checkFilterOrderAccess(things, context, operation) {
1056
+ const func = operation === 'filter' ? 'isFilterable' : 'isOrderable';
1057
+ const failures = [];
1058
+ const returnTypeErrors = [];
1059
+ const accessErrors = [];
1060
+ for (const {
1061
+ fieldKey,
1062
+ list
1063
+ } of things) {
1064
+ const field = list.fields[fieldKey];
1065
+ const rule = field.graphql.isEnabled[operation];
1066
+ if (!rule) throw new Error('Assert failed');
1067
+ if (typeof rule === 'function') {
1068
+ let result;
1069
+ try {
1070
+ result = await rule({
1071
+ context,
1072
+ session: context.session,
1073
+ listKey: list.listKey,
1074
+ fieldKey
1075
+ });
1076
+ } catch (error) {
1077
+ accessErrors.push({
1078
+ error,
1079
+ tag: `${list.listKey}.${fieldKey}.${func}`
1080
+ });
1081
+ continue;
1082
+ }
1083
+ const resultType = typeof result;
1084
+
1085
+ // It's important that we don't cast objects to truthy values, as there's a strong chance that the user
1086
+ // has made a mistake.
1087
+ if (resultType !== 'boolean') {
1088
+ returnTypeErrors.push({
1089
+ tag: `${list.listKey}.${fieldKey}.${func}`,
1090
+ returned: resultType
1091
+ });
1092
+ } else if (!result) {
1093
+ failures.push(`${list.listKey}.${fieldKey}`);
1094
+ }
1095
+ }
1096
+ }
1097
+ if (accessErrors.length) {
1098
+ throw resolveHooks.extensionError(func, accessErrors);
1099
+ }
1100
+ if (returnTypeErrors.length) {
1101
+ throw resolveHooks.accessReturnError(returnTypeErrors);
1102
+ }
1103
+ if (failures.length) {
1104
+ throw resolveHooks.filterAccessError({
1105
+ operation,
1106
+ fieldKeys: failures
1107
+ });
1108
+ }
1109
+ }
1110
+
1111
+ // we want to put the value we get back from the field's unique where resolver into an equals
1112
+ // rather than directly passing the value as the filter (even though Prisma supports that), we use equals
1113
+ // because we want to disallow fields from providing an arbitrary filter
1114
+ function mapUniqueWhereToWhere(uniqueWhere, list) {
1115
+ const where = {};
1116
+ for (const key in uniqueWhere) {
1117
+ if (list.fields[key].dbField.kind === 'relation') {
1118
+ const foreignList = list.lists[list.fields[key].dbField.list];
1119
+ where[key] = mapUniqueWhereToWhere(uniqueWhere[key], foreignList);
1120
+ continue;
1121
+ }
1122
+ where[key] = {
1123
+ equals: uniqueWhere[key]
1124
+ };
1125
+ }
1126
+ return where;
1127
+ }
1128
+ function* traverse(list, inputFilter) {
1129
+ for (const fieldKey in inputFilter) {
1130
+ const value = inputFilter[fieldKey];
1131
+ if (fieldKey === 'OR' || fieldKey === 'AND' || fieldKey === 'NOT') {
1132
+ for (const condition of value) {
1133
+ yield* traverse(list, condition);
1134
+ }
1135
+ } else if (fieldKey === 'some' || fieldKey === 'none' || fieldKey === 'every') {
1136
+ yield* traverse(list, value);
1137
+ } else {
1138
+ yield {
1139
+ fieldKey,
1140
+ list
1141
+ };
1142
+
1143
+ // if it's a relationship, check the nested filters.
1144
+ const field = list.fields[fieldKey];
1145
+ if (field.dbField.kind === 'relation' && value !== null) {
1146
+ const foreignList = list.lists[field.dbField.list];
1147
+ yield* traverse(foreignList, value);
1148
+ }
1149
+ }
1150
+ }
1151
+ }
1152
+ async function accessControlledFilter(list, context, resolvedWhere, accessFilters) {
1153
+ // Merge the filter access control
1154
+ if (typeof accessFilters === 'object') {
1155
+ resolvedWhere = {
1156
+ AND: [resolvedWhere, await resolveWhereInput(accessFilters, list, context)]
1157
+ };
1158
+ }
1159
+ return resolvedWhere;
1160
+ }
1161
+ async function findOne(args, list, context, info) {
1162
+ // check operation permission to pass into single operation
1163
+ const operationAccess = await getOperationAccess(list, context, 'query');
1164
+ if (!operationAccess) return null;
1165
+ const accessFilters = await getAccessFilters(list, context, 'query');
1166
+ if (accessFilters === false) return null;
1167
+
1168
+ // validate and resolve the input filter
1169
+ const uniqueWhere = await resolveUniqueWhereInput(args.where, list, context);
1170
+ const resolvedWhere = mapUniqueWhereToWhere(uniqueWhere, list);
1171
+
1172
+ // findOne requires at least one filter
1173
+ if (Object.keys(resolvedWhere).length === 0) return null;
1174
+
1175
+ // check filter access
1176
+ await checkFilterOrderAccess([...traverse(list, args.where)], context, 'filter');
1177
+
1178
+ // apply access control
1179
+ const filter = await accessControlledFilter(list, context, resolvedWhere, accessFilters);
1180
+ const result = await context.prisma[list.listKey].findFirst({
1181
+ where: filter
1182
+ });
1183
+ if (list.cacheHint) {
1184
+ var _maybeCacheControlFro, _info$operation$name;
1185
+ (_maybeCacheControlFro = cacheControlTypes.maybeCacheControlFromInfo(info)) === null || _maybeCacheControlFro === void 0 || _maybeCacheControlFro.setCacheHint(list.cacheHint({
1186
+ results: result ? [result] : [],
1187
+ operationName: (_info$operation$name = info.operation.name) === null || _info$operation$name === void 0 ? void 0 : _info$operation$name.value,
1188
+ meta: false
1189
+ }));
1190
+ }
1191
+ return result;
1192
+ }
1193
+ async function findMany({
1194
+ where,
1195
+ take,
1196
+ skip,
1197
+ orderBy: rawOrderBy,
1198
+ cursor
1199
+ }, list, context, info, extraFilter) {
1200
+ var _list$graphql$types$f;
1201
+ const maxTake = (_list$graphql$types$f = list.graphql.types.findManyArgs.take.defaultValue) !== null && _list$graphql$types$f !== void 0 ? _list$graphql$types$f : Infinity;
1202
+ if ((take !== null && take !== void 0 ? take : Infinity) > maxTake) {
1203
+ throw resolveHooks.limitsExceededError({
1204
+ list: list.listKey,
1205
+ type: 'maxTake',
1206
+ limit: maxTake
1207
+ });
1208
+ }
1209
+
1210
+ // check operation permission to pass into single operation
1211
+ const operationAccess = await getOperationAccess(list, context, 'query');
1212
+ if (!operationAccess) return [];
1213
+ const accessFilters = await getAccessFilters(list, context, 'query');
1214
+ if (accessFilters === false) return [];
1215
+
1216
+ // validate and resolve the input filter
1217
+ const resolvedWhere = await resolveWhereInput(where, list, context);
1218
+
1219
+ // check filter access (TODO: why isn't this using resolvedWhere)
1220
+ await checkFilterOrderAccess([...traverse(list, where)], context, 'filter');
1221
+
1222
+ // check filter access for cursor
1223
+ if (cursor) {
1224
+ await checkFilterOrderAccess([...traverse(list, cursor)], context, 'filter');
1225
+ }
1226
+
1227
+ // WARNING: this checks .isOrderable
1228
+ const orderBy = await resolveOrderBy(rawOrderBy, list, context);
1229
+
1230
+ // apply access control
1231
+ const filter = await accessControlledFilter(list, context, resolvedWhere, accessFilters);
1232
+ const results = await context.prisma[list.listKey].findMany({
1233
+ where: extraFilter === undefined ? filter : {
1234
+ AND: [filter, extraFilter]
1235
+ },
1236
+ orderBy,
1237
+ take: take !== null && take !== void 0 ? take : undefined,
1238
+ skip,
1239
+ cursor: cursor !== null && cursor !== void 0 ? cursor : undefined
1240
+ });
1241
+ if (list.cacheHint) {
1242
+ var _maybeCacheControlFro2, _info$operation$name2;
1243
+ (_maybeCacheControlFro2 = cacheControlTypes.maybeCacheControlFromInfo(info)) === null || _maybeCacheControlFro2 === void 0 || _maybeCacheControlFro2.setCacheHint(list.cacheHint({
1244
+ results,
1245
+ operationName: (_info$operation$name2 = info.operation.name) === null || _info$operation$name2 === void 0 ? void 0 : _info$operation$name2.value,
1246
+ meta: false
1247
+ }));
1248
+ }
1249
+ return results;
1250
+ }
1251
+ async function resolveOrderBy(orderBy, list, context) {
1252
+ // Check input format. FIXME: Group all errors
1253
+ orderBy.forEach(orderBySelection => {
1254
+ const keys = Object.keys(orderBySelection);
1255
+ if (keys.length !== 1) {
1256
+ throw resolveHooks.userInputError(`Only a single key must be passed to ${list.graphql.types.orderBy.name}`);
1257
+ }
1258
+ const fieldKey = keys[0];
1259
+ const value = orderBySelection[fieldKey];
1260
+ if (value === null) {
1261
+ throw resolveHooks.userInputError('null cannot be passed as an order direction');
1262
+ }
1263
+ });
1264
+
1265
+ // Check orderBy access
1266
+ const orderByKeys = orderBy.map(orderBySelection => ({
1267
+ fieldKey: Object.keys(orderBySelection)[0],
1268
+ list
1269
+ }));
1270
+ await checkFilterOrderAccess(orderByKeys, context, 'orderBy');
1271
+ return await Promise.all(orderBy.map(async orderBySelection => {
1272
+ const keys = Object.keys(orderBySelection);
1273
+ const fieldKey = keys[0];
1274
+ const value = orderBySelection[fieldKey];
1275
+ const field = list.fields[fieldKey];
1276
+ const resolve = field.input.orderBy.resolve;
1277
+ const resolvedValue = resolve ? await resolve(value, context) : value;
1278
+ if (field.dbField.kind === 'multi') {
1279
+ // Note: no built-in field types support multi valued database fields *and* orderBy.
1280
+ // This code path is only relevent to custom fields which fit that criteria.
1281
+ const keys = Object.keys(resolvedValue);
1282
+ if (keys.length !== 1) {
1283
+ throw new Error(`Only a single key must be returned from an orderBy input resolver for a multi db field`);
1284
+ }
1285
+ const innerKey = keys[0];
1286
+ return {
1287
+ [utils.getDBFieldKeyForFieldOnMultiField(fieldKey, innerKey)]: resolvedValue[innerKey]
1288
+ };
1289
+ } else {
1290
+ return {
1291
+ [fieldKey]: resolvedValue
1292
+ };
1293
+ }
1294
+ }));
1295
+ }
1296
+ async function count({
1297
+ where
1298
+ }, list, context, info, extraFilter) {
1299
+ const operationAccess = await getOperationAccess(list, context, 'query');
1300
+ if (!operationAccess) return 0;
1301
+ const accessFilters = await getAccessFilters(list, context, 'query');
1302
+ if (accessFilters === false) return 0;
1303
+ const resolvedWhere = await resolveWhereInput(where, list, context);
1304
+
1305
+ // check filter access (TODO: why isn't this using resolvedWhere)
1306
+ await checkFilterOrderAccess([...traverse(list, where)], context, 'filter');
1307
+ const filter = await accessControlledFilter(list, context, resolvedWhere, accessFilters);
1308
+ const count = await context.prisma[list.listKey].count({
1309
+ where: extraFilter === undefined ? filter : {
1310
+ AND: [filter, extraFilter]
1311
+ }
1312
+ });
1313
+ if (list.cacheHint) {
1314
+ var _maybeCacheControlFro3, _info$operation$name3;
1315
+ (_maybeCacheControlFro3 = cacheControlTypes.maybeCacheControlFromInfo(info)) === null || _maybeCacheControlFro3 === void 0 || _maybeCacheControlFro3.setCacheHint(list.cacheHint({
1316
+ results: count,
1317
+ operationName: (_info$operation$name3 = info.operation.name) === null || _info$operation$name3 === void 0 ? void 0 : _info$operation$name3.value,
1318
+ meta: true
1319
+ }));
1320
+ }
1321
+ return count;
1322
+ }
1323
+
1324
+ function getRelationVal(dbField, id, foreignList, context, info, fk) {
1325
+ const oppositeDbField = foreignList.resolvedDbFields[dbField.field];
1326
+ if (oppositeDbField.kind !== 'relation') throw new Error('failed assert');
1327
+ if (dbField.mode === 'many') {
1328
+ const relationFilter = {
1329
+ [dbField.field]: oppositeDbField.mode === 'many' ? {
1330
+ some: {
1331
+ id
1332
+ }
1333
+ } : {
1334
+ id
1335
+ }
1336
+ };
1337
+ return {
1338
+ findMany: async args => findMany(args, foreignList, context, info, relationFilter),
1339
+ count: async ({
1340
+ where
1341
+ }) => count({
1342
+ where
1343
+ }, foreignList, context, info, relationFilter)
1344
+ };
1345
+ } else {
1346
+ return async () => {
1347
+ if (fk === null) {
1348
+ // If the foreign key is explicitly null, there's no need to anything else,
1349
+ // since we know the related item doesn't exist.
1350
+ return null;
1351
+ }
1352
+ // for one-to-many relationships, the one side always owns the foreign key
1353
+ // so that means we have the id for the related item and we're fetching it by _its_ id.
1354
+ // for the a one-to-one relationship though, the id might be on the related item
1355
+ // so we need to fetch the related item by the id of the current item on the foreign key field
1356
+ const currentItemOwnsForeignKey = fk !== undefined;
1357
+ return fetchRelatedItem(context)(foreignList)(currentItemOwnsForeignKey ? 'id' : `${dbField.field}Id`)(currentItemOwnsForeignKey ? fk : id);
1358
+ };
1359
+ }
1360
+ }
1361
+ function memoize(cb) {
1362
+ const cache = new Map();
1363
+ return arg => {
1364
+ if (!cache.has(arg)) {
1365
+ const result = cb(arg);
1366
+ cache.set(arg, result);
1367
+ }
1368
+ return cache.get(arg);
1369
+ };
1370
+ }
1371
+ const fetchRelatedItem = utils.weakMemoize(context => utils.weakMemoize(foreignList => memoize(idFieldKey => {
1372
+ const relatedItemLoader = new DataLoader__default["default"](keys => fetchRelatedItems(context, foreignList, idFieldKey, keys), {
1373
+ cache: false
1374
+ });
1375
+ return id => relatedItemLoader.load(id);
1376
+ })));
1377
+ async function fetchRelatedItems(context, foreignList, idFieldKey, toFetch) {
1378
+ const operationAccess = await getOperationAccess(foreignList, context, 'query');
1379
+ if (!operationAccess) {
1380
+ return toFetch.map(() => undefined);
1381
+ }
1382
+ const accessFilters = await getAccessFilters(foreignList, context, 'query');
1383
+ if (accessFilters === false) {
1384
+ return toFetch.map(() => undefined);
1385
+ }
1386
+ const toFetchUnique = Array.from(new Set(toFetch));
1387
+ const resolvedWhere = await accessControlledFilter(foreignList, context, {
1388
+ [idFieldKey]: {
1389
+ in: toFetchUnique
1390
+ }
1391
+ }, accessFilters);
1392
+ const results = await context.prisma[foreignList.listKey].findMany({
1393
+ where: resolvedWhere
1394
+ });
1395
+ const resultsById = new Map(results.map(x => [x[idFieldKey], x]));
1396
+ return toFetch.map(id => resultsById.get(id));
1397
+ }
1398
+ function getValueForDBField(item, dbField, id, fieldPath, context, lists, info) {
1399
+ if (dbField.kind === 'multi') {
1400
+ return Object.fromEntries(Object.keys(dbField.fields).map(innerDBFieldKey => {
1401
+ const keyOnDbValue = utils.getDBFieldKeyForFieldOnMultiField(fieldPath, innerDBFieldKey);
1402
+ return [innerDBFieldKey, item[keyOnDbValue]];
1403
+ }));
1404
+ }
1405
+ if (dbField.kind === 'relation') {
1406
+ // If we're holding a foreign key value, let's take advantage of that.
1407
+ let fk;
1408
+ if (dbField.mode === 'one' && dbField.foreignIdField.kind !== 'none') {
1409
+ fk = item[`${fieldPath}Id`];
1410
+ }
1411
+ return getRelationVal(dbField, id, lists[dbField.list], context, info, fk);
1412
+ } else {
1413
+ return item[fieldPath];
1414
+ }
1415
+ }
1416
+ function outputTypeField(output, dbField, cacheHint, access, listKey, fieldKey, lists) {
1417
+ const list = lists[listKey];
1418
+ return nextFields.g.field({
1419
+ type: output.type,
1420
+ deprecationReason: output.deprecationReason,
1421
+ description: output.description,
1422
+ args: output.args,
1423
+ extensions: output.extensions,
1424
+ async resolve(item, args, context, info) {
1425
+ const id = item.id;
1426
+ const fieldAccess = await getOperationFieldAccess(item, list, fieldKey, context, 'read');
1427
+ if (!fieldAccess) return null;
1428
+
1429
+ // only static cache hints are supported at the field level until a use-case makes it clear what parameters a dynamic hint would take
1430
+ if (cacheHint && info) {
1431
+ var _maybeCacheControlFro;
1432
+ (_maybeCacheControlFro = cacheControlTypes.maybeCacheControlFromInfo(info)) === null || _maybeCacheControlFro === void 0 || _maybeCacheControlFro.setCacheHint(cacheHint);
1433
+ }
1434
+ const value = getValueForDBField(item, dbField, id, fieldKey, context, lists, info);
1435
+ if (output.resolve) {
1436
+ return output.resolve({
1437
+ value,
1438
+ item: item
1439
+ }, args, context, info);
1440
+ } else {
1441
+ return value;
1442
+ }
1443
+ }
1444
+ });
1445
+ }
1446
+
1447
+ // note: all nixxie fields correspond to a field here
1448
+ // not all fields here correspond to nixxie fields(the implicit side of one-sided relation fields)
1449
+
1450
+ function sortRelationships(left, right) {
1451
+ if (left.field.mode === 'one' && right.field.mode === 'one') {
1452
+ if (left.field.foreignKey !== undefined && right.field.foreignKey !== undefined) {
1453
+ throw new Error(`You can only set db.foreignKey on one side of a one to one relationship, but foreignKey is set on both ${left.listKey}.${left.fieldPath} and ${right.listKey}.${right.fieldPath}`);
1454
+ }
1455
+
1456
+ // return the field that specifies the foreignKey first
1457
+ if (left.field.foreignKey) return [left, right];
1458
+ if (right.field.foreignKey) return [right, left];
1459
+ } else if (left.field.mode === 'one' || right.field.mode === 'one') {
1460
+ // many relationships will never have a foreign key, so return the one relationship first
1461
+ const rels = left.field.mode === 'one' ? [left, right] : [right, left];
1462
+ // we're only doing this for rels[1] because:
1463
+ // - rels[1] is the many side
1464
+ // - for the one side, TypeScript will already disallow relationName
1465
+ if (rels[1].field.relationName !== undefined) throw new Error(`You can only set db.relationName on one side of a many to many relationship, but db.relationName is set on ${rels[1].listKey}.${rels[1].fieldPath} which is the many side of a many to one relationship with ${rels[0].listKey}.${rels[0].fieldPath}`);
1466
+ return rels;
1467
+ }
1468
+ if (left.field.mode === 'many' && right.field.mode === 'many' && (left.field.relationName !== undefined || right.field.relationName !== undefined)) {
1469
+ if (left.field.relationName !== undefined && right.field.relationName !== undefined) {
1470
+ throw new Error(`You can only set db.relationName on one side of a many to many relationship, but db.relationName is set on both ${left.listKey}.${left.fieldPath} and ${right.listKey}.${right.fieldPath}`);
1471
+ }
1472
+ return left.field.relationName !== undefined ? [left, right] : [right, left];
1473
+ }
1474
+ const order = left.listKey.localeCompare(right.listKey);
1475
+ if (order > 0) return [right, left]; // left comes after right, so swap them
1476
+ if (order === 0) {
1477
+ // self referential list, so check the paths.
1478
+ if (left.fieldPath.localeCompare(right.fieldPath) > 0) {
1479
+ return [right, left];
1480
+ }
1481
+ }
1482
+ return [left, right];
1483
+ }
1484
+
1485
+ // what's going on here:
1486
+ // - validating all the relationships
1487
+ // - for relationships involving to-one: deciding which side owns the foreign key
1488
+ // - turning one-sided relationships into two-sided relationships so that elsewhere in Nixxie,
1489
+ // you only have to reason about two-sided relationships
1490
+ // (note that this means that there are "fields" in the returned ListsWithResolvedRelations
1491
+ // which are not actually proper Nixxie fields, they are just a db field and nothing else)
1492
+ function resolveRelationships(lists) {
1493
+ const alreadyResolvedTwoSidedRelationships = new Set();
1494
+ const resolvedLists = Object.fromEntries(Object.keys(lists).map(listKey => [listKey, {}]));
1495
+ for (const [listKey, fields] of Object.entries(lists)) {
1496
+ const resolvedList = resolvedLists[listKey];
1497
+ for (const [fieldPath, {
1498
+ dbField: field
1499
+ }] of Object.entries(fields.fields)) {
1500
+ if (field.kind !== 'relation') {
1501
+ resolvedList[fieldPath] = field;
1502
+ continue;
1503
+ }
1504
+ const foreignUnresolvedList = lists[field.list];
1505
+ if (!foreignUnresolvedList) {
1506
+ throw new Error(`The relationship field at ${listKey}.${fieldPath} points to the list ${listKey} which does not exist`);
1507
+ }
1508
+ if (foreignUnresolvedList.isSingleton) {
1509
+ throw new Error(`The relationship field at ${listKey}.${fieldPath} points to a singleton list, ${listKey}, which is not allowed`);
1510
+ }
1511
+ if (field.field) {
1512
+ var _foreignUnresolvedLis, _leftRel$field$foreig2;
1513
+ const localRef = `${listKey}.${fieldPath}`;
1514
+ const foreignRef = `${field.list}.${field.field}`;
1515
+ if (alreadyResolvedTwoSidedRelationships.has(localRef)) continue;
1516
+ alreadyResolvedTwoSidedRelationships.add(foreignRef);
1517
+ const foreignField = (_foreignUnresolvedLis = foreignUnresolvedList.fields[field.field]) === null || _foreignUnresolvedLis === void 0 ? void 0 : _foreignUnresolvedLis.dbField;
1518
+ if (!foreignField) throw new Error(`${localRef} points to ${foreignRef}, but ${foreignRef} doesn't exist`);
1519
+ if (foreignField.kind !== 'relation') {
1520
+ throw new Error(`${localRef} points to ${foreignRef}, but ${foreignRef} is not a relationship field`);
1521
+ }
1522
+ const actualRef = foreignField.field ? `${foreignField.list}.${foreignField.field}` : foreignField.list;
1523
+ if (actualRef !== localRef) {
1524
+ throw new Error(`${localRef} expects ${foreignRef} to be a two way relationship, but ${foreignRef} points to ${actualRef}`);
1525
+ }
1526
+ const [leftRel, rightRel] = sortRelationships({
1527
+ listKey,
1528
+ fieldPath,
1529
+ field
1530
+ }, {
1531
+ listKey: field.list,
1532
+ fieldPath: field.field,
1533
+ field: foreignField
1534
+ });
1535
+ if (leftRel.field.mode === 'one' && rightRel.field.mode === 'one') {
1536
+ var _leftRel$field$foreig;
1537
+ const relationName = `${leftRel.listKey}_${leftRel.fieldPath}`;
1538
+ resolvedLists[leftRel.listKey][leftRel.fieldPath] = {
1539
+ kind: 'relation',
1540
+ mode: 'one',
1541
+ field: rightRel.fieldPath,
1542
+ list: rightRel.listKey,
1543
+ extendPrismaSchema: leftRel.field.extendPrismaSchema,
1544
+ foreignIdField: {
1545
+ kind: 'owned-unique',
1546
+ map: typeof leftRel.field.foreignKey === 'object' ? (_leftRel$field$foreig = leftRel.field.foreignKey) === null || _leftRel$field$foreig === void 0 ? void 0 : _leftRel$field$foreig.map : leftRel.fieldPath
1547
+ },
1548
+ relationName
1549
+ };
1550
+ resolvedLists[rightRel.listKey][rightRel.fieldPath] = {
1551
+ kind: 'relation',
1552
+ mode: 'one',
1553
+ field: leftRel.fieldPath,
1554
+ list: leftRel.listKey,
1555
+ extendPrismaSchema: rightRel.field.extendPrismaSchema,
1556
+ foreignIdField: {
1557
+ kind: 'none'
1558
+ },
1559
+ relationName
1560
+ };
1561
+ continue;
1562
+ }
1563
+ if (leftRel.field.mode === 'many' && rightRel.field.mode === 'many') {
1564
+ var _leftRel$field$relati;
1565
+ const relationName = (_leftRel$field$relati = leftRel.field.relationName) !== null && _leftRel$field$relati !== void 0 ? _leftRel$field$relati : `${leftRel.listKey}_${leftRel.fieldPath}`;
1566
+ resolvedLists[leftRel.listKey][leftRel.fieldPath] = {
1567
+ kind: 'relation',
1568
+ mode: 'many',
1569
+ extendPrismaSchema: leftRel.field.extendPrismaSchema,
1570
+ field: rightRel.fieldPath,
1571
+ list: rightRel.listKey,
1572
+ relationName
1573
+ };
1574
+ resolvedLists[rightRel.listKey][rightRel.fieldPath] = {
1575
+ kind: 'relation',
1576
+ mode: 'many',
1577
+ extendPrismaSchema: rightRel.field.extendPrismaSchema,
1578
+ field: leftRel.fieldPath,
1579
+ list: leftRel.listKey,
1580
+ relationName
1581
+ };
1582
+ continue;
1583
+ }
1584
+ const relationName = `${leftRel.listKey}_${leftRel.fieldPath}`;
1585
+ resolvedLists[leftRel.listKey][leftRel.fieldPath] = {
1586
+ kind: 'relation',
1587
+ mode: 'one',
1588
+ field: rightRel.fieldPath,
1589
+ extendPrismaSchema: leftRel.field.extendPrismaSchema,
1590
+ list: rightRel.listKey,
1591
+ foreignIdField: {
1592
+ kind: 'owned',
1593
+ map: typeof leftRel.field.foreignKey === 'object' ? (_leftRel$field$foreig2 = leftRel.field.foreignKey) === null || _leftRel$field$foreig2 === void 0 ? void 0 : _leftRel$field$foreig2.map : leftRel.fieldPath
1594
+ },
1595
+ relationName
1596
+ };
1597
+ resolvedLists[rightRel.listKey][rightRel.fieldPath] = {
1598
+ kind: 'relation',
1599
+ mode: 'many',
1600
+ extendPrismaSchema: rightRel.field.extendPrismaSchema,
1601
+ field: leftRel.fieldPath,
1602
+ list: leftRel.listKey,
1603
+ relationName
1604
+ };
1605
+ continue;
1606
+ }
1607
+ const foreignFieldPath = `from_${listKey}_${fieldPath}`;
1608
+ if (foreignUnresolvedList.fields[foreignFieldPath]) {
1609
+ throw new Error(`The relationship field at ${listKey}.${fieldPath} points to the list ${field.list}, Nixxie needs to a create a relationship field at ${field.list}.${foreignFieldPath} to support the relationship at ${listKey}.${fieldPath} but ${field.list} already has a field named ${foreignFieldPath}`);
1610
+ }
1611
+ if (field.mode === 'many') {
1612
+ var _field$relationName;
1613
+ const relationName = (_field$relationName = field.relationName) !== null && _field$relationName !== void 0 ? _field$relationName : `${listKey}_${fieldPath}`;
1614
+ resolvedLists[field.list][foreignFieldPath] = {
1615
+ kind: 'relation',
1616
+ mode: 'many',
1617
+ extendPrismaSchema: field.extendPrismaSchema,
1618
+ list: listKey,
1619
+ field: fieldPath,
1620
+ relationName
1621
+ };
1622
+ resolvedList[fieldPath] = {
1623
+ kind: 'relation',
1624
+ mode: 'many',
1625
+ extendPrismaSchema: field.extendPrismaSchema,
1626
+ list: field.list,
1627
+ field: foreignFieldPath,
1628
+ relationName
1629
+ };
1630
+ } else {
1631
+ var _field$foreignKey;
1632
+ const relationName = `${listKey}_${fieldPath}`;
1633
+ resolvedLists[field.list][foreignFieldPath] = {
1634
+ kind: 'relation',
1635
+ mode: 'many',
1636
+ extendPrismaSchema: field.extendPrismaSchema,
1637
+ list: listKey,
1638
+ field: fieldPath,
1639
+ relationName
1640
+ };
1641
+ resolvedList[fieldPath] = {
1642
+ kind: 'relation',
1643
+ list: field.list,
1644
+ extendPrismaSchema: field.extendPrismaSchema,
1645
+ field: foreignFieldPath,
1646
+ foreignIdField: {
1647
+ kind: 'owned',
1648
+ map: typeof field.foreignKey === 'object' ? (_field$foreignKey = field.foreignKey) === null || _field$foreignKey === void 0 ? void 0 : _field$foreignKey.map : fieldPath
1649
+ },
1650
+ relationName,
1651
+ mode: 'one'
1652
+ };
1653
+ }
1654
+ }
1655
+ }
1656
+
1657
+ // the way we resolve the relationships means that the relationships will be in a
1658
+ // different order than the order the user specified in their config
1659
+ // doesn't really change the behaviour of anything but it means that the order of the fields in the prisma schema will be
1660
+ // the same as the user provided
1661
+ return Object.fromEntries(Object.entries(resolvedLists).map(([listKey, outOfOrderDbFields]) => {
1662
+ // this adds the fields based on the order that the user passed in
1663
+ // (except it will not add the opposites to one-sided relations)
1664
+ const resolvedDbFields = Object.fromEntries(Object.keys(lists[listKey].fields).map(fieldKey => [fieldKey, outOfOrderDbFields[fieldKey]]));
1665
+ // then we add the opposites to one-sided relations
1666
+ Object.assign(resolvedDbFields, outOfOrderDbFields);
1667
+ return [listKey, resolvedDbFields];
1668
+ }));
1669
+ }
1670
+
1671
+ function printGraphQLType(type) {
1672
+ if (type instanceof graphql.GraphQLNonNull) return `${printGraphQLType(type.ofType)}!`;
1673
+ if (type instanceof graphql.GraphQLList) return `[${printGraphQLType(type.ofType)}]`;
1674
+ return type.name;
1675
+ }
1676
+ function getArgSources(action) {
1677
+ var _action$args;
1678
+ return Object.fromEntries(Object.entries((_action$args = action.args) !== null && _action$args !== void 0 ? _action$args : {}).flatMap(([arg, value]) => {
1679
+ var _value$ui;
1680
+ const field = (_value$ui = value.ui) === null || _value$ui === void 0 || (_value$ui = _value$ui.source) === null || _value$ui === void 0 ? void 0 : _value$ui.itemField;
1681
+ if (!field) return [];
1682
+ return [[arg, {
1683
+ itemField: field
1684
+ }]];
1685
+ }));
1686
+ }
1687
+ function throwIfNotAFilter(x, listKey, fieldKey) {
1688
+ if (['boolean', 'undefined', 'function'].includes(typeof x)) return;
1689
+ throw new Error(`Configuration option '${listKey}.${fieldKey}' must be either a boolean value or a function. Received '${x}'.`);
1690
+ }
1691
+ // TODO: move to defaultLists?
1692
+ function getIsEnabled(listKey, listConfig) {
1693
+ var _listConfig$graphql$o;
1694
+ const omit = (_listConfig$graphql$o = listConfig.graphql.omit) !== null && _listConfig$graphql$o !== void 0 ? _listConfig$graphql$o : false;
1695
+ const {
1696
+ defaultIsFilterable,
1697
+ defaultIsOrderable
1698
+ } = listConfig;
1699
+ throwIfNotAFilter(defaultIsFilterable, listKey, 'defaultIsFilterable');
1700
+ throwIfNotAFilter(defaultIsOrderable, listKey, 'defaultIsOrderable');
1701
+ if (typeof omit === 'boolean') {
1702
+ const notOmit = !omit;
1703
+ return {
1704
+ type: notOmit,
1705
+ query: notOmit,
1706
+ create: notOmit,
1707
+ update: notOmit,
1708
+ delete: notOmit,
1709
+ filter: notOmit ? defaultIsFilterable : false,
1710
+ orderBy: notOmit ? defaultIsOrderable : false
1711
+ };
1712
+ }
1713
+ return {
1714
+ type: true,
1715
+ query: !omit.query,
1716
+ create: !omit.create,
1717
+ update: !omit.update,
1718
+ delete: !omit.delete,
1719
+ filter: defaultIsFilterable,
1720
+ orderBy: defaultIsOrderable
1721
+ };
1722
+ }
1723
+ function getIsEnabledField(f, listKey, list, lists) {
1724
+ var _f$graphql$omit, _f$graphql;
1725
+ const omit = (_f$graphql$omit = (_f$graphql = f.graphql) === null || _f$graphql === void 0 ? void 0 : _f$graphql.omit) !== null && _f$graphql$omit !== void 0 ? _f$graphql$omit : false;
1726
+ const {
1727
+ isFilterable = list.graphql.isEnabled.filter,
1728
+ isOrderable = list.graphql.isEnabled.orderBy
1729
+ } = f;
1730
+
1731
+ // TODO: check types in initConfig
1732
+ throwIfNotAFilter(isFilterable, listKey, 'isFilterable');
1733
+ throwIfNotAFilter(isOrderable, listKey, 'isOrderable');
1734
+ if (f.dbField.kind === 'relation') {
1735
+ if (!lists[f.dbField.list].graphql.isEnabled.type) {
1736
+ return {
1737
+ type: false,
1738
+ read: false,
1739
+ create: false,
1740
+ update: false,
1741
+ filter: false,
1742
+ orderBy: false
1743
+ };
1744
+ }
1745
+ }
1746
+ if (typeof omit === 'boolean') {
1747
+ const notOmit = !omit;
1748
+ return {
1749
+ type: notOmit,
1750
+ read: notOmit,
1751
+ create: notOmit,
1752
+ update: notOmit,
1753
+ filter: notOmit ? isFilterable : false,
1754
+ orderBy: notOmit ? isOrderable : false
1755
+ };
1756
+ }
1757
+ return {
1758
+ type: true,
1759
+ read: !omit.read,
1760
+ create: !omit.create,
1761
+ update: !omit.update,
1762
+ filter: !omit.read ? isFilterable : false,
1763
+ // prevent filtering if read is false
1764
+ orderBy: !omit.read ? isOrderable : false // prevent ordering if read is false
1765
+ };
1766
+ }
1767
+ function defaultListHooksResolveInput({
1768
+ resolvedData
1769
+ }) {
1770
+ return resolvedData;
1771
+ }
1772
+ function parseListHooks(hooks) {
1773
+ var _hooks$resolveInput$c, _hooks$resolveInput, _hooks$resolveInput$u, _hooks$resolveInput2;
1774
+ return {
1775
+ resolveInput: {
1776
+ create: typeof hooks.resolveInput === 'function' ? hooks.resolveInput : (_hooks$resolveInput$c = (_hooks$resolveInput = hooks.resolveInput) === null || _hooks$resolveInput === void 0 ? void 0 : _hooks$resolveInput.create) !== null && _hooks$resolveInput$c !== void 0 ? _hooks$resolveInput$c : defaultListHooksResolveInput,
1777
+ update: typeof hooks.resolveInput === 'function' ? hooks.resolveInput : (_hooks$resolveInput$u = (_hooks$resolveInput2 = hooks.resolveInput) === null || _hooks$resolveInput2 === void 0 ? void 0 : _hooks$resolveInput2.update) !== null && _hooks$resolveInput$u !== void 0 ? _hooks$resolveInput$u : defaultListHooksResolveInput
1778
+ },
1779
+ validate: resolveHooks.expandVoidHooks(hooks.validate),
1780
+ beforeOperation: resolveHooks.expandVoidHooks(hooks.beforeOperation),
1781
+ afterOperation: resolveHooks.expandVoidHooks(hooks.afterOperation)
1782
+ };
1783
+ }
1784
+ function defaultFieldHooksResolveInput({
1785
+ resolvedData,
1786
+ fieldKey
1787
+ }) {
1788
+ return resolvedData[fieldKey];
1789
+ }
1790
+ function parseFieldHooks(hooks) {
1791
+ var _hooks$resolveInput$c2, _hooks$resolveInput3, _hooks$resolveInput$u2, _hooks$resolveInput4;
1792
+ return {
1793
+ resolveInput: {
1794
+ create: typeof hooks.resolveInput === 'function' ? hooks.resolveInput : (_hooks$resolveInput$c2 = (_hooks$resolveInput3 = hooks.resolveInput) === null || _hooks$resolveInput3 === void 0 ? void 0 : _hooks$resolveInput3.create) !== null && _hooks$resolveInput$c2 !== void 0 ? _hooks$resolveInput$c2 : defaultFieldHooksResolveInput,
1795
+ update: typeof hooks.resolveInput === 'function' ? hooks.resolveInput : (_hooks$resolveInput$u2 = (_hooks$resolveInput4 = hooks.resolveInput) === null || _hooks$resolveInput4 === void 0 ? void 0 : _hooks$resolveInput4.update) !== null && _hooks$resolveInput$u2 !== void 0 ? _hooks$resolveInput$u2 : defaultFieldHooksResolveInput
1796
+ },
1797
+ validate: resolveHooks.expandVoidHooks(hooks.validate),
1798
+ beforeOperation: resolveHooks.expandVoidHooks(hooks.beforeOperation),
1799
+ afterOperation: resolveHooks.expandVoidHooks(hooks.afterOperation)
1800
+ };
1801
+ }
1802
+ function getListsWithInitialisedFields(config, listsRef) {
1803
+ const {
1804
+ lists: listsConfig,
1805
+ db: {
1806
+ provider
1807
+ }
1808
+ } = config;
1809
+ const intermediateLists = Object.fromEntries(Object.values(config.lists).map(listConfig => [listConfig.listKey, {
1810
+ graphql: {
1811
+ isEnabled: getIsEnabled(listConfig.listKey, listConfig)
1812
+ }
1813
+ }]));
1814
+ const listGraphqlTypes = {};
1815
+ for (const listConfig of Object.values(listsConfig)) {
1816
+ var _listConfig$graphql;
1817
+ const {
1818
+ listKey
1819
+ } = listConfig;
1820
+ const {
1821
+ graphql: {
1822
+ names
1823
+ }
1824
+ } = utils$1.__getNames(listKey, listConfig);
1825
+ const output = nextFields.g.object()({
1826
+ name: names.outputTypeName,
1827
+ fields: () => {
1828
+ const {
1829
+ fields
1830
+ } = listsRef[listKey];
1831
+ return {
1832
+ ...Object.fromEntries(Object.entries(fields).flatMap(([fieldPath, field]) => {
1833
+ if (!field.output || !field.graphql.isEnabled.read || field.dbField.kind === 'relation' && !intermediateLists[field.dbField.list].graphql.isEnabled.query) {
1834
+ return [];
1835
+ }
1836
+ const outputFieldRoot = graphqlForOutputField(field);
1837
+ return [[fieldPath, outputFieldRoot], ...Object.entries(field.extraOutputFields || {})].map(([outputTypeFieldName, outputField]) => {
1838
+ var _field$graphql;
1839
+ return [outputTypeFieldName, outputTypeField(outputField, field.dbField, (_field$graphql = field.graphql) === null || _field$graphql === void 0 ? void 0 : _field$graphql.cacheHint, field.access.read, listKey, fieldPath, listsRef)];
1840
+ });
1841
+ }))
1842
+ };
1843
+ }
1844
+ });
1845
+ const uniqueWhere = nextFields.g.inputObject({
1846
+ name: names.whereUniqueInputName,
1847
+ fields: () => {
1848
+ const {
1849
+ fields
1850
+ } = listsRef[listKey];
1851
+ return {
1852
+ ...Object.fromEntries(Object.entries(fields).flatMap(([key, field]) => {
1853
+ var _field$input;
1854
+ if (!((_field$input = field.input) !== null && _field$input !== void 0 && (_field$input = _field$input.uniqueWhere) !== null && _field$input !== void 0 && _field$input.arg) || !field.graphql.isEnabled.read || !field.graphql.isEnabled.filter) {
1855
+ return [];
1856
+ }
1857
+
1858
+ // only 1-to-1 relationships can have a uniqueWhere filter on relations
1859
+ if (field.dbField.kind === 'relation') {
1860
+ const remoteField = listsRef[field.dbField.list].resolvedDbFields[field.dbField.field];
1861
+ if (field.dbField.mode === 'one' && remoteField.kind === 'relation' && remoteField.mode === 'one') {
1862
+ return [[key, field.input.uniqueWhere.arg]];
1863
+ }
1864
+ return [];
1865
+ }
1866
+ return [[key, field.input.uniqueWhere.arg]];
1867
+ })),
1868
+ // this is exactly what the id field will add
1869
+ // but this does it more explicitly so that typescript understands
1870
+ id: nextFields.g.arg({
1871
+ type: nextFields.g.ID
1872
+ })
1873
+ };
1874
+ }
1875
+ });
1876
+ const where = nextFields.g.inputObject({
1877
+ name: names.whereInputName,
1878
+ fields: () => {
1879
+ const {
1880
+ fields
1881
+ } = listsRef[listKey];
1882
+ return Object.assign({
1883
+ AND: nextFields.g.arg({
1884
+ type: nextFields.g.list(nextFields.g.nonNull(where))
1885
+ }),
1886
+ OR: nextFields.g.arg({
1887
+ type: nextFields.g.list(nextFields.g.nonNull(where))
1888
+ }),
1889
+ NOT: nextFields.g.arg({
1890
+ type: nextFields.g.list(nextFields.g.nonNull(where))
1891
+ })
1892
+ }, ...Object.entries(fields).map(([fieldKey, field]) => {
1893
+ var _field$input2, _field$input3;
1894
+ return ((_field$input2 = field.input) === null || _field$input2 === void 0 || (_field$input2 = _field$input2.where) === null || _field$input2 === void 0 ? void 0 : _field$input2.arg) && field.graphql.isEnabled.read && field.graphql.isEnabled.filter && {
1895
+ [fieldKey]: (_field$input3 = field.input) === null || _field$input3 === void 0 || (_field$input3 = _field$input3.where) === null || _field$input3 === void 0 ? void 0 : _field$input3.arg
1896
+ };
1897
+ }));
1898
+ }
1899
+ });
1900
+ const create = nextFields.g.inputObject({
1901
+ name: names.createInputName,
1902
+ fields: () => {
1903
+ const {
1904
+ fields
1905
+ } = listsRef[listKey];
1906
+ const ret = {};
1907
+ for (const key in fields) {
1908
+ const arg = graphqlArgForInputField(fields[key], 'create', listsRef);
1909
+ if (!arg) continue;
1910
+ ret[key] = arg;
1911
+ }
1912
+ return ret;
1913
+ }
1914
+ });
1915
+ const update = nextFields.g.inputObject({
1916
+ name: names.updateInputName,
1917
+ fields: () => {
1918
+ const {
1919
+ fields
1920
+ } = listsRef[listKey];
1921
+ const ret = {};
1922
+ for (const key in fields) {
1923
+ const arg = graphqlArgForInputField(fields[key], 'update', listsRef);
1924
+ if (!arg) continue;
1925
+ ret[key] = arg;
1926
+ }
1927
+ return ret;
1928
+ }
1929
+ });
1930
+ const orderBy = nextFields.g.inputObject({
1931
+ name: names.listOrderName,
1932
+ fields: () => {
1933
+ const {
1934
+ fields
1935
+ } = listsRef[listKey];
1936
+ return Object.fromEntries(Object.entries(fields).flatMap(([key, field]) => {
1937
+ var _field$input4;
1938
+ if (!((_field$input4 = field.input) !== null && _field$input4 !== void 0 && (_field$input4 = _field$input4.orderBy) !== null && _field$input4 !== void 0 && _field$input4.arg) || !field.graphql.isEnabled.read || !field.graphql.isEnabled.orderBy) {
1939
+ return [];
1940
+ }
1941
+ return [[key, field.input.orderBy.arg]];
1942
+ }));
1943
+ }
1944
+ });
1945
+ let take = nextFields.g.arg({
1946
+ type: nextFields.g.Int
1947
+ });
1948
+ if (((_listConfig$graphql = listConfig.graphql) === null || _listConfig$graphql === void 0 ? void 0 : _listConfig$graphql.maxTake) !== undefined) {
1949
+ take = nextFields.g.arg({
1950
+ type: nextFields.g.nonNull(nextFields.g.Int),
1951
+ // WARNING: used by queries/resolvers.ts to enforce the limit
1952
+ defaultValue: listConfig.graphql.maxTake
1953
+ });
1954
+ }
1955
+ const findManyArgs = {
1956
+ where: nextFields.g.arg({
1957
+ type: nextFields.g.nonNull(where),
1958
+ defaultValue: listConfig.isSingleton ? {
1959
+ id: {
1960
+ equals: '1'
1961
+ }
1962
+ } : {}
1963
+ }),
1964
+ orderBy: nextFields.g.arg({
1965
+ type: nextFields.g.nonNull(nextFields.g.list(nextFields.g.nonNull(orderBy))),
1966
+ defaultValue: []
1967
+ }),
1968
+ take,
1969
+ skip: nextFields.g.arg({
1970
+ type: nextFields.g.nonNull(nextFields.g.Int),
1971
+ defaultValue: 0
1972
+ }),
1973
+ cursor: nextFields.g.arg({
1974
+ type: uniqueWhere
1975
+ })
1976
+ };
1977
+ const relateToOneForCreate = nextFields.g.inputObject({
1978
+ name: names.relateToOneForCreateInputName,
1979
+ fields: () => {
1980
+ const listRef = listsRef[listKey];
1981
+ return {
1982
+ ...(listRef.graphql.isEnabled.create && {
1983
+ create: nextFields.g.arg({
1984
+ type: listRef.graphql.types.create
1985
+ })
1986
+ }),
1987
+ connect: nextFields.g.arg({
1988
+ type: listRef.graphql.types.uniqueWhere
1989
+ })
1990
+ };
1991
+ }
1992
+ });
1993
+ const relateToOneForUpdate = nextFields.g.inputObject({
1994
+ name: names.relateToOneForUpdateInputName,
1995
+ fields: () => {
1996
+ const listRef = listsRef[listKey];
1997
+ return {
1998
+ ...(listRef.graphql.isEnabled.create && {
1999
+ create: nextFields.g.arg({
2000
+ type: listRef.graphql.types.create
2001
+ })
2002
+ }),
2003
+ connect: nextFields.g.arg({
2004
+ type: listRef.graphql.types.uniqueWhere
2005
+ }),
2006
+ disconnect: nextFields.g.arg({
2007
+ type: nextFields.g.Boolean
2008
+ })
2009
+ };
2010
+ }
2011
+ });
2012
+ const relateToManyForCreate = nextFields.g.inputObject({
2013
+ name: names.relateToManyForCreateInputName,
2014
+ fields: () => {
2015
+ const listRef = listsRef[listKey];
2016
+ return {
2017
+ ...(listRef.graphql.isEnabled.create && {
2018
+ create: nextFields.g.arg({
2019
+ type: nextFields.g.list(nextFields.g.nonNull(listRef.graphql.types.create))
2020
+ })
2021
+ }),
2022
+ connect: nextFields.g.arg({
2023
+ type: nextFields.g.list(nextFields.g.nonNull(listRef.graphql.types.uniqueWhere))
2024
+ }),
2025
+ set: nextFields.g.arg({
2026
+ type: nextFields.g.list(nextFields.g.nonNull(listRef.graphql.types.uniqueWhere))
2027
+ })
2028
+ };
2029
+ }
2030
+ });
2031
+ const relateToManyForUpdate = nextFields.g.inputObject({
2032
+ name: names.relateToManyForUpdateInputName,
2033
+ fields: () => {
2034
+ const listRef = listsRef[listKey];
2035
+ return {
2036
+ // WARNING: the order of these fields reflects the order of mutations
2037
+ disconnect: nextFields.g.arg({
2038
+ type: nextFields.g.list(nextFields.g.nonNull(listRef.graphql.types.uniqueWhere))
2039
+ }),
2040
+ set: nextFields.g.arg({
2041
+ type: nextFields.g.list(nextFields.g.nonNull(listRef.graphql.types.uniqueWhere))
2042
+ }),
2043
+ ...(listRef.graphql.isEnabled.create && {
2044
+ create: nextFields.g.arg({
2045
+ type: nextFields.g.list(nextFields.g.nonNull(listRef.graphql.types.create))
2046
+ })
2047
+ }),
2048
+ connect: nextFields.g.arg({
2049
+ type: nextFields.g.list(nextFields.g.nonNull(listRef.graphql.types.uniqueWhere))
2050
+ })
2051
+ };
2052
+ }
2053
+ });
2054
+ listGraphqlTypes[listKey] = {
2055
+ types: {
2056
+ output,
2057
+ uniqueWhere,
2058
+ where,
2059
+ create,
2060
+ orderBy,
2061
+ update,
2062
+ findManyArgs,
2063
+ relateTo: {
2064
+ one: {
2065
+ create: relateToOneForCreate,
2066
+ update: relateToOneForUpdate
2067
+ },
2068
+ many: {
2069
+ where: nextFields.g.inputObject({
2070
+ name: `${listKey}ManyRelationFilter`,
2071
+ fields: {
2072
+ every: nextFields.g.arg({
2073
+ type: where
2074
+ }),
2075
+ some: nextFields.g.arg({
2076
+ type: where
2077
+ }),
2078
+ none: nextFields.g.arg({
2079
+ type: where
2080
+ })
2081
+ }
2082
+ }),
2083
+ create: relateToManyForCreate,
2084
+ update: relateToManyForUpdate
2085
+ }
2086
+ }
2087
+ }
2088
+ };
2089
+ }
2090
+ const result = {};
2091
+ for (const listConfig of Object.values(listsConfig)) {
2092
+ var _listConfig$ui$labelF, _listConfig$ui$search, _listConfig$hooks, _listConfig$isSinglet;
2093
+ const {
2094
+ listKey
2095
+ } = listConfig;
2096
+ const intermediateList = intermediateLists[listKey];
2097
+ const resultFields = {};
2098
+ const groups = [];
2099
+ const fieldKeys = Object.keys(listConfig.fields);
2100
+ const fieldKeysToGroup = {};
2101
+ for (const [idx, [fieldKey, fieldFunc]] of Object.entries(listConfig.fields).entries()) {
2102
+ var _f$hooks, _f$graphql2, _f$graphql3, _f$graphql$isNonNull$, _f$graphql4, _f$graphql5, _f$graphql$isNonNull$2, _f$graphql6, _f$graphql7, _f$graphql$isNonNull$3, _f$graphql8, _f$ui, _f$ui$description, _f$ui2, _f$ui$views, _f$ui3, _f$ui$createView$isRe, _f$ui4, _ref, _ref2, _f$ui$createView$fiel, _f$ui5, _group$ui, _listConfig$ui$create, _f$ui$itemView$isRequ, _f$ui6, _f$ui$itemView$fieldP, _f$ui7, _ref3, _ref4, _f$ui$itemView$fieldM, _f$ui8, _group$ui2, _listConfig$ui$itemVi, _ref5, _ref6, _f$ui$itemView$fieldM2, _f$ui9, _group$ui3, _listConfig$ui$itemVi2, _ref7, _ref8, _f$ui$listView$fieldM, _f$ui0, _group$ui4, _listConfig$ui$listVi;
2103
+ if (fieldKey.startsWith('__group')) {
2104
+ const group__ = fieldFunc;
2105
+ if (typeof group__ === 'object' && group__ !== null && typeof group__.label === 'string' && (group__.description === null || typeof group__.description === 'string') && Array.isArray(group__.fields) && utils.areArraysEqual(group__.fields, fieldKeys.slice(idx + 1, idx + 1 + group__.fields.length))) {
2106
+ groups.push(group__);
2107
+ for (const field of group__.fields) {
2108
+ fieldKeysToGroup[field] = group__;
2109
+ }
2110
+ continue;
2111
+ }
2112
+ throw new Error(`unexpected value for a group at ${listKey}.${fieldKey}`);
2113
+ }
2114
+ if (typeof fieldFunc !== 'function') {
2115
+ throw new Error(`The field at ${listKey}.${fieldKey} does not provide a function`);
2116
+ }
2117
+ const group = fieldKeysToGroup[fieldKey];
2118
+ const f = fieldFunc({
2119
+ provider,
2120
+ lists: listGraphqlTypes,
2121
+ listKey,
2122
+ fieldKey
2123
+ });
2124
+ const isEnabledField = getIsEnabledField(f, listKey, intermediateList, intermediateLists);
2125
+ resultFields[fieldKey] = {
2126
+ fieldKey,
2127
+ dbField: f.dbField,
2128
+ access: parseFieldAccessControl(f.access),
2129
+ hooks: parseFieldHooks((_f$hooks = f.hooks) !== null && _f$hooks !== void 0 ? _f$hooks : {}),
2130
+ graphql: {
2131
+ cacheHint: (_f$graphql2 = f.graphql) === null || _f$graphql2 === void 0 ? void 0 : _f$graphql2.cacheHint,
2132
+ isEnabled: isEnabledField,
2133
+ isNonNull: {
2134
+ read: typeof ((_f$graphql3 = f.graphql) === null || _f$graphql3 === void 0 ? void 0 : _f$graphql3.isNonNull) === 'boolean' ? f.graphql.isNonNull : (_f$graphql$isNonNull$ = (_f$graphql4 = f.graphql) === null || _f$graphql4 === void 0 || (_f$graphql4 = _f$graphql4.isNonNull) === null || _f$graphql4 === void 0 ? void 0 : _f$graphql4.read) !== null && _f$graphql$isNonNull$ !== void 0 ? _f$graphql$isNonNull$ : false,
2135
+ create: typeof ((_f$graphql5 = f.graphql) === null || _f$graphql5 === void 0 ? void 0 : _f$graphql5.isNonNull) === 'boolean' ? f.graphql.isNonNull : (_f$graphql$isNonNull$2 = (_f$graphql6 = f.graphql) === null || _f$graphql6 === void 0 || (_f$graphql6 = _f$graphql6.isNonNull) === null || _f$graphql6 === void 0 ? void 0 : _f$graphql6.create) !== null && _f$graphql$isNonNull$2 !== void 0 ? _f$graphql$isNonNull$2 : false,
2136
+ update: typeof ((_f$graphql7 = f.graphql) === null || _f$graphql7 === void 0 ? void 0 : _f$graphql7.isNonNull) === 'boolean' ? f.graphql.isNonNull : (_f$graphql$isNonNull$3 = (_f$graphql8 = f.graphql) === null || _f$graphql8 === void 0 || (_f$graphql8 = _f$graphql8.isNonNull) === null || _f$graphql8 === void 0 ? void 0 : _f$graphql8.update) !== null && _f$graphql$isNonNull$3 !== void 0 ? _f$graphql$isNonNull$3 : false
2137
+ }
2138
+ },
2139
+ ui: {
2140
+ label: ((_f$ui = f.ui) === null || _f$ui === void 0 ? void 0 : _f$ui.label) || utils$2.humanize(fieldKey),
2141
+ description: (_f$ui$description = (_f$ui2 = f.ui) === null || _f$ui2 === void 0 ? void 0 : _f$ui2.description) !== null && _f$ui$description !== void 0 ? _f$ui$description : '',
2142
+ views: (_f$ui$views = (_f$ui3 = f.ui) === null || _f$ui3 === void 0 ? void 0 : _f$ui3.views) !== null && _f$ui$views !== void 0 ? _f$ui$views : null,
2143
+ createView: {
2144
+ isRequired: (_f$ui$createView$isRe = (_f$ui4 = f.ui) === null || _f$ui4 === void 0 || (_f$ui4 = _f$ui4.createView) === null || _f$ui4 === void 0 ? void 0 : _f$ui4.isRequired) !== null && _f$ui$createView$isRe !== void 0 ? _f$ui$createView$isRe : false,
2145
+ fieldMode: isEnabledField.create ? (_ref = (_ref2 = (_f$ui$createView$fiel = (_f$ui5 = f.ui) === null || _f$ui5 === void 0 || (_f$ui5 = _f$ui5.createView) === null || _f$ui5 === void 0 ? void 0 : _f$ui5.fieldMode) !== null && _f$ui$createView$fiel !== void 0 ? _f$ui$createView$fiel : group === null || group === void 0 || (_group$ui = group.ui) === null || _group$ui === void 0 || (_group$ui = _group$ui.createView) === null || _group$ui === void 0 ? void 0 : _group$ui.defaultFieldMode) !== null && _ref2 !== void 0 ? _ref2 : (_listConfig$ui$create = listConfig.ui.createView) === null || _listConfig$ui$create === void 0 ? void 0 : _listConfig$ui$create.defaultFieldMode) !== null && _ref !== void 0 ? _ref : 'edit' : 'hidden'
2146
+ },
2147
+ itemView: {
2148
+ isRequired: (_f$ui$itemView$isRequ = (_f$ui6 = f.ui) === null || _f$ui6 === void 0 || (_f$ui6 = _f$ui6.itemView) === null || _f$ui6 === void 0 ? void 0 : _f$ui6.isRequired) !== null && _f$ui$itemView$isRequ !== void 0 ? _f$ui$itemView$isRequ : false,
2149
+ fieldPosition: (_f$ui$itemView$fieldP = (_f$ui7 = f.ui) === null || _f$ui7 === void 0 || (_f$ui7 = _f$ui7.itemView) === null || _f$ui7 === void 0 ? void 0 : _f$ui7.fieldPosition) !== null && _f$ui$itemView$fieldP !== void 0 ? _f$ui$itemView$fieldP : 'form',
2150
+ fieldMode: isEnabledField.update ? (_ref3 = (_ref4 = (_f$ui$itemView$fieldM = (_f$ui8 = f.ui) === null || _f$ui8 === void 0 || (_f$ui8 = _f$ui8.itemView) === null || _f$ui8 === void 0 ? void 0 : _f$ui8.fieldMode) !== null && _f$ui$itemView$fieldM !== void 0 ? _f$ui$itemView$fieldM : group === null || group === void 0 || (_group$ui2 = group.ui) === null || _group$ui2 === void 0 || (_group$ui2 = _group$ui2.itemView) === null || _group$ui2 === void 0 ? void 0 : _group$ui2.defaultFieldMode) !== null && _ref4 !== void 0 ? _ref4 : (_listConfig$ui$itemVi = listConfig.ui.itemView) === null || _listConfig$ui$itemVi === void 0 ? void 0 : _listConfig$ui$itemVi.defaultFieldMode) !== null && _ref3 !== void 0 ? _ref3 : 'edit' : isEnabledField.read ? (_ref5 = (_ref6 = (_f$ui$itemView$fieldM2 = (_f$ui9 = f.ui) === null || _f$ui9 === void 0 || (_f$ui9 = _f$ui9.itemView) === null || _f$ui9 === void 0 ? void 0 : _f$ui9.fieldMode) !== null && _f$ui$itemView$fieldM2 !== void 0 ? _f$ui$itemView$fieldM2 : group === null || group === void 0 || (_group$ui3 = group.ui) === null || _group$ui3 === void 0 || (_group$ui3 = _group$ui3.itemView) === null || _group$ui3 === void 0 ? void 0 : _group$ui3.defaultFieldMode) !== null && _ref6 !== void 0 ? _ref6 : (_listConfig$ui$itemVi2 = listConfig.ui.itemView) === null || _listConfig$ui$itemVi2 === void 0 ? void 0 : _listConfig$ui$itemVi2.defaultFieldMode) !== null && _ref5 !== void 0 ? _ref5 : 'read' : 'hidden'
2151
+ },
2152
+ listView: {
2153
+ fieldMode: isEnabledField.read ? (_ref7 = (_ref8 = (_f$ui$listView$fieldM = (_f$ui0 = f.ui) === null || _f$ui0 === void 0 || (_f$ui0 = _f$ui0.listView) === null || _f$ui0 === void 0 ? void 0 : _f$ui0.fieldMode) !== null && _f$ui$listView$fieldM !== void 0 ? _f$ui$listView$fieldM : group === null || group === void 0 || (_group$ui4 = group.ui) === null || _group$ui4 === void 0 || (_group$ui4 = _group$ui4.listView) === null || _group$ui4 === void 0 ? void 0 : _group$ui4.defaultFieldMode) !== null && _ref8 !== void 0 ? _ref8 : (_listConfig$ui$listVi = listConfig.ui.listView) === null || _listConfig$ui$listVi === void 0 ? void 0 : _listConfig$ui$listVi.defaultFieldMode) !== null && _ref7 !== void 0 ? _ref7 : 'read' : 'hidden'
2154
+ }
2155
+ },
2156
+ // copy
2157
+ __ksTelemetryFieldTypeName: f.__ksTelemetryFieldTypeName,
2158
+ extraOutputFields: f.extraOutputFields,
2159
+ getAdminMeta: f.getAdminMeta,
2160
+ input: {
2161
+ ...f.input
2162
+ },
2163
+ output: {
2164
+ ...f.output
2165
+ },
2166
+ unreferencedConcreteInterfaceImplementations: f.unreferencedConcreteInterfaceImplementations,
2167
+ views: f.views
2168
+ };
2169
+ }
2170
+
2171
+ // default labelField to `name`, `label`, or `title`; fallback to `id`
2172
+ const labelField = (_listConfig$ui$labelF = listConfig.ui.labelField) !== null && _listConfig$ui$labelF !== void 0 ? _listConfig$ui$labelF : listConfig.fields.label ? 'label' : listConfig.fields.name ? 'name' : listConfig.fields.title ? 'title' : 'id';
2173
+ const searchFields = new Set((_listConfig$ui$search = listConfig.ui.searchFields) !== null && _listConfig$ui$search !== void 0 ? _listConfig$ui$search : []);
2174
+ if (searchFields.has('id')) {
2175
+ throw new Error(`${listKey}.ui.searchFields cannot include 'id'`);
2176
+ }
2177
+ const names = utils$1.__getNames(listKey, listConfig);
2178
+ result[listKey] = {
2179
+ access: parseListAccessControl(listConfig.access),
2180
+ fields: resultFields,
2181
+ groups,
2182
+ actions: [],
2183
+ graphql: {
2184
+ types: {
2185
+ ...listGraphqlTypes[listKey].types
2186
+ },
2187
+ names: {
2188
+ ...names.graphql.names
2189
+ },
2190
+ ...intermediateList.graphql
2191
+ },
2192
+ prisma: {
2193
+ types: {
2194
+ ...names.graphql.names
2195
+ },
2196
+ listKey: listKey[0].toLowerCase() + listKey.slice(1),
2197
+ mapping: listConfig.db.map,
2198
+ extendPrismaSchema: listConfig.db.extendPrismaSchema
2199
+ },
2200
+ ui: {
2201
+ labels: names.ui.labels,
2202
+ labelField,
2203
+ searchFields,
2204
+ searchableFields: new Map(),
2205
+ triviallySearchableFields: new Set()
2206
+ },
2207
+ hooks: parseListHooks((_listConfig$hooks = listConfig.hooks) !== null && _listConfig$hooks !== void 0 ? _listConfig$hooks : {}),
2208
+ listKey,
2209
+ cacheHint: (() => {
2210
+ const cacheHint = listConfig.graphql.cacheHint;
2211
+ if (typeof cacheHint === 'function') return cacheHint;
2212
+ if (cacheHint !== undefined) return () => cacheHint;
2213
+ return undefined;
2214
+ })(),
2215
+ isSingleton: (_listConfig$isSinglet = listConfig.isSingleton) !== null && _listConfig$isSinglet !== void 0 ? _listConfig$isSinglet : false
2216
+ };
2217
+ }
2218
+ return result;
2219
+ }
2220
+ function introspectGraphQLTypes(lists) {
2221
+ const namesOfRelationInputs = new Set();
2222
+ for (const list of Object.values(lists)) {
2223
+ const {
2224
+ types
2225
+ } = list.graphql;
2226
+ namesOfRelationInputs.add(types.where.name);
2227
+ namesOfRelationInputs.add(types.relateTo.many.where.name);
2228
+ }
2229
+ for (const list of Object.values(lists)) {
2230
+ const {
2231
+ listKey,
2232
+ ui: {
2233
+ searchFields,
2234
+ searchableFields,
2235
+ triviallySearchableFields
2236
+ }
2237
+ } = list;
2238
+ if (searchFields.has('id')) {
2239
+ throw new Error(`The ui.searchFields option on the ${listKey} list includes 'id'. Lists can always be searched by an item's id so it must not be specified as a search field`);
2240
+ }
2241
+ const whereInputFields = list.graphql.types.where.getFields();
2242
+ for (const [fieldKey, field] of Object.entries(list.fields)) {
2243
+ var _whereInputFields$fie, _fieldFilterFields$co;
2244
+ const filterType = (_whereInputFields$fie = whereInputFields[fieldKey]) === null || _whereInputFields$fie === void 0 ? void 0 : _whereInputFields$fie.type;
2245
+ const fieldFilterFields = graphql.isInputObjectType(filterType) ? filterType.getFields() : undefined;
2246
+ const filterTypeName = graphql.isInputObjectType(filterType) ? filterType.name : undefined;
2247
+ if ((fieldFilterFields === null || fieldFilterFields === void 0 || (_fieldFilterFields$co = fieldFilterFields.contains) === null || _fieldFilterFields$co === void 0 ? void 0 : _fieldFilterFields$co.type) === graphql.GraphQLString) {
2248
+ var _fieldFilterFields$mo;
2249
+ searchableFields.set(fieldKey, (fieldFilterFields === null || fieldFilterFields === void 0 || (_fieldFilterFields$mo = fieldFilterFields.mode) === null || _fieldFilterFields$mo === void 0 ? void 0 : _fieldFilterFields$mo.type) === nextFields.QueryMode ? 'insensitive' : 'default');
2250
+ triviallySearchableFields.add(fieldKey);
2251
+ } else if (field.dbField.kind === 'relation' && filterTypeName !== undefined && namesOfRelationInputs.has(filterTypeName)) {
2252
+ searchableFields.set(fieldKey, 'default');
2253
+ }
2254
+ }
2255
+ if (searchFields.size === 0) {
2256
+ if (searchableFields.has(list.ui.labelField)) {
2257
+ searchFields.add(list.ui.labelField);
2258
+ }
2259
+ }
2260
+ }
2261
+ }
2262
+ function stripDefaultValue(thing) {
2263
+ return nextFields.g.arg({
2264
+ ...thing,
2265
+ defaultValue: undefined
2266
+ });
2267
+ }
2268
+ function graphqlArgForInputField(field, operation, listsRef) {
2269
+ var _field$input5;
2270
+ const input = (_field$input5 = field.input) === null || _field$input5 === void 0 ? void 0 : _field$input5[operation];
2271
+ if (!(input !== null && input !== void 0 && input.arg) || !field.graphql.isEnabled[operation]) return;
2272
+ if (field.dbField.kind === 'relation') {
2273
+ if (!listsRef[field.dbField.list].graphql.isEnabled.type) return;
2274
+ }
2275
+ if (!field.graphql.isNonNull[operation]) return stripDefaultValue(input.arg);
2276
+ if (input.arg.type instanceof schema.GNonNull) return input.arg;
2277
+ return nextFields.g.arg({
2278
+ ...input.arg,
2279
+ type: nextFields.g.nonNull(input.arg.type)
2280
+ });
2281
+ }
2282
+ function graphqlForOutputField(field) {
2283
+ const output = field.output;
2284
+ if (!output || !field.graphql.isEnabled.read) return output;
2285
+ if (!field.graphql.isNonNull.read) return output;
2286
+ if (output.type instanceof schema.GNonNull) return output;
2287
+ return nextFields.g.field({
2288
+ ...output,
2289
+ type: nextFields.g.nonNull(output.type)
2290
+ });
2291
+ }
2292
+ function getInitialisedActionGraphql(list, listGraphqlNames, actionKey, action) {
2293
+ var _action$graphql$singu, _action$graphql, _action$graphql$plura, _action$graphql2, _action$args2;
2294
+ const graphqlNames = {
2295
+ one: (_action$graphql$singu = (_action$graphql = action.graphql) === null || _action$graphql === void 0 ? void 0 : _action$graphql.singular) !== null && _action$graphql$singu !== void 0 ? _action$graphql$singu : `${actionKey}${listGraphqlNames.singular}`,
2296
+ many: (_action$graphql$plura = (_action$graphql2 = action.graphql) === null || _action$graphql2 === void 0 ? void 0 : _action$graphql2.plural) !== null && _action$graphql$plura !== void 0 ? _action$graphql$plura : `${actionKey}${listGraphqlNames.plural}`
2297
+ };
2298
+ const argsName = `${graphqlNames.one[0].toUpperCase()}${graphqlNames.one.slice(1)}Args`;
2299
+ const argumentFields = Object.fromEntries(Object.entries((_action$args2 = action.args) !== null && _action$args2 !== void 0 ? _action$args2 : {}).map(([arg, value]) => [arg, value.graphql]));
2300
+ return {
2301
+ arguments: Object.entries(argumentFields).map(([name, arg]) => {
2302
+ var _getArgSources$name;
2303
+ return {
2304
+ name,
2305
+ type: printGraphQLType(arg.type),
2306
+ source: (_getArgSources$name = getArgSources(action)[name]) !== null && _getArgSources$name !== void 0 ? _getArgSources$name : null
2307
+ };
2308
+ }),
2309
+ names: {
2310
+ ...graphqlNames,
2311
+ args: argsName
2312
+ },
2313
+ types: {
2314
+ arguments: argumentFields,
2315
+ args: nextFields.g.inputObject({
2316
+ name: argsName,
2317
+ isOneOf: false,
2318
+ fields: {
2319
+ where: nextFields.g.arg({
2320
+ type: nextFields.g.nonNull(list.graphql.types.uniqueWhere)
2321
+ }),
2322
+ ...argumentFields
2323
+ }
2324
+ })
2325
+ }
2326
+ };
2327
+ }
2328
+ function initialiseLists(config) {
2329
+ const listsRef = {};
2330
+ let intermediateLists;
2331
+
2332
+ // step 1
2333
+ intermediateLists = getListsWithInitialisedFields(config, listsRef);
2334
+
2335
+ // step 2
2336
+ const resolvedDBFieldsForLists = resolveRelationships(intermediateLists);
2337
+ intermediateLists = Object.fromEntries(Object.values(intermediateLists).map(list => [list.listKey, {
2338
+ ...list,
2339
+ resolvedDbFields: resolvedDBFieldsForLists[list.listKey]
2340
+ }]));
2341
+
2342
+ // step 3
2343
+ intermediateLists = Object.fromEntries(Object.values(intermediateLists).map(list => {
2344
+ const fields = {};
2345
+ for (const [fieldKey, field] of Object.entries(list.fields)) {
2346
+ fields[fieldKey] = {
2347
+ ...field,
2348
+ dbField: list.resolvedDbFields[fieldKey]
2349
+ };
2350
+ }
2351
+ return [list.listKey, {
2352
+ ...list,
2353
+ fields
2354
+ }];
2355
+ }));
2356
+
2357
+ // fixup the GraphQL refs
2358
+ for (const list of Object.values(intermediateLists)) {
2359
+ listsRef[list.listKey] = {
2360
+ ...list,
2361
+ lists: listsRef
2362
+ };
2363
+ }
2364
+ for (const list of Object.values(listsRef)) {
2365
+ var _listConfig$actions;
2366
+ const listConfig = config.lists[list.listKey];
2367
+ let hasAnEnabledCreateField = false;
2368
+ let hasAnEnabledUpdateField = false;
2369
+ for (const field of Object.values(list.fields)) {
2370
+ var _field$input6, _field$input7;
2371
+ if ((_field$input6 = field.input) !== null && _field$input6 !== void 0 && (_field$input6 = _field$input6.create) !== null && _field$input6 !== void 0 && _field$input6.arg && field.graphql.isEnabled.create) {
2372
+ hasAnEnabledCreateField = true;
2373
+ }
2374
+ if ((_field$input7 = field.input) !== null && _field$input7 !== void 0 && _field$input7.update && field.graphql.isEnabled.update) {
2375
+ hasAnEnabledUpdateField = true;
2376
+ }
2377
+ }
2378
+ if (!hasAnEnabledCreateField) {
2379
+ list.graphql.types.create = nextFields.g.Empty;
2380
+ list.graphql.names.createInputName = 'Empty';
2381
+ }
2382
+ if (!hasAnEnabledUpdateField) {
2383
+ list.graphql.types.update = nextFields.g.Empty;
2384
+ list.graphql.names.updateInputName = 'Empty';
2385
+ }
2386
+ list.actions = Object.entries((_listConfig$actions = listConfig.actions) !== null && _listConfig$actions !== void 0 ? _listConfig$actions : {}).map(([actionKey, action]) => {
2387
+ var _action$ui$icon, _action$ui$itemView$a, _action$ui$itemView, _action$ui$itemView$n, _action$ui$itemView2, _action$ui$itemView$h, _action$ui$itemView3, _action$ui$itemView$h2, _action$ui$itemView4, _action$ui$listView$a, _action$ui$listView;
2388
+ const {
2389
+ label
2390
+ } = action.ui;
2391
+ const graphql = getInitialisedActionGraphql(list, utils$1.__getNames(list.listKey, listConfig).graphql, actionKey, action);
2392
+ return {
2393
+ ...action,
2394
+ actionKey,
2395
+ graphql,
2396
+ otel: utils$2.humanize(graphql.names.one, true).toLowerCase(),
2397
+ ui: {
2398
+ label,
2399
+ icon: (_action$ui$icon = action.ui.icon) !== null && _action$ui$icon !== void 0 ? _action$ui$icon : null,
2400
+ messages: {
2401
+ promptTitle: `{Label} {singular}`,
2402
+ promptTitleMany: `{Label} {count} {singular|plural}`,
2403
+ prompt: `Are you sure you want to {label} {singular} "{itemLabel}"?`,
2404
+ promptMany: `Are you sure you want to {label} {count} {singular|plural}?`,
2405
+ promptConfirmLabel: `Yes, {label} this {singular}`,
2406
+ promptConfirmLabelMany: `Yes, {label} {count} {singular|plural}`,
2407
+ fail: `Could not {label} {singular}`,
2408
+ failMany: `Could not {label} {countFail} {singular|plural}`,
2409
+ success: `Completed {label} action for {singular}`,
2410
+ successMany: `Completed {label} action for {countSuccess} {singular|plural}`,
2411
+ ...action.ui.messages
2412
+ },
2413
+ itemView: {
2414
+ actionMode: (_action$ui$itemView$a = (_action$ui$itemView = action.ui.itemView) === null || _action$ui$itemView === void 0 ? void 0 : _action$ui$itemView.actionMode) !== null && _action$ui$itemView$a !== void 0 ? _action$ui$itemView$a : 'enabled',
2415
+ navigation: (_action$ui$itemView$n = (_action$ui$itemView2 = action.ui.itemView) === null || _action$ui$itemView2 === void 0 ? void 0 : _action$ui$itemView2.navigation) !== null && _action$ui$itemView$n !== void 0 ? _action$ui$itemView$n : 'follow',
2416
+ hidePrompt: (_action$ui$itemView$h = (_action$ui$itemView3 = action.ui.itemView) === null || _action$ui$itemView3 === void 0 ? void 0 : _action$ui$itemView3.hidePrompt) !== null && _action$ui$itemView$h !== void 0 ? _action$ui$itemView$h : false,
2417
+ hideToast: (_action$ui$itemView$h2 = (_action$ui$itemView4 = action.ui.itemView) === null || _action$ui$itemView4 === void 0 ? void 0 : _action$ui$itemView4.hideToast) !== null && _action$ui$itemView$h2 !== void 0 ? _action$ui$itemView$h2 : false
2418
+ },
2419
+ listView: {
2420
+ actionMode: (_action$ui$listView$a = (_action$ui$listView = action.ui.listView) === null || _action$ui$listView === void 0 ? void 0 : _action$ui$listView.actionMode) !== null && _action$ui$listView$a !== void 0 ? _action$ui$listView$a : 'enabled'
2421
+ },
2422
+ argSources: getArgSources(action)
2423
+ }
2424
+ };
2425
+ });
2426
+ }
2427
+
2428
+ // error checking
2429
+ for (const list of Object.values(listsRef)) {
2430
+ assertFieldsValid(list);
2431
+ }
2432
+
2433
+ // do some introspection
2434
+ introspectGraphQLTypes(listsRef);
2435
+ return listsRef;
2436
+ }
2437
+
2438
+ const NixxieAdminUIFieldMeta = nextFields.g.object()({
2439
+ name: 'NixxieAdminUIFieldMeta',
2440
+ fields: {
2441
+ key: nextFields.g.field({
2442
+ type: nextFields.g.nonNull(nextFields.g.String)
2443
+ }),
2444
+ label: nextFields.g.field({
2445
+ type: nextFields.g.nonNull(nextFields.g.String)
2446
+ }),
2447
+ description: nextFields.g.field({
2448
+ type: nextFields.g.String
2449
+ }),
2450
+ isOrderable: nextFields.g.field({
2451
+ type: nextFields.g.nonNull(nextFields.g.Boolean)
2452
+ }),
2453
+ isFilterable: nextFields.g.field({
2454
+ type: nextFields.g.nonNull(nextFields.g.Boolean)
2455
+ }),
2456
+ isNonNull: nextFields.g.field({
2457
+ type: nextFields.g.list(nextFields.g.nonNull(nextFields.g.enum({
2458
+ name: 'NixxieAdminUIFieldMetaIsNonNull',
2459
+ values: nextFields.g.enumValues(['read', 'create', 'update'])
2460
+ })))
2461
+ }),
2462
+ fieldMeta: nextFields.g.field({
2463
+ type: nextFields.g.JSON
2464
+ }),
2465
+ viewsIndex: nextFields.g.field({
2466
+ type: nextFields.g.nonNull(nextFields.g.Int)
2467
+ }),
2468
+ customViewsIndex: nextFields.g.field({
2469
+ type: nextFields.g.Int
2470
+ }),
2471
+ createView: nextFields.g.field({
2472
+ type: nextFields.g.nonNull(nextFields.g.object()({
2473
+ name: 'NixxieAdminUIFieldMetaCreateView',
2474
+ fields: {
2475
+ fieldMode: nextFields.g.field({
2476
+ type: nextFields.g.nonNull(nextFields.g.JSON)
2477
+ }),
2478
+ isRequired: nextFields.g.field({
2479
+ type: nextFields.g.nonNull(nextFields.g.JSON)
2480
+ })
2481
+ }
2482
+ }))
2483
+ }),
2484
+ itemView: nextFields.g.field({
2485
+ resolve: args => args,
2486
+ type: nextFields.g.object()({
2487
+ name: 'NixxieAdminUIFieldMetaItemView',
2488
+ fields: {
2489
+ fieldMode: nextFields.g.field({
2490
+ type: nextFields.g.nonNull(nextFields.g.JSON),
2491
+ async resolve({
2492
+ listKey,
2493
+ fieldKey,
2494
+ itemView,
2495
+ item,
2496
+ itemField
2497
+ }, _, context) {
2498
+ const {
2499
+ fieldMode
2500
+ } = itemView;
2501
+ if (typeof fieldMode !== 'function') return fieldMode;
2502
+ return fieldMode({
2503
+ session: context.session,
2504
+ context,
2505
+ listKey,
2506
+ fieldKey,
2507
+ item,
2508
+ itemField
2509
+ });
2510
+ }
2511
+ }),
2512
+ fieldPosition: nextFields.g.field({
2513
+ type: nextFields.g.nonNull(nextFields.g.enum({
2514
+ name: 'NixxieAdminUIFieldMetaItemViewFieldPosition',
2515
+ values: nextFields.g.enumValues(['form', 'sidebar'])
2516
+ })),
2517
+ async resolve({
2518
+ listKey,
2519
+ fieldKey,
2520
+ itemView,
2521
+ item,
2522
+ itemField
2523
+ }, _, context) {
2524
+ const {
2525
+ fieldPosition
2526
+ } = itemView;
2527
+ if (typeof fieldPosition !== 'function') return fieldPosition;
2528
+ return fieldPosition({
2529
+ session: context.session,
2530
+ context,
2531
+ listKey,
2532
+ fieldKey,
2533
+ item,
2534
+ itemField
2535
+ });
2536
+ }
2537
+ }),
2538
+ isRequired: nextFields.g.field({
2539
+ type: nextFields.g.nonNull(nextFields.g.JSON),
2540
+ resolve({
2541
+ listKey,
2542
+ fieldKey,
2543
+ itemView,
2544
+ item,
2545
+ itemField
2546
+ }, _, context) {
2547
+ const {
2548
+ isRequired
2549
+ } = itemView;
2550
+ if (typeof isRequired !== 'function') return isRequired;
2551
+ return isRequired({
2552
+ session: context.session,
2553
+ context,
2554
+ listKey,
2555
+ fieldKey,
2556
+ item,
2557
+ itemField
2558
+ });
2559
+ }
2560
+ })
2561
+ }
2562
+ })
2563
+ }),
2564
+ listView: nextFields.g.field({
2565
+ type: nextFields.g.nonNull(nextFields.g.object()({
2566
+ name: 'NixxieAdminUIFieldMetaListView',
2567
+ fields: {
2568
+ fieldMode: nextFields.g.field({
2569
+ type: nextFields.g.nonNull(nextFields.g.enum({
2570
+ name: 'NixxieAdminUIFieldMetaListViewFieldMode',
2571
+ values: nextFields.g.enumValues(['read', 'hidden'])
2572
+ }))
2573
+ })
2574
+ }
2575
+ }))
2576
+ }),
2577
+ search: nextFields.g.field({
2578
+ type: nextFields.QueryMode
2579
+ })
2580
+ }
2581
+ });
2582
+ const NixxieAdminUIActionMeta = nextFields.g.object()({
2583
+ name: 'NixxieAdminUIActionMeta',
2584
+ fields: {
2585
+ key: nextFields.g.field({
2586
+ type: nextFields.g.nonNull(nextFields.g.String)
2587
+ }),
2588
+ label: nextFields.g.field({
2589
+ type: nextFields.g.nonNull(nextFields.g.String)
2590
+ }),
2591
+ icon: nextFields.g.field({
2592
+ type: nextFields.g.String
2593
+ }),
2594
+ messages: nextFields.g.field({
2595
+ type: nextFields.g.nonNull(nextFields.g.object()({
2596
+ name: 'NixxieAdminUIActionMetaMessages',
2597
+ fields: {
2598
+ promptTitle: nextFields.g.field({
2599
+ type: nextFields.g.nonNull(nextFields.g.String)
2600
+ }),
2601
+ promptTitleMany: nextFields.g.field({
2602
+ type: nextFields.g.String
2603
+ }),
2604
+ prompt: nextFields.g.field({
2605
+ type: nextFields.g.nonNull(nextFields.g.String)
2606
+ }),
2607
+ promptMany: nextFields.g.field({
2608
+ type: nextFields.g.String
2609
+ }),
2610
+ promptConfirmLabel: nextFields.g.field({
2611
+ type: nextFields.g.nonNull(nextFields.g.String)
2612
+ }),
2613
+ promptConfirmLabelMany: nextFields.g.field({
2614
+ type: nextFields.g.String
2615
+ }),
2616
+ fail: nextFields.g.field({
2617
+ type: nextFields.g.nonNull(nextFields.g.String)
2618
+ }),
2619
+ failMany: nextFields.g.field({
2620
+ type: nextFields.g.String
2621
+ }),
2622
+ success: nextFields.g.field({
2623
+ type: nextFields.g.nonNull(nextFields.g.String)
2624
+ }),
2625
+ successMany: nextFields.g.field({
2626
+ type: nextFields.g.String
2627
+ })
2628
+ }
2629
+ }))
2630
+ }),
2631
+ graphql: nextFields.g.field({
2632
+ type: nextFields.g.object()({
2633
+ name: 'NixxieAdminUIActionMetaGraphQL',
2634
+ fields: {
2635
+ arguments: nextFields.g.field({
2636
+ type: nextFields.g.nonNull(nextFields.g.list(nextFields.g.nonNull(nextFields.g.object()({
2637
+ name: 'NixxieAdminUIActionMetaGraphQLArgument',
2638
+ fields: {
2639
+ name: nextFields.g.field({
2640
+ type: nextFields.g.nonNull(nextFields.g.String)
2641
+ }),
2642
+ type: nextFields.g.field({
2643
+ type: nextFields.g.nonNull(nextFields.g.String)
2644
+ }),
2645
+ source: nextFields.g.field({
2646
+ type: nextFields.g.JSON
2647
+ })
2648
+ }
2649
+ }))))
2650
+ }),
2651
+ names: nextFields.g.field({
2652
+ type: nextFields.g.nonNull(nextFields.g.object()({
2653
+ name: 'NixxieAdminUIActionMetaGraphQLNames',
2654
+ fields: {
2655
+ one: nextFields.g.field({
2656
+ type: nextFields.g.nonNull(nextFields.g.String)
2657
+ }),
2658
+ many: nextFields.g.field({
2659
+ type: nextFields.g.String
2660
+ })
2661
+ }
2662
+ }))
2663
+ })
2664
+ }
2665
+ })
2666
+ }),
2667
+ itemView: nextFields.g.field({
2668
+ resolve: args => args,
2669
+ type: nextFields.g.object()({
2670
+ name: 'NixxieAdminUIActionMetaItemView',
2671
+ fields: {
2672
+ actionMode: nextFields.g.field({
2673
+ type: nextFields.g.nonNull(nextFields.g.JSON),
2674
+ async resolve({
2675
+ listKey,
2676
+ key,
2677
+ itemView,
2678
+ item
2679
+ }, _, context) {
2680
+ const {
2681
+ actionMode
2682
+ } = itemView;
2683
+ if (typeof actionMode !== 'function') return actionMode;
2684
+ return actionMode({
2685
+ session: context.session,
2686
+ context,
2687
+ listKey,
2688
+ actionKey: key,
2689
+ item
2690
+ });
2691
+ }
2692
+ }),
2693
+ navigation: nextFields.g.field({
2694
+ type: nextFields.g.nonNull(nextFields.g.enum({
2695
+ name: 'NixxieAdminUIActionMetaItemViewNavigation',
2696
+ values: nextFields.g.enumValues(['follow', 'refetch', 'return'])
2697
+ })),
2698
+ resolve({
2699
+ itemView
2700
+ }) {
2701
+ return itemView.navigation;
2702
+ }
2703
+ }),
2704
+ hidePrompt: nextFields.g.field({
2705
+ type: nextFields.g.nonNull(nextFields.g.Boolean),
2706
+ resolve({
2707
+ itemView
2708
+ }) {
2709
+ return itemView.hidePrompt;
2710
+ }
2711
+ }),
2712
+ hideToast: nextFields.g.field({
2713
+ type: nextFields.g.nonNull(nextFields.g.Boolean),
2714
+ resolve({
2715
+ itemView
2716
+ }) {
2717
+ return itemView.hideToast;
2718
+ }
2719
+ })
2720
+ }
2721
+ })
2722
+ }),
2723
+ listView: nextFields.g.field({
2724
+ type: nextFields.g.nonNull(nextFields.g.object()({
2725
+ name: 'NixxieAdminUIActionMetaListView',
2726
+ fields: {
2727
+ actionMode: nextFields.g.field({
2728
+ type: nextFields.g.nonNull(nextFields.g.JSON)
2729
+ })
2730
+ }
2731
+ }))
2732
+ })
2733
+ }
2734
+ });
2735
+ const NixxieAdminUIFieldGroupMeta = nextFields.g.object()({
2736
+ name: 'NixxieAdminUIFieldGroupMeta',
2737
+ fields: {
2738
+ label: nextFields.g.field({
2739
+ type: nextFields.g.nonNull(nextFields.g.String)
2740
+ }),
2741
+ description: nextFields.g.field({
2742
+ type: nextFields.g.String
2743
+ }),
2744
+ fields: nextFields.g.field({
2745
+ type: nextFields.g.nonNull(nextFields.g.list(nextFields.g.nonNull(NixxieAdminUIFieldMeta)))
2746
+ })
2747
+ }
2748
+ });
2749
+ const NixxieAdminUISort = nextFields.g.object()({
2750
+ name: 'NixxieAdminUISort',
2751
+ fields: {
2752
+ field: nextFields.g.field({
2753
+ type: nextFields.g.nonNull(nextFields.g.String)
2754
+ }),
2755
+ direction: nextFields.g.field({
2756
+ type: nextFields.g.nonNull(nextFields.g.enum({
2757
+ name: 'NixxieAdminUISortDirection',
2758
+ values: nextFields.g.enumValues(['ASC', 'DESC'])
2759
+ }))
2760
+ })
2761
+ }
2762
+ });
2763
+ const NixxieAdminUIGraphQL = nextFields.g.object()({
2764
+ name: 'NixxieAdminUIGraphQL',
2765
+ fields: {
2766
+ names: nextFields.g.field({
2767
+ type: nextFields.g.nonNull(nextFields.g.object()({
2768
+ name: 'NixxieAdminUIGraphQLNames',
2769
+ fields: {
2770
+ outputTypeName: nextFields.g.field({
2771
+ type: nextFields.g.nonNull(nextFields.g.String)
2772
+ }),
2773
+ whereInputName: nextFields.g.field({
2774
+ type: nextFields.g.nonNull(nextFields.g.String)
2775
+ }),
2776
+ whereUniqueInputName: nextFields.g.field({
2777
+ type: nextFields.g.nonNull(nextFields.g.String)
2778
+ }),
2779
+ // create
2780
+ createInputName: nextFields.g.field({
2781
+ type: nextFields.g.nonNull(nextFields.g.String)
2782
+ }),
2783
+ createMutationName: nextFields.g.field({
2784
+ type: nextFields.g.nonNull(nextFields.g.String)
2785
+ }),
2786
+ createManyMutationName: nextFields.g.field({
2787
+ type: nextFields.g.nonNull(nextFields.g.String)
2788
+ }),
2789
+ relateToOneForCreateInputName: nextFields.g.field({
2790
+ type: nextFields.g.nonNull(nextFields.g.String)
2791
+ }),
2792
+ relateToManyForCreateInputName: nextFields.g.field({
2793
+ type: nextFields.g.nonNull(nextFields.g.String)
2794
+ }),
2795
+ // read
2796
+ itemQueryName: nextFields.g.field({
2797
+ type: nextFields.g.nonNull(nextFields.g.String)
2798
+ }),
2799
+ listOrderName: nextFields.g.field({
2800
+ type: nextFields.g.nonNull(nextFields.g.String)
2801
+ }),
2802
+ listQueryCountName: nextFields.g.field({
2803
+ type: nextFields.g.nonNull(nextFields.g.String)
2804
+ }),
2805
+ listQueryName: nextFields.g.field({
2806
+ type: nextFields.g.nonNull(nextFields.g.String)
2807
+ }),
2808
+ // update
2809
+ updateInputName: nextFields.g.field({
2810
+ type: nextFields.g.nonNull(nextFields.g.String)
2811
+ }),
2812
+ updateMutationName: nextFields.g.field({
2813
+ type: nextFields.g.nonNull(nextFields.g.String)
2814
+ }),
2815
+ updateManyInputName: nextFields.g.field({
2816
+ type: nextFields.g.nonNull(nextFields.g.String)
2817
+ }),
2818
+ updateManyMutationName: nextFields.g.field({
2819
+ type: nextFields.g.nonNull(nextFields.g.String)
2820
+ }),
2821
+ relateToOneForUpdateInputName: nextFields.g.field({
2822
+ type: nextFields.g.nonNull(nextFields.g.String)
2823
+ }),
2824
+ relateToManyForUpdateInputName: nextFields.g.field({
2825
+ type: nextFields.g.nonNull(nextFields.g.String)
2826
+ }),
2827
+ // delete
2828
+ deleteMutationName: nextFields.g.field({
2829
+ type: nextFields.g.nonNull(nextFields.g.String)
2830
+ }),
2831
+ deleteManyMutationName: nextFields.g.field({
2832
+ type: nextFields.g.nonNull(nextFields.g.String)
2833
+ })
2834
+ }
2835
+ }))
2836
+ })
2837
+ }
2838
+ });
2839
+ const NixxieAdminUIListMeta = nextFields.g.object()({
2840
+ name: 'NixxieAdminUIListMeta',
2841
+ fields: {
2842
+ key: nextFields.g.field({
2843
+ type: nextFields.g.nonNull(nextFields.g.String)
2844
+ }),
2845
+ label: nextFields.g.field({
2846
+ type: nextFields.g.nonNull(nextFields.g.String)
2847
+ }),
2848
+ singular: nextFields.g.field({
2849
+ type: nextFields.g.nonNull(nextFields.g.String)
2850
+ }),
2851
+ plural: nextFields.g.field({
2852
+ type: nextFields.g.nonNull(nextFields.g.String)
2853
+ }),
2854
+ path: nextFields.g.field({
2855
+ type: nextFields.g.nonNull(nextFields.g.String)
2856
+ }),
2857
+ labelField: nextFields.g.field({
2858
+ type: nextFields.g.nonNull(nextFields.g.String)
2859
+ }),
2860
+ fields: nextFields.g.field({
2861
+ resolve: ({
2862
+ fields,
2863
+ item
2864
+ }) => {
2865
+ return fields.map(f => {
2866
+ var _item$f$key;
2867
+ return {
2868
+ ...f,
2869
+ item,
2870
+ itemField: (_item$f$key = item === null || item === void 0 ? void 0 : item[f.key]) !== null && _item$f$key !== void 0 ? _item$f$key : null
2871
+ };
2872
+ });
2873
+ },
2874
+ type: nextFields.g.nonNull(nextFields.g.list(nextFields.g.nonNull(NixxieAdminUIFieldMeta)))
2875
+ }),
2876
+ groups: nextFields.g.field({
2877
+ type: nextFields.g.nonNull(nextFields.g.list(nextFields.g.nonNull(NixxieAdminUIFieldGroupMeta)))
2878
+ }),
2879
+ actions: nextFields.g.field({
2880
+ resolve: ({
2881
+ actions,
2882
+ item
2883
+ }) => actions.map(action => ({
2884
+ ...action,
2885
+ item
2886
+ })),
2887
+ type: nextFields.g.nonNull(nextFields.g.list(nextFields.g.nonNull(NixxieAdminUIActionMeta)))
2888
+ }),
2889
+ graphql: nextFields.g.field({
2890
+ type: nextFields.g.nonNull(NixxieAdminUIGraphQL)
2891
+ }),
2892
+ pageSize: nextFields.g.field({
2893
+ type: nextFields.g.nonNull(nextFields.g.Int)
2894
+ }),
2895
+ initialColumns: nextFields.g.field({
2896
+ type: nextFields.g.nonNull(nextFields.g.list(nextFields.g.nonNull(nextFields.g.String)))
2897
+ }),
2898
+ initialSearchFields: nextFields.g.field({
2899
+ type: nextFields.g.nonNull(nextFields.g.list(nextFields.g.nonNull(nextFields.g.String)))
2900
+ }),
2901
+ initialSort: nextFields.g.field({
2902
+ type: NixxieAdminUISort
2903
+ }),
2904
+ initialFilter: nextFields.g.field({
2905
+ type: nextFields.g.JSON
2906
+ }),
2907
+ isSingleton: nextFields.g.field({
2908
+ type: nextFields.g.nonNull(nextFields.g.Boolean)
2909
+ }),
2910
+ hideNavigation: nextFields.g.field({
2911
+ type: nextFields.g.nonNull(nextFields.g.Boolean)
2912
+ }),
2913
+ hideCreate: nextFields.g.field({
2914
+ type: nextFields.g.nonNull(nextFields.g.Boolean)
2915
+ }),
2916
+ hideDelete: nextFields.g.field({
2917
+ type: nextFields.g.nonNull(nextFields.g.Boolean)
2918
+ })
2919
+ }
2920
+ });
2921
+ const adminMeta = nextFields.g.object()({
2922
+ name: 'NixxieAdminMeta',
2923
+ fields: {
2924
+ lists: nextFields.g.field({
2925
+ type: nextFields.g.nonNull(nextFields.g.list(nextFields.g.nonNull(NixxieAdminUIListMeta)))
2926
+ }),
2927
+ list: nextFields.g.field({
2928
+ type: NixxieAdminUIListMeta,
2929
+ args: {
2930
+ key: nextFields.g.arg({
2931
+ type: nextFields.g.nonNull(nextFields.g.String)
2932
+ }),
2933
+ itemId: nextFields.g.arg({
2934
+ type: nextFields.g.ID
2935
+ })
2936
+ },
2937
+ async resolve(source, {
2938
+ key,
2939
+ itemId
2940
+ }, context) {
2941
+ if (itemId === null || itemId === undefined) {
2942
+ return {
2943
+ ...source.listsByKey[key],
2944
+ item: null
2945
+ };
2946
+ }
2947
+ // WARNING: do not use sudo
2948
+ const item = await context.db[key].findOne({
2949
+ where: {
2950
+ id: itemId
2951
+ }
2952
+ });
2953
+ if (!item) {
2954
+ return {
2955
+ ...source.listsByKey[key],
2956
+ item: null
2957
+ };
2958
+ }
2959
+ return {
2960
+ ...source.listsByKey[key],
2961
+ item
2962
+ };
2963
+ }
2964
+ })
2965
+ }
2966
+ });
2967
+ const NixxieMeta = nextFields.g.object()({
2968
+ name: 'NixxieMeta',
2969
+ fields: {
2970
+ adminMeta: nextFields.g.field({
2971
+ type: nextFields.g.nonNull(adminMeta),
2972
+ async resolve({
2973
+ adminMeta
2974
+ }, _, context) {
2975
+ if (context.__internal.sudo) return adminMeta;
2976
+ const isAllowed = await adminMeta.isAccessAllowed(context);
2977
+ if (isAllowed) return adminMeta;
2978
+
2979
+ // TODO: we need better errors
2980
+ throw new Error('Access denied');
2981
+ }
2982
+ })
2983
+ }
2984
+ });
2985
+
2986
+ const tracer = api.trace.getTracer('nixxie');
2987
+ async function withSpan(name, fn, attrs) {
2988
+ return tracer.startActiveSpan(name, {
2989
+ attributes: attrs
2990
+ }, async span => {
2991
+ try {
2992
+ const result = await fn(span);
2993
+ span.setStatus({
2994
+ code: api.SpanStatusCode.OK
2995
+ });
2996
+ return result;
2997
+ } catch (err) {
2998
+ span.recordException(err instanceof Error ? err : {
2999
+ message: String(err)
3000
+ });
3001
+ span.setStatus({
3002
+ code: api.SpanStatusCode.ERROR
3003
+ });
3004
+ throw err;
3005
+ } finally {
3006
+ span.end();
3007
+ }
3008
+ });
3009
+ }
3010
+
3011
+ async function validate({
3012
+ list,
3013
+ hookArgs
3014
+ }) {
3015
+ const messages = [];
3016
+ const fieldsErrors = [];
3017
+ const {
3018
+ operation
3019
+ } = hookArgs;
3020
+
3021
+ // field validation hooks
3022
+ await Promise.all(Object.entries(list.fields).map(async ([fieldKey, field]) => {
3023
+ const addValidationError = msg => void messages.push(`${list.listKey}.${fieldKey}: ${msg}`);
3024
+ const hook = field.hooks.validate[operation];
3025
+ try {
3026
+ var _hookArgs$item, _hookArgs$inputData, _hookArgs$resolvedDat;
3027
+ await hook({
3028
+ ...hookArgs,
3029
+ addValidationError,
3030
+ fieldKey,
3031
+ itemField: (_hookArgs$item = hookArgs.item) === null || _hookArgs$item === void 0 ? void 0 : _hookArgs$item[fieldKey],
3032
+ inputFieldData: (_hookArgs$inputData = hookArgs.inputData) === null || _hookArgs$inputData === void 0 ? void 0 : _hookArgs$inputData[fieldKey],
3033
+ resolvedFieldData: (_hookArgs$resolvedDat = hookArgs.resolvedData) === null || _hookArgs$resolvedDat === void 0 ? void 0 : _hookArgs$resolvedDat[fieldKey]
3034
+ }); // TODO: FIXME
3035
+ } catch (error) {
3036
+ fieldsErrors.push({
3037
+ error,
3038
+ tag: `${list.listKey}.${fieldKey}.hooks.validateInput`
3039
+ });
3040
+ }
3041
+ }));
3042
+ if (fieldsErrors.length) {
3043
+ throw resolveHooks.extensionError('validateInput', fieldsErrors);
3044
+ }
3045
+
3046
+ // list validation hooks
3047
+ {
3048
+ const addValidationError = msg => void messages.push(`${list.listKey}: ${msg}`);
3049
+ const hook = list.hooks.validate[operation];
3050
+ try {
3051
+ await hook({
3052
+ ...hookArgs,
3053
+ addValidationError
3054
+ }); // TODO: FIXME
3055
+ } catch (error) {
3056
+ throw resolveHooks.extensionError('validateInput', [{
3057
+ error,
3058
+ tag: `${list.listKey}.hooks.validateInput`
3059
+ }]);
3060
+ }
3061
+ if (messages.length) {
3062
+ throw resolveHooks.validationFailureError(messages);
3063
+ }
3064
+ }
3065
+ }
3066
+ async function runSideEffectOnlyHook(list, hookName, args) {
3067
+ const {
3068
+ operation
3069
+ } = args;
3070
+ let shouldRunFieldLevelHook;
3071
+ if (operation === 'delete') {
3072
+ // always run field hooks for delete operations
3073
+ shouldRunFieldLevelHook = () => true;
3074
+ } else {
3075
+ // only run field hooks on if the field was specified in the
3076
+ // original input for create and update operations.
3077
+ const inputDataKeys = new Set(Object.keys(args.inputData));
3078
+ shouldRunFieldLevelHook = fieldKey => inputDataKeys.has(fieldKey);
3079
+ }
3080
+
3081
+ // field hooks
3082
+ const fieldsErrors = [];
3083
+ await Promise.all(Object.entries(list.fields).map(async ([fieldKey, field]) => {
3084
+ if (shouldRunFieldLevelHook(fieldKey)) {
3085
+ try {
3086
+ var _args$item, _args$inputData, _args$resolvedData, _originalItem;
3087
+ await field.hooks[hookName][operation]({
3088
+ ...args,
3089
+ fieldKey,
3090
+ itemField: (_args$item = args.item) === null || _args$item === void 0 ? void 0 : _args$item[fieldKey],
3091
+ inputFieldData: (_args$inputData = args.inputData) === null || _args$inputData === void 0 ? void 0 : _args$inputData[fieldKey],
3092
+ resolvedFieldData: (_args$resolvedData = args.resolvedData) === null || _args$resolvedData === void 0 ? void 0 : _args$resolvedData[fieldKey],
3093
+ originalItemField: (_originalItem = args.originalItem) === null || _originalItem === void 0 ? void 0 : _originalItem[fieldKey]
3094
+ }); // TODO: FIXME any
3095
+ } catch (error) {
3096
+ fieldsErrors.push({
3097
+ error,
3098
+ tag: `${list.listKey}.${fieldKey}.hooks.${hookName}`
3099
+ });
3100
+ }
3101
+ }
3102
+ }));
3103
+ if (fieldsErrors.length) {
3104
+ throw resolveHooks.extensionError(hookName, fieldsErrors);
3105
+ }
3106
+
3107
+ // list hooks
3108
+ try {
3109
+ await list.hooks[hookName][operation](args); // TODO: FIXME any
3110
+ } catch (error) {
3111
+ throw resolveHooks.extensionError(hookName, [{
3112
+ error,
3113
+ tag: `${list.listKey}.hooks.${hookName}`
3114
+ }]);
3115
+ }
3116
+ }
3117
+
3118
+ class RelationshipErrors extends Error {
3119
+ constructor(errors) {
3120
+ super('Multiple relationship errors');
3121
+ this.errors = errors;
3122
+ }
3123
+ }
3124
+ function getResolvedUniqueWheres(uniqueInputs, context, foreignList, operation) {
3125
+ return uniqueInputs.map(uniqueInput => checkUniqueItemExists(uniqueInput, foreignList, context, operation));
3126
+ }
3127
+ function resolveRelateToManyForCreateInput(nestedMutationState, context, foreignList, tag) {
3128
+ return async value => {
3129
+ var _value$connect, _value$set, _value$create;
3130
+ if (!Array.isArray(value.connect) && !Array.isArray(value.create) && !Array.isArray(value.set)) {
3131
+ throw resolveHooks.userInputError(`You must provide at least one of "set", "connect" or "create" in to-many relationship inputs for "create" operations.`);
3132
+ }
3133
+
3134
+ // Perform queries for the connections
3135
+ const connects = Promise.allSettled(getResolvedUniqueWheres((_value$connect = value.connect) !== null && _value$connect !== void 0 ? _value$connect : [], context, foreignList, 'connect'));
3136
+ const sets = Promise.allSettled(getResolvedUniqueWheres((_value$set = value.set) !== null && _value$set !== void 0 ? _value$set : [], context, foreignList, 'set'));
3137
+
3138
+ // Perform nested mutations for the creations
3139
+ const creates = Promise.allSettled(((_value$create = value.create) !== null && _value$create !== void 0 ? _value$create : []).map(x => nestedMutationState.create(x, foreignList)));
3140
+
3141
+ // Resolve items
3142
+ const [connectResult, createResult, setResult] = await Promise.all([connects, creates, sets]);
3143
+
3144
+ // Collect all the errors
3145
+ const errors = [...connectResult, ...createResult, ...setResult].filter(utils.isRejected);
3146
+ if (errors.length) throw new RelationshipErrors(errors.map(x => ({
3147
+ error: x.reason,
3148
+ tag
3149
+ })));
3150
+ return {
3151
+ connect: [...setResult, ...connectResult, ...createResult].filter(utils.isFulfilled).map(x => x.value)
3152
+ };
3153
+ };
3154
+ }
3155
+ function resolveRelateToManyForUpdateInput(nestedMutationState, context, foreignList, tag) {
3156
+ return async value => {
3157
+ var _value$connect2, _value$disconnect, _value$set2, _value$create2;
3158
+ if (!Array.isArray(value.connect) && !Array.isArray(value.create) && !Array.isArray(value.disconnect) && !Array.isArray(value.set)) {
3159
+ throw resolveHooks.userInputError(`You must provide at least one of "set", "connect", "create" or "disconnect" in to-many relationship inputs for "update" operations.`);
3160
+ }
3161
+ if (value.set && value.disconnect) {
3162
+ throw resolveHooks.userInputError(`The "set" and "disconnect" fields cannot both be provided to to-many relationship inputs for "update" operations.`);
3163
+ }
3164
+
3165
+ // Perform queries for the connections
3166
+ const connects = Promise.allSettled(getResolvedUniqueWheres((_value$connect2 = value.connect) !== null && _value$connect2 !== void 0 ? _value$connect2 : [], context, foreignList, 'connect'));
3167
+ const disconnects = Promise.allSettled(getResolvedUniqueWheres((_value$disconnect = value.disconnect) !== null && _value$disconnect !== void 0 ? _value$disconnect : [], context, foreignList, 'disconnect'));
3168
+ const sets = Promise.allSettled(getResolvedUniqueWheres((_value$set2 = value.set) !== null && _value$set2 !== void 0 ? _value$set2 : [], context, foreignList, 'set'));
3169
+
3170
+ // Perform nested mutations for the creations
3171
+ const creates = Promise.allSettled(((_value$create2 = value.create) !== null && _value$create2 !== void 0 ? _value$create2 : []).map(x => nestedMutationState.create(x, foreignList)));
3172
+
3173
+ // Resolve items
3174
+ const [connectResult, createResult, disconnectResult, setResult] = await Promise.all([connects, creates, disconnects, sets]);
3175
+
3176
+ // Collect all the errors
3177
+ const errors = [...connectResult, ...createResult, ...disconnectResult, ...setResult].filter(utils.isRejected);
3178
+ if (errors.length) throw new RelationshipErrors(errors.map(x => ({
3179
+ error: x.reason,
3180
+ tag
3181
+ })));
3182
+ return {
3183
+ // unlike all the other operations, an empty array isn't a no-op for set
3184
+ set: value.set ? setResult.filter(utils.isFulfilled).map(x => x.value) : undefined,
3185
+ disconnect: disconnectResult.filter(utils.isFulfilled).map(x => x.value),
3186
+ connect: [...connectResult, ...createResult].filter(utils.isFulfilled).map(x => x.value)
3187
+ };
3188
+ };
3189
+ }
3190
+
3191
+ async function handleCreateAndUpdate(value, nestedMutationState, context, foreignList) {
3192
+ if (value.connect) {
3193
+ return {
3194
+ connect: await checkUniqueItemExists(value.connect, foreignList, context, 'connect')
3195
+ };
3196
+ }
3197
+ if (value.create) {
3198
+ const {
3199
+ id
3200
+ } = await nestedMutationState.create(value.create, foreignList);
3201
+ return {
3202
+ connect: {
3203
+ id
3204
+ }
3205
+ };
3206
+ }
3207
+ }
3208
+ function resolveRelateToOneForCreateInput(nestedMutationState, context, foreignList) {
3209
+ return async value => {
3210
+ const numOfKeys = Object.keys(value).length;
3211
+ if (numOfKeys !== 1) {
3212
+ throw resolveHooks.userInputError(`You must provide "connect" or "create" in to-one relationship inputs for "create" operations.`);
3213
+ }
3214
+ return handleCreateAndUpdate(value, nestedMutationState, context, foreignList);
3215
+ };
3216
+ }
3217
+ function resolveRelateToOneForUpdateInput(nestedMutationState, context, foreignList) {
3218
+ return async value => {
3219
+ if (Object.keys(value).length !== 1) {
3220
+ throw resolveHooks.userInputError(`You must provide one of "connect", "create" or "disconnect" in to-one relationship inputs for "update" operations.`);
3221
+ }
3222
+ if (value.connect || value.create) {
3223
+ return handleCreateAndUpdate(value, nestedMutationState, context, foreignList);
3224
+ }
3225
+ if (value.disconnect) {
3226
+ return {
3227
+ disconnect: true
3228
+ };
3229
+ }
3230
+ };
3231
+ }
3232
+
3233
+ async function getFilteredItem(list, context, uniqueWhere, accessFilters, operation) {
3234
+ // early exit if they want to exclude everything
3235
+ if (accessFilters === false) {
3236
+ throw resolveHooks.accessDeniedError(cannotForItem(operation, list));
3237
+ }
3238
+
3239
+ // merge the filter access control and try to get the item
3240
+ let where = mapUniqueWhereToWhere(uniqueWhere, list);
3241
+ await checkFilterOrderAccess([...traverse(list, where)], context, 'filter');
3242
+ if (typeof accessFilters === 'object') {
3243
+ where = {
3244
+ AND: [where, await resolveWhereInput(accessFilters, list, context)]
3245
+ };
3246
+ }
3247
+ const item = await context.prisma[list.listKey].findFirst({
3248
+ where
3249
+ });
3250
+ if (item !== null) return item;
3251
+ throw resolveHooks.accessDeniedError(cannotForItem(operation, list));
3252
+ }
3253
+ async function createSingle__(inputData, list, context) {
3254
+ return await withSpan(`create ${list.graphql.names.outputTypeNameLower}`, async span => {
3255
+ var _result$id;
3256
+ // throw an accessDeniedError if not allowed
3257
+ await enforceListLevelAccessControl(context, 'create', list, inputData, undefined);
3258
+ await enforceFieldLevelAccessControl(context, 'create', list, inputData, undefined);
3259
+ const {
3260
+ beforeOperation,
3261
+ afterOperation,
3262
+ data
3263
+ } = await resolveInputForCreateOrUpdate(list, context, inputData, undefined);
3264
+
3265
+ // before operation
3266
+ await beforeOperation();
3267
+
3268
+ // operation
3269
+ const result = await context.prisma[list.listKey].create({
3270
+ data: list.isSingleton ? {
3271
+ ...data,
3272
+ id: 1
3273
+ } : data
3274
+ });
3275
+ span.setAttribute('nixxie.result.id', (_result$id = result === null || result === void 0 ? void 0 : result.id) !== null && _result$id !== void 0 ? _result$id : '');
3276
+ return {
3277
+ item: result,
3278
+ afterOperation
3279
+ };
3280
+ }, {
3281
+ 'nixxie.list': list.listKey,
3282
+ 'nixxie.operation': 'create'
3283
+ });
3284
+ }
3285
+ var _afterOperations = /*#__PURE__*/new WeakMap();
3286
+ var _context = /*#__PURE__*/new WeakMap();
3287
+ class NestedMutationState {
3288
+ constructor(context) {
3289
+ _classPrivateFieldInitSpec(this, _afterOperations, []);
3290
+ _classPrivateFieldInitSpec(this, _context, void 0);
3291
+ _classPrivateFieldSet(_context, this, context);
3292
+ }
3293
+ async create(data, list) {
3294
+ const context = _classPrivateFieldGet(_context, this);
3295
+ const operationAccess = await getOperationAccess(list, context, 'create');
3296
+ if (!operationAccess) throw resolveHooks.accessDeniedError(cannotForItem('create', list));
3297
+
3298
+ // before operation AND operation
3299
+ const {
3300
+ item,
3301
+ afterOperation
3302
+ } = await createSingle__(data, list, context);
3303
+
3304
+ // after operation
3305
+ _classPrivateFieldGet(_afterOperations, this).push(() => afterOperation(item));
3306
+ return {
3307
+ id: item.id
3308
+ };
3309
+ }
3310
+ async afterOperation() {
3311
+ await utils.promiseAllRejectWithAllErrors(_classPrivateFieldGet(_afterOperations, this).map(async x => x()));
3312
+ }
3313
+ }
3314
+ async function updateSingle__({
3315
+ where,
3316
+ data: inputData
3317
+ }, list, context, accessFilters) {
3318
+ return await withSpan(`update ${list.graphql.names.outputTypeNameLower}`, async span => {
3319
+ var _result$id2;
3320
+ // validate and resolve the input filter
3321
+ const uniqueWhere = await resolveUniqueWhereInput(where, list, context);
3322
+
3323
+ // filter and item access control - throws an AccessDeniedError if not allowed
3324
+ const item = await getFilteredItem(list, context, uniqueWhere, accessFilters, 'update');
3325
+
3326
+ // throw an accessDeniedError if not allowed
3327
+ await enforceListLevelAccessControl(context, 'update', list, inputData !== null && inputData !== void 0 ? inputData : {}, item);
3328
+ await enforceFieldLevelAccessControl(context, 'update', list, inputData !== null && inputData !== void 0 ? inputData : {}, item);
3329
+ const {
3330
+ beforeOperation,
3331
+ afterOperation,
3332
+ data
3333
+ } = await resolveInputForCreateOrUpdate(list, context, inputData !== null && inputData !== void 0 ? inputData : {}, item);
3334
+
3335
+ // before operation
3336
+ await beforeOperation();
3337
+
3338
+ // operation
3339
+ const result = await context.prisma[list.listKey].update({
3340
+ where: {
3341
+ id: item.id
3342
+ },
3343
+ data
3344
+ });
3345
+ span.setAttribute('nixxie.result.id', (_result$id2 = result === null || result === void 0 ? void 0 : result.id) !== null && _result$id2 !== void 0 ? _result$id2 : '');
3346
+
3347
+ // after operation
3348
+ await afterOperation(result);
3349
+ return result;
3350
+ }, {
3351
+ 'nixxie.list': list.listKey,
3352
+ 'nixxie.operation': 'update'
3353
+ });
3354
+ }
3355
+ async function deleteSingle__(where, list, context, accessFilters) {
3356
+ return await withSpan(`delete ${list.graphql.names.outputTypeNameLower}`, async span => {
3357
+ var _result$id3;
3358
+ // validate and resolve the input filter
3359
+ const uniqueWhere = await resolveUniqueWhereInput(where, list, context);
3360
+
3361
+ // filter and item access control throw an AccessDeniedError if not allowed
3362
+ // apply access.filter.* controls
3363
+ const item = await getFilteredItem(list, context, uniqueWhere, accessFilters, 'delete');
3364
+ await enforceListLevelAccessControl(context, 'delete', list, {}, item);
3365
+ // WARNING: no field level access control for delete operations
3366
+
3367
+ const hookArgs = {
3368
+ operation: 'delete',
3369
+ listKey: list.listKey,
3370
+ context,
3371
+ item,
3372
+ resolvedData: undefined,
3373
+ inputData: undefined
3374
+ };
3375
+
3376
+ // hooks
3377
+ await validate({
3378
+ list,
3379
+ hookArgs
3380
+ });
3381
+
3382
+ // before operation
3383
+ await runSideEffectOnlyHook(list, 'beforeOperation', hookArgs);
3384
+
3385
+ // operation
3386
+ const result = await context.prisma[list.listKey].delete({
3387
+ where: {
3388
+ id: item.id
3389
+ }
3390
+ });
3391
+ span.setAttribute('nixxie.result.id', (_result$id3 = result === null || result === void 0 ? void 0 : result.id) !== null && _result$id3 !== void 0 ? _result$id3 : '');
3392
+
3393
+ // after operation
3394
+ await runSideEffectOnlyHook(list, 'afterOperation', {
3395
+ ...hookArgs,
3396
+ item: undefined,
3397
+ originalItem: item
3398
+ });
3399
+ return result;
3400
+ }, {
3401
+ 'nixxie.list': list.listKey,
3402
+ 'nixxie.operation': 'delete'
3403
+ });
3404
+ }
3405
+ async function actionSingle__(context, list, action, {
3406
+ where,
3407
+ args
3408
+ }) {
3409
+ return await withSpan(action.otel, async span => {
3410
+ var _ref;
3411
+ // no before operation hook for actions
3412
+
3413
+ // operation
3414
+ const result = await action.resolve({
3415
+ listKey: list.listKey,
3416
+ actionKey: action.actionKey,
3417
+ where,
3418
+ args
3419
+ }, context);
3420
+ span.setAttribute('nixxie.result.id', (_ref = result === null || result === void 0 ? void 0 : result.id) !== null && _ref !== void 0 ? _ref : '');
3421
+
3422
+ // no after operation hook for actions
3423
+ return result;
3424
+ }, {
3425
+ 'nixxie.list': list.listKey,
3426
+ 'nixxie.action': action.actionKey
3427
+ });
3428
+ }
3429
+
3430
+ //
3431
+
3432
+ async function createOne(inputData, list, context) {
3433
+ const operationAccess = await getOperationAccess(list, context, 'create');
3434
+ if (!operationAccess) throw resolveHooks.accessDeniedError(cannotForItem('create', list));
3435
+
3436
+ // get list-level access control filters
3437
+ // NOTHING - no filters for create operations
3438
+
3439
+ // operation
3440
+ const {
3441
+ item,
3442
+ afterOperation
3443
+ } = await createSingle__(inputData !== null && inputData !== void 0 ? inputData : {}, list, context);
3444
+
3445
+ // after operation // TODO: move to createSingle__
3446
+ await afterOperation(item);
3447
+ return item;
3448
+ }
3449
+ async function createMany(inputDatas, list, context) {
3450
+ const operationAccess = await getOperationAccess(list, context, 'create');
3451
+ // WARNING: we do not short-circuit here, we throw for each
3452
+
3453
+ // get list-level access control filters
3454
+ // NOTHING - no filters for create operations
3455
+
3456
+ return inputDatas.map(async inputData => {
3457
+ // throw for each attempt
3458
+ if (!operationAccess) throw resolveHooks.accessDeniedError(cannotForItem('create', list));
3459
+
3460
+ // operation
3461
+ const {
3462
+ item,
3463
+ afterOperation
3464
+ } = await createSingle__(inputData !== null && inputData !== void 0 ? inputData : {}, list, context);
3465
+
3466
+ // after operation // TODO: move to createSingle__
3467
+ await afterOperation(item);
3468
+ return item;
3469
+ });
3470
+ }
3471
+ async function updateOne(updateInput, list, context) {
3472
+ const operationAccess = await getOperationAccess(list, context, 'update');
3473
+ if (!operationAccess) throw resolveHooks.accessDeniedError(cannotForItem('update', list));
3474
+
3475
+ // get list-level access control filters
3476
+ const accessFilters = await getAccessFilters(list, context, 'update');
3477
+ return updateSingle__(updateInput, list, context, accessFilters);
3478
+ }
3479
+ async function updateMany(updateManyInput, list, context) {
3480
+ const operationAccess = await getOperationAccess(list, context, 'update');
3481
+ // WARNING: we do not short-circuit here, we throw for each
3482
+
3483
+ // get list-level access control filters
3484
+ const accessFilters = await getAccessFilters(list, context, 'update');
3485
+ return updateManyInput.map(async updateInput => {
3486
+ // throw for each attempt
3487
+ if (!operationAccess) throw resolveHooks.accessDeniedError(cannotForItem('update', list));
3488
+ return updateSingle__(updateInput, list, context, accessFilters);
3489
+ });
3490
+ }
3491
+ async function deleteOne(where, list, context) {
3492
+ const operationAccess = await getOperationAccess(list, context, 'delete');
3493
+ if (!operationAccess) throw resolveHooks.accessDeniedError(cannotForItem('delete', list));
3494
+
3495
+ // get list-level access control filters
3496
+ const accessFilters = await getAccessFilters(list, context, 'delete');
3497
+ return deleteSingle__(where, list, context, accessFilters);
3498
+ }
3499
+ async function deleteMany(wheres, list, context) {
3500
+ const operationAccess = await getOperationAccess(list, context, 'delete');
3501
+ // WARNING: we do not short-circuit here, we throw for each
3502
+
3503
+ // get list-level access control filters
3504
+ const accessFilters = await getAccessFilters(list, context, 'delete');
3505
+ return wheres.map(async where => {
3506
+ // throw for each attempt
3507
+ if (!operationAccess) throw resolveHooks.accessDeniedError(cannotForItem('delete', list));
3508
+ return deleteSingle__(where, list, context, accessFilters);
3509
+ });
3510
+ }
3511
+ async function actionOne(input, list, context, action) {
3512
+ const operationAccess = await action.access({
3513
+ context,
3514
+ session: context.session,
3515
+ // TODO: remove in breaking change
3516
+ listKey: list.listKey,
3517
+ actionKey: action.actionKey
3518
+ });
3519
+ if (!operationAccess) throw resolveHooks.accessDeniedError(cannotActionForItem(action, list));
3520
+
3521
+ // get list-level access control filters
3522
+ // NOTHING - no filters for action operations
3523
+
3524
+ return actionSingle__(context, list, action, input);
3525
+ }
3526
+ async function actionMany(inputs, list, context, action) {
3527
+ const operationAccess = await action.access({
3528
+ context,
3529
+ session: context.session,
3530
+ // TODO: remove in breaking change
3531
+ listKey: list.listKey,
3532
+ actionKey: action.actionKey
3533
+ });
3534
+ // WARNING: we do not short-circuit here, we throw for each
3535
+
3536
+ // get list-level access control filters
3537
+ // NOTHING - no filters for action operations
3538
+
3539
+ return inputs.map(async ({
3540
+ where,
3541
+ ...args
3542
+ }) => {
3543
+ // throw for each attempt
3544
+ if (!operationAccess) throw resolveHooks.accessDeniedError(cannotActionForItem(action, list));
3545
+ return actionSingle__(context, list, action, {
3546
+ where,
3547
+ args
3548
+ });
3549
+ });
3550
+ }
3551
+ async function getResolvedData(list, hookArgs, nestedMutationState) {
3552
+ const {
3553
+ context,
3554
+ operation
3555
+ } = hookArgs;
3556
+ let resolvedData = hookArgs.inputData;
3557
+
3558
+ // apply non-relationship field type input resolvers
3559
+ const resolverErrors = [];
3560
+ resolvedData = Object.fromEntries(await Promise.all(Object.entries(list.fields).map(async ([fieldKey, field]) => {
3561
+ var _field$input;
3562
+ const inputResolver = (_field$input = field.input) === null || _field$input === void 0 || (_field$input = _field$input[operation]) === null || _field$input === void 0 ? void 0 : _field$input.resolve;
3563
+ if (inputResolver && field.dbField.kind !== 'relation') {
3564
+ try {
3565
+ return [fieldKey, await inputResolver(resolvedData[fieldKey], context, undefined)];
3566
+ } catch (error) {
3567
+ resolverErrors.push({
3568
+ error,
3569
+ tag: `${list.listKey}.${fieldKey}`
3570
+ });
3571
+ }
3572
+ }
3573
+ return [fieldKey, resolvedData[fieldKey]];
3574
+ })));
3575
+ if (resolverErrors.length) throw resolveHooks.resolverError(resolverErrors);
3576
+
3577
+ // apply relationship field type input resolvers
3578
+ const relationshipErrors = [];
3579
+ resolvedData = Object.fromEntries(await Promise.all(Object.entries(list.fields).map(async ([fieldKey, field]) => {
3580
+ var _field$input2;
3581
+ const inputResolver = (_field$input2 = field.input) === null || _field$input2 === void 0 || (_field$input2 = _field$input2[operation]) === null || _field$input2 === void 0 ? void 0 : _field$input2.resolve;
3582
+ let input = resolvedData[fieldKey];
3583
+ if (inputResolver && field.dbField.kind === 'relation') {
3584
+ const tag = `${list.listKey}.${fieldKey}`;
3585
+ try {
3586
+ input = await inputResolver(input, context,
3587
+ // this third argument only applies to relationship fields
3588
+ (() => {
3589
+ if (input === undefined) {
3590
+ // no-op: this is what we want
3591
+ return () => undefined;
3592
+ }
3593
+ if (input === null) {
3594
+ // no-op: should this be userinputerror?
3595
+ return () => undefined;
3596
+ }
3597
+ const foreignList = list.lists[field.dbField.list];
3598
+ if (field.dbField.mode === 'many' && operation === 'create') {
3599
+ return resolveRelateToManyForCreateInput(nestedMutationState, context, foreignList, tag);
3600
+ }
3601
+ if (field.dbField.mode === 'many' && operation === 'update') {
3602
+ return resolveRelateToManyForUpdateInput(nestedMutationState, context, foreignList, tag);
3603
+ }
3604
+ if (field.dbField.mode === 'one' && operation === 'create') {
3605
+ return resolveRelateToOneForCreateInput(nestedMutationState, context, foreignList);
3606
+ }
3607
+ if (field.dbField.mode === 'one' && operation === 'update') {
3608
+ return resolveRelateToOneForUpdateInput(nestedMutationState, context, foreignList);
3609
+ }
3610
+ throw new Error('Unknown relationship field type input mode or operation');
3611
+ })());
3612
+ } catch (error) {
3613
+ if (error instanceof RelationshipErrors) {
3614
+ relationshipErrors.push(...error.errors);
3615
+ } else {
3616
+ relationshipErrors.push({
3617
+ error,
3618
+ tag
3619
+ });
3620
+ }
3621
+ }
3622
+ }
3623
+ return [fieldKey, input];
3624
+ })));
3625
+ if (relationshipErrors.length) throw resolveHooks.relationshipError(relationshipErrors);
3626
+
3627
+ // field hooks
3628
+ const fieldsErrors = [];
3629
+ resolvedData = Object.fromEntries(await Promise.all(Object.entries(list.fields).map(async ([fieldKey, field]) => {
3630
+ try {
3631
+ return [fieldKey, operation === 'create' ? await field.hooks.resolveInput.create({
3632
+ ...hookArgs,
3633
+ itemField: undefined,
3634
+ inputFieldData: hookArgs.inputData[fieldKey],
3635
+ resolvedData,
3636
+ resolvedFieldData: resolvedData[fieldKey],
3637
+ fieldKey
3638
+ }) : await field.hooks.resolveInput.update({
3639
+ ...hookArgs,
3640
+ itemField: hookArgs.item[fieldKey],
3641
+ inputFieldData: hookArgs.inputData[fieldKey],
3642
+ resolvedData,
3643
+ resolvedFieldData: resolvedData[fieldKey],
3644
+ fieldKey
3645
+ })];
3646
+ } catch (error) {
3647
+ fieldsErrors.push({
3648
+ error,
3649
+ tag: `${list.listKey}.${fieldKey}.hooks.resolveInput`
3650
+ });
3651
+ return [fieldKey, undefined];
3652
+ }
3653
+ })));
3654
+ if (fieldsErrors.length) throw resolveHooks.extensionError('resolveInput', fieldsErrors);
3655
+
3656
+ // list hooks
3657
+ try {
3658
+ if (operation === 'create') {
3659
+ resolvedData = await list.hooks.resolveInput.create({
3660
+ ...hookArgs,
3661
+ resolvedData
3662
+ });
3663
+ } else if (operation === 'update') {
3664
+ resolvedData = await list.hooks.resolveInput.update({
3665
+ ...hookArgs,
3666
+ resolvedData
3667
+ });
3668
+ }
3669
+ } catch (error) {
3670
+ throw resolveHooks.extensionError('resolveInput', [{
3671
+ error,
3672
+ tag: `${list.listKey}.hooks.resolveInput`
3673
+ }]);
3674
+ }
3675
+ return resolvedData;
3676
+ }
3677
+ async function resolveInputForCreateOrUpdate(list, context, inputData, item) {
3678
+ const nestedMutationState = new NestedMutationState(context);
3679
+ const baseHookArgs = {
3680
+ context,
3681
+ listKey: list.listKey,
3682
+ inputData,
3683
+ resolvedData: {}
3684
+ };
3685
+ const hookArgs = item === undefined ? {
3686
+ ...baseHookArgs,
3687
+ operation: 'create',
3688
+ item,
3689
+ originalItem: undefined
3690
+ } : {
3691
+ ...baseHookArgs,
3692
+ operation: 'update',
3693
+ item,
3694
+ originalItem: item
3695
+ };
3696
+
3697
+ // Take the original input and resolve all the fields down to what
3698
+ // will be saved into the database.
3699
+ hookArgs.resolvedData = await getResolvedData(list, hookArgs, nestedMutationState);
3700
+
3701
+ // Apply all validation checks
3702
+ await validate({
3703
+ list,
3704
+ hookArgs
3705
+ });
3706
+
3707
+ // Return the full resolved input (ready for prisma level operation),
3708
+ // and the afterOperation hook to be applied
3709
+ return {
3710
+ data: transformForPrismaClient(list, context, hookArgs.resolvedData),
3711
+ beforeOperation: async () => {
3712
+ // before operation
3713
+ await runSideEffectOnlyHook(list, 'beforeOperation', hookArgs);
3714
+ },
3715
+ afterOperation: async updatedItem => {
3716
+ await nestedMutationState.afterOperation();
3717
+
3718
+ // after operation
3719
+ await runSideEffectOnlyHook(list, 'afterOperation', {
3720
+ ...hookArgs,
3721
+ item: updatedItem
3722
+ });
3723
+ }
3724
+ };
3725
+ }
3726
+ function transformInnerDBField(dbField, context, value) {
3727
+ if (dbField.kind === 'scalar' && dbField.scalar === 'Json' && value === null) {
3728
+ return context.__internal.prisma.DbNull;
3729
+ }
3730
+ return value;
3731
+ }
3732
+ function transformForPrismaClient(list, context, data) {
3733
+ return Object.fromEntries([...function* () {
3734
+ for (const fieldKey in data) {
3735
+ if (!(fieldKey in list.fields)) {
3736
+ // either the types are wrong, or someone didnt use them, either way, bail out
3737
+ throw new Error(`Attempted to use unknown field "${fieldKey}"`);
3738
+ }
3739
+ const value = data[fieldKey];
3740
+ const {
3741
+ dbField
3742
+ } = list.fields[fieldKey];
3743
+ if (dbField.kind === 'multi') {
3744
+ for (const innerFieldKey in value) {
3745
+ const innerFieldValue = value[innerFieldKey];
3746
+ yield [utils.getDBFieldKeyForFieldOnMultiField(fieldKey, innerFieldKey), transformInnerDBField(dbField.fields[innerFieldKey], context, innerFieldValue)];
3747
+ }
3748
+ continue;
3749
+ }
3750
+ yield [fieldKey, transformInnerDBField(dbField, context, value)];
3751
+ }
3752
+ }()]);
3753
+ }
3754
+
3755
+ // This is not a thing that I really agree with but it's to make the behaviour consistent with old nixxie.
3756
+ // Basically, old nixxie uses Promise.allSettled and then after that maps that into promises that resolve and reject,
3757
+ // whereas the new stuff is just like "here are some promises" with no guarantees about the order they will be settled in.
3758
+ // That doesn't matter when they all resolve successfully because the order they resolve successfully in
3759
+ // doesn't affect anything, If some reject though, the order that they reject in will be the order in the errors array
3760
+ // and some of our tests rely on the order of the graphql errors array. They shouldn't, but they do.
3761
+ function promisesButSettledWhenAllSettledAndInOrder(promises) {
3762
+ const resultsPromise = Promise.allSettled(promises);
3763
+ return promises.map(async (_, i) => {
3764
+ const result = (await resultsPromise)[i];
3765
+ return result.status === 'fulfilled' ? Promise.resolve(result.value) : Promise.reject(result.reason);
3766
+ });
3767
+ }
3768
+ function nonNull(t) {
3769
+ if (t === nextFields.g.Empty) return t;
3770
+ return nextFields.g.nonNull(t);
3771
+ }
3772
+ function getMutationsForList(list) {
3773
+ const defaultUniqueWhereInput = list.isSingleton ? {
3774
+ id: '1'
3775
+ } : undefined;
3776
+ const createOne_ = nextFields.g.field({
3777
+ type: list.graphql.types.output,
3778
+ args: {
3779
+ data: nextFields.g.arg({
3780
+ type: nonNull(list.graphql.types.create)
3781
+ })
3782
+ },
3783
+ async resolve(_, {
3784
+ data
3785
+ }, context, info) {
3786
+ return await withSpan(`mutation ${info.fieldName}`, async () => {
3787
+ return createOne(data, list, context);
3788
+ }, {
3789
+ 'nixxie.list': list.listKey,
3790
+ 'nixxie.operation': 'create'
3791
+ });
3792
+ }
3793
+ });
3794
+ const createMany_ = nextFields.g.field({
3795
+ type: nextFields.g.list(list.graphql.types.output),
3796
+ args: {
3797
+ data: nextFields.g.arg({
3798
+ type: nextFields.g.nonNull(nextFields.g.list(nonNull(list.graphql.types.create)))
3799
+ })
3800
+ },
3801
+ async resolve(_, {
3802
+ data
3803
+ }, context, info) {
3804
+ return await withSpan(`mutation ${info.fieldName}`, async () => {
3805
+ return promisesButSettledWhenAllSettledAndInOrder(await createMany(data, list, context));
3806
+ }, {
3807
+ 'nixxie.list': list.listKey,
3808
+ 'nixxie.operation': 'create',
3809
+ 'nixxie.many': true
3810
+ });
3811
+ }
3812
+ });
3813
+ const updateOne_ = nextFields.g.field({
3814
+ type: list.graphql.types.output,
3815
+ args: {
3816
+ where: nextFields.g.arg({
3817
+ type: nextFields.g.nonNull(list.graphql.types.uniqueWhere),
3818
+ defaultValue: defaultUniqueWhereInput
3819
+ }),
3820
+ data: nextFields.g.arg({
3821
+ type: nonNull(list.graphql.types.update)
3822
+ })
3823
+ },
3824
+ async resolve(_, {
3825
+ where,
3826
+ data
3827
+ }, context, info) {
3828
+ return await withSpan(`mutation ${info.fieldName}`, async () => {
3829
+ return updateOne({
3830
+ where,
3831
+ data
3832
+ }, list, context);
3833
+ }, {
3834
+ 'nixxie.list': list.listKey,
3835
+ 'nixxie.operation': 'update'
3836
+ });
3837
+ }
3838
+ });
3839
+ const updateManyInput = nextFields.g.inputObject({
3840
+ name: list.graphql.names.updateManyInputName,
3841
+ fields: {
3842
+ where: nextFields.g.arg({
3843
+ type: nextFields.g.nonNull(list.graphql.types.uniqueWhere),
3844
+ defaultValue: defaultUniqueWhereInput
3845
+ }),
3846
+ data: nextFields.g.arg({
3847
+ type: nonNull(list.graphql.types.update)
3848
+ })
3849
+ }
3850
+ });
3851
+ const updateMany_ = nextFields.g.field({
3852
+ type: nextFields.g.list(list.graphql.types.output),
3853
+ args: {
3854
+ data: nextFields.g.arg({
3855
+ type: nextFields.g.nonNull(nextFields.g.list(nextFields.g.nonNull(updateManyInput)))
3856
+ })
3857
+ },
3858
+ async resolve(_, {
3859
+ data
3860
+ }, context, info) {
3861
+ return await withSpan(`mutation ${info.fieldName}`, async () => {
3862
+ return promisesButSettledWhenAllSettledAndInOrder(await updateMany(data, list, context));
3863
+ }, {
3864
+ 'nixxie.list': list.listKey,
3865
+ 'nixxie.operation': 'update',
3866
+ 'nixxie.many': true
3867
+ });
3868
+ }
3869
+ });
3870
+ const deleteOne_ = nextFields.g.field({
3871
+ type: list.graphql.types.output,
3872
+ args: {
3873
+ where: nextFields.g.arg({
3874
+ type: nextFields.g.nonNull(list.graphql.types.uniqueWhere),
3875
+ defaultValue: defaultUniqueWhereInput
3876
+ })
3877
+ },
3878
+ async resolve(_, {
3879
+ where
3880
+ }, context, info) {
3881
+ return await withSpan(`mutation ${info.fieldName}`, async () => {
3882
+ return deleteOne(where, list, context);
3883
+ }, {
3884
+ 'nixxie.list': list.listKey,
3885
+ 'nixxie.operation': 'delete'
3886
+ });
3887
+ }
3888
+ });
3889
+ const deleteMany_ = nextFields.g.field({
3890
+ type: nextFields.g.list(list.graphql.types.output),
3891
+ args: {
3892
+ where: nextFields.g.arg({
3893
+ type: nextFields.g.nonNull(nextFields.g.list(nextFields.g.nonNull(list.graphql.types.uniqueWhere)))
3894
+ })
3895
+ },
3896
+ async resolve(_, {
3897
+ where
3898
+ }, context, info) {
3899
+ return await withSpan(`mutation ${info.fieldName}`, async () => {
3900
+ return promisesButSettledWhenAllSettledAndInOrder(await deleteMany(where, list, context));
3901
+ }, {
3902
+ 'nixxie.list': list.listKey,
3903
+ 'nixxie.operation': 'delete',
3904
+ 'nixxie.many': true
3905
+ });
3906
+ }
3907
+ });
3908
+ const collectedTypes = [];
3909
+ const {
3910
+ isEnabled
3911
+ } = list.graphql;
3912
+ if (isEnabled.type) {
3913
+ // adding all of these types explicitly isn't strictly necessary but we do it to create a certain order in the schema
3914
+ collectedTypes.push(list.graphql.types.output);
3915
+ if (isEnabled.query || isEnabled.update || isEnabled.delete) {
3916
+ collectedTypes.push(list.graphql.types.uniqueWhere);
3917
+ }
3918
+ if (isEnabled.query) {
3919
+ for (const field of Object.values(list.fields)) {
3920
+ if (isEnabled.query && field.graphql.isEnabled.read && field.unreferencedConcreteInterfaceImplementations) {
3921
+ // this _IS_ actually necessary since they aren't implicitly referenced by other types, unlike the types above
3922
+ collectedTypes.push(...field.unreferencedConcreteInterfaceImplementations);
3923
+ }
3924
+ }
3925
+ collectedTypes.push(list.graphql.types.where);
3926
+ collectedTypes.push(list.graphql.types.orderBy);
3927
+ }
3928
+ if (isEnabled.update) {
3929
+ if (list.graphql.types.update instanceof schema.GInputObjectType) {
3930
+ collectedTypes.push(list.graphql.types.update);
3931
+ }
3932
+ collectedTypes.push(updateManyInput);
3933
+ }
3934
+ if (isEnabled.create) {
3935
+ if (list.graphql.types.create instanceof schema.GInputObjectType) {
3936
+ collectedTypes.push(list.graphql.types.create);
3937
+ }
3938
+ }
3939
+ }
3940
+ return {
3941
+ mutations: {
3942
+ ...(list.graphql.isEnabled.create && {
3943
+ [list.graphql.names.createMutationName]: createOne_,
3944
+ [list.graphql.names.createManyMutationName]: createMany_
3945
+ }),
3946
+ ...(list.graphql.isEnabled.update && {
3947
+ [list.graphql.names.updateMutationName]: updateOne_,
3948
+ [list.graphql.names.updateManyMutationName]: updateMany_
3949
+ }),
3950
+ ...(list.graphql.isEnabled.delete && {
3951
+ [list.graphql.names.deleteMutationName]: deleteOne_,
3952
+ [list.graphql.names.deleteManyMutationName]: deleteMany_
3953
+ }),
3954
+ ...Object.fromEntries(function* () {
3955
+ for (const action of list.actions) {
3956
+ yield [action.graphql.names.one, nextFields.g.field({
3957
+ type: list.graphql.types.output,
3958
+ args: {
3959
+ where: nextFields.g.arg({
3960
+ type: nextFields.g.nonNull(list.graphql.types.uniqueWhere),
3961
+ defaultValue: defaultUniqueWhereInput
3962
+ }),
3963
+ ...action.graphql.types.arguments
3964
+ },
3965
+ async resolve(_, {
3966
+ where,
3967
+ ...args
3968
+ }, context, info) {
3969
+ return await withSpan(`mutation ${info.fieldName}`, async () => {
3970
+ return actionOne({
3971
+ where,
3972
+ args
3973
+ }, list, context, action);
3974
+ }, {
3975
+ 'nixxie.list': list.listKey,
3976
+ 'nixxie.action': action.actionKey
3977
+ });
3978
+ }
3979
+ })];
3980
+ yield [action.graphql.names.many, nextFields.g.field({
3981
+ type: nextFields.g.list(list.graphql.types.output),
3982
+ args: {
3983
+ data: nextFields.g.arg({
3984
+ type: nextFields.g.nonNull(nextFields.g.list(nextFields.g.nonNull(action.graphql.types.args)))
3985
+ })
3986
+ },
3987
+ async resolve(_, {
3988
+ data
3989
+ }, context, info) {
3990
+ return await withSpan(`mutation ${info.fieldName}`, async () => {
3991
+ return promisesButSettledWhenAllSettledAndInOrder(await actionMany(data, list, context, action));
3992
+ }, {
3993
+ 'nixxie.list': list.listKey,
3994
+ 'nixxie.action': action.actionKey,
3995
+ 'nixxie.many': true
3996
+ });
3997
+ }
3998
+ })];
3999
+ }
4000
+ }())
4001
+ },
4002
+ types: collectedTypes
4003
+ };
4004
+ }
4005
+
4006
+ function getQueriesForList(list) {
4007
+ if (!list.graphql.isEnabled.query) return {};
4008
+ const findOne$1 = nextFields.g.field({
4009
+ type: list.graphql.types.output,
4010
+ args: {
4011
+ where: nextFields.g.arg({
4012
+ type: nextFields.g.nonNull(list.graphql.types.uniqueWhere),
4013
+ defaultValue: list.isSingleton ? {
4014
+ id: '1'
4015
+ } : undefined
4016
+ })
4017
+ },
4018
+ async resolve(_, args, context, info) {
4019
+ return await withSpan(`query ${info.fieldName}`, async () => {
4020
+ return findOne(args, list, context, info);
4021
+ }, {
4022
+ 'nixxie.list': list.listKey
4023
+ });
4024
+ }
4025
+ });
4026
+ const findMany$1 = nextFields.g.field({
4027
+ type: nextFields.g.list(nextFields.g.nonNull(list.graphql.types.output)),
4028
+ args: list.graphql.types.findManyArgs,
4029
+ async resolve(_, args, context, info) {
4030
+ return await withSpan(`query ${info.fieldName}`, async () => {
4031
+ return findMany(args, list, context, info);
4032
+ }, {
4033
+ 'nixxie.list': list.listKey
4034
+ });
4035
+ }
4036
+ });
4037
+ const countQuery = nextFields.g.field({
4038
+ type: nextFields.g.Int,
4039
+ args: {
4040
+ where: nextFields.g.arg({
4041
+ type: nextFields.g.nonNull(list.graphql.types.where),
4042
+ defaultValue: list.isSingleton ? {
4043
+ id: {
4044
+ equals: '1'
4045
+ }
4046
+ } : {}
4047
+ })
4048
+ },
4049
+ async resolve(_, args, context, info) {
4050
+ return await withSpan(`query ${info.fieldName}`, async () => {
4051
+ return count(args, list, context, info);
4052
+ }, {
4053
+ 'nixxie.list': list.listKey
4054
+ });
4055
+ }
4056
+ });
4057
+ return {
4058
+ [list.graphql.names.itemQueryName]: findOne$1,
4059
+ [list.graphql.names.listQueryName]: findMany$1,
4060
+ [list.graphql.names.listQueryCountName]: countQuery
4061
+ };
4062
+ }
4063
+
4064
+ function getGraphQLSchema(lists, extraFields, sudo) {
4065
+ const query = nextFields.g.object()({
4066
+ name: 'Query',
4067
+ fields: Object.assign({}, ...Object.values(lists).map(list => getQueriesForList(list)), extraFields.query)
4068
+ });
4069
+ const collectedTypes = [];
4070
+ const mutation = nextFields.g.object()({
4071
+ name: 'Mutation',
4072
+ fields: Object.assign({}, ...Object.values(lists).map(list => {
4073
+ const {
4074
+ mutations,
4075
+ types
4076
+ } = getMutationsForList(list);
4077
+ collectedTypes.push(...types);
4078
+ return mutations;
4079
+ }), extraFields.mutation)
4080
+ });
4081
+ return new graphql.GraphQLSchema({
4082
+ query,
4083
+ mutation,
4084
+ types: [...collectedTypes, nextFields.g.JSON, mutation],
4085
+ extensions: {
4086
+ sudo
4087
+ }
4088
+ });
4089
+ }
4090
+ function createGraphQLSchema(config, lists, adminMeta, sudo) {
4091
+ var _config$graphql$exten, _config$graphql, _config$graphql$exten2;
4092
+ const graphQLSchema = getGraphQLSchema(lists, {
4093
+ mutation: {},
4094
+ query: adminMeta ? {
4095
+ nixxie: nextFields.g.field({
4096
+ type: nextFields.g.nonNull(NixxieMeta),
4097
+ resolve: () => ({
4098
+ adminMeta
4099
+ })
4100
+ })
4101
+ } : {}
4102
+ }, sudo);
4103
+
4104
+ // merge in the user defined graphQL API
4105
+ return (_config$graphql$exten = (_config$graphql = config.graphql) === null || _config$graphql === void 0 || (_config$graphql$exten2 = _config$graphql.extendGraphqlSchema) === null || _config$graphql$exten2 === void 0 ? void 0 : _config$graphql$exten2.call(_config$graphql, graphQLSchema)) !== null && _config$graphql$exten !== void 0 ? _config$graphql$exten : graphQLSchema;
4106
+ }
4107
+
4108
+ // TODO: this cannot be changed for now, circular dependency with getSystemPaths, getEsbuildConfig
4109
+ function getBuiltNixxieConfigurationPath(cwd) {
4110
+ return path__default["default"].join(cwd, '.nixxie/config.js');
4111
+ }
4112
+ function posixify(s) {
4113
+ return s.split(path__default["default"].sep).join('/');
4114
+ }
4115
+ function getSystemPaths(cwd, config) {
4116
+ var _config$types, _config$db, _config$graphql;
4117
+ const prismaClientPath = config.db.prismaClientPath === '@prisma/client' ? null : config.db.prismaClientPath ? path__default["default"].join(cwd, config.db.prismaClientPath) : null;
4118
+ const builtTypesPath = (_config$types = config.types) !== null && _config$types !== void 0 && _config$types.path ? path__default["default"].join(cwd, config.types.path) // TODO: enforce initConfig before getSystemPaths
4119
+ : path__default["default"].join(cwd, 'node_modules/.nixxie/types.ts');
4120
+ const builtPrismaPath = (_config$db = config.db) !== null && _config$db !== void 0 && _config$db.prismaSchemaPath ? path__default["default"].join(cwd, config.db.prismaSchemaPath) // TODO: enforce initConfig before getSystemPaths
4121
+ : path__default["default"].join(cwd, 'schema.prisma');
4122
+ const relativePrismaPath = prismaClientPath ? `./${posixify(path__default["default"].relative(path__default["default"].dirname(builtTypesPath), prismaClientPath))}` : '@prisma/client';
4123
+ const builtGraphqlPath = (_config$graphql = config.graphql) !== null && _config$graphql !== void 0 && _config$graphql.schemaPath ? path__default["default"].join(cwd, config.graphql.schemaPath) // TODO: enforce initConfig before getSystemPaths
4124
+ : path__default["default"].join(cwd, 'schema.graphql');
4125
+ return {
4126
+ config: getBuiltNixxieConfigurationPath(cwd),
4127
+ admin: path__default["default"].join(cwd, '.nixxie/admin'),
4128
+ prisma: prismaClientPath !== null && prismaClientPath !== void 0 ? prismaClientPath : '@prisma/client',
4129
+ types: {
4130
+ relativePrismaPath
4131
+ },
4132
+ schema: {
4133
+ types: builtTypesPath,
4134
+ prisma: builtPrismaPath,
4135
+ graphql: builtGraphqlPath
4136
+ }
4137
+ };
4138
+ }
4139
+ function getInternalGraphQLSchema(config) {
4140
+ // omit `graphql.omit`
4141
+ const withoutOmit = {
4142
+ ...config,
4143
+ lists: Object.fromEntries(Object.entries(config.lists).map(([listKey, list]) => {
4144
+ return [listKey, {
4145
+ ...list,
4146
+ graphql: {
4147
+ ...(list.graphql || {}),
4148
+ omit: false
4149
+ },
4150
+ fields: Object.fromEntries(Object.entries(list.fields).map(([fieldKey, field]) => {
4151
+ if (fieldKey.startsWith('__group')) return [fieldKey, field];
4152
+ return [fieldKey, data => {
4153
+ const f = field(data);
4154
+ return {
4155
+ ...f,
4156
+ graphql: {
4157
+ ...(f.graphql || {}),
4158
+ omit: false
4159
+ },
4160
+ // WARNING: this bypasses access control checks for filtering and ordering on the internal schema
4161
+ isFilterable: true,
4162
+ // TODO: remove when moved to .access.filter and .omit.filter
4163
+ isOrderable: true // TODO: remove when moved to .access.filter and .omit.filter
4164
+ };
4165
+ }];
4166
+ }))
4167
+ }];
4168
+ }))
4169
+ };
4170
+ const lists = initialiseLists(withoutOmit);
4171
+ const adminMeta = adminMeta$1.createAdminMeta(withoutOmit, lists);
4172
+ return createGraphQLSchema(withoutOmit, lists, adminMeta, true);
4173
+ }
4174
+ function injectNewDefaults(prismaClient, lists) {
4175
+ for (const listKey in lists) {
4176
+ var _dbField$default;
4177
+ const list = lists[listKey];
4178
+
4179
+ // TODO: other fields might use 'random' too
4180
+ const {
4181
+ dbField
4182
+ } = list.fields.id;
4183
+ if ('default' in dbField && ((_dbField$default = dbField.default) === null || _dbField$default === void 0 ? void 0 : _dbField$default.kind) === 'random') {
4184
+ const {
4185
+ bytes,
4186
+ encoding
4187
+ } = dbField.default;
4188
+ prismaClient = prismaClient.$extends({
4189
+ query: {
4190
+ [list.prisma.listKey]: {
4191
+ async create({
4192
+ args,
4193
+ query
4194
+ }) {
4195
+ var _args$data$id;
4196
+ return query({
4197
+ ...args,
4198
+ data: {
4199
+ ...args.data,
4200
+ id: (_args$data$id = args.data.id) !== null && _args$data$id !== void 0 ? _args$data$id : node_crypto.randomBytes(bytes).toString(encoding)
4201
+ }
4202
+ });
4203
+ }
4204
+ }
4205
+ }
4206
+ });
4207
+ }
4208
+ }
4209
+ return prismaClient;
4210
+ }
4211
+ function formatUrl(provider, url) {
4212
+ if (url.startsWith('file:')) {
4213
+ const parsed = new URL(url);
4214
+ if (provider === 'sqlite' && !parsed.searchParams.get('connection_limit')) {
4215
+ // https://github.com/prisma/prisma/issues/9562
4216
+ // https://github.com/prisma/prisma/issues/10403
4217
+ // https://github.com/prisma/prisma/issues/11789
4218
+ parsed.searchParams.set('connection_limit', '1');
4219
+ const [uri] = url.split('?');
4220
+ return `${uri}?${parsed.search}`;
4221
+ }
4222
+ }
4223
+ return url;
4224
+ }
4225
+ function createSystem(config) {
4226
+ const lists = initialiseLists(config);
4227
+ const adminMeta = adminMeta$1.createAdminMeta(config, lists);
4228
+ const graphQLSchemas = {
4229
+ public: createGraphQLSchema(config, lists, adminMeta, false),
4230
+ internal: getInternalGraphQLSchema(config)
4231
+ };
4232
+ return {
4233
+ config,
4234
+ graphql: {
4235
+ schemas: graphQLSchemas
4236
+ },
4237
+ adminMeta,
4238
+ lists,
4239
+ getPaths: cwd => getSystemPaths(cwd, config),
4240
+ getNixxie: PM => {
4241
+ const prePrismaClient = new PM.PrismaClient({
4242
+ datasourceUrl: formatUrl(config.db.provider, config.db.url),
4243
+ log: config.db.enableLogging
4244
+ });
4245
+ const prismaClient = config.db.extendPrismaClient(injectNewDefaults(prePrismaClient, lists));
4246
+ const context = createContext({
4247
+ config,
4248
+ lists,
4249
+ graphQLSchemas,
4250
+ prismaClient,
4251
+ prismaTypes: {
4252
+ DbNull: PM.Prisma.DbNull,
4253
+ JsonNull: PM.Prisma.JsonNull
4254
+ }
4255
+ });
4256
+ return {
4257
+ // TODO: replace with server.onStart, remove in breaking change
4258
+ async connect() {
4259
+ var _config$db$onConnect, _config$db2;
4260
+ await prismaClient.$connect();
4261
+ await ((_config$db$onConnect = (_config$db2 = config.db).onConnect) === null || _config$db$onConnect === void 0 ? void 0 : _config$db$onConnect.call(_config$db2, context));
4262
+ },
4263
+ // TODO: only used by tests, remove in breaking change
4264
+ async disconnect() {
4265
+ await prismaClient.$disconnect();
4266
+ },
4267
+ context
4268
+ };
4269
+ }
4270
+ };
4271
+ }
4272
+ function getContext(config, PrismaModule) {
4273
+ const system = createSystem(config);
4274
+ const {
4275
+ context
4276
+ } = system.getNixxie(PrismaModule);
4277
+ return context;
4278
+ }
4279
+
4280
+ exports.createSystem = createSystem;
4281
+ exports.getBuiltNixxieConfigurationPath = getBuiltNixxieConfigurationPath;
4282
+ exports.getContext = getContext;
4283
+ exports.withSpan = withSpan;