@convex-dev/better-auth 0.10.5 → 0.10.7
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.
- package/dist/auth-options.d.ts +1 -1
- package/dist/auth-options.d.ts.map +1 -1
- package/dist/auth.js +1 -1
- package/dist/auth.js.map +1 -1
- package/dist/client/adapter-utils.d.ts +3 -3
- package/dist/client/adapter-utils.js +1 -1
- package/dist/client/adapter-utils.js.map +1 -1
- package/dist/client/adapter.d.ts.map +1 -1
- package/dist/client/adapter.js +15 -13
- package/dist/client/adapter.js.map +1 -1
- package/dist/client/create-api.d.ts +4 -2
- package/dist/client/create-api.d.ts.map +1 -1
- package/dist/client/create-api.js +2 -0
- package/dist/client/create-api.js.map +1 -1
- package/dist/client/create-client.d.ts.map +1 -1
- package/dist/client/create-client.js +3 -0
- package/dist/client/create-client.js.map +1 -1
- package/dist/client/create-schema.js +1 -1
- package/dist/component/_generated/component.d.ts +4 -8
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/adapter.d.ts +3 -1
- package/dist/component/adapter.d.ts.map +1 -1
- package/dist/component/adapterTest.d.ts +8 -15
- package/dist/component/adapterTest.d.ts.map +1 -1
- package/dist/component/adapterTest.js +390 -61
- package/dist/component/adapterTest.js.map +1 -1
- package/dist/nextjs/index.js +1 -1
- package/dist/nextjs/index.js.map +1 -1
- package/dist/plugins/convex/index.d.ts +2 -1
- package/dist/plugins/convex/index.d.ts.map +1 -1
- package/dist/plugins/convex/index.js +5 -5
- package/dist/plugins/convex/index.js.map +1 -1
- package/dist/react-start/index.js +1 -1
- package/dist/react-start/index.js.map +1 -1
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/package.json +5 -4
- package/src/auth-options.ts +1 -1
- package/src/auth.ts +1 -1
- package/src/client/adapter-utils.ts +1 -1
- package/src/client/adapter.test.ts +24 -440
- package/src/client/adapter.ts +19 -14
- package/src/client/create-api.ts +3 -1
- package/src/client/create-client.ts +3 -0
- package/src/client/create-schema.ts +1 -1
- package/src/component/_generated/component.ts +4 -8
- package/src/component/adapterTest.ts +457 -100
- package/src/nextjs/index.ts +1 -1
- package/src/plugins/convex/index.ts +6 -10
- package/src/react-start/index.ts +1 -1
- package/src/utils/index.ts +3 -1
package/src/client/adapter.ts
CHANGED
|
@@ -84,15 +84,21 @@ type ConvexCleanedWhere<TableName extends TableNames = TableNames> = Where & {
|
|
|
84
84
|
field: keyof WithoutSystemFields<Doc<TableName>> & string;
|
|
85
85
|
};
|
|
86
86
|
|
|
87
|
-
const parseWhere = (
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
const parseWhere = (
|
|
88
|
+
where?: (Where & { join?: undefined }) | (Where & { join?: undefined })[]
|
|
89
|
+
): ConvexCleanedWhere[] => {
|
|
90
|
+
if (!where) {
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
const whereArray = Array.isArray(where) ? where : [where];
|
|
94
|
+
return whereArray.map((w) => {
|
|
95
|
+
if (w.value instanceof Date) {
|
|
90
96
|
return {
|
|
91
|
-
...
|
|
92
|
-
value:
|
|
97
|
+
...w,
|
|
98
|
+
value: w.value.getTime(),
|
|
93
99
|
};
|
|
94
100
|
}
|
|
95
|
-
return
|
|
101
|
+
return w;
|
|
96
102
|
}) as ConvexCleanedWhere[];
|
|
97
103
|
};
|
|
98
104
|
|
|
@@ -121,6 +127,8 @@ export const convexAdapter = <
|
|
|
121
127
|
transaction: false,
|
|
122
128
|
supportsNumericIds: false,
|
|
123
129
|
supportsJSON: false,
|
|
130
|
+
supportsDates: false,
|
|
131
|
+
supportsArrays: true,
|
|
124
132
|
usePlural: false,
|
|
125
133
|
mapKeysTransformInput: {
|
|
126
134
|
id: "_id",
|
|
@@ -128,8 +136,6 @@ export const convexAdapter = <
|
|
|
128
136
|
mapKeysTransformOutput: {
|
|
129
137
|
_id: "id",
|
|
130
138
|
},
|
|
131
|
-
// Dates provided as strings
|
|
132
|
-
supportsDates: false,
|
|
133
139
|
// Convert dates to numbers. This aligns with how
|
|
134
140
|
// Convex stores _creationTime and avoids a breaking change.
|
|
135
141
|
customTransformInput: ({ data, fieldAttributes }) => {
|
|
@@ -179,7 +185,7 @@ export const convexAdapter = <
|
|
|
179
185
|
const result = await ctx.runQuery(api.adapter.findOne, {
|
|
180
186
|
...data,
|
|
181
187
|
model: data.model as TableNames,
|
|
182
|
-
where: parseWhere(
|
|
188
|
+
where: parseWhere(w),
|
|
183
189
|
});
|
|
184
190
|
if (result) {
|
|
185
191
|
return result;
|
|
@@ -196,6 +202,7 @@ export const convexAdapter = <
|
|
|
196
202
|
if (data.offset) {
|
|
197
203
|
throw new Error("offset not supported");
|
|
198
204
|
}
|
|
205
|
+
|
|
199
206
|
if (data.where?.some((w) => w.connector === "OR")) {
|
|
200
207
|
const results = await asyncMap(data.where, async (w) =>
|
|
201
208
|
handlePagination(
|
|
@@ -203,7 +210,7 @@ export const convexAdapter = <
|
|
|
203
210
|
return await ctx.runQuery(api.adapter.findMany, {
|
|
204
211
|
...data,
|
|
205
212
|
model: data.model as TableNames,
|
|
206
|
-
where: parseWhere(
|
|
213
|
+
where: parseWhere(w),
|
|
207
214
|
paginationOpts,
|
|
208
215
|
});
|
|
209
216
|
},
|
|
@@ -212,12 +219,10 @@ export const convexAdapter = <
|
|
|
212
219
|
);
|
|
213
220
|
const docs = unique(results.flatMap((r) => r.docs));
|
|
214
221
|
if (data.sortBy) {
|
|
215
|
-
|
|
222
|
+
return sortBy(docs, [
|
|
216
223
|
prop(data.sortBy.field),
|
|
217
224
|
data.sortBy.direction,
|
|
218
225
|
]);
|
|
219
|
-
console.log(result);
|
|
220
|
-
return result;
|
|
221
226
|
}
|
|
222
227
|
return docs;
|
|
223
228
|
}
|
|
@@ -243,7 +248,7 @@ export const convexAdapter = <
|
|
|
243
248
|
return await ctx.runQuery(api.adapter.findMany, {
|
|
244
249
|
...data,
|
|
245
250
|
model: data.model as TableNames,
|
|
246
|
-
where: parseWhere(
|
|
251
|
+
where: parseWhere(w),
|
|
247
252
|
paginationOpts,
|
|
248
253
|
});
|
|
249
254
|
})
|
package/src/client/create-api.ts
CHANGED
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
} from "./adapter-utils.js";
|
|
19
19
|
import { getAuthTables } from "better-auth/db";
|
|
20
20
|
import type { TableNames } from "../component/_generated/dataModel.js";
|
|
21
|
-
import type { BetterAuthOptions } from "better-auth";
|
|
21
|
+
import type { BetterAuthOptions } from "better-auth/minimal";
|
|
22
22
|
|
|
23
23
|
const whereValidator = (
|
|
24
24
|
schema: SchemaDefinition<any, any>,
|
|
@@ -112,6 +112,7 @@ export const createApi = <Schema extends SchemaDefinition<any, any>>(
|
|
|
112
112
|
),
|
|
113
113
|
where: v.optional(v.array(adapterWhereValidator)),
|
|
114
114
|
select: v.optional(v.array(v.string())),
|
|
115
|
+
join: v.optional(v.any()),
|
|
115
116
|
},
|
|
116
117
|
handler: async (ctx, args) => {
|
|
117
118
|
return await listOne(ctx, schema, betterAuthSchema, args);
|
|
@@ -131,6 +132,7 @@ export const createApi = <Schema extends SchemaDefinition<any, any>>(
|
|
|
131
132
|
})
|
|
132
133
|
),
|
|
133
134
|
offset: v.optional(v.number()),
|
|
135
|
+
join: v.optional(v.any()),
|
|
134
136
|
paginationOpts: paginationOptsValidator,
|
|
135
137
|
},
|
|
136
138
|
handler: async (ctx, args) => {
|
|
@@ -354,12 +354,15 @@ export const createClient = <
|
|
|
354
354
|
const path = staticAuth.options.basePath ?? "/api/auth";
|
|
355
355
|
const authRequestHandler = httpActionGeneric(async (ctx, request) => {
|
|
356
356
|
if (config?.verbose) {
|
|
357
|
+
// eslint-disable-next-line no-console
|
|
357
358
|
console.log("options.baseURL", staticAuth.options.baseURL);
|
|
359
|
+
// eslint-disable-next-line no-console
|
|
358
360
|
console.log("request headers", request.headers);
|
|
359
361
|
}
|
|
360
362
|
const auth = createAuth(ctx as any);
|
|
361
363
|
const response = await auth.handler(request);
|
|
362
364
|
if (config?.verbose) {
|
|
365
|
+
// eslint-disable-next-line no-console
|
|
363
366
|
console.log("response headers", response.headers);
|
|
364
367
|
}
|
|
365
368
|
return response;
|
|
@@ -87,7 +87,7 @@ export const createSchema = async ({
|
|
|
87
87
|
*
|
|
88
88
|
* To customize the schema, generate to an alternate file and import
|
|
89
89
|
* the table definitions to your schema file. See
|
|
90
|
-
* https://convex
|
|
90
|
+
* https://labs.convex.dev/better-auth/features/local-install#adding-custom-indexes.
|
|
91
91
|
*/
|
|
92
92
|
|
|
93
93
|
import { defineSchema, defineTable } from "convex/server";
|
|
@@ -934,6 +934,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
934
934
|
"query",
|
|
935
935
|
"internal",
|
|
936
936
|
{
|
|
937
|
+
join?: any;
|
|
937
938
|
limit?: number;
|
|
938
939
|
model:
|
|
939
940
|
| "user"
|
|
@@ -988,6 +989,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
988
989
|
"query",
|
|
989
990
|
"internal",
|
|
990
991
|
{
|
|
992
|
+
join?: any;
|
|
991
993
|
model:
|
|
992
994
|
| "user"
|
|
993
995
|
| "session"
|
|
@@ -2000,13 +2002,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
2000
2002
|
>;
|
|
2001
2003
|
};
|
|
2002
2004
|
adapterTest: {
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
delete: FunctionReference<"mutation", "internal", any, any, Name>;
|
|
2006
|
-
deleteMany: FunctionReference<"mutation", "internal", any, any, Name>;
|
|
2007
|
-
findMany: FunctionReference<"query", "internal", any, any, Name>;
|
|
2008
|
-
findOne: FunctionReference<"query", "internal", any, any, Name>;
|
|
2009
|
-
update: FunctionReference<"mutation", "internal", any, any, Name>;
|
|
2010
|
-
updateMany: FunctionReference<"mutation", "internal", any, any, Name>;
|
|
2005
|
+
runCustomTests: FunctionReference<"action", "internal", any, any, Name>;
|
|
2006
|
+
runTests: FunctionReference<"action", "internal", any, any, Name>;
|
|
2011
2007
|
};
|
|
2012
2008
|
};
|