better-auth 0.7.1-beta.3 → 0.7.1-beta.4

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 (233) hide show
  1. package/dist/adapters/drizzle.cjs +1 -168
  2. package/dist/adapters/drizzle.d.cts +1 -1
  3. package/dist/adapters/drizzle.d.ts +1 -1
  4. package/dist/adapters/drizzle.js +1 -168
  5. package/dist/adapters/kysely.cjs +1 -9
  6. package/dist/adapters/kysely.d.cts +1 -1
  7. package/dist/adapters/kysely.d.ts +1 -1
  8. package/dist/adapters/kysely.js +1 -9
  9. package/dist/adapters/mongodb.cjs +1 -140
  10. package/dist/adapters/mongodb.d.cts +1 -1
  11. package/dist/adapters/mongodb.d.ts +1 -1
  12. package/dist/adapters/mongodb.js +1 -140
  13. package/dist/adapters/prisma.cjs +1 -132
  14. package/dist/adapters/prisma.d.cts +1 -1
  15. package/dist/adapters/prisma.d.ts +1 -1
  16. package/dist/adapters/prisma.js +1 -132
  17. package/dist/api.cjs +1 -81
  18. package/dist/api.d.cts +1 -1
  19. package/dist/api.d.ts +1 -1
  20. package/dist/api.js +1 -81
  21. package/dist/{auth-Clegl4dW.d.cts → auth-BBNkEaBr.d.cts} +51 -48
  22. package/dist/{auth-fiexy-Ap.d.ts → auth-C-KGyOLK.d.ts} +51 -48
  23. package/dist/chunk-3YGH2GCB.js +1 -0
  24. package/dist/chunk-BHZNUXMD.js +3 -0
  25. package/dist/chunk-G6KW3IG2.cjs +1 -0
  26. package/dist/chunk-GR5EVNV5.cjs +3 -0
  27. package/dist/chunk-JXET6I3M.cjs +1 -0
  28. package/dist/{chunk-ECKSI3LF.js → chunk-LG3F6WBM.js} +1 -1
  29. package/dist/chunk-PZNLZ2U5.js +1 -0
  30. package/dist/{chunk-4KD3N77Y.js → chunk-V3VZ52YT.js} +4 -4
  31. package/dist/{chunk-RTFC3YX2.cjs → chunk-VEVVGKP4.cjs} +4 -4
  32. package/dist/{chunk-NA5JFN3P.cjs → chunk-XFBOWZRM.cjs} +1 -1
  33. package/dist/client/plugins.cjs +1 -210
  34. package/dist/client/plugins.d.cts +3 -3
  35. package/dist/client/plugins.d.ts +3 -3
  36. package/dist/client/plugins.js +1 -210
  37. package/dist/client.cjs +1 -15
  38. package/dist/client.d.cts +1 -1
  39. package/dist/client.d.ts +1 -1
  40. package/dist/client.js +1 -15
  41. package/dist/cookies.cjs +1 -19
  42. package/dist/cookies.d.cts +1 -1
  43. package/dist/cookies.d.ts +1 -1
  44. package/dist/cookies.js +1 -19
  45. package/dist/crypto.cjs +1 -35
  46. package/dist/crypto.js +1 -35
  47. package/dist/db.cjs +1 -32
  48. package/dist/db.d.cts +2 -2
  49. package/dist/db.d.ts +2 -2
  50. package/dist/db.js +1 -32
  51. package/dist/{index-BwRLAahA.d.ts → index-D6zK_G5l.d.ts} +49 -7
  52. package/dist/{index-vi0Dko6t.d.cts → index-oFeqw_y0.d.cts} +49 -7
  53. package/dist/index.cjs +1 -254
  54. package/dist/index.d.cts +2 -2
  55. package/dist/index.d.ts +2 -2
  56. package/dist/index.js +1 -254
  57. package/dist/next-js.cjs +1 -14
  58. package/dist/next-js.js +1 -14
  59. package/dist/node.cjs +1 -23
  60. package/dist/node.d.cts +1 -1
  61. package/dist/node.d.ts +1 -1
  62. package/dist/node.js +1 -23
  63. package/dist/oauth2.cjs +1 -22
  64. package/dist/oauth2.d.cts +2 -2
  65. package/dist/oauth2.d.ts +2 -2
  66. package/dist/oauth2.js +1 -22
  67. package/dist/plugins.cjs +2 -4659
  68. package/dist/plugins.d.cts +3 -3
  69. package/dist/plugins.d.ts +3 -3
  70. package/dist/plugins.js +2 -4659
  71. package/dist/react.cjs +1 -51
  72. package/dist/react.d.cts +1 -1
  73. package/dist/react.d.ts +1 -1
  74. package/dist/react.js +1 -51
  75. package/dist/social.cjs +1 -39
  76. package/dist/social.js +1 -39
  77. package/dist/solid-start.cjs +1 -14
  78. package/dist/solid-start.d.cts +1 -1
  79. package/dist/solid-start.d.ts +1 -1
  80. package/dist/solid-start.js +1 -14
  81. package/dist/solid.cjs +1 -45
  82. package/dist/solid.d.cts +1 -1
  83. package/dist/solid.d.ts +1 -1
  84. package/dist/solid.js +1 -45
  85. package/dist/{state-DdkSSZ5k.d.ts → state-DNpYMSdX.d.ts} +5 -2
  86. package/dist/{state-C0fWhgUT.d.cts → state-HoMoNUY9.d.cts} +5 -2
  87. package/dist/svelte-kit.cjs +1 -38
  88. package/dist/svelte-kit.d.cts +1 -1
  89. package/dist/svelte-kit.d.ts +1 -1
  90. package/dist/svelte-kit.js +1 -38
  91. package/dist/svelte.cjs +1 -44
  92. package/dist/svelte.d.cts +1 -1
  93. package/dist/svelte.d.ts +1 -1
  94. package/dist/svelte.js +1 -44
  95. package/dist/types.cjs +1 -2
  96. package/dist/types.d.cts +2 -2
  97. package/dist/types.d.ts +2 -2
  98. package/dist/types.js +1 -2
  99. package/dist/vue.cjs +1 -66
  100. package/dist/vue.d.cts +1 -1
  101. package/dist/vue.d.ts +1 -1
  102. package/dist/vue.js +1 -66
  103. package/package.json +1 -1
  104. package/dist/adapters/drizzle.cjs.map +0 -1
  105. package/dist/adapters/drizzle.js.map +0 -1
  106. package/dist/adapters/kysely.cjs.map +0 -1
  107. package/dist/adapters/kysely.js.map +0 -1
  108. package/dist/adapters/mongodb.cjs.map +0 -1
  109. package/dist/adapters/mongodb.js.map +0 -1
  110. package/dist/adapters/prisma.cjs.map +0 -1
  111. package/dist/adapters/prisma.js.map +0 -1
  112. package/dist/api.cjs.map +0 -1
  113. package/dist/api.js.map +0 -1
  114. package/dist/chunk-3DABXBNB.js +0 -282
  115. package/dist/chunk-3DABXBNB.js.map +0 -1
  116. package/dist/chunk-4CQRLFDN.js +0 -47
  117. package/dist/chunk-4CQRLFDN.js.map +0 -1
  118. package/dist/chunk-4DCNB6OE.js +0 -3
  119. package/dist/chunk-4LSFAAZW.js +0 -1
  120. package/dist/chunk-4LSFAAZW.js.map +0 -1
  121. package/dist/chunk-4O5CM5CV.cjs +0 -47
  122. package/dist/chunk-4O5CM5CV.cjs.map +0 -1
  123. package/dist/chunk-4UOL2GR4.cjs +0 -23
  124. package/dist/chunk-4UOL2GR4.cjs.map +0 -1
  125. package/dist/chunk-5XCPVMZU.js +0 -276
  126. package/dist/chunk-5XCPVMZU.js.map +0 -1
  127. package/dist/chunk-6WF4N6YK.cjs +0 -2112
  128. package/dist/chunk-6WF4N6YK.cjs.map +0 -1
  129. package/dist/chunk-7QMWCIKA.cjs +0 -39
  130. package/dist/chunk-7QMWCIKA.cjs.map +0 -1
  131. package/dist/chunk-7S233WKF.cjs +0 -53
  132. package/dist/chunk-7S233WKF.cjs.map +0 -1
  133. package/dist/chunk-ACIPPPH7.js +0 -39
  134. package/dist/chunk-ACIPPPH7.js.map +0 -1
  135. package/dist/chunk-BCPAHBK6.cjs +0 -9
  136. package/dist/chunk-BCPAHBK6.cjs.map +0 -1
  137. package/dist/chunk-BL5VP5GZ.cjs +0 -60
  138. package/dist/chunk-BL5VP5GZ.cjs.map +0 -1
  139. package/dist/chunk-BMC4BVAH.js +0 -198
  140. package/dist/chunk-BMC4BVAH.js.map +0 -1
  141. package/dist/chunk-CXXEVYAT.cjs +0 -18
  142. package/dist/chunk-CXXEVYAT.cjs.map +0 -1
  143. package/dist/chunk-D5M6WJ2A.cjs +0 -751
  144. package/dist/chunk-D5M6WJ2A.cjs.map +0 -1
  145. package/dist/chunk-FFH4Z67Z.cjs +0 -45
  146. package/dist/chunk-FFH4Z67Z.cjs.map +0 -1
  147. package/dist/chunk-G4HNVD4Y.js +0 -151
  148. package/dist/chunk-G4HNVD4Y.js.map +0 -1
  149. package/dist/chunk-GXHB7XZT.cjs +0 -276
  150. package/dist/chunk-GXHB7XZT.cjs.map +0 -1
  151. package/dist/chunk-HJBRDRCG.cjs +0 -36
  152. package/dist/chunk-HJBRDRCG.cjs.map +0 -1
  153. package/dist/chunk-HQJTAUZE.cjs +0 -1
  154. package/dist/chunk-KLAIMH5Z.js +0 -9
  155. package/dist/chunk-KLAIMH5Z.js.map +0 -1
  156. package/dist/chunk-KY7ED5I7.cjs +0 -3
  157. package/dist/chunk-LXL7WUAT.js +0 -1
  158. package/dist/chunk-M3DA5GU5.js +0 -60
  159. package/dist/chunk-M3DA5GU5.js.map +0 -1
  160. package/dist/chunk-MKM4WBWC.cjs +0 -331
  161. package/dist/chunk-MKM4WBWC.cjs.map +0 -1
  162. package/dist/chunk-MTZRVGEF.cjs +0 -151
  163. package/dist/chunk-MTZRVGEF.cjs.map +0 -1
  164. package/dist/chunk-O63RY6PO.js +0 -53
  165. package/dist/chunk-O63RY6PO.js.map +0 -1
  166. package/dist/chunk-OHAZSKMN.js +0 -36
  167. package/dist/chunk-OHAZSKMN.js.map +0 -1
  168. package/dist/chunk-OSCVTNMU.js +0 -42
  169. package/dist/chunk-OSCVTNMU.js.map +0 -1
  170. package/dist/chunk-QG6ADTFG.js +0 -45
  171. package/dist/chunk-QG6ADTFG.js.map +0 -1
  172. package/dist/chunk-QHREMIUB.js +0 -23
  173. package/dist/chunk-QHREMIUB.js.map +0 -1
  174. package/dist/chunk-R3AZFFUZ.cjs +0 -42
  175. package/dist/chunk-R3AZFFUZ.cjs.map +0 -1
  176. package/dist/chunk-R6WU2STT.js +0 -751
  177. package/dist/chunk-R6WU2STT.js.map +0 -1
  178. package/dist/chunk-RWLFIPR5.js +0 -122
  179. package/dist/chunk-RWLFIPR5.js.map +0 -1
  180. package/dist/chunk-S2A33E6V.cjs +0 -282
  181. package/dist/chunk-S2A33E6V.cjs.map +0 -1
  182. package/dist/chunk-S3PFIC72.cjs +0 -122
  183. package/dist/chunk-S3PFIC72.cjs.map +0 -1
  184. package/dist/chunk-SNTVJM3F.js +0 -1141
  185. package/dist/chunk-SNTVJM3F.js.map +0 -1
  186. package/dist/chunk-SULZDCPX.cjs +0 -1141
  187. package/dist/chunk-SULZDCPX.cjs.map +0 -1
  188. package/dist/chunk-TCHOIK53.cjs +0 -1
  189. package/dist/chunk-TCHOIK53.cjs.map +0 -1
  190. package/dist/chunk-WANG2DRW.js +0 -2112
  191. package/dist/chunk-WANG2DRW.js.map +0 -1
  192. package/dist/chunk-Y64UTTIO.js +0 -18
  193. package/dist/chunk-Y64UTTIO.js.map +0 -1
  194. package/dist/chunk-YVZFJF7J.cjs +0 -198
  195. package/dist/chunk-YVZFJF7J.cjs.map +0 -1
  196. package/dist/chunk-YWR7GY7E.js +0 -331
  197. package/dist/chunk-YWR7GY7E.js.map +0 -1
  198. package/dist/client/plugins.cjs.map +0 -1
  199. package/dist/client/plugins.js.map +0 -1
  200. package/dist/client.cjs.map +0 -1
  201. package/dist/client.js.map +0 -1
  202. package/dist/cookies.cjs.map +0 -1
  203. package/dist/cookies.js.map +0 -1
  204. package/dist/crypto.cjs.map +0 -1
  205. package/dist/crypto.js.map +0 -1
  206. package/dist/db.cjs.map +0 -1
  207. package/dist/db.js.map +0 -1
  208. package/dist/index.cjs.map +0 -1
  209. package/dist/index.js.map +0 -1
  210. package/dist/next-js.cjs.map +0 -1
  211. package/dist/next-js.js.map +0 -1
  212. package/dist/node.cjs.map +0 -1
  213. package/dist/node.js.map +0 -1
  214. package/dist/oauth2.cjs.map +0 -1
  215. package/dist/oauth2.js.map +0 -1
  216. package/dist/plugins.cjs.map +0 -1
  217. package/dist/plugins.js.map +0 -1
  218. package/dist/react.cjs.map +0 -1
  219. package/dist/react.js.map +0 -1
  220. package/dist/social.cjs.map +0 -1
  221. package/dist/social.js.map +0 -1
  222. package/dist/solid-start.cjs.map +0 -1
  223. package/dist/solid-start.js.map +0 -1
  224. package/dist/solid.cjs.map +0 -1
  225. package/dist/solid.js.map +0 -1
  226. package/dist/svelte-kit.cjs.map +0 -1
  227. package/dist/svelte-kit.js.map +0 -1
  228. package/dist/svelte.cjs.map +0 -1
  229. package/dist/svelte.js.map +0 -1
  230. package/dist/types.cjs.map +0 -1
  231. package/dist/types.js.map +0 -1
  232. package/dist/vue.cjs.map +0 -1
  233. package/dist/vue.js.map +0 -1
