@velajs/better-auth 0.2.0 → 0.2.2

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.
@@ -1,10 +1,29 @@
1
- import { type DynamicModule, type Token } from '@velajs/vela';
1
+ import { type DynamicModule, type InferTokens, type Token } from '@velajs/vela';
2
2
  import type { BetterAuthInstance, BetterAuthModuleOptions } from './better-auth.types';
3
- type AsyncAuthFactory = (...deps: any[]) => BetterAuthInstance;
4
- interface ForRootAsyncOptions {
5
- inject?: Token[];
3
+ /**
4
+ * Options for {@link BetterAuthModule.forRootAsync}.
5
+ *
6
+ * The `Inject` type parameter captures the literal `inject` tuple at the
7
+ * call site (via `const` inference on the consuming generic) so
8
+ * `useFactory` parameters are typed from the inject array, position-by-position.
9
+ * No `as const`, no `(...deps: any[])` workaround:
10
+ *
11
+ * ```ts
12
+ * BetterAuthModule.forRootAsync({
13
+ * inject: [D1Service, ConfigService], // captured as readonly tuple
14
+ * useFactory: (d1, config) => // d1: D1Service, config: ConfigService
15
+ * betterAuth({ database: drizzleAdapter(drizzle(d1.database), ...) }),
16
+ * });
17
+ * ```
18
+ *
19
+ * When `inject` isn't a literal tuple (or is omitted), `Inject` falls back
20
+ * to `readonly Token<unknown>[]` and `useFactory` accepts variadic
21
+ * `unknown[]` — the historical loose-typing behavior.
22
+ */
23
+ interface ForRootAsyncOptions<Inject extends readonly Token<unknown>[] = readonly Token<unknown>[]> {
24
+ inject?: Inject;
6
25
  imports?: DynamicModule['imports'];
7
- useFactory: AsyncAuthFactory;
26
+ useFactory: (...deps: InferTokens<Inject>) => BetterAuthInstance;
8
27
  isGlobal?: boolean;
9
28
  mountHandler?: boolean;
10
29
  basePath?: string;
@@ -34,6 +53,6 @@ export declare class BetterAuthModule {
34
53
  * inside your factory body — `(d1: D1Service) => betterAuth({ database:
35
54
  * drizzleAdapter(drizzle(d1.database), ...) })`.
36
55
  */
37
- static forRootAsync(options: ForRootAsyncOptions): DynamicModule;
56
+ static forRootAsync<const Inject extends readonly Token<unknown>[] = readonly Token<unknown>[]>(options: ForRootAsyncOptions<Inject>): DynamicModule;
38
57
  }
39
58
  export {};
@@ -68,6 +68,12 @@ export class BetterAuthModule {
68
68
  // invoked lazily by BetterAuthService.auth on first access; vela
69
69
  // can resolve this provider at module load without running the user
70
70
  // factory — the factory body lives behind the closure.
71
+ //
72
+ // The inner factory is typed `unknown[]` (vela's runtime contract:
73
+ // deps are resolved by token order). The outer user-facing
74
+ // `options.useFactory` is statically typed via `InferTokens<Inject>`.
75
+ // We narrow at the boundary with a single cast — runtime order
76
+ // matches the declared `inject` order by construction.
71
77
  provide: BETTER_AUTH_BUILDER,
72
78
  useFactory: (...deps)=>()=>options.useFactory(...deps),
73
79
  inject: options.inject ?? []
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@velajs/better-auth",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "better-auth integration for the Vela framework",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -42,7 +42,7 @@
42
42
  "node": ">=20"
43
43
  },
44
44
  "peerDependencies": {
45
- "@velajs/vela": ">=1.8.1",
45
+ "@velajs/vela": ">=1.8.2",
46
46
  "better-auth": ">=1.2.0",
47
47
  "hono": ">=4"
48
48
  },
@@ -50,7 +50,7 @@
50
50
  "@swc/cli": "^0.8.0",
51
51
  "@swc/core": "^1.15.11",
52
52
  "@velajs/testing": "^0.2.1",
53
- "@velajs/vela": "^1.8.1",
53
+ "@velajs/vela": "^1.8.2",
54
54
  "better-auth": "^1.2.0",
55
55
  "hono": "^4",
56
56
  "typescript": "^5",