@convex-dev/better-auth 0.7.0-alpha.10 → 0.7.0-alpha.12

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 (91) hide show
  1. package/dist/commonjs/client/adapter.d.ts +10 -1
  2. package/dist/commonjs/client/adapter.d.ts.map +1 -1
  3. package/dist/commonjs/client/adapter.js +183 -192
  4. package/dist/commonjs/client/adapter.js.map +1 -1
  5. package/dist/commonjs/client/index.d.ts +238 -179
  6. package/dist/commonjs/client/index.d.ts.map +1 -1
  7. package/dist/commonjs/client/index.js +46 -58
  8. package/dist/commonjs/client/index.js.map +1 -1
  9. package/dist/commonjs/component/adapterTest.d.ts +19 -0
  10. package/dist/commonjs/component/adapterTest.d.ts.map +1 -0
  11. package/dist/commonjs/component/adapterTest.js +82 -0
  12. package/dist/commonjs/component/adapterTest.js.map +1 -0
  13. package/dist/commonjs/component/lib.d.ts +218 -548
  14. package/dist/commonjs/component/lib.d.ts.map +1 -1
  15. package/dist/commonjs/component/lib.js +315 -286
  16. package/dist/commonjs/component/lib.js.map +1 -1
  17. package/dist/commonjs/component/schema.d.ts +90 -28
  18. package/dist/commonjs/component/schema.d.ts.map +1 -1
  19. package/dist/commonjs/component/schema.js +76 -18
  20. package/dist/commonjs/component/schema.js.map +1 -1
  21. package/dist/commonjs/component/util.d.ts +148 -86
  22. package/dist/commonjs/component/util.d.ts.map +1 -1
  23. package/dist/commonjs/nextjs/index.d.ts.map +1 -1
  24. package/dist/commonjs/nextjs/index.js +3 -9
  25. package/dist/commonjs/nextjs/index.js.map +1 -1
  26. package/dist/commonjs/plugins/convex/index.d.ts +14 -11
  27. package/dist/commonjs/plugins/convex/index.d.ts.map +1 -1
  28. package/dist/commonjs/plugins/convex/index.js +3 -2
  29. package/dist/commonjs/plugins/convex/index.js.map +1 -1
  30. package/dist/commonjs/plugins/cross-domain/client.d.ts +1 -1
  31. package/dist/commonjs/plugins/cross-domain/index.d.ts +5 -3
  32. package/dist/commonjs/plugins/cross-domain/index.d.ts.map +1 -1
  33. package/dist/commonjs/plugins/cross-domain/index.js +19 -5
  34. package/dist/commonjs/plugins/cross-domain/index.js.map +1 -1
  35. package/dist/commonjs/react-start/index.d.ts +4 -4
  36. package/dist/commonjs/utils/index.d.ts +2 -0
  37. package/dist/commonjs/utils/index.d.ts.map +1 -0
  38. package/dist/commonjs/utils/index.js +8 -0
  39. package/dist/commonjs/utils/index.js.map +1 -0
  40. package/dist/esm/client/adapter.d.ts +10 -1
  41. package/dist/esm/client/adapter.d.ts.map +1 -1
  42. package/dist/esm/client/adapter.js +183 -192
  43. package/dist/esm/client/adapter.js.map +1 -1
  44. package/dist/esm/client/index.d.ts +238 -179
  45. package/dist/esm/client/index.d.ts.map +1 -1
  46. package/dist/esm/client/index.js +46 -58
  47. package/dist/esm/client/index.js.map +1 -1
  48. package/dist/esm/component/adapterTest.d.ts +19 -0
  49. package/dist/esm/component/adapterTest.d.ts.map +1 -0
  50. package/dist/esm/component/adapterTest.js +82 -0
  51. package/dist/esm/component/adapterTest.js.map +1 -0
  52. package/dist/esm/component/lib.d.ts +218 -548
  53. package/dist/esm/component/lib.d.ts.map +1 -1
  54. package/dist/esm/component/lib.js +315 -286
  55. package/dist/esm/component/lib.js.map +1 -1
  56. package/dist/esm/component/schema.d.ts +90 -28
  57. package/dist/esm/component/schema.d.ts.map +1 -1
  58. package/dist/esm/component/schema.js +76 -18
  59. package/dist/esm/component/schema.js.map +1 -1
  60. package/dist/esm/component/util.d.ts +148 -86
  61. package/dist/esm/component/util.d.ts.map +1 -1
  62. package/dist/esm/nextjs/index.d.ts.map +1 -1
  63. package/dist/esm/nextjs/index.js +3 -9
  64. package/dist/esm/nextjs/index.js.map +1 -1
  65. package/dist/esm/plugins/convex/index.d.ts +14 -11
  66. package/dist/esm/plugins/convex/index.d.ts.map +1 -1
  67. package/dist/esm/plugins/convex/index.js +3 -2
  68. package/dist/esm/plugins/convex/index.js.map +1 -1
  69. package/dist/esm/plugins/cross-domain/client.d.ts +1 -1
  70. package/dist/esm/plugins/cross-domain/index.d.ts +5 -3
  71. package/dist/esm/plugins/cross-domain/index.d.ts.map +1 -1
  72. package/dist/esm/plugins/cross-domain/index.js +19 -5
  73. package/dist/esm/plugins/cross-domain/index.js.map +1 -1
  74. package/dist/esm/react-start/index.d.ts +4 -4
  75. package/dist/esm/utils/index.d.ts +2 -0
  76. package/dist/esm/utils/index.d.ts.map +1 -0
  77. package/dist/esm/utils/index.js +8 -0
  78. package/dist/esm/utils/index.js.map +1 -0
  79. package/package.json +20 -5
  80. package/src/client/adapter.test.ts +144 -0
  81. package/src/client/adapter.ts +191 -195
  82. package/src/client/index.ts +46 -71
  83. package/src/component/_generated/api.d.ts +605 -149
  84. package/src/component/adapterTest.ts +141 -0
  85. package/src/component/lib.ts +444 -335
  86. package/src/component/schema.ts +81 -19
  87. package/src/nextjs/index.ts +3 -14
  88. package/src/plugins/convex/index.ts +5 -2
  89. package/src/plugins/cross-domain/index.ts +19 -5
  90. package/src/client/cors.ts +0 -425
  91. /package/src/{util.ts → utils/index.ts} +0 -0