@@ -1,168 +1 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
-
3
- var _chunk4UOL2GR4cjs = require('../chunk-4UOL2GR4.cjs');
4
-
5
- // src/adapters/drizzle-adapter/index.ts
6
- var _drizzleorm = require('drizzle-orm');
7
- function getSchema(modelName, options) {
8
- const schema = options.schema;
9
- if (!schema) {
10
- throw new (0, _chunk4UOL2GR4cjs.BetterAuthError)(
11
- "Drizzle adapter failed to initialize. Schema not found. Please provide a schema object in the adapter options object."
12
- );
13
- }
14
- const model = options.usePlural ? `${modelName}s` : modelName;
15
- const schemaModel = schema[model];
16
- if (!schemaModel) {
17
- throw new (0, _chunk4UOL2GR4cjs.BetterAuthError)(
18
- `[# Drizzle Adapter]: The model "${modelName}" was not found in the schema object. Please pass the schema directly to the adapter options.`
19
- );
20
- }
21
- return schemaModel;
22
- }
23
- function whereConvertor(where, schemaModel) {
24
- if (!where) return [];
25
- if (where.length === 1) {
26
- const w = where[0];
27
- if (!w) {
28
- return [];
29
- }
30
- if (w.operator === "in") {
31
- if (!Array.isArray(w.value)) {
32
- throw new (0, _chunk4UOL2GR4cjs.BetterAuthError)(
33
- `The value for the field "${w.field}" must be an array when using the "in" operator.`
34
- );
35
- }
36
- return [_drizzleorm.inArray.call(void 0, schemaModel[w.field], w.value)];
37
- }
38
- if (w.operator === "contains") {
39
- return [_drizzleorm.like.call(void 0, schemaModel[w.field], `%${w.value}%`)];
40
- }
41
- if (w.operator === "starts_with") {
42
- return [_drizzleorm.like.call(void 0, schemaModel[w.field], `${w.value}%`)];
43
- }
44
- if (w.operator === "ends_with") {
45
- return [_drizzleorm.like.call(void 0, schemaModel[w.field], `%${w.value}`)];
46
- }
47
- return [_drizzleorm.eq.call(void 0, schemaModel[w.field], w.value)];
48
- }
49
- const andGroup = where.filter((w) => w.connector === "AND" || !w.connector);
50
- const orGroup = where.filter((w) => w.connector === "OR");
51
- const andClause = _drizzleorm.and.call(void 0,
52
- ...andGroup.map((w) => {
53
- if (w.operator === "in") {
54
- if (!Array.isArray(w.value)) {
55
- throw new (0, _chunk4UOL2GR4cjs.BetterAuthError)(
56
- `The value for the field "${w.field}" must be an array when using the "in" operator.`
57
- );
58
- }
59
- return _drizzleorm.inArray.call(void 0, schemaModel[w.field], w.value);
60
- }
61
- return _drizzleorm.eq.call(void 0, schemaModel[w.field], w.value);
62
- })
63
- );
64
- const orClause = _drizzleorm.or.call(void 0,
65
- ...orGroup.map((w) => {
66
- return _drizzleorm.eq.call(void 0, schemaModel[w.field], w.value);
67
- })
68
- );
69
- const clause = [];
70
- if (andGroup.length) clause.push(andClause);
71
- if (orGroup.length) clause.push(orClause);
72
- return clause;
73
- }
74
- var drizzleAdapter = (db, options) => {
75
- const schema = options.schema || db._.fullSchema;
76
- const databaseType = _optionalChain([options, 'optionalAccess', _2 => _2.provider]);
77
- return {
78
- id: "drizzle",
79
- async create(data) {
80
- const { model, data: val } = data;
81
- const schemaModel = getSchema(model, {
82
- schema,
83
- usePlural: options.usePlural
84
- });
85
- if (options.generateId !== void 0) {
86
- val.id = options.generateId ? options.generateId() : void 0;
87
- }
88
- const mutation = db.insert(schemaModel).values(val);
89
- if (databaseType !== "mysql") return (await mutation.returning())[0];
90
- await mutation;
91
- const res = await db.select().from(schemaModel).where(_drizzleorm.eq.call(void 0, schemaModel.id, data.data.id));
92
- return res[0];
93
- },
94
- async findOne(data) {
95
- const { model, where, select: included } = data;
96
- const schemaModel = getSchema(model, {
97
- schema,
98
- usePlural: options.usePlural
99
- });
100
- const wheres = whereConvertor(where, schemaModel);
101
- let res = null;
102
- if (!!_optionalChain([included, 'optionalAccess', _3 => _3.length])) {
103
- res = await db.select(
104
- ...included.map((include) => {
105
- return {
106
- [include]: schemaModel[include]
107
- };
108
- })
109
- ).from(schemaModel).where(...wheres);
110
- } else {
111
- res = await db.select().from(schemaModel).where(...wheres);
112
- }
113
- if (!!res.length) return res[0];
114
- else return null;
115
- },
116
- async findMany(data) {
117
- const { model, where, limit, offset, sortBy } = data;
118
- const schemaModel = getSchema(model, {
119
- schema,
120
- usePlural: options.usePlural
121
- });
122
- const filters = where ? whereConvertor(where, schemaModel) : [];
123
- const fn = _optionalChain([sortBy, 'optionalAccess', _4 => _4.direction]) === "desc" ? _drizzleorm.desc : _drizzleorm.asc;
124
- const res = await db.select().from(schemaModel).limit(limit || 100).offset(offset || 0).orderBy(fn(schemaModel[_optionalChain([sortBy, 'optionalAccess', _5 => _5.field]) || "id"])).where(...filters.length ? filters : []);
125
- return res;
126
- },
127
- async update(data) {
128
- const { model, where, update } = data;
129
- const schemaModel = getSchema(model, {
130
- schema,
131
- usePlural: options.usePlural
132
- });
133
- if (update.id) {
134
- update.id = void 0;
135
- }
136
- const wheres = whereConvertor(where, schemaModel);
137
- const mutation = db.update(schemaModel).set(update).where(...wheres);
138
- if (databaseType !== "mysql") return (await mutation.returning())[0];
139
- await mutation;
140
- const res = await db.select().from(schemaModel).where(_drizzleorm.eq.call(void 0, schemaModel.id, data.update.id));
141
- return res[0];
142
- },
143
- async delete(data) {
144
- const { model, where } = data;
145
- const schemaModel = getSchema(model, {
146
- schema,
147
- usePlural: options.usePlural
148
- });
149
- const wheres = whereConvertor(where, schemaModel);
150
- const res = await db.delete(schemaModel).where(...wheres);
151
- return res[0];
152
- },
153
- async deleteMany(data) {
154
- const { model, where } = data;
155
- const schemaModel = getSchema(model, {
156
- schema,
157
- usePlural: options.usePlural
158
- });
159
- const wheres = whereConvertor(where, schemaModel);
160
- await db.delete(schemaModel).where(...wheres);
161
- },
162
- options
163
- };
164
- };
165
-
166
-
167
- exports.drizzleAdapter = drizzleAdapter;
168
- //# sourceMappingURL=drizzle.cjs.map
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkJ6NPEQIVcjs = require('../chunk-J6NPEQIV.cjs');var _drizzleorm = require('drizzle-orm');function f(t,r){let i=r.schema;if(!i)throw new (0, _chunkJ6NPEQIVcjs.a)("Drizzle adapter failed to initialize. Schema not found. Please provide a schema object in the adapter options object.");let c=r.usePlural?`${t}s`:t,n=i[c];if(!n)throw new (0, _chunkJ6NPEQIVcjs.a)(`[# Drizzle Adapter]: The model "${t}" was not found in the schema object. Please pass the schema directly to the adapter options.`);return n}function m(t,r){if(!t)return[];if(t.length===1){let e=t[0];if(!e)return[];if(e.operator==="in"){if(!Array.isArray(e.value))throw new (0, _chunkJ6NPEQIVcjs.a)(`The value for the field "${e.field}" must be an array when using the "in" operator.`);return[_drizzleorm.inArray.call(void 0, r[e.field],e.value)]}return e.operator==="contains"?[_drizzleorm.like.call(void 0, r[e.field],`%${e.value}%`)]:e.operator==="starts_with"?[_drizzleorm.like.call(void 0, r[e.field],`${e.value}%`)]:e.operator==="ends_with"?[_drizzleorm.like.call(void 0, r[e.field],`%${e.value}`)]:[_drizzleorm.eq.call(void 0, r[e.field],e.value)]}let i=t.filter(e=>e.connector==="AND"||!e.connector),c=t.filter(e=>e.connector==="OR"),n=_drizzleorm.and.call(void 0, ...i.map(e=>{if(e.operator==="in"){if(!Array.isArray(e.value))throw new (0, _chunkJ6NPEQIVcjs.a)(`The value for the field "${e.field}" must be an array when using the "in" operator.`);return _drizzleorm.inArray.call(void 0, r[e.field],e.value)}return _drizzleorm.eq.call(void 0, r[e.field],e.value)})),l=_drizzleorm.or.call(void 0, ...c.map(e=>_drizzleorm.eq.call(void 0, r[e.field],e.value))),s=[];return i.length&&s.push(n),c.length&&s.push(l),s}var S=(t,r)=>{let i=r.schema||t._.fullSchema,c=_optionalChain([r, 'optionalAccess', _2 => _2.provider]);return{id:"drizzle",async create(n){let{model:l,data:s}=n,e=f(l,{schema:i,usePlural:r.usePlural});r.generateId!==void 0&&(s.id=r.generateId?r.generateId():void 0);let a=t.insert(e).values(s);return c!=="mysql"?(await a.returning())[0]:(await a,(await t.select().from(e).where(_drizzleorm.eq.call(void 0, e.id,n.data.id)))[0])},async findOne(n){let{model:l,where:s,select:e}=n,a=f(l,{schema:i,usePlural:r.usePlural}),u=m(s,a),o=null;return _optionalChain([e, 'optionalAccess', _3 => _3.length])?o=await t.select(...e.map(d=>({[d]:a[d]}))).from(a).where(...u):o=await t.select().from(a).where(...u),o.length?o[0]:null},async findMany(n){let{model:l,where:s,limit:e,offset:a,sortBy:u}=n,o=f(l,{schema:i,usePlural:r.usePlural}),d=s?m(s,o):[],g=_optionalChain([u, 'optionalAccess', _4 => _4.direction])==="desc"?_drizzleorm.desc:_drizzleorm.asc;return await t.select().from(o).limit(e||100).offset(a||0).orderBy(g(o[_optionalChain([u, 'optionalAccess', _5 => _5.field])||"id"])).where(...d.length?d:[])},async update(n){let{model:l,where:s,update:e}=n,a=f(l,{schema:i,usePlural:r.usePlural});e.id&&(e.id=void 0);let u=m(s,a),o=t.update(a).set(e).where(...u);return c!=="mysql"?(await o.returning())[0]:(await o,(await t.select().from(a).where(_drizzleorm.eq.call(void 0, a.id,n.update.id)))[0])},async delete(n){let{model:l,where:s}=n,e=f(l,{schema:i,usePlural:r.usePlural}),a=m(s,e);return(await t.delete(e).where(...a))[0]},async deleteMany(n){let{model:l,where:s}=n,e=f(l,{schema:i,usePlural:r.usePlural}),a=m(s,e);await t.delete(e).where(...a)},options:r}};exports.drizzleAdapter = S;
@@ -1,4 +1,4 @@
1
- import { A as Adapter } from '../auth-Clegl4dW.cjs';
1
+ import { A as Adapter } from '../auth-BBNkEaBr.cjs';
2
2
  import 'zod';
