payload-auth 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 (200) hide show
  1. package/LICENSE.md +17 -0
  2. package/dist/authjs/index.d.ts +1 -0
  3. package/dist/authjs/index.js +3 -0
  4. package/dist/authjs/index.js.map +1 -0
  5. package/dist/better-auth/adapter/dev/bin/run.d.ts +1 -0
  6. package/dist/better-auth/adapter/dev/bin/run.js +64 -0
  7. package/dist/better-auth/adapter/dev/bin/run.js.map +1 -0
  8. package/dist/better-auth/adapter/dev/bin/schema.d.ts +22 -0
  9. package/dist/better-auth/adapter/dev/bin/schema.js +160 -0
  10. package/dist/better-auth/adapter/dev/bin/schema.js.map +1 -0
  11. package/dist/better-auth/adapter/dev/collections.d.ts +3 -0
  12. package/dist/better-auth/adapter/dev/collections.js +212 -0
  13. package/dist/better-auth/adapter/dev/collections.js.map +1 -0
  14. package/dist/better-auth/adapter/dev/index.d.ts +3 -0
  15. package/dist/better-auth/adapter/dev/index.js +168 -0
  16. package/dist/better-auth/adapter/dev/index.js.map +1 -0
  17. package/dist/better-auth/adapter/generate-schema/generate-schema-builder.d.ts +23 -0
  18. package/dist/better-auth/adapter/generate-schema/generate-schema-builder.js +326 -0
  19. package/dist/better-auth/adapter/generate-schema/generate-schema-builder.js.map +1 -0
  20. package/dist/better-auth/adapter/generate-schema/get-payload-schema.d.ts +1 -0
  21. package/dist/better-auth/adapter/generate-schema/get-payload-schema.js +23 -0
  22. package/dist/better-auth/adapter/generate-schema/get-payload-schema.js.map +1 -0
  23. package/dist/better-auth/adapter/generate-schema/index.d.ts +4 -0
  24. package/dist/better-auth/adapter/generate-schema/index.js +19 -0
  25. package/dist/better-auth/adapter/generate-schema/index.js.map +1 -0
  26. package/dist/better-auth/adapter/generate-schema/utils.d.ts +2 -0
  27. package/dist/better-auth/adapter/generate-schema/utils.js +20 -0
  28. package/dist/better-auth/adapter/generate-schema/utils.js.map +1 -0
  29. package/dist/better-auth/adapter/index.d.ts +5 -0
  30. package/dist/better-auth/adapter/index.js +578 -0
  31. package/dist/better-auth/adapter/index.js.map +1 -0
  32. package/dist/better-auth/adapter/test/adapter.test.d.ts +1 -0
  33. package/dist/better-auth/adapter/test/adapter.test.js +181 -0
  34. package/dist/better-auth/adapter/test/adapter.test.js.map +1 -0
  35. package/dist/better-auth/adapter/test/better-auth-adapter-test.d.ts +7 -0
  36. package/dist/better-auth/adapter/test/better-auth-adapter-test.js +425 -0
  37. package/dist/better-auth/adapter/test/better-auth-adapter-test.js.map +1 -0
  38. package/dist/better-auth/adapter/test/schema.test.d.ts +1 -0
  39. package/dist/better-auth/adapter/test/schema.test.js +796 -0
  40. package/dist/better-auth/adapter/test/schema.test.js.map +1 -0
  41. package/dist/better-auth/adapter/test/test_payload1/schema.d.ts +23 -0
  42. package/dist/better-auth/adapter/test/test_payload1/schema.js +177 -0
  43. package/dist/better-auth/adapter/test/test_payload1/schema.js.map +1 -0
  44. package/dist/better-auth/adapter/test/test_payload2/schema.d.ts +23 -0
  45. package/dist/better-auth/adapter/test/test_payload2/schema.js +167 -0
  46. package/dist/better-auth/adapter/test/test_payload2/schema.js.map +1 -0
  47. package/dist/better-auth/adapter/test/test_payload3/schema.d.ts +23 -0
  48. package/dist/better-auth/adapter/test/test_payload3/schema.js +198 -0
  49. package/dist/better-auth/adapter/test/test_payload3/schema.js.map +1 -0
  50. package/dist/better-auth/adapter/transform/index.d.ts +16 -0
  51. package/dist/better-auth/adapter/transform/index.js +252 -0
  52. package/dist/better-auth/adapter/transform/index.js.map +1 -0
  53. package/dist/better-auth/adapter/types.d.ts +6 -0
  54. package/dist/better-auth/adapter/types.js +3 -0
  55. package/dist/better-auth/adapter/types.js.map +1 -0
  56. package/dist/better-auth/index.d.ts +6 -0
  57. package/dist/better-auth/index.js +8 -0
  58. package/dist/better-auth/index.js.map +1 -0
  59. package/dist/better-auth/plugin/collections/accounts/hooks/sync-password-to-user.d.ts +7 -0
  60. package/dist/better-auth/plugin/collections/accounts/hooks/sync-password-to-user.js +47 -0
  61. package/dist/better-auth/plugin/collections/accounts/hooks/sync-password-to-user.js.map +1 -0
  62. package/dist/better-auth/plugin/collections/users/endpoints/refresh-token.d.ts +6 -0
  63. package/dist/better-auth/plugin/collections/users/endpoints/refresh-token.js +106 -0
  64. package/dist/better-auth/plugin/collections/users/endpoints/refresh-token.js.map +1 -0
  65. package/dist/better-auth/plugin/collections/users/hooks/after-login.d.ts +11 -0
  66. package/dist/better-auth/plugin/collections/users/hooks/after-login.js +71 -0
  67. package/dist/better-auth/plugin/collections/users/hooks/after-login.js.map +1 -0
  68. package/dist/better-auth/plugin/collections/users/hooks/after-logout.d.ts +6 -0
  69. package/dist/better-auth/plugin/collections/users/hooks/after-logout.js +49 -0
  70. package/dist/better-auth/plugin/collections/users/hooks/after-logout.js.map +1 -0
  71. package/dist/better-auth/plugin/collections/users/hooks/before-login.d.ts +5 -0
  72. package/dist/better-auth/plugin/collections/users/hooks/before-login.js +18 -0
  73. package/dist/better-auth/plugin/collections/users/hooks/before-login.js.map +1 -0
  74. package/dist/better-auth/plugin/collections/users/hooks/clean-up-user-after-delete.d.ts +5 -0
  75. package/dist/better-auth/plugin/collections/users/hooks/clean-up-user-after-delete.js +33 -0
  76. package/dist/better-auth/plugin/collections/users/hooks/clean-up-user-after-delete.js.map +1 -0
  77. package/dist/better-auth/plugin/collections/users/hooks/on-verified-change.d.ts +2 -0
  78. package/dist/better-auth/plugin/collections/users/hooks/on-verified-change.js +14 -0
  79. package/dist/better-auth/plugin/collections/users/hooks/on-verified-change.js.map +1 -0
  80. package/dist/better-auth/plugin/collections/users/hooks/sync-account.d.ts +7 -0
  81. package/dist/better-auth/plugin/collections/users/hooks/sync-account.js +82 -0
  82. package/dist/better-auth/plugin/collections/users/hooks/sync-account.js.map +1 -0
  83. package/dist/better-auth/plugin/helpers/generate-verify-email-url.d.ts +29 -0
  84. package/dist/better-auth/plugin/helpers/generate-verify-email-url.js +46 -0
  85. package/dist/better-auth/plugin/helpers/generate-verify-email-url.js.map +1 -0
  86. package/dist/better-auth/plugin/helpers/get-ip.d.ts +2 -0
  87. package/dist/better-auth/plugin/helpers/get-ip.js +31 -0
  88. package/dist/better-auth/plugin/helpers/get-ip.js.map +1 -0
  89. package/dist/better-auth/plugin/helpers/index.d.ts +1 -0
  90. package/dist/better-auth/plugin/helpers/index.js +3 -0
  91. package/dist/better-auth/plugin/helpers/index.js.map +1 -0
  92. package/dist/better-auth/plugin/helpers/serialize-cookie.d.ts +104 -0
  93. package/dist/better-auth/plugin/helpers/serialize-cookie.js +186 -0
  94. package/dist/better-auth/plugin/helpers/serialize-cookie.js.map +1 -0
  95. package/dist/better-auth/plugin/index.d.ts +7 -0
  96. package/dist/better-auth/plugin/index.js +64 -0
  97. package/dist/better-auth/plugin/index.js.map +1 -0
  98. package/dist/better-auth/plugin/lib/auth-strategy.d.ts +8 -0
  99. package/dist/better-auth/plugin/lib/auth-strategy.js +48 -0
  100. package/dist/better-auth/plugin/lib/auth-strategy.js.map +1 -0
  101. package/dist/better-auth/plugin/lib/build-collection-configs.d.ts +11 -0
  102. package/dist/better-auth/plugin/lib/build-collection-configs.js +1558 -0
  103. package/dist/better-auth/plugin/lib/build-collection-configs.js.map +1 -0
  104. package/dist/better-auth/plugin/lib/config.d.ts +41 -0
  105. package/dist/better-auth/plugin/lib/config.js +43 -0
  106. package/dist/better-auth/plugin/lib/config.js.map +1 -0
  107. package/dist/better-auth/plugin/lib/ensure-password-set-before-create.d.ts +7 -0
  108. package/dist/better-auth/plugin/lib/ensure-password-set-before-create.js +24 -0
  109. package/dist/better-auth/plugin/lib/ensure-password-set-before-create.js.map +1 -0
  110. package/dist/better-auth/plugin/lib/get-payload-auth.d.ts +5 -0
  111. package/dist/better-auth/plugin/lib/get-payload-auth.js +9 -0
  112. package/dist/better-auth/plugin/lib/get-payload-auth.js.map +1 -0
  113. package/dist/better-auth/plugin/lib/get-required-collection-slugs.d.ts +9 -0
  114. package/dist/better-auth/plugin/lib/get-required-collection-slugs.js +52 -0
  115. package/dist/better-auth/plugin/lib/get-required-collection-slugs.js.map +1 -0
  116. package/dist/better-auth/plugin/lib/init-better-auth.d.ts +6 -0
  117. package/dist/better-auth/plugin/lib/init-better-auth.js +13 -0
  118. package/dist/better-auth/plugin/lib/init-better-auth.js.map +1 -0
  119. package/dist/better-auth/plugin/lib/password.d.ts +25 -0
  120. package/dist/better-auth/plugin/lib/password.js +63 -0
  121. package/dist/better-auth/plugin/lib/password.js.map +1 -0
  122. package/dist/better-auth/plugin/lib/payload-access.d.ts +14 -0
  123. package/dist/better-auth/plugin/lib/payload-access.js +64 -0
  124. package/dist/better-auth/plugin/lib/payload-access.js.map +1 -0
  125. package/dist/better-auth/plugin/lib/prepare-session-data.d.ts +21 -0
  126. package/dist/better-auth/plugin/lib/prepare-session-data.js +42 -0
  127. package/dist/better-auth/plugin/lib/prepare-session-data.js.map +1 -0
  128. package/dist/better-auth/plugin/lib/respect-save-to-jwt-fields-middleware.d.ts +15 -0
  129. package/dist/better-auth/plugin/lib/respect-save-to-jwt-fields-middleware.js +30 -0
  130. package/dist/better-auth/plugin/lib/respect-save-to-jwt-fields-middleware.js.map +1 -0
  131. package/dist/better-auth/plugin/lib/sanitize-auth-options.d.ts +5 -0
  132. package/dist/better-auth/plugin/lib/sanitize-auth-options.js +298 -0
  133. package/dist/better-auth/plugin/lib/sanitize-auth-options.js.map +1 -0
  134. package/dist/better-auth/plugin/payload/components/admin-buttons.d.ts +5 -0
  135. package/dist/better-auth/plugin/payload/components/admin-buttons.js +222 -0
  136. package/dist/better-auth/plugin/payload/components/admin-buttons.js.map +1 -0
  137. package/dist/better-auth/plugin/payload/components/login-redirect.d.ts +1 -0
  138. package/dist/better-auth/plugin/payload/components/login-redirect.js +6 -0
  139. package/dist/better-auth/plugin/payload/components/login-redirect.js.map +1 -0
  140. package/dist/better-auth/plugin/payload/components/logo.d.ts +1 -0
  141. package/dist/better-auth/plugin/payload/components/logo.js +36 -0
  142. package/dist/better-auth/plugin/payload/components/logo.js.map +1 -0
  143. package/dist/better-auth/plugin/payload/components/logout.d.ts +1 -0
  144. package/dist/better-auth/plugin/payload/components/logout.js +61 -0
  145. package/dist/better-auth/plugin/payload/components/logout.js.map +1 -0
  146. package/dist/better-auth/plugin/payload/components/sign-in.d.ts +3 -0
  147. package/dist/better-auth/plugin/payload/components/sign-in.js +384 -0
  148. package/dist/better-auth/plugin/payload/components/sign-in.js.map +1 -0
  149. package/dist/better-auth/plugin/payload/components/sign-up.d.ts +6 -0
  150. package/dist/better-auth/plugin/payload/components/sign-up.js +502 -0
  151. package/dist/better-auth/plugin/payload/components/sign-up.js.map +1 -0
  152. package/dist/better-auth/plugin/payload/components/styles.css +73 -0
  153. package/dist/better-auth/plugin/payload/components/ui/button.d.ts +10 -0
  154. package/dist/better-auth/plugin/payload/components/ui/button.js +42 -0
  155. package/dist/better-auth/plugin/payload/components/ui/button.js.map +1 -0
  156. package/dist/better-auth/plugin/payload/components/ui/card.d.ts +9 -0
  157. package/dist/better-auth/plugin/payload/components/ui/card.js +55 -0
  158. package/dist/better-auth/plugin/payload/components/ui/card.js.map +1 -0
  159. package/dist/better-auth/plugin/payload/components/ui/checkbox.d.ts +4 -0
  160. package/dist/better-auth/plugin/payload/components/ui/checkbox.js +23 -0
  161. package/dist/better-auth/plugin/payload/components/ui/checkbox.js.map +1 -0
  162. package/dist/better-auth/plugin/payload/components/ui/cn.d.ts +2 -0
  163. package/dist/better-auth/plugin/payload/components/ui/cn.js +7 -0
  164. package/dist/better-auth/plugin/payload/components/ui/cn.js.map +1 -0
  165. package/dist/better-auth/plugin/payload/components/ui/input.d.ts +3 -0
  166. package/dist/better-auth/plugin/payload/components/ui/input.js +14 -0
  167. package/dist/better-auth/plugin/payload/components/ui/input.js.map +1 -0
  168. package/dist/better-auth/plugin/payload/components/ui/label.d.ts +4 -0
  169. package/dist/better-auth/plugin/payload/components/ui/label.js +15 -0
  170. package/dist/better-auth/plugin/payload/components/ui/label.js.map +1 -0
  171. package/dist/better-auth/plugin/payload/components/ui/password-input.d.ts +2 -0
  172. package/dist/better-auth/plugin/payload/components/ui/password-input.js +55 -0
  173. package/dist/better-auth/plugin/payload/components/ui/password-input.js.map +1 -0
  174. package/dist/better-auth/plugin/payload/exports/client.d.ts +3 -0
  175. package/dist/better-auth/plugin/payload/exports/client.js +5 -0
  176. package/dist/better-auth/plugin/payload/exports/client.js.map +1 -0
  177. package/dist/better-auth/plugin/payload/exports/rsc.d.ts +5 -0
  178. package/dist/better-auth/plugin/payload/exports/rsc.js +7 -0
  179. package/dist/better-auth/plugin/payload/exports/rsc.js.map +1 -0
  180. package/dist/better-auth/plugin/payload/views/create-first-admin/index.d.ts +4 -0
  181. package/dist/better-auth/plugin/payload/views/create-first-admin/index.js +112 -0
  182. package/dist/better-auth/plugin/payload/views/create-first-admin/index.js.map +1 -0
  183. package/dist/better-auth/plugin/payload/views/login/index.d.ts +4 -0
  184. package/dist/better-auth/plugin/payload/views/login/index.js +78 -0
  185. package/dist/better-auth/plugin/payload/views/login/index.js.map +1 -0
  186. package/dist/better-auth/plugin/types.d.ts +224 -0
  187. package/dist/better-auth/plugin/types.js +3 -0
  188. package/dist/better-auth/plugin/types.js.map +1 -0
  189. package/dist/better-auth/types.d.ts +2 -0
  190. package/dist/better-auth/types.js +4 -0
  191. package/dist/better-auth/types.js.map +1 -0
  192. package/dist/clerk/index.d.ts +1 -0
  193. package/dist/clerk/index.js +3 -0
  194. package/dist/clerk/index.js.map +1 -0
  195. package/dist/index.js +7 -0
  196. package/dist/index.js.map +1 -0
  197. package/dist/kinde/index.d.ts +1 -0
  198. package/dist/kinde/index.js +3 -0
  199. package/dist/kinde/index.js.map +1 -0
  200. package/package.json +87 -0
