@forklaunch/better-auth-mikro-orm-fork 0.4.103 → 0.4.105
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/lib/adapter.cjs +8 -4
- package/lib/adapter.d.cts +3 -3
- package/lib/adapter.d.ts +3 -3
- package/lib/adapter.js +10 -4
- package/package.json +2 -2
- package/readme.md +28 -21
package/lib/adapter.cjs
CHANGED
|
@@ -25,7 +25,7 @@ __export(src_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(src_exports);
|
|
26
26
|
|
|
27
27
|
// src/adapter.ts
|
|
28
|
-
var import_adapters = require("better-auth/adapters");
|
|
28
|
+
var import_adapters = require("@forklaunch/better-auth/adapters");
|
|
29
29
|
var import_dset2 = require("dset");
|
|
30
30
|
|
|
31
31
|
// src/utils/adapterUtils.ts
|
|
@@ -33,7 +33,7 @@ var import_core = require("@mikro-orm/core");
|
|
|
33
33
|
var import_dset = require("dset");
|
|
34
34
|
|
|
35
35
|
// src/utils/createAdapterError.ts
|
|
36
|
-
var import_better_auth = require("better-auth");
|
|
36
|
+
var import_better_auth = require("@forklaunch/better-auth");
|
|
37
37
|
function createAdapterError(message) {
|
|
38
38
|
throw new import_better_auth.BetterAuthError(`[Mikro ORM Adapter] ${message}`);
|
|
39
39
|
}
|
|
@@ -188,14 +188,18 @@ function createAdapterUtils(orm) {
|
|
|
188
188
|
}
|
|
189
189
|
const result = {};
|
|
190
190
|
where.filter(({ connector }) => !connector || connector === "AND").forEach(({ field, operator, value }, index) => {
|
|
191
|
-
const path = ["$and", index].concat(
|
|
191
|
+
const path = ["$and", index].concat(
|
|
192
|
+
getFieldPath(metadata2, field, true)
|
|
193
|
+
);
|
|
192
194
|
if (operator === "in") {
|
|
193
195
|
return createWhereInClause(field, path, value, result);
|
|
194
196
|
}
|
|
195
197
|
return createWhereClause(path, value, "eq", result);
|
|
196
198
|
});
|
|
197
199
|
where.filter(({ connector }) => connector === "OR").forEach(({ field, value }, index) => {
|
|
198
|
-
const path = ["$and", index].concat(
|
|
200
|
+
const path = ["$and", index].concat(
|
|
201
|
+
getFieldPath(metadata2, field, true)
|
|
202
|
+
);
|
|
199
203
|
return createWhereClause(path, value, "eq", result);
|
|
200
204
|
});
|
|
201
205
|
return result;
|
package/lib/adapter.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _forklaunch_better_auth from '@forklaunch/better-auth';
|
|
2
2
|
import { MikroORM } from '@mikro-orm/core';
|
|
3
|
-
import { AdapterDebugLogs } from 'better-auth/adapters';
|
|
3
|
+
import { AdapterDebugLogs } from '@forklaunch/better-auth/adapters';
|
|
4
4
|
|
|
5
5
|
interface MikroOrmAdapterConfig {
|
|
6
6
|
/**
|
|
@@ -32,6 +32,6 @@ interface MikroOrmAdapterConfig {
|
|
|
32
32
|
* @param orm - Instance of Mikro ORM returned from `MikroORM.init` or `MikroORM.initSync` methods
|
|
33
33
|
* @param config - Additional configuration for Mikro ORM adapter
|
|
34
34
|
*/
|
|
35
|
-
declare const mikroOrmAdapter: (orm: MikroORM, { debugLogs, supportsJSON }?: MikroOrmAdapterConfig) => (options:
|
|
35
|
+
declare const mikroOrmAdapter: (orm: MikroORM, { debugLogs, supportsJSON }?: MikroOrmAdapterConfig) => (options: _forklaunch_better_auth.BetterAuthOptions) => _forklaunch_better_auth.Adapter;
|
|
36
36
|
|
|
37
37
|
export { type MikroOrmAdapterConfig, mikroOrmAdapter };
|
package/lib/adapter.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _forklaunch_better_auth from '@forklaunch/better-auth';
|
|
2
2
|
import { MikroORM } from '@mikro-orm/core';
|
|
3
|
-
import { AdapterDebugLogs } from 'better-auth/adapters';
|
|
3
|
+
import { AdapterDebugLogs } from '@forklaunch/better-auth/adapters';
|
|
4
4
|
|
|
5
5
|
interface MikroOrmAdapterConfig {
|
|
6
6
|
/**
|
|
@@ -32,6 +32,6 @@ interface MikroOrmAdapterConfig {
|
|
|
32
32
|
* @param orm - Instance of Mikro ORM returned from `MikroORM.init` or `MikroORM.initSync` methods
|
|
33
33
|
* @param config - Additional configuration for Mikro ORM adapter
|
|
34
34
|
*/
|
|
35
|
-
declare const mikroOrmAdapter: (orm: MikroORM, { debugLogs, supportsJSON }?: MikroOrmAdapterConfig) => (options:
|
|
35
|
+
declare const mikroOrmAdapter: (orm: MikroORM, { debugLogs, supportsJSON }?: MikroOrmAdapterConfig) => (options: _forklaunch_better_auth.BetterAuthOptions) => _forklaunch_better_auth.Adapter;
|
|
36
36
|
|
|
37
37
|
export { type MikroOrmAdapterConfig, mikroOrmAdapter };
|
package/lib/adapter.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// src/adapter.ts
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
createAdapter
|
|
4
|
+
} from "@forklaunch/better-auth/adapters";
|
|
3
5
|
import { dset as dset2 } from "dset";
|
|
4
6
|
|
|
5
7
|
// src/utils/adapterUtils.ts
|
|
@@ -7,7 +9,7 @@ import { ReferenceKind, serialize } from "@mikro-orm/core";
|
|
|
7
9
|
import { dset } from "dset";
|
|
8
10
|
|
|
9
11
|
// src/utils/createAdapterError.ts
|
|
10
|
-
import { BetterAuthError } from "better-auth";
|
|
12
|
+
import { BetterAuthError } from "@forklaunch/better-auth";
|
|
11
13
|
function createAdapterError(message) {
|
|
12
14
|
throw new BetterAuthError(`[Mikro ORM Adapter] ${message}`);
|
|
13
15
|
}
|
|
@@ -162,14 +164,18 @@ function createAdapterUtils(orm) {
|
|
|
162
164
|
}
|
|
163
165
|
const result = {};
|
|
164
166
|
where.filter(({ connector }) => !connector || connector === "AND").forEach(({ field, operator, value }, index) => {
|
|
165
|
-
const path = ["$and", index].concat(
|
|
167
|
+
const path = ["$and", index].concat(
|
|
168
|
+
getFieldPath(metadata2, field, true)
|
|
169
|
+
);
|
|
166
170
|
if (operator === "in") {
|
|
167
171
|
return createWhereInClause(field, path, value, result);
|
|
168
172
|
}
|
|
169
173
|
return createWhereClause(path, value, "eq", result);
|
|
170
174
|
});
|
|
171
175
|
where.filter(({ connector }) => connector === "OR").forEach(({ field, value }, index) => {
|
|
172
|
-
const path = ["$and", index].concat(
|
|
176
|
+
const path = ["$and", index].concat(
|
|
177
|
+
getFieldPath(metadata2, field, true)
|
|
178
|
+
);
|
|
173
179
|
return createWhereClause(path, value, "eq", result);
|
|
174
180
|
});
|
|
175
181
|
return result;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"private": false,
|
|
3
3
|
"type": "module",
|
|
4
4
|
"name": "@forklaunch/better-auth-mikro-orm-fork",
|
|
5
|
-
"version": "0.4.
|
|
5
|
+
"version": "0.4.105",
|
|
6
6
|
"description": "Mikro ORM Adapter for Better Auth",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"auth",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"@types/uuid": "10.0.0",
|
|
60
60
|
"@vitest/coverage-v8": "3.1.1",
|
|
61
61
|
"@vitest/ui": "3.1.1",
|
|
62
|
-
"better-auth": "1.
|
|
62
|
+
"@forklaunch/better-auth": "1.3.8",
|
|
63
63
|
"del-cli": "6.0.0",
|
|
64
64
|
"es-toolkit": "1.39.7",
|
|
65
65
|
"husky": "9.1.7",
|
package/readme.md
CHANGED
|
@@ -1,57 +1,64 @@
|
|
|
1
1
|
# better-auth-mikro-orm
|
|
2
2
|
|
|
3
|
-
[
|
|
4
|
-
|
|
3
|
+
[MikroORM](https://mikro-orm.io/) adapter for [Better Auth](https://www.better-auth.com/)
|
|
5
4
|
|
|
6
5
|
[](https://github.com/octet-stream/better-auth-mikro-orm/actions/workflows/ci.yaml)
|
|
7
6
|
[](https://codecov.io/gh/octet-stream/better-auth-mikro-orm)
|
|
8
7
|
|
|
9
8
|
## Installation
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
Using npm:
|
|
12
11
|
|
|
13
12
|
```sh
|
|
14
|
-
|
|
13
|
+
npm i better-auth-mikro-orm
|
|
15
14
|
```
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
Using yarn:
|
|
18
17
|
|
|
19
18
|
```sh
|
|
20
|
-
|
|
19
|
+
yarn add better-auth-mikro-orm
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Using pnpm:
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
pnpm add better-auth-mikro-orm
|
|
21
26
|
```
|
|
22
27
|
|
|
23
28
|
## Usage
|
|
24
29
|
|
|
25
|
-
1. First you'll need to set up
|
|
26
|
-
If you use any plugin
|
|
27
|
-
2. When you finished with the schema
|
|
30
|
+
1. First you'll need to set up MikroORM and define the [core schema](https://www.better-auth.com/docs/concepts/database#core-schema) for Better Auth.
|
|
31
|
+
If you use any plugin, don't forget to check if they have any additional database schema definitions, then define entities you'll need for each plugin.
|
|
32
|
+
2. When you're finished with the schema definitions, you can simply pass the result of the `mikroOrmAdapter` call to the `database` option like this:
|
|
28
33
|
|
|
29
34
|
```ts
|
|
30
|
-
import {mikroOrmAdapter} from "better-auth-mikro-orm"
|
|
31
|
-
import {betterAuth} from "better-auth"
|
|
35
|
+
import { mikroOrmAdapter } from "@forklaunch/better-auth-mikro-orm";
|
|
36
|
+
import { betterAuth } from "@forklaunch/better-auth";
|
|
32
37
|
|
|
33
|
-
import {orm} from "./orm.js" // Your Mikro ORM instance
|
|
38
|
+
import { orm } from "./orm.js"; // Your Mikro ORM instance
|
|
34
39
|
|
|
35
40
|
export const auth = betterAuth({
|
|
36
41
|
database: mikroOrmAdapter(orm),
|
|
37
42
|
|
|
38
|
-
// Don't forget to disable ID generator if it already managed by
|
|
43
|
+
// Don't forget to disable the ID generator if it is already managed by MikroORM
|
|
39
44
|
advanced: {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
45
|
+
database: {
|
|
46
|
+
generateId: false,
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
});
|
|
43
50
|
```
|
|
44
51
|
|
|
45
52
|
## API
|
|
46
53
|
|
|
47
54
|
### `mikroOrmAdapter(orm: MikroORM): AdapterInstance`
|
|
48
55
|
|
|
49
|
-
Creates
|
|
50
|
-
This means you'll have to manage database
|
|
51
|
-
Please refer to Better Auth and
|
|
56
|
+
Creates the MikroORM adapter instance. Note that this adapter **does not** manage database schemas for you, so you can't use it with [`@better-auth/cli`](https://www.better-auth.com/docs/concepts/cli).
|
|
57
|
+
This means you'll have to manage database schemas on your own.
|
|
58
|
+
Please refer to the Better Auth and MikroORM documentations for details.
|
|
52
59
|
|
|
53
|
-
Returns `AdapterInstance` function for Better Auth `database` option.
|
|
60
|
+
Returns the `AdapterInstance` function for the Better Auth `database` option.
|
|
54
61
|
|
|
55
62
|
This function expects a single argument:
|
|
56
63
|
|
|
57
|
-
|
|
64
|
+
- `orm` - An instance of `MikroORM` returned from either `MikroORM.init` or `MikroORM.initSync`.
|