3
3
  import 'kysely';
4
4
  import '../index-DUqGSAH3.cjs';
@@ -1,4 +1,4 @@
1
- import { A as Adapter } from '../auth-fiexy-Ap.js';
1
+ import { A as Adapter } from '../auth-C-KGyOLK.js';
2
2
  import 'zod';
3
3
  import 'kysely';
4
4
  import '../index-DUqGSAH3.js';
@@ -1,168 +1 @@
1
- import {
2
- BetterAuthError
3
- } from "../chunk-QHREMIUB.js";
4
-
5
- // src/adapters/drizzle-adapter/index.ts
6
- import { and, asc, desc, eq, or, inArray, like } from "drizzle-orm";
7
- function getSchema(modelName, options) {
8
- const schema = options.schema;
9
- if (!schema) {
10
- throw new BetterAuthError(
11
- "Drizzle adapter failed to initialize. Schema not found. Please provide a schema object in the adapter options object."
12
- );
13
- }
14
- const model = options.usePlural ? `${modelName}s` : modelName;
15
- const schemaModel = schema[model];
16
- if (!schemaModel) {
17
- throw new BetterAuthError(
18
- `[# Drizzle Adapter]: The model "${modelName}" was not found in the schema object. Please pass the schema directly to the adapter options.`
19
- );
20
- }
21
- return schemaModel;
22
- }
23
- function whereConvertor(where, schemaModel) {
24
- if (!where) return [];
25
- if (where.length === 1) {
26
- const w = where[0];
27
- if (!w) {
28
- return [];
29
- }
30
- if (w.operator === "in") {
31
- if (!Array.isArray(w.value)) {
32
- throw new BetterAuthError(
33
- `The value for the field "${w.field}" must be an array when using the "in" operator.`
34
- );
35
- }
36
- return [inArray(schemaModel[w.field], w.value)];
37
- }
38
- if (w.operator === "contains") {
39
- return [like(schemaModel[w.field], `%${w.value}%`)];
40
- }
41
- if (w.operator === "starts_with") {
42
- return [like(schemaModel[w.field], `${w.value}%`)];
43
- }
44
- if (w.operator === "ends_with") {
45
- return [like(schemaModel[w.field], `%${w.value}`)];
46
- }
47
- return [eq(schemaModel[w.field], w.value)];
48
- }
49
- const andGroup = where.filter((w) => w.connector === "AND" || !w.connector);
50
- const orGroup = where.filter((w) => w.connector === "OR");
51
- const andClause = and(
52
- ...andGroup.map((w) => {
53
- if (w.operator === "in") {
54
- if (!Array.isArray(w.value)) {
55
- throw new BetterAuthError(
56
- `The value for the field "${w.field}" must be an array when using the "in" operator.`
57
- );
58
- }
59
- return inArray(schemaModel[w.field], w.value);
60
- }
61
- return eq(schemaModel[w.field], w.value);
62
- })
63
- );
64
- const orClause = or(
65
- ...orGroup.map((w) => {
66
- return eq(schemaModel[w.field], w.value);
67
- })
68
- );
69
- const clause = [];
70
- if (andGroup.length) clause.push(andClause);
71
- if (orGroup.length) clause.push(orClause);
72
- return clause;
73
- }
74
- var drizzleAdapter = (db, options) => {
75
- const schema = options.schema || db._.fullSchema;
76
- const databaseType = options?.provider;
77
- return {
78
- id: "drizzle",
79
- async create(data) {
80
- const { model, data: val } = data;
81
- const schemaModel = getSchema(model, {
82
- schema,
83
- usePlural: options.usePlural
84
- });
85
- if (options.generateId !== void 0) {
86
- val.id = options.generateId ? options.generateId() : void 0;
87
- }
88
- const mutation = db.insert(schemaModel).values(val);
89
- if (databaseType !== "mysql") return (await mutation.returning())[0];
90
- await mutation;
91
- const res = await db.select().from(schemaModel).where(eq(schemaModel.id, data.data.id));
92
- return res[0];
93
- },
94
- async findOne(data) {
95
- const { model, where, select: included } = data;
96
- const schemaModel = getSchema(model, {
97
- schema,
98
- usePlural: options.usePlural
99
- });
100
- const wheres = whereConvertor(where, schemaModel);
101
- let res = null;
102
- if (!!included?.length) {
103
- res = await db.select(
104
- ...included.map((include) => {
105
- return {
106
- [include]: schemaModel[include]
107
- };
108
- })
109
- ).from(schemaModel).where(...wheres);
110
- } else {
111
- res = await db.select().from(schemaModel).where(...wheres);
112
- }
113
- if (!!res.length) return res[0];
114
- else return null;
115
- },
116
- async findMany(data) {
117
- const { model, where, limit, offset, sortBy } = data;
118
- const schemaModel = getSchema(model, {
119
- schema,
120
- usePlural: options.usePlural
121
- });
122
- const filters = where ? whereConvertor(where, schemaModel) : [];
123
- const fn = sortBy?.direction === "desc" ? desc : asc;
124
- const res = await db.select().from(schemaModel).limit(limit || 100).offset(offset || 0).orderBy(fn(schemaModel[sortBy?.field || "id"])).where(...filters.length ? filters : []);
125
- return res;
126
- },
127
- async update(data) {
128
- const { model, where, update } = data;
129
- const schemaModel = getSchema(model, {
130
- schema,
131
- usePlural: options.usePlural
132
- });
133
- if (update.id) {
134
- update.id = void 0;
135
- }
136
- const wheres = whereConvertor(where, schemaModel);
137
- const mutation = db.update(schemaModel).set(update).where(...wheres);
138
- if (databaseType !== "mysql") return (await mutation.returning())[0];
139
- await mutation;
140
- const res = await db.select().from(schemaModel).where(eq(schemaModel.id, data.update.id));
141
- return res[0];
142
- },
143
- async delete(data) {
144
- const { model, where } = data;
145
- const schemaModel = getSchema(model, {
146
- schema,
147
- usePlural: options.usePlural
148
- });
149
- const wheres = whereConvertor(where, schemaModel);
150
- const res = await db.delete(schemaModel).where(...wheres);
151
- return res[0];
152
- },
153
- async deleteMany(data) {
154
- const { model, where } = data;
155
- const schemaModel = getSchema(model, {
156
- schema,
157
- usePlural: options.usePlural
158
- });
159
- const wheres = whereConvertor(where, schemaModel);
160
- await db.delete(schemaModel).where(...wheres);
161
- },
162
- options
163
- };
164
- };
165
- export {
166
- drizzleAdapter
167
- };
168
- //# sourceMappingURL=drizzle.js.map
1
+ import{a as h}from"../chunk-72JSMFWS.js";import{and as v,asc as P,desc as z,eq as p,or as A,inArray as y,like as w}from"drizzle-orm";function f(t,r){let i=r.schema;if(!i)throw new h("Drizzle adapter failed to initialize. Schema not found. Please provide a schema object in the adapter options object.");let c=r.usePlural?`${t}s`:t,n=i[c];if(!n)throw new h(`[# Drizzle Adapter]: The model "${t}" was not found in the schema object. Please pass the schema directly to the adapter options.`);return n}function m(t,r){if(!t)return[];if(t.length===1){let e=t[0];if(!e)return[];if(e.operator==="in"){if(!Array.isArray(e.value))throw new h(`The value for the field "${e.field}" must be an array when using the "in" operator.`);return[y(r[e.field],e.value)]}return e.operator==="contains"?[w(r[e.field],`%${e.value}%`)]:e.operator==="starts_with"?[w(r[e.field],`${e.value}%`)]:e.operator==="ends_with"?[w(r[e.field],`%${e.value}`)]:[p(r[e.field],e.value)]}let i=t.filter(e=>e.connector==="AND"||!e.connector),c=t.filter(e=>e.connector==="OR"),n=v(...i.map(e=>{if(e.operator==="in"){if(!Array.isArray(e.value))throw new h(`The value for the field "${e.field}" must be an array when using the "in" operator.`);return y(r[e.field],e.value)}return p(r[e.field],e.value)})),l=A(...c.map(e=>p(r[e.field],e.value))),s=[];return i.length&&s.push(n),c.length&&s.push(l),s}var S=(t,r)=>{let i=r.schema||t._.fullSchema,c=r?.provider;return{id:"drizzle",async create(n){let{model:l,data:s}=n,e=f(l,{schema:i,usePlural:r.usePlural});r.generateId!==void 0&&(s.id=r.generateId?r.generateId():void 0);let a=t.insert(e).values(s);return c!=="mysql"?(await a.returning())[0]:(await a,(await t.select().from(e).where(p(e.id,n.data.id)))[0])},async findOne(n){let{model:l,where:s,select:e}=n,a=f(l,{schema:i,usePlural:r.usePlural}),u=m(s,a),o=null;return e?.length?o=await t.select(...e.map(d=>({[d]:a[d]}))).from(a).where(...u):o=await t.select().from(a).where(...u),o.length?o[0]:null},async findMany(n){let{model:l,where:s,limit:e,offset:a,sortBy:u}=n,o=f(l,{schema:i,usePlural:r.usePlural}),d=s?m(s,o):[],g=u?.direction==="desc"?z:P;return await t.select().from(o).limit(e||100).offset(a||0).orderBy(g(o[u?.field||"id"])).where(...d.length?d:[])},async update(n){let{model:l,where:s,update:e}=n,a=f(l,{schema:i,usePlural:r.usePlural});e.id&&(e.id=void 0);let u=m(s,a),o=t.update(a).set(e).where(...u);return c!=="mysql"?(await o.returning())[0]:(await o,(await t.select().from(a).where(p(a.id,n.update.id)))[0])},async delete(n){let{model:l,where:s}=n,e=f(l,{schema:i,usePlural:r.usePlural}),a=m(s,e);return(await t.delete(e).where(...a))[0]},async deleteMany(n){let{model:l,where:s}=n,e=f(l,{schema:i,usePlural:r.usePlural}),a=m(s,e);await t.delete(e).where(...a)},options:r}};export{S as drizzleAdapter};
@@ -1,9 +1 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
-
4
- var _chunkS2A33E6Vcjs = require('../chunk-S2A33E6V.cjs');
5
-
6
-
7
-
8
- exports.createKyselyAdapter = _chunkS2A33E6Vcjs.createKyselyAdapter; exports.kyselyAdapter = _chunkS2A33E6Vcjs.kyselyAdapter;
9
- //# sourceMappingURL=kysely.cjs.map
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkWWY76I3Pcjs = require('../chunk-WWY76I3P.cjs');exports.createKyselyAdapter = _chunkWWY76I3Pcjs.a; exports.kyselyAdapter = _chunkWWY76I3Pcjs.b;
@@ -1,5 +1,5 @@
1
1
  import { Kysely } from 'kysely';