@@ -61,12 +61,12 @@ export declare const crossDomainClient: (opts?: {
61
61
  onSuccess(context: import("@better-fetch/fetch").SuccessContext<any>): Promise<void>;
62
62
  };
63
63
  init(url: string, options: {
64
+ method?: string | undefined;
64
65
  headers?: (HeadersInit & (HeadersInit | {
65
66
  accept: "application/json" | "text/plain" | "application/octet-stream";
66
67
  "content-type": "application/json" | "text/plain" | "application/x-www-form-urlencoded" | "multipart/form-data" | "application/octet-stream";
67
68
  authorization: "Bearer" | "Basic";
68
69
  })) | undefined;
69
- method?: string | undefined;
70
70
  cache?: RequestCache | undefined;
71
71
  credentials?: RequestCredentials | undefined;
72
72
  integrity?: string | undefined;
@@ -3,6 +3,11 @@ export declare const crossDomain: ({ siteUrl }: {
3
3
  siteUrl: string;
4
4
  }) => {
5
5
  id: "cross-domain";
6
+ init(ctx: import("better-auth").AuthContext): {
7
+ options: {
8
+ trustedOrigins: string[];
9
+ };
10
+ };
6
11
  hooks: {
7
12
  before: ({
8
13
  matcher(context: import("better-auth").HookEndpointContext): boolean;
@@ -74,8 +79,5 @@ export declare const crossDomain: ({ siteUrl }: {
74
79
  path: "/cross-domain/one-time-token/verify";
75
80
  };
76
81
  };
77
- options: {
78
- trustedOrigins: string[];
79
- };
80
82
  };
81
83
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/cross-domain/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,WAAW,GAAI,aAAa;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiJ3D,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/cross-domain/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,WAAW,GAAI,aAAa;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+J3D,CAAC"}
@@ -13,6 +13,13 @@ export const crossDomain = ({ siteUrl }) => {
13
13
  };
14
14
  return {
15
15
  id: "cross-domain",
16
+ init(ctx) {
17
+ return {
18
+ options: {
19
+ trustedOrigins: [siteUrl],
20
+ },
21
+ };
22
+ },
16
23
  hooks: {
17
24
  before: [
18
25
  {
@@ -44,9 +51,19 @@ export const crossDomain = ({ siteUrl }) => {
44
51
  },
45
52
  {
46
53
  matcher: (ctx) => {
47
- return (ctx.path.startsWith("/link-social") ||
54
+ return ctx.method === "GET" && ctx.path.startsWith("/verify-email");
55
+ },
56
+ handler: createAuthMiddleware(async (ctx) => {
57
+ if (ctx.query?.callbackURL) {
58
+ ctx.query.callbackURL = rewriteCallbackURL(ctx.query.callbackURL);
59
+ }
60
+ return { context: ctx };
61
+ }),
62
+ },
63
+ {
64
+ matcher: (ctx) => {
65
+ return ((ctx.method === "POST" && ctx.path.startsWith("/link-social")) ||
48
66
  ctx.path.startsWith("/send-verification-email") ||
49
- ctx.path.startsWith("/verify-email") ||
50
67
  ctx.path.startsWith("/sign-in/email") ||
51
68
  ctx.path.startsWith("/sign-in/social") ||
52
69
  ctx.path.startsWith("/sign-in/magic-link") ||
@@ -127,9 +144,6 @@ export const crossDomain = ({ siteUrl }) => {
127
144
  return response;
128
145
  }),
129
146
  },
130
- options: {
131
- trustedOrigins: [siteUrl],
132
- },
133
147
  };
134
148
  };
135
149
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/plugins/cross-domain/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAEL,kBAAkB,EAClB,oBAAoB,EACpB,YAAY,IAAI,kBAAkB,GACnC,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,EAAE,OAAO,EAAuB,EAAE,EAAE;IAC9D,MAAM,YAAY,GAAG,kBAAkB,EAAE,CAAC;IAE1C,MAAM,kBAAkB,GAAG,CAAC,WAAoB,EAAE,EAAE;QAClD,IAAI,WAAW,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YAChD,OAAO,WAAW,CAAC;QACrB,CAAC;QACD,MAAM,mBAAmB,GAAG,WAAW,IAAI,GAAG,CAAC;QAC/C,OAAO,IAAI,GAA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AAC;oBACrC,CAAC,CAAC;iBACH;aACF;SACF;QACD,SAAS,EAAE;YACT,kBAAkB,EAAE,kBAAkB,CACpC,qCAAqC,EACrC;gBACE,MAAM,EAAE,MAAM;gBACd,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;oBACb,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;iBAClB,CAAC;aACH,EACD,KAAK,EAAE,GAAG,EAAE,EAAE;gBACZ,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,SAAS,CAAC,kBAAkB,CAAC;oBAC/D,GAAG,GAAG;oBACN,aAAa,EAAE,KAAK;iBACrB,CAAC,CAAC;gBACH,MAAM,gBAAgB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;gBACtC,OAAO,QAAQ,CAAC;YAClB,CAAC,CACF;SACF;KACyB,CAAC;AAC/B,CAAC,CAAC"}
@@ -19,19 +19,19 @@ export declare const reactStartHelpers: (createAuth: (ctx: GenericActionCtx<any>
19
19
  session: {
20
20
  session: {
21
21
  id: string;
22
- createdAt: Date;
23
- updatedAt: Date;
22
+ token: string;
24
23
  userId: string;
25
24
  expiresAt: Date;
26
- token: string;
25
+ createdAt: Date;
26
+ updatedAt: Date;
27
27
  ipAddress?: string | null | undefined | undefined;
28
28
  userAgent?: string | null | undefined | undefined;
29
29
  };
30
30
  user: {
31
31
  id: string;
32
32
  name: string;
33
- email: string;
34
33
  emailVerified: boolean;
34
+ email: string;
35
35
  createdAt: Date;
36
36
  updatedAt: Date;
37
37
  image?: string | null | undefined | undefined;
@@ -0,0 +1,2 @@
1
+ export declare const requireEnv: (name: string) => string;
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,WAMtC,CAAC"}
@@ -0,0 +1,8 @@
1
+ export const requireEnv = (name) => {
2
+ const value = process.env[name];
3
+ if (value === undefined) {
4
+ throw new Error(`Missing environment variable \`${name}\``);
5
+ }
6
+ return value;
7
+ };
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,EAAE;IACzC,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,kCAAkC,IAAI,IAAI,CAAC,CAAC;IAC9D,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC"}
@@ -1,4 +1,13 @@
1
1
  import { BetterAuth } from "./index.js";
2
+ import { AdapterDebugLogs } from "better-auth/adapters";
2
3
  import { GenericActionCtx, GenericMutationCtx, GenericQueryCtx } from "convex/server";
3
- export declare const convexAdapter: <Ctx extends GenericQueryCtx<any> | GenericMutationCtx<any> | GenericActionCtx<any>>(ctx: Ctx, component: BetterAuth) => (options: import("better-auth").BetterAuthOptions) => import("better-auth").Adapter;
4
+ type GenericCtx = GenericQueryCtx<any> | GenericMutationCtx<any> | GenericActionCtx<any>;
5
+ interface ConvexAdapterConfig {
6
+ /**
7
+ * Helps you debug issues with the adapter.
8
+ */
9
+ debugLogs?: AdapterDebugLogs;
10
+ }
11
+ export declare const convexAdapter: (ctx: GenericCtx, component: BetterAuth, config?: ConvexAdapterConfig) => (options: import("better-auth").BetterAuthOptions) => import("better-auth").Adapter;
12
+ export {};
4
13
  //# sourceMappingURL=adapter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/client/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGrC,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EAChB,MAAM,eAAe,CAAC;AAEvB,eAAO,MAAM,aAAa,GACxB,GAAG,SACC,eAAe,CAAC,GAAG,CAAC,GACpB,kBAAkB,CAAC,GAAG,CAAC,GACvB,gBAAgB,CAAC,GAAG,CAAC,EAEzB,KAAK,GAAG,EACR,WAAW,UAAU,wFAoPnB,CAAC"}
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/client/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EACL,gBAAgB,EAGjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EAGhB,MAAM,eAAe,CAAC;AAyEvB,KAAK,UAAU,GACX,eAAe,CAAC,GAAG,CAAC,GACpB,kBAAkB,CAAC,GAAG,CAAC,GACvB,gBAAgB,CAAC,GAAG,CAAC,CAAC;AAE1B,UAAU,mBAAmB;IAC3B;;OAEG;IACH,SAAS,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AACD,eAAO,MAAM,aAAa,GACxB,KAAK,UAAU,EACf,WAAW,UAAU,EACrB,SAAQ,mBAAwB,wFA6JjC,CAAC"}
@@ -1,207 +1,198 @@
1
- import { transformInput } from "../component/lib.js";
2
- import { createAdapter } from "better-auth/adapters";
3
- export const convexAdapter = (ctx, component) => createAdapter({
4
- config: {
5
- adapterId: "convex",
6
- adapterName: "Convex Adapter",
7
- debugLogs: component.config.verbose ?? false,
8
- disableIdGeneration: true,
9
- },
10
- adapter: ({ schema }) => {
11
- return {
12
- id: "convex",
13
- create: async ({ model, data, select }) => {
14
- if (!("runMutation" in ctx)) {
15
- throw new Error("ctx is not an action ctx");
16
- }
17
- if (select) {
18
- throw new Error("select is not supported");
19
- }
20
- const createFn = model === "user"
21
- ? component.config.authFunctions.createUser
22
- : model === "session"
23
- ? component.config.authFunctions.createSession
24
- : component.component.lib.create;
25
- return ctx.runMutation(createFn, {
26
- input: { table: model, ...transformInput(model, data) },
27
- });
1
+ import { createAdapter, } from "better-auth/adapters";
2
+ const paginate = async (next, { limit, numItems } = {}) => {
3
+ const state = {
4
+ isDone: false,
5
+ cursor: null,
6
+ docs: [],
7
+ count: 0,
8
+ };
9
+ const onResult = (result) => {
10
+ state.cursor =
11
+ result.pageStatus === "SplitRecommended" ||
12
+ result.pageStatus === "SplitRequired"
13
+ ? result.splitCursor ?? result.continueCursor
14
+ : result.continueCursor;
15
+ if (result.page) {
16
+ state.docs.push(...result.page);
17
+ state.isDone = (limit && state.docs.length >= limit) || result.isDone;
18
+ return;
19
+ }
20
+ if (result.count) {
21
+ state.count += result.count;
22
+ state.isDone = (limit && state.count >= limit) || result.isDone;
23
+ return;
24
+ }
25
+ state.isDone = result.isDone;
26
+ };
27
+ do {
28
+ const result = await next({
29
+ paginationOpts: {
30
+ numItems: Math.min(numItems ?? 200, limit ?? 200, 200),
31
+ cursor: state.cursor,
28
32
  },
29
- findOne: async ({ model, where }) => {
30
- if (where.length === 1 && where[0].operator === "eq") {
31
- const { value, field } = where[0];
32
- const result = await ctx.runQuery(component.component.lib.getBy, {
33
- table: model,
34
- field,
35
- unique: field === "id" ? true : schema[model].fields[field].unique,
36
- value: value instanceof Date ? value.getTime() : value,
37
- });
33
+ });
34
+ onResult(result);
35
+ } while (!state.isDone);
36
+ return state;
37
+ };
38
+ const parseWhere = (where) => {
39
+ return where?.map((where) => {
40
+ if (where.value instanceof Date) {
41
+ return {
42
+ ...where,
43
+ value: where.value.getTime(),
44
+ };
45
+ }
46
+ return where;
47
+ });
48
+ };
49
+ export const convexAdapter = (ctx, component, config = {}) => {
50
+ const { debugLogs } = config;
51
+ return createAdapter({
52
+ config: {
53
+ adapterId: "convex",
54
+ adapterName: "Convex Adapter",
55
+ debugLogs: component.config.verbose ?? debugLogs ?? false,
56
+ disableIdGeneration: true,
57
+ supportsNumericIds: false,
58
+ usePlural: false,
59
+ mapKeysTransformOutput: {
60
+ _id: "id",
61
+ },
62
+ customTransformInput: ({ data, fieldAttributes, field }) => {
63
+ if (data && fieldAttributes.type === "date") {
64
+ const result = data.getTime();
65
+ console.log("transformed input", field, result);
38
66
  return result;
39
67
  }
40
- if (model === "account" &&
41
- where.length === 2 &&
42
- where[0].field === "accountId" &&
43
- where[1].field === "providerId" &&
44
- where[0].connector === "AND") {
45
- return ctx.runQuery(component.component.lib.getAccountByAccountIdAndProviderId, {
46
- accountId: where[0].value,
47
- providerId: where[1].value,
48
- });
49
- }
50
- throw new Error("where clause not supported");
68
+ return data;
51
69
  },
52
- findMany: async ({ model, where, sortBy, offset, limit, }) => {
53
- if (offset) {
54
- throw new Error("offset not supported");
55
- }
56
- if (model === "jwks" &&
57
- !where &&
58
- (!sortBy ||
59
- (sortBy?.field === "createdAt" && sortBy?.direction === "desc"))) {
60
- return ctx.runQuery(component.component.lib.getJwks, { limit });
61
- }
62
- if (where?.length !== 1 ||
63
- (where[0].operator && where[0].operator !== "eq")) {
64
- throw new Error("where clause not supported");
65
- }
66
- if (model === "verification" && where[0].field === "identifier") {
67
- return ctx.runQuery(component.component.lib.listVerificationsByIdentifier, {
68
- identifier: where[0].value,
69
- sortBy,
70
- limit,
71
- });
70
+ customTransformOutput: ({ data, fieldAttributes, field }) => {
71
+ if (data && fieldAttributes.type === "date") {
72
+ const result = new Date(data);
73
+ console.log("transformed output", field, result);
74
+ return result;
72
75
  }
73
- if (model === "account" && where[0].field === "userId" && !sortBy) {
74
- return ctx.runQuery(component.component.lib.getAccountsByUserId, {
75
- userId: where[0].value,
76
- limit,
76
+ return data;
77
+ },
78
+ },
79
+ adapter: ({ schema }) => {
80
+ return {
81
+ id: "convex",
82
+ create: async ({ model, data, select }) => {
83
+ if (!("runMutation" in ctx)) {
84
+ throw new Error("ctx is not a mutation ctx");
85
+ }
86
+ if (select) {
87
+ throw new Error("select is not supported");
88
+ }
89
+ const createFn = model === "user"
90
+ ? component.config.authFunctions.createUser
91
+ : model === "session"
92
+ ? component.config.authFunctions.createSession
93
+ : component.component.lib.create;
94
+ return await ctx.runMutation(createFn, {
95
+ input: { model, data },
77
96
  });
78
- }
79
- if (model === "session" && where[0].field === "userId" && !sortBy) {
80
- return ctx.runQuery(component.component.lib.getSessionsByUserId, {
81
- userId: where[0].value,
82
- limit,
97
+ },
98
+ findOne: async (data) => {
99
+ return await ctx.runQuery(component.component.lib.findOne, {
100
+ ...data,
101
+ where: parseWhere(data.where),
83
102
  });
84
- }
85
- throw new Error("where clause not supported");
86
- },
87
- count: async ({ where }) => {
88
- throw new Error("count not implemented");
89
- // return 0;
90
- },
91
- update: async ({ model, where, update }) => {
92
- if (!("runMutation" in ctx)) {
93
- throw new Error("ctx is not an action ctx");
94
- }
95
- if (where?.length === 1 && where[0].operator === "eq") {
96
- const { value, field } = where[0];
97
- const updateFn = model === "user"
98
- ? component.config.authFunctions.updateUser
99
- : component.component.lib.update;
100
- return ctx.runMutation(updateFn, {
101
- input: {
102
- table: model,
103
- where: {
104
- field,
105
- value: value instanceof Date ? value.getTime() : value,
103
+ },
104
+ findMany: async (data) => {
105
+ if (data.offset) {
106
+ throw new Error("offset not supported");
107
+ }
108
+ if (data.where?.length === 1 && data.where[0].operator === "in") {
109
+ return ctx.runQuery(component.component.lib.getIn, {
110
+ ...data,
111
+ where: parseWhere(data.where),
112
+ });
113
+ }
114
+ const result = await paginate(async ({ paginationOpts }) => {
115
+ return await ctx.runQuery(component.component.lib.findMany, {
116
+ ...data,
117
+ where: parseWhere(data.where),
118
+ paginationOpts,
119
+ });
120
+ }, { limit: data.limit });
121
+ return result.docs;
122
+ },
123
+ count: async () => {
124
+ throw new Error("count not implemented");
125
+ },
126
+ update: async (data) => {
127
+ if (!("runMutation" in ctx)) {
128
+ throw new Error("ctx is not a mutation ctx");
129
+ }
130
+ if (data.where?.length === 1 && data.where[0].operator === "eq") {
131
+ const updateFn = data.model === "user"
132
+ ? component.config.authFunctions.updateUser
133
+ : component.component.lib.updateOne;
134
+ return ctx.runMutation(updateFn, {
135
+ input: {
136
+ model: data.model,
137
+ where: parseWhere(data.where),
138
+ update: data.update,
106
139
  },
107
- value: transformInput(model, update),
108
- },
109
- });
110
- }
111
- throw new Error("where clause not supported");
112
- },
113
- delete: async ({ model, where }) => {
114
- if (!("runMutation" in ctx)) {
115
- throw new Error("ctx is not an action ctx");
116
- }
117
- if (where?.length === 1 && where[0].operator === "eq") {
118
- const { field, value } = where[0];
119
- const deleteFn = model === "user"
140
+ });
141
+ }
142
+ throw new Error("where clause not supported");
143
+ },
144
+ delete: async (data) => {
145
+ if (!("runMutation" in ctx)) {
146
+ throw new Error("ctx is not a mutation ctx");
147
+ }
148
+ const deleteFn = data.model === "user"
120
149
  ? component.config.authFunctions.deleteUser
121
- : component.component.lib.deleteBy;
150
+ : component.component.lib.deleteOne;
122
151
  await ctx.runMutation(deleteFn, {
123
- table: model,
124
- field,
125
- value: value instanceof Date ? value.getTime() : value,
152
+ model: data.model,
153
+ where: parseWhere(data.where),
126
154
  });
127
155
  return;
128
- }
129
- throw new Error("where clause not supported");
130
- // return null
131
- },
132
- deleteMany: async ({ model, where }) => {
133
- if (!("runAction" in ctx)) {
134
- throw new Error("ctx is not an action ctx");
135
- }
136
- if (model === "verification" &&
137
- where?.length === 1 &&
138
- where[0].operator === "lt" &&
139
- where[0].field === "expiresAt") {
140
- return ctx.runAction(component.component.lib.deleteOldVerifications, {
141
- currentTimestamp: Date.now(),
142
- });
143
- }
144
- if (where?.length === 1 && where[0].field === "userId") {
145
- return ctx.runAction(component.component.lib.deleteAllForUser, {
146
- table: model,
147
- userId: where[0].value,
148
- });
149
- }
150
- if (model === "session" &&
151
- where?.length === 2 &&
152
- where[0].operator === "eq" &&
153
- where[0].connector === "AND" &&
154
- where[0].field === "userId" &&
155
- where[1].operator === "lte" &&
156
- where[1].field === "expiresAt" &&
157
- typeof where[1].value === "number") {
158
- return ctx.runMutation(component.component.lib.deleteExpiredSessions, {
159
- userId: where[0].value,
160
- expiresAt: where[1].value,
161
- });
162
- }
163
- throw new Error("where clause not supported");
164
- // return count;
165
- },
166
- updateMany: async ({ model, where, update }) => {
167
- if (!("runMutation" in ctx)) {
168
- throw new Error("ctx is not an action ctx");
169
- }
170
- if (model === "twoFactor" &&
171
- where?.length === 1 &&
172
- where[0].operator === "eq" &&
173
- where[0].field === "userId") {
174
- return ctx.runMutation(component.component.lib.updateTwoFactor, {
175
- userId: where[0].value,
176
- update: transformInput(model, update),
156
+ },
157
+ deleteMany: async (data) => {
158
+ if (!("runMutation" in ctx)) {
159
+ throw new Error("ctx is not a mutation ctx");
160
+ }
161
+ if (data.model === "session" &&
162
+ data.where?.length === 1 &&
163
+ data.where[0].operator === "in") {
164
+ return ctx.runMutation(component.component.lib.deleteIn, {
165
+ input: {
166
+ table: data.model,
167
+ field: data.where[0].field,
168
+ values: data.where[0].value,
169
+ },
170
+ });
171
+ }
172
+ const result = await paginate(async ({ paginationOpts }) => {
173
+ return await ctx.runMutation(component.component.lib.deleteMany, {
174
+ ...data,
175
+ where: parseWhere(data.where),
176
+ paginationOpts,
177
+ });
177
178
  });
178
- }
179
- if (model === "account" &&
180
- where?.length === 2 &&
181
- where[0].operator === "eq" &&
182
- where[0].connector === "AND" &&
183
- where[0].field === "userId" &&
184
- where[1].operator === "eq" &&
185
- where[1].field === "providerId") {
186
- return ctx.runMutation(component.component.lib.updateUserProviderAccounts, {
187
- userId: where[0].value,
188
- providerId: where[1].value,
189
- update: transformInput(model, update),
179
+ return result.count;
180
+ },
181
+ updateMany: async (data) => {
182
+ if (!("runMutation" in ctx)) {
183
+ throw new Error("ctx is not an action ctx");
184
+ }
185
+ const result = await paginate(async ({ paginationOpts }) => {
186
+ return await ctx.runMutation(component.component.lib.updateMany, {
187
+ ...data,
188
+ where: parseWhere(data.where),
189
+ paginationOpts,
190
+ });
190
191
  });
191
- }
192
- throw new Error("updateMany not implemented");
193
- //return 0;
194
- /*
195
- const { model, where, update } = data;
196
- const table = db[model];
197
- const res = convertWhereClause(where, table, model);
198
- res.forEach((record) => {
199
- Object.assign(record, update);
200
- });
201
- return res[0] || null;
202
- */
203
- },
204
- };
205
- },
206
- });
192
+ return result.count;
193
+ },
194
+ };
195
+ },
196
+ });
197
+ };
207
198
  //# sourceMappingURL=adapter.js.map