@fougere/auth-better 0.5.0-alpha.1 → 0.6.0-alpha.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.
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # @fougere/auth-better
2
2
  > Fougere's auth
3
3
  A translation layer onto [better-auth](https://better-auth.com): its writes go through
4
- Fougere's ORM, and the application's `User` stays its own — Session and Account are
4
+ Fougere's storage, and the application's `User` stays its own — Session and Account are
5
5
  built against it.
6
6
 
7
7
  ## Installation
package/dist/adapter.d.ts CHANGED
@@ -1,15 +1,15 @@
1
- import type { EntityOrm } from '@fougere/core';
1
+ import type { Storage } from '@fougere/core';
2
2
  /**
3
3
  * Map of better-auth model names ('user', 'session', 'account', ...)
4
- * to Fougere EntityOrm instances. Built once at boot by create() in index.ts.
4
+ * to Fougere Storage instances. Built once at boot by create() in index.ts.
5
5
  */
6
- export type OrmMap = Map<string, EntityOrm>;
6
+ export type StorageMap = Map<string, Storage>;
7
7
  /**
8
- * Better-auth adapter that routes every operation through Fougere EntityOrm.
8
+ * Better-auth adapter that routes every operation through Fougere Storage.
9
9
  *
10
10
  * This closes the loop: the same `db` resolved by Fougere's bootstrap is the
11
- * one EntityOrm writes to, and better-auth never touches the storage directly.
11
+ * one Storage writes to, and better-auth never touches the storage directly.
12
12
  * If Fougere swaps Kysely for another backend, this adapter follows for free.
13
13
  */
14
- export declare function fougereAdapter(ormMap: OrmMap): import("better-auth/adapters").AdapterFactory<import("better-auth").BetterAuthOptions>;
14
+ export declare function fougereAdapter(storageMap: StorageMap): import("better-auth/adapters").AdapterFactory<import("better-auth").BetterAuthOptions>;
15
15
  //# sourceMappingURL=adapter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C;;;GAGG;AACH,MAAM,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAqC5C;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,0FAyG5C"}
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE7C;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAqC9C;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,UAAU,0FAyGpD"}
package/dist/adapter.js CHANGED
@@ -3,7 +3,7 @@ import { createAdapterFactory } from 'better-auth/adapters';
3
3
  * Where[] supported subset:
4
4
  * - All clauses use 'eq' operator
5
5
  * - Implicit AND between clauses (no OR connector)
6
- * Anything else throws — extend EntityOrm or add an engine-level fallback when needed.
6
+ * Anything else throws — extend Storage or add an engine-level fallback when needed.
7
7
  */
8
8
  function whereToCriteria(where) {
9
9
  const criteria = {};
@@ -19,23 +19,23 @@ function whereToCriteria(where) {
19
19
  }
20
20
  return criteria;
21
21
  }
22
- function getOrm(ormMap, model) {
23
- const orm = ormMap.get(model);
24
- if (!orm) {
22
+ function storageOf(storageMap, model) {
23
+ const storage = storageMap.get(model);
24
+ if (!storage) {
25
25
  throw new Error(`[fougereAdapter] Unknown model '${model}'. ` +
26
- `Known models: ${[...ormMap.keys()].join(', ')}. ` +
26
+ `Known models: ${[...storageMap.keys()].join(', ')}. ` +
27
27
  `Plugins that ship their own schema need entities registered explicitly.`);
28
28
  }
29
- return orm;
29
+ return storage;
30
30
  }
31
31
  /**
32
- * Better-auth adapter that routes every operation through Fougere EntityOrm.
32
+ * Better-auth adapter that routes every operation through Fougere Storage.
33
33
  *
34
34
  * This closes the loop: the same `db` resolved by Fougere's bootstrap is the
35
- * one EntityOrm writes to, and better-auth never touches the storage directly.
35
+ * one Storage writes to, and better-auth never touches the storage directly.
36
36
  * If Fougere swaps Kysely for another backend, this adapter follows for free.
37
37
  */
38
- export function fougereAdapter(ormMap) {
38
+ export function fougereAdapter(storageMap) {
39
39
  return createAdapterFactory({
40
40
  config: {
41
41
  adapterId: 'fougere',
@@ -43,34 +43,34 @@ export function fougereAdapter(ormMap) {
43
43
  usePlural: false,
44
44
  supportsArrays: false,
45
45
  supportsJSON: false,
46
- // The ORM converts both ways now (`schema-sql/src/values.ts`), so better-auth
46
+ // The storage converts both ways now (`schema-sql/src/values.ts`), so better-auth
47
47
  // can hand over the Dates and booleans its own types declare.
48
48
  supportsDates: true,
49
49
  supportsBooleans: true,
50
50
  },
51
51
  adapter: () => ({
52
52
  create: async ({ model, data }) => {
53
- const orm = getOrm(ormMap, model);
54
- return (await orm.create(data));
53
+ const storage = storageOf(storageMap, model);
54
+ return (await storage.create(data));
55
55
  },
56
56
  findOne: async ({ model, where }) => {
57
- const orm = getOrm(ormMap, model);
57
+ const storage = storageOf(storageMap, model);
58
58
  const criteria = whereToCriteria(where);
59
59
  if (Object.keys(criteria).length === 1 && 'id' in criteria) {
60
- const found = await orm.findById(criteria.id);
60
+ const found = await storage.findById(criteria.id);
61
61
  return (found ?? null);
62
62
  }
63
- const found = await orm.findBy(criteria);
63
+ const found = await storage.findBy(criteria);
64
64
  return (found ?? null);
65
65
  },
66
66
  findMany: async ({ model, where, limit, offset, sortBy, }) => {
67
- const orm = getOrm(ormMap, model);
67
+ const storage = storageOf(storageMap, model);
68
68
  if (where && where.length > 0) {
69
69
  const criteria = whereToCriteria(where);
70
- const rows = await orm.findAllBy(criteria);
70
+ const rows = await storage.findAllBy(criteria);
71
71
  return applyClientSidePagination(rows, sortBy, offset, limit);
72
72
  }
73
- const rows = await orm.list({
73
+ const rows = await storage.list({
74
74
  limit,
75
75
  offset,
76
76
  orderBy: sortBy?.field,
@@ -79,59 +79,59 @@ export function fougereAdapter(ormMap) {
79
79
  return rows;
80
80
  },
81
81
  count: async ({ model, where }) => {
82
- const orm = getOrm(ormMap, model);
82
+ const storage = storageOf(storageMap, model);
83
83
  if (where && where.length > 0) {
84
84
  const criteria = whereToCriteria(where);
85
- const rows = await orm.findAllBy(criteria);
85
+ const rows = await storage.findAllBy(criteria);
86
86
  return rows.length;
87
87
  }
88
- const rows = await orm.list({ count: true });
88
+ const rows = await storage.list({ count: true });
89
89
  return rows.total ?? rows.length;
90
90
  },
91
91
  update: async ({ model, where, update }) => {
92
- const orm = getOrm(ormMap, model);
92
+ const storage = storageOf(storageMap, model);
93
93
  const criteria = whereToCriteria(where);
94
94
  const target = 'id' in criteria
95
- ? await orm.findById(criteria.id)
96
- : await orm.findBy(criteria);
95
+ ? await storage.findById(criteria.id)
96
+ : await storage.findBy(criteria);
97
97
  if (!target)
98
98
  return null;
99
- return (await orm.update(target.id, update));
99
+ return (await storage.update(target.id, update));
100
100
  },
101
101
  updateMany: async ({ model, where, update }) => {
102
- const orm = getOrm(ormMap, model);
102
+ const storage = storageOf(storageMap, model);
103
103
  const criteria = whereToCriteria(where);
104
- const targets = await orm.findAllBy(criteria);
104
+ const targets = await storage.findAllBy(criteria);
105
105
  for (const target of targets)
106
- await orm.update(target.id, update);
106
+ await storage.update(target.id, update);
107
107
  return targets.length;
108
108
  },
109
109
  delete: async ({ model, where }) => {
110
- const orm = getOrm(ormMap, model);
110
+ const storage = storageOf(storageMap, model);
111
111
  const criteria = whereToCriteria(where);
112
112
  const target = 'id' in criteria
113
- ? await orm.findById(criteria.id)
114
- : await orm.findBy(criteria);
113
+ ? await storage.findById(criteria.id)
114
+ : await storage.findBy(criteria);
115
115
  if (target)
116
- await orm.delete(target.id);
116
+ await storage.delete(target.id);
117
117
  },
118
118
  deleteMany: async ({ model, where }) => {
119
- const orm = getOrm(ormMap, model);
119
+ const storage = storageOf(storageMap, model);
120
120
  const criteria = whereToCriteria(where);
121
- const targets = await orm.findAllBy(criteria);
121
+ const targets = await storage.findAllBy(criteria);
122
122
  for (const target of targets)
123
- await orm.delete(target.id);
123
+ await storage.delete(target.id);
124
124
  return targets.length;
125
125
  },
126
126
  }),
127
127
  });
128
128
  }
129
129
  /**
130
- * Augmented EntityOrm shape — the core interface doesn't expose findBy/findAllBy
131
- * but SqlEntityOrm (the only impl today) does. Cast locally to use them.
130
+ * Augmented Storage shape — the core interface doesn't expose findBy/findAllBy
131
+ * but SqlStorage (the only impl today) does. Cast locally to use them.
132
132
  */
133
133
  /**
134
- * EntityOrm.findAllBy doesn't expose pagination/sort, so we apply them in JS
134
+ * Storage.findAllBy doesn't expose pagination/sort, so we apply them in JS
135
135
  * after fetching the eq-filtered rows. Fine for auth volumes (orgs/sessions/accounts).
136
136
  */
137
137
  function applyClientSidePagination(rows, sortBy, offset, limit) {
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAU5D;;;;;GAKG;AACH,SAAS,eAAe,CAAC,KAA8B;IACrD,MAAM,QAAQ,GAA4B,EAAE,CAAC;IAC7C,KAAK,MAAM,MAAM,IAAI,KAAK,EAAE,CAAC;QAC3B,IAAI,MAAM,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CACb,8BAA8B,MAAM,CAAC,QAAQ,iCAAiC,MAAM,CAAC,KAAK,KAAK;gBAC/F,6CAA6C,CAC9C,CAAC;QACJ,CAAC;QACD,IAAI,MAAM,CAAC,SAAS,KAAK,IAAI,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CAAC,2DAA2D,MAAM,CAAC,KAAK,KAAK,CAAC,CAAC;QAChG,CAAC;QACD,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC;IACxC,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,MAAM,CAAC,MAAc,EAAE,KAAa;IAC3C,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AAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IACzD,OAAO,MAAM,CAAC;AAChB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -33,7 +33,7 @@ export interface BetterAuthOptions {
33
33
  * ```
34
34
  *
35
35
  * Returns a lazy AuthConfig — the better-auth engine is only constructed when
36
- * the core calls `create(ctx)` at boot, with the resolved db + ormFactory.
36
+ * the core calls `create(ctx)` at boot, with the resolved db + storageFactory.
37
37
  */
38
38
  export declare function betterAuth(opts: BetterAuthOptions): AuthConfig;
39
39
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ export { AuthUser, AuthVerification, authEntities } from './entities.js';
14
14
  * ```
15
15
  *
16
16
  * Returns a lazy AuthConfig — the better-auth engine is only constructed when
17
- * the core calls `create(ctx)` at boot, with the resolved db + ormFactory.
17
+ * the core calls `create(ctx)` at boot, with the resolved db + storageFactory.
18
18
  */
19
19
  export function betterAuth(opts) {
20
20
  const userSchema = opts.user ?? AuthUser;
@@ -31,15 +31,15 @@ export function betterAuth(opts) {
31
31
  account: accountSchema,
32
32
  verification: verificationSchema,
33
33
  },
34
- create({ ormFactory }) {
35
- const ormMap = new Map([
36
- ['user', ormFactory(userSchema, 'user')],
37
- ['session', ormFactory(sessionSchema, 'session')],
38
- ['account', ormFactory(accountSchema, 'account')],
39
- ['verification', ormFactory(verificationSchema, 'verification')],
34
+ create({ storageFactory }) {
35
+ const storageMap = new Map([
36
+ ['user', storageFactory(userSchema, 'user')],
37
+ ['session', storageFactory(sessionSchema, 'session')],
38
+ ['account', storageFactory(accountSchema, 'account')],
39
+ ['verification', storageFactory(verificationSchema, 'verification')],
40
40
  ]);
41
41
  const engine = betterAuthLib({
42
- database: fougereAdapter(ormMap),
42
+ database: fougereAdapter(storageMap),
43
43
  secret: opts.secret,
44
44
  baseURL: opts.baseUrl,
45
45
  basePath,
@@ -57,7 +57,7 @@ export function betterAuth(opts) {
57
57
  account: accountSchema,
58
58
  verification: verificationSchema,
59
59
  },
60
- orms: Object.fromEntries(ormMap),
60
+ storages: Object.fromEntries(storageMap),
61
61
  handler: engine.handler,
62
62
  api: engine.api,
63
63
  basePath,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,aAAa,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAGhD,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,cAAc,EAAe,MAAM,cAAc,CAAC;AAC3D,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,gBAAgB,GAEjB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAwBzE;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,UAAU,CAAC,IAAuB;IAChD,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,IAAI,QAAQ,CAAC;IACzC,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC;IAC9D,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,IAAI,WAAW,CAAC;IAClD,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,IAAI,WAAW,CAAC;IAClD,MAAM,kBAAkB,GAAG,IAAI,CAAC,YAAY,IAAI,gBAAgB,CAAC;IACjE,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,EAAE,CAAC;IACvC,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,OAAO,CAAC;IAE1C,OAAO;QACL,QAAQ,EAAE;YACR,IAAI,EAAE,UAAU;YAChB,OAAO,EAAE,aAAa;YACtB,OAAO,EAAE,aAAa;YACtB,YA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J,CAAC;KACF,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fougere/auth-better",
3
- "version": "0.5.0-alpha.1",
3
+ "version": "0.6.0-alpha.0",
4
4
  "description": "Fougere's auth — a translation layer onto better-auth.",
5
5
  "keywords": [
6
6
  "fougere",
@@ -31,12 +31,12 @@
31
31
  "dependencies": {
32
32
  "@paralleldrive/cuid2": "^3.3.0",
33
33
  "better-auth": "^1.6.11",
34
- "@fougere/core": "0.5.0-alpha.1",
35
- "@fougere/schema": "0.5.0-alpha.1"
34
+ "@fougere/core": "0.6.0-alpha.0",
35
+ "@fougere/schema": "0.6.0-alpha.0"
36
36
  },
37
37
  "devDependencies": {
38
38
  "vitest": "^4.1.0",
39
- "@fougere/adapter-sql": "0.5.0-alpha.1"
39
+ "@fougere/adapter-sql": "0.6.0-alpha.0"
40
40
  },
41
41
  "publishConfig": {
42
42
  "access": "public"
package/src/adapter.ts CHANGED
@@ -1,18 +1,18 @@
1
1
  import { createAdapterFactory } from 'better-auth/adapters';
2
2
  import type { CleanedWhere, CustomAdapter } from 'better-auth/adapters';
3
- import type { EntityOrm } from '@fougere/core';
3
+ import type { Storage } from '@fougere/core';
4
4
 
5
5
  /**
6
6
  * Map of better-auth model names ('user', 'session', 'account', ...)
7
- * to Fougere EntityOrm instances. Built once at boot by create() in index.ts.
7
+ * to Fougere Storage instances. Built once at boot by create() in index.ts.
8
8
  */
9
- export type OrmMap = Map<string, EntityOrm>;
9
+ export type StorageMap = Map<string, Storage>;
10
10
 
11
11
  /**
12
12
  * Where[] supported subset:
13
13
  * - All clauses use 'eq' operator
14
14
  * - Implicit AND between clauses (no OR connector)
15
- * Anything else throws — extend EntityOrm or add an engine-level fallback when needed.
15
+ * Anything else throws — extend Storage or add an engine-level fallback when needed.
16
16
  */
17
17
  function whereToCriteria(where: readonly CleanedWhere[]): Record<string, unknown> {
18
18
  const criteria: Record<string, unknown> = {};
@@ -31,26 +31,26 @@ function whereToCriteria(where: readonly CleanedWhere[]): Record<string, unknown
31
31
  return criteria;
32
32
  }
33
33
 
34
- function getOrm(ormMap: OrmMap, model: string): EntityOrm {
35
- const orm = ormMap.get(model);
36
- if (!orm) {
34
+ function storageOf(storageMap: StorageMap, model: string): Storage {
35
+ const storage = storageMap.get(model);
36
+ if (!storage) {
37
37
  throw new Error(
38
38
  `[fougereAdapter] Unknown model '${model}'. ` +
39
- `Known models: ${[...ormMap.keys()].join(', ')}. ` +
39
+ `Known models: ${[...storageMap.keys()].join(', ')}. ` +
40
40
  `Plugins that ship their own schema need entities registered explicitly.`,
41
41
  );
42
42
  }
43
- return orm;
43
+ return storage;
44
44
  }
45
45
 
46
46
  /**
47
- * Better-auth adapter that routes every operation through Fougere EntityOrm.
47
+ * Better-auth adapter that routes every operation through Fougere Storage.
48
48
  *
49
49
  * This closes the loop: the same `db` resolved by Fougere's bootstrap is the
50
- * one EntityOrm writes to, and better-auth never touches the storage directly.
50
+ * one Storage writes to, and better-auth never touches the storage directly.
51
51
  * If Fougere swaps Kysely for another backend, this adapter follows for free.
52
52
  */
53
- export function fougereAdapter(ormMap: OrmMap) {
53
+ export function fougereAdapter(storageMap: StorageMap) {
54
54
  return createAdapterFactory({
55
55
  config: {
56
56
  adapterId: 'fougere',
@@ -58,25 +58,25 @@ export function fougereAdapter(ormMap: OrmMap) {
58
58
  usePlural: false,
59
59
  supportsArrays: false,
60
60
  supportsJSON: false,
61
- // The ORM converts both ways now (`schema-sql/src/values.ts`), so better-auth
61
+ // The storage converts both ways now (`schema-sql/src/values.ts`), so better-auth
62
62
  // can hand over the Dates and booleans its own types declare.
63
63
  supportsDates: true,
64
64
  supportsBooleans: true,
65
65
  },
66
66
  adapter: (): CustomAdapter => ({
67
67
  create: async ({ model, data }: { model: string; data: Record<string, unknown> }) => {
68
- const orm = getOrm(ormMap, model);
69
- return (await orm.create(data)) as never;
68
+ const storage = storageOf(storageMap, model);
69
+ return (await storage.create(data)) as never;
70
70
  },
71
71
 
72
72
  findOne: async ({ model, where }: { model: string; where: CleanedWhere[] }) => {
73
- const orm = getOrm(ormMap, model);
73
+ const storage = storageOf(storageMap, model);
74
74
  const criteria = whereToCriteria(where);
75
75
  if (Object.keys(criteria).length === 1 && 'id' in criteria) {
76
- const found = await orm.findById(criteria.id as string);
76
+ const found = await storage.findById(criteria.id as string);
77
77
  return (found ?? null) as never;
78
78
  }
79
- const found = await orm.findBy(criteria);
79
+ const found = await storage.findBy(criteria);
80
80
  return (found ?? null) as never;
81
81
  },
82
82
 
@@ -93,13 +93,13 @@ export function fougereAdapter(ormMap: OrmMap) {
93
93
  offset?: number;
94
94
  sortBy?: { field: string; direction: 'asc' | 'desc' };
95
95
  }) => {
96
- const orm = getOrm(ormMap, model);
96
+ const storage = storageOf(storageMap, model);
97
97
  if (where && where.length > 0) {
98
98
  const criteria = whereToCriteria(where);
99
- const rows = await orm.findAllBy(criteria);
99
+ const rows = await storage.findAllBy(criteria);
100
100
  return applyClientSidePagination(rows, sortBy, offset, limit) as never;
101
101
  }
102
- const rows = await orm.list({
102
+ const rows = await storage.list({
103
103
  limit,
104
104
  offset,
105
105
  orderBy: sortBy?.field,
@@ -109,48 +109,48 @@ export function fougereAdapter(ormMap: OrmMap) {
109
109
  },
110
110
 
111
111
  count: async ({ model, where }: { model: string; where?: CleanedWhere[] }) => {
112
- const orm = getOrm(ormMap, model);
112
+ const storage = storageOf(storageMap, model);
113
113
  if (where && where.length > 0) {
114
114
  const criteria = whereToCriteria(where);
115
- const rows = await orm.findAllBy(criteria);
115
+ const rows = await storage.findAllBy(criteria);
116
116
  return rows.length;
117
117
  }
118
- const rows = await orm.list({ count: true });
118
+ const rows = await storage.list({ count: true });
119
119
  return rows.total ?? rows.length;
120
120
  },
121
121
 
122
122
  update: async <T>({ model, where, update }: { model: string; where: CleanedWhere[]; update: T }): Promise<T | null> => {
123
- const orm = getOrm(ormMap, model);
123
+ const storage = storageOf(storageMap, model);
124
124
  const criteria = whereToCriteria(where);
125
125
  const target = 'id' in criteria
126
- ? await orm.findById(criteria.id as string)
127
- : await orm.findBy(criteria);
126
+ ? await storage.findById(criteria.id as string)
127
+ : await storage.findBy(criteria);
128
128
  if (!target) return null;
129
- return (await orm.update(target.id as string, update as Partial<Record<string, unknown>>)) as T;
129
+ return (await storage.update(target.id as string, update as Partial<Record<string, unknown>>)) as T;
130
130
  },
131
131
 
132
132
  updateMany: async ({ model, where, update }: { model: string; where: CleanedWhere[]; update: Record<string, unknown> }) => {
133
- const orm = getOrm(ormMap, model);
133
+ const storage = storageOf(storageMap, model);
134
134
  const criteria = whereToCriteria(where);
135
- const targets = await orm.findAllBy(criteria);
136
- for (const target of targets) await orm.update(target.id as string, update);
135
+ const targets = await storage.findAllBy(criteria);
136
+ for (const target of targets) await storage.update(target.id as string, update);
137
137
  return targets.length;
138
138
  },
139
139
 
140
140
  delete: async ({ model, where }: { model: string; where: CleanedWhere[] }) => {
141
- const orm = getOrm(ormMap, model);
141
+ const storage = storageOf(storageMap, model);
142
142
  const criteria = whereToCriteria(where);
143
143
  const target = 'id' in criteria
144
- ? await orm.findById(criteria.id as string)
145
- : await orm.findBy(criteria);
146
- if (target) await orm.delete(target.id as string);
144
+ ? await storage.findById(criteria.id as string)
145
+ : await storage.findBy(criteria);
146
+ if (target) await storage.delete(target.id as string);
147
147
  },
148
148
 
149
149
  deleteMany: async ({ model, where }: { model: string; where: CleanedWhere[] }) => {
150
- const orm = getOrm(ormMap, model);
150
+ const storage = storageOf(storageMap, model);
151
151
  const criteria = whereToCriteria(where);
152
- const targets = await orm.findAllBy(criteria);
153
- for (const target of targets) await orm.delete(target.id as string);
152
+ const targets = await storage.findAllBy(criteria);
153
+ for (const target of targets) await storage.delete(target.id as string);
154
154
  return targets.length;
155
155
  },
156
156
  }),
@@ -158,11 +158,11 @@ export function fougereAdapter(ormMap: OrmMap) {
158
158
  }
159
159
 
160
160
  /**
161
- * Augmented EntityOrm shape — the core interface doesn't expose findBy/findAllBy
162
- * but SqlEntityOrm (the only impl today) does. Cast locally to use them.
161
+ * Augmented Storage shape — the core interface doesn't expose findBy/findAllBy
162
+ * but SqlStorage (the only impl today) does. Cast locally to use them.
163
163
  */
164
164
  /**
165
- * EntityOrm.findAllBy doesn't expose pagination/sort, so we apply them in JS
165
+ * Storage.findAllBy doesn't expose pagination/sort, so we apply them in JS
166
166
  * after fetching the eq-filtered rows. Fine for auth volumes (orgs/sessions/accounts).
167
167
  */
168
168
  function applyClientSidePagination(
package/src/index.ts CHANGED
@@ -3,7 +3,7 @@ import { createId } from '@paralleldrive/cuid2';
3
3
  import type { AuthConfig, AuthContext, AuthRuntime } from '@fougere/core';
4
4
  import type { SchemaView } from '@fougere/schema';
5
5
  import { AuthVerification, AuthUser, authEntities } from './entities.js';
6
- import { fougereAdapter, type OrmMap } from './adapter.js';
6
+ import { fougereAdapter, type StorageMap } from './adapter.js';
7
7
  import {
8
8
  translateCredential,
9
9
  translateSocial,
@@ -45,7 +45,7 @@ export interface BetterAuthOptions {
45
45
  * ```
46
46
  *
47
47
  * Returns a lazy AuthConfig — the better-auth engine is only constructed when
48
- * the core calls `create(ctx)` at boot, with the resolved db + ormFactory.
48
+ * the core calls `create(ctx)` at boot, with the resolved db + storageFactory.
49
49
  */
50
50
  export function betterAuth(opts: BetterAuthOptions): AuthConfig {
51
51
  const userSchema = opts.user ?? AuthUser;
@@ -63,16 +63,16 @@ export function betterAuth(opts: BetterAuthOptions): AuthConfig {
63
63
  account: accountSchema,
64
64
  verification: verificationSchema,
65
65
  },
66
- create({ ormFactory }: AuthContext): AuthRuntime {
67
- const ormMap: OrmMap = new Map([
68
- ['user', ormFactory(userSchema, 'user')],
69
- ['session', ormFactory(sessionSchema, 'session')],
70
- ['account', ormFactory(accountSchema, 'account')],
71
- ['verification', ormFactory(verificationSchema, 'verification')],
66
+ create({ storageFactory }: AuthContext): AuthRuntime {
67
+ const storageMap: StorageMap = new Map([
68
+ ['user', storageFactory(userSchema, 'user')],
69
+ ['session', storageFactory(sessionSchema, 'session')],
70
+ ['account', storageFactory(accountSchema, 'account')],
71
+ ['verification', storageFactory(verificationSchema, 'verification')],
72
72
  ]);
73
73
 
74
74
  const engine = betterAuthLib({
75
- database: fougereAdapter(ormMap),
75
+ database: fougereAdapter(storageMap),
76
76
  secret: opts.secret,
77
77
  baseURL: opts.baseUrl,
78
78
  basePath,
@@ -91,7 +91,7 @@ export function betterAuth(opts: BetterAuthOptions): AuthConfig {
91
91
  account: accountSchema,
92
92
  verification: verificationSchema,
93
93
  },
94
- orms: Object.fromEntries(ormMap),
94
+ storages: Object.fromEntries(storageMap),
95
95
  handler: engine.handler,
96
96
  api: engine.api as Record<string, unknown>,
97
97
  basePath,