2
- import { e as BetterAuthOptions, K as KyselyDatabaseType, F as FieldAttribute, A as Adapter } from '../auth-Clegl4dW.cjs';
2
+ import { e as BetterAuthOptions, K as KyselyDatabaseType, F as FieldAttribute, A as Adapter } from '../auth-BBNkEaBr.cjs';
3
3
  import 'zod';
4
4
  import '../index-DUqGSAH3.cjs';
5
5
  import 'better-call';
@@ -1,5 +1,5 @@
1
1
  import { Kysely } from 'kysely';
2
- import { e as BetterAuthOptions, K as KyselyDatabaseType, F as FieldAttribute, A as Adapter } from '../auth-fiexy-Ap.js';
2
+ import { e as BetterAuthOptions, K as KyselyDatabaseType, F as FieldAttribute, A as Adapter } from '../auth-C-KGyOLK.js';
3
3
  import 'zod';
4
4
  import '../index-DUqGSAH3.js';
5
5
  import 'better-call';
@@ -1,9 +1 @@
1
- import {
2
- createKyselyAdapter,
3
- kyselyAdapter
4
- } from "../chunk-3DABXBNB.js";
5
- export {
6
- createKyselyAdapter,
7
- kyselyAdapter
8
- };
9
- //# sourceMappingURL=kysely.js.map
1
+ import{a,b}from"../chunk-CM4YNNZQ.js";export{a as createKyselyAdapter,b as kyselyAdapter};
@@ -1,140 +1 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/adapters/mongodb-adapter/index.ts
2
- function whereConvertor(where) {
3
- if (!where) return {};
4
- const conditions = where.map((w) => {
5
- const { field, value, operator = "eq", connector = "AND" } = w;
6
- let condition;
7
- switch (operator.toLowerCase()) {
8
- case "eq":
9
- condition = { [field]: value };
10
- break;
11
- case "in":
12
- condition = {
13
- [field]: { $in: Array.isArray(value) ? value : [value] }
14
- };
15
- break;
16
- case "gt":
17
- condition = { [field]: { $gt: value } };
18
- break;
19
- case "gte":
20
- condition = { [field]: { $gte: value } };
21
- break;
22
- case "lt":
23
- condition = { [field]: { $lt: value } };
24
- break;
25
- case "lte":
26
- condition = { [field]: { $lte: value } };
27
- break;
28
- case "ne":
29
- condition = { [field]: { $ne: value } };
30
- break;
31
- case "contains":
32
- condition = { [field]: { $regex: `.*${value}.*` } };
33
- break;
34
- case "starts_with":
35
- condition = { [field]: { $regex: `${value}.*` } };
36
- break;
37
- case "ends_with":
38
- condition = { [field]: { $regex: `.*${value}` } };
39
- break;
40
- // Add more operators as needed
41
- default:
42
- throw new Error(`Unsupported operator: ${operator}`);
43
- }
44
- return { condition, connector };
45
- });
46
- const andConditions = conditions.filter((c) => c.connector === "AND").map((c) => c.condition);
47
- const orConditions = conditions.filter((c) => c.connector === "OR").map((c) => c.condition);
48
- let clause = {};
49
- if (andConditions.length) {
50
- clause = { ...clause, $and: andConditions };
51
- }
52
- if (orConditions.length) {
53
- clause = { ...clause, $or: orConditions };
54
- }
55
- return clause;
56
- }
57
- function removeMongoId(data) {
58
- const { _id, ...rest } = data;
59
- return rest;
60
- }
61
- function selectConvertor(selects) {
62
- const selectConstruct = selects.reduce((acc, field) => {
63
- acc[field] = 1;
64
- return acc;
65
- }, {});
66
- return selectConstruct;
67
- }
68
- var mongodbAdapter = (mongo, opts) => {
69
- const db = mongo;
70
- const getModelName = (name) => _optionalChain([opts, 'optionalAccess', _ => _.usePlural]) ? `${name}s` : name;
71
- return {
72
- id: "mongodb",
73
- async create(data) {
74
- const { model, data: val } = data;
75
- if (_optionalChain([opts, 'optionalAccess', _2 => _2.generateId]) !== void 0) {
76
- val.id = opts.generateId ? opts.generateId() : void 0;
77
- }
78
- const res = await db.collection(getModelName(model)).insertOne({
79
- ...val
80
- });
81
- const id_ = res.insertedId;
82
- const returned = { ...val, id: id_ };
83
- return removeMongoId(returned);
84
- },
85
- async findOne(data) {
86
- const { model, where, select } = data;
87
- const wheres = whereConvertor(where);
88
- let selects = {};
89
- if (select) {
90
- selects = selectConvertor(select);
91
- }
92
- const result = await db.collection(getModelName(model)).findOne(wheres, { projection: selects });
93
- if (!result) {
94
- return null;
95
- }
96
- return removeMongoId(result);
97
- },
98
- async findMany(data) {
99
- const { model, where, limit, offset, sortBy } = data;
100
- const wheres = whereConvertor(where);
101
- const toReturn = await db.collection(getModelName(model)).find(wheres).skip(offset || 0).limit(limit || 100).sort(_optionalChain([sortBy, 'optionalAccess', _3 => _3.field]) || "id", _optionalChain([sortBy, 'optionalAccess', _4 => _4.direction]) === "desc" ? -1 : 1).toArray();
102
- return toReturn.map(removeMongoId);
103
- },
104
- async update(data) {
105
- const { model, where, update } = data;
106
- const wheres = whereConvertor(where);
107
- if (update.id) {
108
- update.id = void 0;
109
- }
110
- if (where.length === 1) {
111
- const res2 = await db.collection(getModelName(model)).findOneAndUpdate(
112
- wheres,
113
- {
114
- $set: update
115
- },
116
- { returnDocument: "after" }
117
- );
118
- return removeMongoId(res2);
119
- }
120
- const res = await db.collection(getModelName(model)).updateMany(wheres, {
121
- $set: update
122
- });
123
- return {};
124
- },
125
- async delete(data) {
126
- const { model, where } = data;
127
- const wheres = whereConvertor(where);
128
- const res = await db.collection(getModelName(model)).findOneAndDelete(wheres);
129
- },
130
- async deleteMany(data) {
131
- const { model, where } = data;
132
- const wheres = whereConvertor(where);
133
- const res = await db.collection(getModelName(model)).deleteMany(wheres);
134
- }
135
- };
136
- };
137
-
138
-
139
- exports.mongodbAdapter = mongodbAdapter;
140
- //# sourceMappingURL=mongodb.cjs.map
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }function u(l){if(!l)return{};let d=l.map(n=>{let{field:t,value:e,operator:c="eq",connector:i="AND"}=n,o;switch(c.toLowerCase()){case"eq":o={[t]:e};break;case"in":o={[t]:{$in:Array.isArray(e)?e:[e]}};break;case"gt":o={[t]:{$gt:e}};break;case"gte":o={[t]:{$gte:e}};break;case"lt":o={[t]:{$lt:e}};break;case"lte":o={[t]:{$lte:e}};break;case"ne":o={[t]:{$ne:e}};break;case"contains":o={[t]:{$regex:`.*${e}.*`}};break;case"starts_with":o={[t]:{$regex:`${e}.*`}};break;case"ends_with":o={[t]:{$regex:`.*${e}`}};break;default:throw new Error(`Unsupported operator: ${c}`)}return{condition:o,connector:i}}),s=d.filter(n=>n.connector==="AND").map(n=>n.condition),a=d.filter(n=>n.connector==="OR").map(n=>n.condition),r={};return s.length&&(r={...r,$and:s}),a.length&&(r={...r,$or:a}),r}function f(l){let{_id:d,...s}=l;return s}function w(l){return l.reduce((s,a)=>(s[a]=1,s),{})}var m=(l,d)=>{let s=l,a=r=>_optionalChain([d, 'optionalAccess', _ => _.usePlural])?`${r}s`:r;return{id:"mongodb",async create(r){let{model:n,data:t}=r;_optionalChain([d, 'optionalAccess', _2 => _2.generateId])!==void 0&&(t.id=d.generateId?d.generateId():void 0);let c=(await s.collection(a(n)).insertOne({...t})).insertedId,i={...t,id:c};return f(i)},async findOne(r){let{model:n,where:t,select:e}=r,c=u(t),i={};e&&(i=w(e));let o=await s.collection(a(n)).findOne(c,{projection:i});return o?f(o):null},async findMany(r){let{model:n,where:t,limit:e,offset:c,sortBy:i}=r,o=u(t);return(await s.collection(a(n)).find(o).skip(c||0).limit(e||100).sort(_optionalChain([i, 'optionalAccess', _3 => _3.field])||"id",_optionalChain([i, 'optionalAccess', _4 => _4.direction])==="desc"?-1:1).toArray()).map(f)},async update(r){let{model:n,where:t,update:e}=r,c=u(t);if(e.id&&(e.id=void 0),t.length===1){let o=await s.collection(a(n)).findOneAndUpdate(c,{$set:e},{returnDocument:"after"});return f(o)}let i=await s.collection(a(n)).updateMany(c,{$set:e});return{}},async delete(r){let{model:n,where:t}=r,e=u(t),c=await s.collection(a(n)).findOneAndDelete(e)},async deleteMany(r){let{model:n,where:t}=r,e=u(t),c=await s.collection(a(n)).deleteMany(e)}}};exports.mongodbAdapter = m;
@@ -1,5 +1,5 @@
1
1
  import { Db } from 'mongodb';
2
- import { W as Where } from '../auth-Clegl4dW.cjs';
2
+ import { W as Where } from '../auth-BBNkEaBr.cjs';
3
3
  import 'zod';
4
4
  import 'kysely';
5
5
  import '../index-DUqGSAH3.cjs';
@@ -1,5 +1,5 @@
1
1
  import { Db } from 'mongodb';
2
- import { W as Where } from '../auth-fiexy-Ap.js';
2
+ import { W as Where } from '../auth-C-KGyOLK.js';
3
3
  import 'zod';
4
4
  import 'kysely';
5
5
  import '../index-DUqGSAH3.js';