@@ -0,0 +1,168 @@
1
+ import { getPayload as getPayloadBase } from 'payload';
2
+ import { buildConfig } from 'payload';
3
+ import { postgresAdapter } from '@payloadcms/db-postgres';
4
+ export const payloadConfig = buildConfig({
5
+ admin: {
6
+ user: 'user'
7
+ },
8
+ secret: 'super-secret-payload-key',
9
+ db: postgresAdapter({
10
+ pool: {
11
+ connectionString: process.env.DATABASE_URL
12
+ },
13
+ push: false,
14
+ transactionOptions: false
15
+ }),
16
+ collections: [
17
+ {
18
+ slug: 'user',
19
+ admin: {
20
+ useAsTitle: 'name'
21
+ },
22
+ auth: {
23
+ disableLocalStrategy: true
24
+ },
25
+ fields: [
26
+ {
27
+ name: 'name',
28
+ type: 'text',
29
+ required: true
30
+ },
31
+ {
32
+ name: 'email',
33
+ type: 'email',
34
+ required: true,
35
+ unique: true
36
+ },
37
+ {
38
+ name: 'emailVerified',
39
+ type: 'checkbox',
40
+ required: true
41
+ },
42
+ {
43
+ name: 'image',
44
+ type: 'text'
45
+ }
46
+ ],
47
+ timestamps: true
48
+ },
49
+ {
50
+ slug: 'account',
51
+ admin: {
52
+ useAsTitle: 'accountId'
53
+ },
54
+ fields: [
55
+ {
56
+ name: 'accountId',
57
+ type: 'number',
58
+ required: true
59
+ },
60
+ {
61
+ name: 'providerId',
62
+ type: 'text'
63
+ },
64
+ {
65
+ name: 'user',
66
+ type: 'relationship',
67
+ required: true,
68
+ relationTo: 'user'
69
+ },
70
+ {
71
+ name: 'accessToken',
72
+ type: 'text'
73
+ },
74
+ {
75
+ name: 'refreshToken',
76
+ type: 'text'
77
+ },
78
+ {
79
+ name: 'idToken',
80
+ type: 'text'
81
+ },
82
+ {
83
+ name: 'accessTokenExpiresAt',
84
+ type: 'date'
85
+ },
86
+ {
87
+ name: 'refreshTokenExpiresAt',
88
+ type: 'date'
89
+ },
90
+ {
91
+ name: 'scope',
92
+ type: 'text'
93
+ },
94
+ {
95
+ name: 'password',
96
+ type: 'text'
97
+ }
98
+ ],
99
+ timestamps: true
100
+ },
101
+ {
102
+ slug: 'verification',
103
+ admin: {
104
+ useAsTitle: 'identifier'
105
+ },
106
+ fields: [
107
+ {
108
+ name: 'identifier',
109
+ type: 'text',
110
+ required: true
111
+ },
112
+ {
113
+ name: 'value',
114
+ type: 'text',
115
+ required: true
116
+ },
117
+ {
118
+ name: 'expiresAt',
119
+ type: 'date',
120
+ required: true
121
+ }
122
+ ],
123
+ timestamps: true
124
+ },
125
+ {
126
+ slug: 'session',
127
+ admin: {
128
+ useAsTitle: 'expiresAt'
129
+ },
130
+ fields: [
131
+ {
132
+ name: 'expiresAt',
133
+ type: 'date',
134
+ required: true
135
+ },
136
+ {
137
+ name: 'token',
138
+ type: 'text',
139
+ required: true,
140
+ unique: true
141
+ },
142
+ {
143
+ name: 'ipAddress',
144
+ type: 'text'
145
+ },
146
+ {
147
+ name: 'userAgent',
148
+ type: 'text'
149
+ },
150
+ {
151
+ name: 'user',
152
+ type: 'relationship',
153
+ required: true,
154
+ relationTo: 'user'
155
+ }
156
+ ],
157
+ timestamps: true
158
+ }
159
+ ]
160
+ });
161
+ export async function getPayload() {
162
+ return await getPayloadBase({
163
+ config: payloadConfig
164
+ });
165
+ }
166
+ export default payloadConfig;
167
+
168
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/adapter/dev/index.ts"],"sourcesContent":["import { getPayload as getPayloadBase } from 'payload'\n\nimport { buildConfig } from 'payload'\nimport { postgresAdapter } from '@payloadcms/db-postgres'\n\nexport const payloadConfig = buildConfig({\n admin: {\n user: 'user',\n },\n secret: 'super-secret-payload-key',\n db: postgresAdapter({\n pool: {\n connectionString: process.env.DATABASE_URL,\n },\n push: false,\n transactionOptions: false,\n }),\n collections: [\n {\n slug: 'user',\n admin: {\n useAsTitle: 'name',\n },\n auth: {\n disableLocalStrategy: true,\n },\n fields: [\n {\n name: 'name',\n type: 'text',\n required: true,\n },\n {\n name: 'email',\n type: 'email',\n required: true,\n unique: true,\n },\n {\n name: 'emailVerified',\n type: 'checkbox',\n required: true,\n },\n {\n name: 'image',\n type: 'text',\n },\n ],\n timestamps: true,\n },\n {\n slug: 'account',\n admin: {\n useAsTitle: 'accountId',\n },\n fields: [\n {\n name: 'accountId',\n type: 'number',\n required: true,\n },\n {\n name: 'providerId',\n type: 'text',\n },\n {\n name: 'user',\n type: 'relationship',\n required: true,\n relationTo: 'user',\n },\n {\n name: 'accessToken',\n type: 'text',\n },\n {\n name: 'refreshToken',\n type: 'text',\n },\n {\n name: 'idToken',\n type: 'text',\n },\n {\n name: 'accessTokenExpiresAt',\n type: 'date',\n },\n {\n name: 'refreshTokenExpiresAt',\n type: 'date',\n },\n {\n name: 'scope',\n type: 'text',\n },\n {\n name: 'password',\n type: 'text',\n },\n ],\n timestamps: true,\n },\n {\n slug: 'verification',\n admin: {\n useAsTitle: 'identifier',\n },\n fields: [\n {\n name: 'identifier',\n type: 'text',\n required: true,\n },\n {\n name: 'value',\n type: 'text',\n required: true,\n },\n {\n name: 'expiresAt',\n type: 'date',\n required: true,\n },\n ],\n timestamps: true,\n },\n {\n slug: 'session',\n admin: {\n useAsTitle: 'expiresAt',\n },\n fields: [\n {\n name: 'expiresAt',\n type: 'date',\n required: true,\n },\n {\n name: 'token',\n type: 'text',\n required: true,\n unique: true,\n },\n {\n name: 'ipAddress',\n type: 'text',\n },\n {\n name: 'userAgent',\n type: 'text',\n },\n {\n name: 'user',\n type: 'relationship',\n required: true,\n relationTo: 'user',\n },\n ],\n timestamps: true,\n },\n ],\n})\n\nexport async function getPayload() {\n return await getPayloadBase({ config: payloadConfig })\n}\n\nexport default payloadConfig\n"],"names":["getPayload","getPayloadBase","buildConfig","postgresAdapter","payloadConfig","admin","user","secret","db","pool","connectionString","process","env","DATABASE_URL","push","transactionOptions","collections","slug","useAsTitle","auth","disableLocalStrategy","fields","name","type","required","unique","timestamps","relationTo","config"],"mappings":"AAAA,SAASA,cAAcC,cAAc,QAAQ,UAAS;AAEtD,SAASC,WAAW,QAAQ,UAAS;AACrC,SAASC,eAAe,QAAQ,0BAAyB;AAEzD,OAAO,MAAMC,gBAAgBF,YAAY;IACvCG,OAAO;QACLC,MAAM;IACR;IACAC,QAAQ;IACRC,IAAIL,gBAAgB;QAClBM,MAAM;YACJC,kBAAkBC,QAAQC,GAAG,CAACC,YAAY;QAC5C;QACAC,MAAM;QACNC,oBAAoB;IACtB;IACAC,aAAa;QACX;YACEC,MAAM;YACNZ,OAAO;gBACLa,YAAY;YACd;YACAC,MAAM;gBACJC,sBAAsB;YACxB;YACAC,QAAQ;gBACN;oBACEC,MAAM;oBACNC,MAAM;oBACNC,UAAU;gBACZ;gBACA;oBACEF,MAAM;oBACNC,MAAM;oBACNC,UAAU;oBACVC,QAAQ;gBACV;gBACA;oBACEH,MAAM;oBACNC,MAAM;oBACNC,UAAU;gBACZ;gBACA;oBACEF,MAAM;oBACNC,MAAM;gBACR;aACD;YACDG,YAAY;QACd;QACA;YACET,MAAM;YACNZ,OAAO;gBACLa,YAAY;YACd;YACAG,QAAQ;gBACN;oBACEC,MAAM;oBACNC,MAAM;oBACNC,UAAU;gBACZ;gBACA;oBACEF,MAAM;oBACNC,MAAM;gBACR;gBACA;oBACED,MAAM;oBACNC,MAAM;oBACNC,UAAU;oBACVG,YAAY;gBACd;gBACA;oBACEL,MAAM;oBACNC,MAAM;gBACR;gBACA;oBACED,MAAM;oBACNC,MAAM;gBACR;gBACA;oBACED,MAAM;oBACNC,MAAM;gBACR;gBACA;oBACED,MAAM;oBACNC,MAAM;gBACR;gBACA;oBACED,MAAM;oBACNC,MAAM;gBACR;gBACA;oBACED,MAAM;oBACNC,MAAM;gBACR;gBACA;oBACED,MAAM;oBACNC,MAAM;gBACR;aACD;YACDG,YAAY;QACd;QACA;YACET,MAAM;YACNZ,OAAO;gBACLa,YAAY;YACd;YACAG,QAAQ;gBACN;oBACEC,MAAM;oBACNC,MAAM;oBACNC,UAAU;gBACZ;gBACA;oBACEF,MAAM;oBACNC,MAAM;oBACNC,UAAU;gBACZ;gBACA;oBACEF,MAAM;oBACNC,MAAM;oBACNC,UAAU;gBACZ;aACD;YACDE,YAAY;QACd;QACA;YACET,MAAM;YACNZ,OAAO;gBACLa,YAAY;YACd;YACAG,QAAQ;gBACN;oBACEC,MAAM;oBACNC,MAAM;oBACNC,UAAU;gBACZ;gBACA;oBACEF,MAAM;oBACNC,MAAM;oBACNC,UAAU;oBACVC,QAAQ;gBACV;gBACA;oBACEH,MAAM;oBACNC,MAAM;gBACR;gBACA;oBACED,MAAM;oBACNC,MAAM;gBACR;gBACA;oBACED,MAAM;oBACNC,MAAM;oBACNC,UAAU;oBACVG,YAAY;gBACd;aACD;YACDD,YAAY;QACd;KACD;AACH,GAAE;AAEF,OAAO,eAAe1B;IACpB,OAAO,MAAMC,eAAe;QAAE2B,QAAQxB;IAAc;AACtD;AAEA,eAAeA,cAAa"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * This module generates PayloadCMS collection configurations based on the Better Auth schema.
3
+ *
4
+ * The generated collection configs include:
5
+ * - Users: For user management with proper auth configuration
6
+ * - Sessions: For maintaining user sessions
7
+ * - Accounts: For OAuth provider accounts
8
+ * - VerificationTokens: For email verification or social sign in
9
+ *
10
+ * Each collection is properly formatted with:
11
+ * - Appropriate field types (text, relationship, checkbox, etc.)
12
+ * - Admin configuration for better UI experience
13
+ * - Auth configuration for the Users collection
14
+ * - Proper field relationships between collections
15
+ *
16
+ * Users can copy these generated collection configs to their PayloadCMS project
17
+ * and add authentication strategies as needed.
18
+ */
19
+ import type { BetterAuthOptions } from 'better-auth';
20
+ export declare const generateSchemaBuilderStage: ({ BAOptions, code, }: {
21
+ code: string;
22
+ BAOptions: BetterAuthOptions;
23
+ }) => Promise<string>;
@@ -0,0 +1,326 @@
1
+ /**
2
+ * This module generates PayloadCMS collection configurations based on the Better Auth schema.
3
+ *
4
+ * The generated collection configs include:
5
+ * - Users: For user management with proper auth configuration
6
+ * - Sessions: For maintaining user sessions
7
+ * - Accounts: For OAuth provider accounts
8
+ * - VerificationTokens: For email verification or social sign in
9
+ *
10
+ * Each collection is properly formatted with:
11
+ * - Appropriate field types (text, relationship, checkbox, etc.)
12
+ * - Admin configuration for better UI experience
13
+ * - Auth configuration for the Users collection
14
+ * - Proper field relationships between collections
15
+ *
16
+ * Users can copy these generated collection configs to their PayloadCMS project
17
+ * and add authentication strategies as needed.
18
+ */ import { getAuthTables } from 'better-auth/db';
19
+ import { format } from 'prettier';
20
+ export const generateSchemaBuilderStage = async ({ BAOptions, code })=>{
21
+ const formattedCode = await format(code, {
22
+ filepath: 'schema.ts'
23
+ });
24
+ const { post, collections } = parseExistingSchema(formattedCode);
25
+ const payloadSchemaStr = generatePayloadCollectionConfigs({
26
+ options: BAOptions,
27
+ collections,
28
+ exports: post
29
+ });
30
+ return await format(`${payloadSchemaStr}`, {
31
+ filepath: 'schema.ts'
32
+ });
33
+ };
34
+ function parseExistingSchema(code) {
35
+ const collections = [];
36
+ let post = '';
37
+ // Extract collection definitions
38
+ const collectionRegex = /const\s+([A-Z][a-zA-Z0-9]*)\s*:\s*CollectionConfig\s*=\s*{[\s\S]*?}\s*as\s*const;/g;
39
+ let match;
40
+ while((match = collectionRegex.exec(code)) !== null){
41
+ const collectionName = match[1];
42
+ const collectionDef = match[0];
43
+ // Extract slug
44
+ const slugMatch = collectionDef.match(/slug:\s*"([^"]+)"/);
45
+ const slug = slugMatch ? slugMatch[1] : collectionName.toLowerCase();
46
+ // Extract useAsTitle
47
+ const titleMatch = collectionDef.match(/useAsTitle:\s*"([^"]+)"/);
48
+ const useAsTitle = titleMatch ? titleMatch[1] : 'id';
49
+ // Extract fields
50
+ const fieldsRegex = /fields:\s*\[([\s\S]*?)\],/;
51
+ const fieldsMatch = collectionDef.match(fieldsRegex);
52
+ const fields = [];
53
+ if (fieldsMatch) {
54
+ const fieldBlockRegex = /{[\s\S]*?},/g;
55
+ const fieldBlocks = fieldsMatch[1].match(fieldBlockRegex) || [];
56
+ for (const fieldBlock of fieldBlocks){
57
+ const nameMatch = fieldBlock.match(/name:\s*"([^"]+)"/);
58
+ const typeMatch = fieldBlock.match(/type:\s*"([^"]+)"/);
59
+ const requiredMatch = fieldBlock.match(/required:\s*(true|false)/);
60
+ const uniqueMatch = fieldBlock.match(/unique:\s*(true|false)/);
61
+ const relationToMatch = fieldBlock.match(/relationTo:\s*"([^"]+)"/);
62
+ if (nameMatch && typeMatch) {
63
+ const field = {
64
+ name: nameMatch[1],
65
+ type: typeMatch[1]
66
+ };
67
+ if (requiredMatch) {
68
+ ;
69
+ field.required = requiredMatch[1] === 'true';
70
+ }
71
+ if (uniqueMatch) {
72
+ ;
73
+ field.unique = uniqueMatch[1] === 'true';
74
+ }
75
+ if (relationToMatch) {
76
+ ;
77
+ field.relationTo = relationToMatch[1];
78
+ }
79
+ fields.push(field);
80
+ }
81
+ }
82
+ }
83
+ // Check for timestamps
84
+ const timestampsMatch = collectionDef.match(/timestamps:\s*(true|false)/);
85
+ const hasTimestamps = timestampsMatch ? timestampsMatch[1] === 'true' : false;
86
+ collections.push({
87
+ slug,
88
+ admin: {
89
+ useAsTitle
90
+ },
91
+ fields,
92
+ ...hasTimestamps && {
93
+ timestamps: true
94
+ }
95
+ });
96
+ }
97
+ // Extract export statement
98
+ const exportRegex = /export\s*{[\s\S]*?};/;
99
+ const exportMatch = code.match(exportRegex);
100
+ if (exportMatch) {
101
+ post = exportMatch[0];
102
+ }
103
+ return {
104
+ collections,
105
+ post
106
+ };
107
+ }
108
+ function generatePayloadCollectionConfigs({ options, collections, exports }) {
109
+ let result = '';
110
+ // add pre message and import statements
111
+ result += `/**
112
+ * EXAMPLE COLLECTIONS FOR BETTER AUTH
113
+ *
114
+ * Below is what your Payload collections should look like.
115
+ * Please copy these to your actual collection configs.
116
+ * Make sure to add an authStrategy for the users collection if there is one.
117
+ *
118
+ * Example auth strategy:
119
+ * auth: {
120
+ * disableLocalStrategy: true,
121
+ * strategies: [
122
+ * betterAuthStrategy(),
123
+ * // Add other strategies as needed
124
+ * ],
125
+ * },
126
+ */
127
+ import type { CollectionConfig } from 'payload';
128
+
129
+ `;
130
+ // add the collections
131
+ let collectionsStr = '';
132
+ const tables = getAuthTables(options);
133
+ // Process existing collections first
134
+ const existingCollectionsBySlug = collections.reduce((acc, collection)=>{
135
+ if (collection.slug) {
136
+ acc[collection.slug] = collection;
137
+ }
138
+ return acc;
139
+ }, {});
140
+ for (const [tableKey, table] of Object.entries(tables)){
141
+ const modelName = table.modelName;
142
+ const capitalized = modelName.charAt(0).toUpperCase() + modelName.slice(1);
143
+ // Check if this collection already exists in the provided collections
144
+ const existingCollection = existingCollectionsBySlug[modelName];
145
+ if (existingCollection) {
146
+ // Convert existing collection to string representation
147
+ collectionsStr += `const ${capitalized}: CollectionConfig = ${JSON.stringify(existingCollection, null, 2).replace(/"([^"]+)":/g, '$1:')} as const;\n\n`;
148
+ continue;
149
+ }
150
+ // Create new collection if it doesn't exist
151
+ collectionsStr += `const ${capitalized}: CollectionConfig = {
152
+ slug: "${modelName}",
153
+ `;
154
+ // Add admin section for better UX
155
+ collectionsStr += ` admin: {
156
+ useAsTitle: "${getNameField(table.fields)}",
157
+ },
158
+ `;
159
+ // Add auth section ONLY for users collection
160
+ if (modelName === 'users') {
161
+ collectionsStr += ` auth: {
162
+ disableLocalStrategy: true,
163
+ strategies: [],
164
+ // Add your auth strategies here if needed
165
+ },
166
+ `;
167
+ }
168
+ // Add fields
169
+ collectionsStr += ` fields: [
170
+ `;
171
+ for (const [fieldKey, field] of Object.entries(table.fields)){
172
+ const fieldName = field.fieldName || fieldKey;
173
+ // Skip id field as Payload handles it automatically
174
+ if (fieldName === 'id') continue;
175
+ if (fieldName === 'createdAt' || fieldName === 'updatedAt') continue;
176
+ // Handle field type mapping with safer type approach
177
+ let fieldType = mapFieldType(field.type, fieldName);
178
+ const isRelationship = fieldName.endsWith('_id') || !!field.references?.model;
179
+ collectionsStr += ` {
180
+ name: "${isRelationship ? fieldName.replace('_id', '') : fieldName}",
181
+ `;
182
+ if (isRelationship) {
183
+ collectionsStr += ` type: "relationship",
184
+ relationTo: "${field.references?.model || fieldName.replace('_id', '')}",
185
+ `;
186
+ } else if (fieldType === 'upload') {
187
+ collectionsStr += ` type: "upload",
188
+ relationTo: "media",
189
+ `;
190
+ } else {
191
+ collectionsStr += ` type: "${fieldType}",
192
+ `;
193
+ }
194
+ if (field.required) {
195
+ collectionsStr += ` required: true,
196
+ `;
197
+ }
198
+ if (field.unique) {
199
+ collectionsStr += ` unique: true,
200
+ `;
201
+ }
202
+ // Check if field has options and fieldType is select
203
+ if (fieldType === 'select' && 'options' in field && Array.isArray(field.options)) {
204
+ collectionsStr += ` options: ${JSON.stringify(field.options)},
205
+ `;
206
+ }
207
+ if (field.defaultValue !== undefined) {
208
+ if (typeof field.defaultValue === 'string') {
209
+ collectionsStr += ` defaultValue: "${field.defaultValue}",
210
+ `;
211
+ } else if (typeof field.defaultValue === 'boolean') {
212
+ collectionsStr += ` defaultValue: ${field.defaultValue ? 'true' : 'false'},
213
+ `;
214
+ } else if (field.defaultValue && typeof field.defaultValue === 'function' && field.defaultValue.toString().includes('() => !1')) {
215
+ // Handle function-like default values with are false
216
+ collectionsStr += ` defaultValue: false,
217
+ `;
218
+ } else if (field.defaultValue && typeof field.defaultValue === 'function' && field.defaultValue.toString().includes('() => !0')) {
219
+ // Handle function-like default values with are true
220
+ collectionsStr += ` defaultValue: true,
221
+ `;
222
+ } else {
223
+ collectionsStr += ` defaultValue: ${field.defaultValue},
224
+ `;
225
+ }
226
+ }
227
+ // Add admin section for fields if needed - safely check for admin property
228
+ if ('admin' in field && field.admin && typeof field.admin === 'object' && 'readOnly' in field.admin && field.admin.readOnly) {
229
+ collectionsStr += ` admin: {
230
+ readOnly: true,
231
+ },
232
+ `;
233
+ }
234
+ collectionsStr += ` },
235
+ `;
236
+ }
237
+ collectionsStr += ` ],
238
+ timestamps: true,
239
+ } as const;
240
+
241
+ `;
242
+ }
243
+ // Add any collections from the input that aren't in the tables
244
+ for (const collection of collections){
245
+ if (!collection.slug || tables[collection.slug]) {
246
+ continue; // Skip if no slug or already processed
247
+ }
248
+ const capitalized = collection.slug.charAt(0).toUpperCase() + collection.slug.slice(1);
249
+ collectionsStr += `const ${capitalized}: CollectionConfig = ${JSON.stringify(collection, null, 2).replace(/"([^"]+)":/g, '$1:')} as const;\n\n`;
250
+ }
251
+ result += collectionsStr;
252
+ // Add export statements for all collections
253
+ // Check if we have an existing export statement to adapt
254
+ if (exports && exports.trim()) {
255
+ // Parse the existing exports to get collection names
256
+ const existingExportMatch = exports.match(/export\s*{\s*(.*?)\s*}/);
257
+ const existingCollections = existingExportMatch ? existingExportMatch[1].split(',').map((name)=>name.trim()) : [];
258
+ // Get the collection names from our tables
259
+ const tableCollections = Object.keys(tables).map((model)=>{
260
+ return model.charAt(0).toUpperCase() + model.slice(1);
261
+ });
262
+ // Combine existing and new collections, removing duplicates
263
+ const allCollections = [
264
+ ...new Set([
265
+ ...existingCollections,
266
+ ...tableCollections
267
+ ])
268
+ ];
269
+ // Create the new export statement
270
+ result += `export { ${allCollections.join(', ')} };
271
+ `;
272
+ } else if (Object.keys(tables).length > 0) {
273
+ const collectionNames = Object.keys(tables).map((model)=>{
274
+ // Convert model name to PascalCase for export
275
+ const pascalCase = model.charAt(0).toUpperCase() + model.slice(1);
276
+ return pascalCase;
277
+ });
278
+ result += `export { ${collectionNames.join(', ')} };
279
+ `;
280
+ } else {
281
+ result += `export {};
282
+ `;
283
+ }
284
+ return result;
285
+ }
286
+ // Helper functions
287
+ function mapFieldType(type, fieldName) {
288
+ if (fieldName.endsWith('_id')) return 'relationship';
289
+ switch(type){
290
+ case 'boolean':
291
+ return 'checkbox';
292
+ case 'number':
293
+ return 'number';
294
+ case 'string':
295
+ if (fieldName === 'email') return 'email';
296
+ if (fieldName.includes('password')) return 'text';
297
+ if (fieldName.includes('image') || fieldName.includes('avatar')) return 'upload';
298
+ return 'text';
299
+ case 'date':
300
+ return 'date';
301
+ case 'array':
302
+ return 'array';
303
+ default:
304
+ return 'text';
305
+ }
306
+ }
307
+ function getNameField(fields) {
308
+ // Try to find an appropriate field to use as title
309
+ const nameOptions = [
310
+ 'name',
311
+ 'title',
312
+ 'label',
313
+ 'email',
314
+ 'username'
315
+ ];
316
+ for (const option of nameOptions){
317
+ if (Object.keys(fields).includes(option)) {
318
+ return option;
319
+ }
320
+ }
321
+ // Default to first field that's not id
322
+ const firstNonIdField = Object.keys(fields).find((k)=>k !== 'id');
323
+ return firstNonIdField || 'id';
324
+ }
325
+
326
+ //# sourceMappingURL=generate-schema-builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/adapter/generate-schema/generate-schema-builder.ts"],"sourcesContent":["/**\n * This module generates PayloadCMS collection configurations based on the Better Auth schema.\n *\n * The generated collection configs include:\n * - Users: For user management with proper auth configuration\n * - Sessions: For maintaining user sessions\n * - Accounts: For OAuth provider accounts\n * - VerificationTokens: For email verification or social sign in\n *\n * Each collection is properly formatted with:\n * - Appropriate field types (text, relationship, checkbox, etc.)\n * - Admin configuration for better UI experience\n * - Auth configuration for the Users collection\n * - Proper field relationships between collections\n *\n * Users can copy these generated collection configs to their PayloadCMS project\n * and add authentication strategies as needed.\n */\nimport type { BetterAuthOptions } from 'better-auth'\nimport { getAuthTables } from 'better-auth/db'\nimport type { CollectionConfig, Field } from 'payload'\nimport { format } from 'prettier'\n\nexport const generateSchemaBuilderStage = async ({\n BAOptions,\n code,\n}: {\n code: string\n BAOptions: BetterAuthOptions\n}) => {\n const formattedCode = await format(code, { filepath: 'schema.ts' })\n\n const { post, collections } = parseExistingSchema(formattedCode)\n\n const payloadSchemaStr = generatePayloadCollectionConfigs({\n options: BAOptions,\n collections,\n exports: post,\n })\n\n return await format(`${payloadSchemaStr}`, {\n filepath: 'schema.ts',\n })\n}\n\nfunction parseExistingSchema(code: string): {\n collections: CollectionConfig[]\n post: string\n} {\n const collections: CollectionConfig[] = []\n let post = ''\n\n // Extract collection definitions\n const collectionRegex =\n /const\\s+([A-Z][a-zA-Z0-9]*)\\s*:\\s*CollectionConfig\\s*=\\s*{[\\s\\S]*?}\\s*as\\s*const;/g\n let match\n while ((match = collectionRegex.exec(code)) !== null) {\n const collectionName = match[1]\n const collectionDef = match[0]\n\n // Extract slug\n const slugMatch = collectionDef.match(/slug:\\s*\"([^\"]+)\"/)\n const slug = slugMatch ? slugMatch[1] : collectionName.toLowerCase()\n\n // Extract useAsTitle\n const titleMatch = collectionDef.match(/useAsTitle:\\s*\"([^\"]+)\"/)\n const useAsTitle = titleMatch ? titleMatch[1] : 'id'\n\n // Extract fields\n const fieldsRegex = /fields:\\s*\\[([\\s\\S]*?)\\],/\n const fieldsMatch = collectionDef.match(fieldsRegex)\n const fields: Field[] = []\n\n if (fieldsMatch) {\n const fieldBlockRegex = /{[\\s\\S]*?},/g\n const fieldBlocks = fieldsMatch[1].match(fieldBlockRegex) || []\n\n for (const fieldBlock of fieldBlocks) {\n const nameMatch = fieldBlock.match(/name:\\s*\"([^\"]+)\"/)\n const typeMatch = fieldBlock.match(/type:\\s*\"([^\"]+)\"/)\n const requiredMatch = fieldBlock.match(/required:\\s*(true|false)/)\n const uniqueMatch = fieldBlock.match(/unique:\\s*(true|false)/)\n const relationToMatch = fieldBlock.match(/relationTo:\\s*\"([^\"]+)\"/)\n\n if (nameMatch && typeMatch) {\n const field = {\n name: nameMatch[1],\n type: typeMatch[1] as Field['type'],\n }\n\n if (requiredMatch) {\n ;(field as any).required = requiredMatch[1] === 'true'\n }\n\n if (uniqueMatch) {\n ;(field as any).unique = uniqueMatch[1] === 'true'\n }\n\n if (relationToMatch) {\n ;(field as any).relationTo = relationToMatch[1]\n }\n\n fields.push(field as Field)\n }\n }\n }\n\n // Check for timestamps\n const timestampsMatch = collectionDef.match(/timestamps:\\s*(true|false)/)\n const hasTimestamps = timestampsMatch ? timestampsMatch[1] === 'true' : false\n\n collections.push({\n slug,\n admin: {\n useAsTitle,\n },\n fields,\n ...(hasTimestamps && { timestamps: true }),\n })\n }\n\n // Extract export statement\n const exportRegex = /export\\s*{[\\s\\S]*?};/\n const exportMatch = code.match(exportRegex)\n if (exportMatch) {\n post = exportMatch[0]\n }\n\n return { collections, post }\n}\n\nfunction generatePayloadCollectionConfigs({\n options,\n collections,\n exports,\n}: {\n options: BetterAuthOptions\n collections: CollectionConfig[]\n exports: string\n}): string {\n let result = ''\n\n // add pre message and import statements\n result += `/**\n * EXAMPLE COLLECTIONS FOR BETTER AUTH\n * \n * Below is what your Payload collections should look like.\n * Please copy these to your actual collection configs.\n * Make sure to add an authStrategy for the users collection if there is one.\n * \n * Example auth strategy:\n * auth: {\n * disableLocalStrategy: true,\n * strategies: [\n * betterAuthStrategy(),\n * // Add other strategies as needed\n * ],\n * },\n */\nimport type { CollectionConfig } from 'payload';\n\n`\n\n // add the collections\n let collectionsStr = ''\n const tables = getAuthTables(options)\n\n // Process existing collections first\n const existingCollectionsBySlug = collections.reduce(\n (acc, collection) => {\n if (collection.slug) {\n acc[collection.slug] = collection\n }\n return acc\n },\n {} as Record<string, CollectionConfig>,\n )\n\n for (const [tableKey, table] of Object.entries(tables)) {\n const modelName = table.modelName\n const capitalized = modelName.charAt(0).toUpperCase() + modelName.slice(1)\n\n // Check if this collection already exists in the provided collections\n const existingCollection = existingCollectionsBySlug[modelName]\n\n if (existingCollection) {\n // Convert existing collection to string representation\n collectionsStr += `const ${capitalized}: CollectionConfig = ${JSON.stringify(existingCollection, null, 2).replace(/\"([^\"]+)\":/g, '$1:')} as const;\\n\\n`\n continue\n }\n\n // Create new collection if it doesn't exist\n collectionsStr += `const ${capitalized}: CollectionConfig = {\n slug: \"${modelName}\",\n`\n\n // Add admin section for better UX\n collectionsStr += ` admin: {\n useAsTitle: \"${getNameField(table.fields)}\",\n },\n`\n\n // Add auth section ONLY for users collection\n if (modelName === 'users') {\n collectionsStr += ` auth: {\n disableLocalStrategy: true,\n strategies: [],\n // Add your auth strategies here if needed\n },\n`\n }\n\n // Add fields\n collectionsStr += ` fields: [\n`\n\n for (const [fieldKey, field] of Object.entries(table.fields)) {\n const fieldName = field.fieldName || fieldKey\n // Skip id field as Payload handles it automatically\n if (fieldName === 'id') continue\n\n if (fieldName === 'createdAt' || fieldName === 'updatedAt') continue\n\n // Handle field type mapping with safer type approach\n let fieldType = mapFieldType(field.type as string, fieldName)\n const isRelationship = fieldName.endsWith('_id') || !!field.references?.model\n\n collectionsStr += ` {\n name: \"${isRelationship ? fieldName.replace('_id', '') : fieldName}\",\n`\n\n if (isRelationship) {\n collectionsStr += ` type: \"relationship\",\n relationTo: \"${field.references?.model || fieldName.replace('_id', '')}\",\n`\n } else if (fieldType === 'upload') {\n collectionsStr += ` type: \"upload\",\n relationTo: \"media\",\n`\n } else {\n collectionsStr += ` type: \"${fieldType}\",\n`\n }\n\n if (field.required) {\n collectionsStr += ` required: true,\n`\n }\n\n if (field.unique) {\n collectionsStr += ` unique: true,\n`\n }\n\n // Check if field has options and fieldType is select\n if (fieldType === 'select' && 'options' in field && Array.isArray(field.options)) {\n collectionsStr += ` options: ${JSON.stringify(field.options)},\n`\n }\n\n if (field.defaultValue !== undefined) {\n if (typeof field.defaultValue === 'string') {\n collectionsStr += ` defaultValue: \"${field.defaultValue}\",\n`\n } else if (typeof field.defaultValue === 'boolean') {\n collectionsStr += ` defaultValue: ${field.defaultValue ? 'true' : 'false'},\n`\n } else if (\n field.defaultValue &&\n typeof field.defaultValue === 'function' &&\n field.defaultValue.toString().includes('() => !1')\n ) {\n // Handle function-like default values with are false\n collectionsStr += ` defaultValue: false,\n`\n } else if (\n field.defaultValue &&\n typeof field.defaultValue === 'function' &&\n field.defaultValue.toString().includes('() => !0')\n ) {\n // Handle function-like default values with are true\n collectionsStr += ` defaultValue: true,\n`\n } else {\n collectionsStr += ` defaultValue: ${field.defaultValue},\n`\n }\n }\n\n // Add admin section for fields if needed - safely check for admin property\n if (\n 'admin' in field &&\n field.admin &&\n typeof field.admin === 'object' &&\n 'readOnly' in field.admin &&\n field.admin.readOnly\n ) {\n collectionsStr += ` admin: {\n readOnly: true,\n },\n`\n }\n\n collectionsStr += ` },\n`\n }\n\n collectionsStr += ` ],\n timestamps: true,\n} as const;\n\n`\n }\n\n // Add any collections from the input that aren't in the tables\n for (const collection of collections) {\n if (!collection.slug || tables[collection.slug]) {\n continue // Skip if no slug or already processed\n }\n\n const capitalized = collection.slug.charAt(0).toUpperCase() + collection.slug.slice(1)\n collectionsStr += `const ${capitalized}: CollectionConfig = ${JSON.stringify(collection, null, 2).replace(/\"([^\"]+)\":/g, '$1:')} as const;\\n\\n`\n }\n\n result += collectionsStr\n\n // Add export statements for all collections\n // Check if we have an existing export statement to adapt\n if (exports && exports.trim()) {\n // Parse the existing exports to get collection names\n const existingExportMatch = exports.match(/export\\s*{\\s*(.*?)\\s*}/)\n const existingCollections = existingExportMatch\n ? existingExportMatch[1].split(',').map((name) => name.trim())\n : []\n\n // Get the collection names from our tables\n const tableCollections = Object.keys(tables).map((model) => {\n return model.charAt(0).toUpperCase() + model.slice(1)\n })\n\n // Combine existing and new collections, removing duplicates\n const allCollections = [...new Set([...existingCollections, ...tableCollections])]\n\n // Create the new export statement\n result += `export { ${allCollections.join(', ')} };\n`\n } else if (Object.keys(tables).length > 0) {\n const collectionNames = Object.keys(tables).map((model) => {\n // Convert model name to PascalCase for export\n const pascalCase = model.charAt(0).toUpperCase() + model.slice(1)\n return pascalCase\n })\n\n result += `export { ${collectionNames.join(', ')} };\n`\n } else {\n result += `export {};\n`\n }\n\n return result\n}\n\n// Helper functions\nfunction mapFieldType(type: string, fieldName: string): string {\n if (fieldName.endsWith('_id')) return 'relationship'\n\n switch (type) {\n case 'boolean':\n return 'checkbox'\n case 'number':\n return 'number'\n case 'string':\n if (fieldName === 'email') return 'email'\n if (fieldName.includes('password')) return 'text'\n if (fieldName.includes('image') || fieldName.includes('avatar')) return 'upload'\n return 'text'\n case 'date':\n return 'date'\n case 'array':\n return 'array'\n default:\n return 'text'\n }\n}\n\nfunction getNameField(fields: Record<string, any>): string {\n // Try to find an appropriate field to use as title\n const nameOptions = ['name', 'title', 'label', 'email', 'username']\n\n for (const option of nameOptions) {\n if (Object.keys(fields).includes(option)) {\n return option\n }\n }\n\n // Default to first field that's not id\n const firstNonIdField = Object.keys(fields).find((k) => k !== 'id')\n return firstNonIdField || 'id'\n}\n"],"names":["getAuthTables","format","generateSchemaBuilderStage","BAOptions","code","formattedCode","filepath","post","collections","parseExistingSchema","payloadSchemaStr","generatePayloadCollectionConfigs","options","exports","collectionRegex","match","exec","collectionName","collectionDef","slugMatch","slug","toLowerCase","titleMatch","useAsTitle","fieldsRegex","fieldsMatch","fields","fieldBlockRegex","fieldBlocks","fieldBlock","nameMatch","typeMatch","requiredMatch","uniqueMatch","relationToMatch","field","name","type","required","unique","relationTo","push","timestampsMatch","hasTimestamps","admin","timestamps","exportRegex","exportMatch","result","collectionsStr","tables","existingCollectionsBySlug","reduce","acc","collection","tableKey","table","Object","entries","modelName","capitalized","charAt","toUpperCase","slice","existingCollection","JSON","stringify","replace","getNameField","fieldKey","fieldName","fieldType","mapFieldType","isRelationship","endsWith","references","model","Array","isArray","defaultValue","undefined","toString","includes","readOnly","trim","existingExportMatch","existingCollections","split","map","tableCollections","keys","allCollections","Set","join","length","collectionNames","pascalCase","nameOptions","option","firstNonIdField","find","k"],"mappings":"AAAA;;;;;;;;;;;;;;;;;CAiBC,GAED,SAASA,aAAa,QAAQ,iBAAgB;AAE9C,SAASC,MAAM,QAAQ,WAAU;AAEjC,OAAO,MAAMC,6BAA6B,OAAO,EAC/CC,SAAS,EACTC,IAAI,EAIL;IACC,MAAMC,gBAAgB,MAAMJ,OAAOG,MAAM;QAAEE,UAAU;IAAY;IAEjE,MAAM,EAAEC,IAAI,EAAEC,WAAW,EAAE,GAAGC,oBAAoBJ;IAElD,MAAMK,mBAAmBC,iCAAiC;QACxDC,SAAST;QACTK;QACAK,SAASN;IACX;IAEA,OAAO,MAAMN,OAAO,GAAGS,kBAAkB,EAAE;QACzCJ,UAAU;IACZ;AACF,EAAC;AAED,SAASG,oBAAoBL,IAAY;IAIvC,MAAMI,cAAkC,EAAE;IAC1C,IAAID,OAAO;IAEX,iCAAiC;IACjC,MAAMO,kBACJ;IACF,IAAIC;IACJ,MAAO,AAACA,CAAAA,QAAQD,gBAAgBE,IAAI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AAOiC;QACT;QAEAhD,UAAU,CAAC,SAAS,EAAE+C,gBAAgBF,IAAI,CAAC,MAAM;AACrD,CAAC;IACC,OAAO;QACL7C,UAAU,CAAC;AACf,CAAC;IACC;IAEA,OAAOA;AACT;AAEA,mBAAmB;AACnB,SAASwB,aAAanC,IAAY,EAAEiC,SAAiB;IACnD,IAAIA,UAAUI,QAAQ,CAAC,QAAQ,OAAO;IAEtC,OAAQrC;QACN,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT,KAAK;YACH,IAAIiC,cAAc,SAAS,OAAO;YAClC,IAAIA,UAAUY,QAAQ,CAAC,aAAa,OAAO;YAC3C,IAAIZ,UAAUY,QAAQ,CAAC,YAAYZ,UAAUY,QAAQ,CAAC,WAAW,OAAO;YACxE,OAAO;QACT,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT;YACE,OAAO;IACX;AACF;AAEA,SAASd,aAAa1C,MAA2B;IAC/C,mDAAmD;IACnD,MAAMuE,cAAc;QAAC;QAAQ;QAAS;QAAS;QAAS;KAAW;IAEnE,KAAK,MAAMC,UAAUD,YAAa;QAChC,IAAIxC,OAAOiC,IAAI,CAAChE,QAAQwD,QAAQ,CAACgB,SAAS;YACxC,OAAOA;QACT;IACF;IAEA,uCAAuC;IACvC,MAAMC,kBAAkB1C,OAAOiC,IAAI,CAAChE,QAAQ0E,IAAI,CAAC,CAACC,IAAMA,MAAM;IAC9D,OAAOF,mBAAmB;AAC5B"}
@@ -0,0 +1 @@
1
+ export declare const getPayloadSchema: (payloadDirPath: string) => Promise<string>;
@@ -0,0 +1,23 @@
1
+ import fs from "node:fs/promises";
2
+ export const getPayloadSchema = async (payloadDirPath)=>{
3
+ let files;
4
+ try {
5
+ files = await fs.readdir(payloadDirPath);
6
+ } catch (error) {
7
+ if (error.code === "ENOENT") {
8
+ throw new Error(`Payload directory not found at "${payloadDirPath}". Please run this CLI from the project root directory where the payload directory is located, otherwise specify a payload directory path in your payloadAdapter options, under schema_generation.payload_dir_path.`);
9
+ }
10
+ console.error(error);
11
+ throw new Error(`Failed to access payload directory at "${payloadDirPath}".`);
12
+ }
13
+ if (!files.includes(`schema.ts`)) return "";
14
+ try {
15
+ const schemaCode = await fs.readFile(`${payloadDirPath}/schema.ts`, "utf8");
16
+ return schemaCode;
17
+ } catch (error) {
18
+ console.error(error);
19
+ throw new Error(`PayloadAdapter: Failed to read schema.ts file from "${payloadDirPath}".`);
20
+ }
21
+ };
22
+
23
+ //# sourceMappingURL=get-payload-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/adapter/generate-schema/get-payload-schema.ts"],"sourcesContent":["import fs from \"node:fs/promises\";\n\nexport const getPayloadSchema = async (\n\tpayloadDirPath: string,\n): Promise<string> => {\n\tlet files: string[];\n\ttry {\n\t\tfiles = await fs.readdir(payloadDirPath);\n\t} catch (error: any) {\n\t\tif (error.code === \"ENOENT\") {\n\t\t\tthrow new Error(\n\t\t\t\t`Payload directory not found at \"${payloadDirPath}\". Please run this CLI from the project root directory where the payload directory is located, otherwise specify a payload directory path in your payloadAdapter options, under schema_generation.payload_dir_path.`,\n\t\t\t);\n\t\t}\n\t\tconsole.error(error);\n\t\tthrow new Error(\n\t\t\t`Failed to access payload directory at \"${payloadDirPath}\".`,\n\t\t);\n\t}\n\n\tif (!files.includes(`schema.ts`)) return \"\";\n\ttry {\n\t\tconst schemaCode = await fs.readFile(`${payloadDirPath}/schema.ts`, \"utf8\");\n\t\treturn schemaCode;\n\t} catch (error) {\n\t\tconsole.error(error);\n\t\tthrow new Error(\n\t\t\t`PayloadAdapter: Failed to read schema.ts file from \"${payloadDirPath}\".`,\n\t\t);\n\t}\n};\n"],"names":["fs","getPayloadSchema","payloadDirPath","files","readdir","error","code","Error","console","includes","schemaCode","readFile"],"mappings":"AAAA,OAAOA,QAAQ,mBAAmB;AAElC,OAAO,MAAMC,mBAAmB,OAC/BC;IAEA,IAAIC;IACJ,IAAI;QACHA,QAAQ,MAAMH,GAAGI,OAAO,CAACF;IAC1B,EAAE,OAAOG,OAAY;QACpB,IAAIA,MAAMC,IAAI,KAAK,UAAU;YAC5B,MAAM,IAAIC,MACT,CAAC,gCAAgC,EAAEL,eAAe,mNAAmN,CAAC;QAExQ;QACAM,QAAQH,KAAK,CAACA;QACd,MAAM,IAAIE,MACT,CAAC,uCAAuC,EAAEL,eAAe,EAAE,CAAC;IAE9D;IAEA,IAAI,CAACC,MAAMM,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,OAAO;IACzC,IAAI;QACH,MAAMC,aAAa,MAAMV,GAAGW,QAAQ,CAAC,GAAGT,eAAe,UAAU,CAAC,EAAE;QACpE,OAAOQ;IACR,EAAE,OAAOL,OAAO;QACfG,QAAQH,KAAK,CAACA;QACd,MAAM,IAAIE,MACT,CAAC,oDAAoD,EAAEL,eAAe,EAAE,CAAC;IAE3E;AACD,EAAE"}
@@ -0,0 +1,4 @@
1
+ import type { BetterAuthOptions } from 'better-auth';
2
+ export declare const generateSchema: (BAoptions: BetterAuthOptions, options?: {
3
+ outputDir: string;
4
+ }) => Promise<string>;
@@ -0,0 +1,19 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { generateSchemaBuilderStage } from './generate-schema-builder.js';
4
+ import { getPayloadSchema } from './get-payload-schema.js';
5
+ export const generateSchema = async (BAoptions, options = {
6
+ outputDir: './generated'
7
+ })=>{
8
+ const { outputDir } = options;
9
+ const existing_schema_code = await getPayloadSchema(outputDir);
10
+ const new_schema_code = await generateSchemaBuilderStage({
11
+ code: existing_schema_code,
12
+ BAOptions: BAoptions
13
+ });
14
+ const schemaPath = path.resolve(outputDir, 'schema.ts');
15
+ await fs.writeFile(schemaPath, new_schema_code, 'utf8');
16
+ return new_schema_code;
17
+ };
18
+
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/adapter/generate-schema/index.ts"],"sourcesContent":["import fs from 'node:fs/promises'\nimport path from 'node:path'\nimport type { BetterAuthOptions } from 'better-auth'\nimport { generateSchemaBuilderStage } from './generate-schema-builder.js'\nimport { getPayloadSchema } from './get-payload-schema.js'\n\nexport const generateSchema = async (\n BAoptions: BetterAuthOptions,\n options: { outputDir: string } = {\n outputDir: './generated',\n },\n): Promise<string> => {\n const { outputDir } = options\n const existing_schema_code: string = await getPayloadSchema(outputDir)\n\n const new_schema_code = await generateSchemaBuilderStage({\n code: existing_schema_code,\n BAOptions: BAoptions,\n })\n\n const schemaPath = path.resolve(outputDir, 'schema.ts')\n await fs.writeFile(schemaPath, new_schema_code, 'utf8')\n\n return new_schema_code\n}\n"],"names":["fs","path","generateSchemaBuilderStage","getPayloadSchema","generateSchema","BAoptions","options","outputDir","existing_schema_code","new_schema_code","code","BAOptions","schemaPath","resolve","writeFile"],"mappings":"AAAA,OAAOA,QAAQ,mBAAkB;AACjC,OAAOC,UAAU,YAAW;AAE5B,SAASC,0BAA0B,QAAQ,+BAA8B;AACzE,SAASC,gBAAgB,QAAQ,0BAAyB;AAE1D,OAAO,MAAMC,iBAAiB,OAC5BC,WACAC,UAAiC;IAC/BC,WAAW;AACb,CAAC;IAED,MAAM,EAAEA,SAAS,EAAE,GAAGD;IACtB,MAAME,uBAA+B,MAAML,iBAAiBI;IAE5D,MAAME,kBAAkB,MAAMP,2BAA2B;QACvDQ,MAAMF;QACNG,WAAWN;IACb;IAEA,MAAMO,aAAaX,KAAKY,OAAO,CAACN,WAAW;IAC3C,MAAMP,GAAGc,SAAS,CAACF,YAAYH,iBAAiB;IAEhD,OAAOA;AACT,EAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function padding(str: string, indent?: number): string;
2
+ export declare function getPayloadPath(provided_payload_dir_path?: string): string;