@a77ay/better-auth-mikro-orm 0.1.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/LICENSE +20 -0
- package/README.md +191 -0
- package/dist/cli-cy61BGrg.mjs +977 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +10 -0
- package/dist/index.d.mts +177 -0
- package/dist/index.mjs +2 -0
- package/package.json +86 -0
package/dist/cli.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { t as runCli } from "./cli-cy61BGrg.mjs";
|
|
3
|
+
//#region src/cli.ts
|
|
4
|
+
runCli(process.argv.slice(2)).catch((error) => {
|
|
5
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
6
|
+
process.stderr.write(`Error: ${message}\n`);
|
|
7
|
+
process.exitCode = 1;
|
|
8
|
+
});
|
|
9
|
+
//#endregion
|
|
10
|
+
export {};
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { EntityManager, EntityMetadata, MikroORM } from "@mikro-orm/core";
|
|
2
|
+
import { BetterAuthOptions } from "better-auth";
|
|
3
|
+
import { DBAdapterDebugLogOption, DBAdapterSchemaCreation } from "better-auth/adapters";
|
|
4
|
+
import { BetterAuthDBSchema } from "better-auth/db";
|
|
5
|
+
//#region src/generator/types.d.ts
|
|
6
|
+
type EntityStyle = "define-entity" | "decorators";
|
|
7
|
+
type SchemaCasing = "snake_case" | "camelCase";
|
|
8
|
+
interface MikroOrmSchemaGeneratorOptions {
|
|
9
|
+
tables: BetterAuthDBSchema;
|
|
10
|
+
file?: string;
|
|
11
|
+
directory?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Optional suffix for generated entity file names (e.g. `".entity"` or `".model"`).
|
|
14
|
+
* When set to `".entity"`, generates `user.entity.ts`, `session.entity.ts`, etc.
|
|
15
|
+
*
|
|
16
|
+
* @default ""
|
|
17
|
+
*/
|
|
18
|
+
fileSuffix?: string;
|
|
19
|
+
numericIds?: boolean;
|
|
20
|
+
supportsArrays?: boolean;
|
|
21
|
+
supportsBooleans?: boolean;
|
|
22
|
+
supportsDates?: boolean;
|
|
23
|
+
supportsJSON?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Field and column naming convention:
|
|
26
|
+
* - "snake_case": Convert field names to snake_case (e.g. `user_id`, `created_at`)
|
|
27
|
+
* - "camelCase" (default): Keep default Better Auth field names (e.g. `userId`, `createdAt`)
|
|
28
|
+
*
|
|
29
|
+
* @default "camelCase"
|
|
30
|
+
*/
|
|
31
|
+
casing?: SchemaCasing;
|
|
32
|
+
/**
|
|
33
|
+
* Entity definition style:
|
|
34
|
+
* - "define-entity" (default): Modern MikroORM v7 fluent `defineEntity()` schema API
|
|
35
|
+
* - "decorators": Class-based entities with `@Entity()`, `@Property()`, `@PrimaryKey()`, `@ManyToOne()`
|
|
36
|
+
*
|
|
37
|
+
* @default "define-entity"
|
|
38
|
+
*/
|
|
39
|
+
entityStyle?: EntityStyle;
|
|
40
|
+
}
|
|
41
|
+
interface GeneratedSchemaFile {
|
|
42
|
+
path: string;
|
|
43
|
+
code: string;
|
|
44
|
+
}
|
|
45
|
+
interface GeneratedSchemaDirectory {
|
|
46
|
+
directory: string;
|
|
47
|
+
files: GeneratedSchemaFile[];
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/generator/directory.d.ts
|
|
51
|
+
declare function generateMikroOrmSchemaDirectory(options: MikroOrmSchemaGeneratorOptions): GeneratedSchemaDirectory;
|
|
52
|
+
declare function writeMikroOrmSchemaDirectory(options: MikroOrmSchemaGeneratorOptions): Promise<GeneratedSchemaDirectory>;
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/generator/generator.d.ts
|
|
55
|
+
/**
|
|
56
|
+
* Generate a deterministic MikroORM entity module for Better Auth and its plugins.
|
|
57
|
+
*
|
|
58
|
+
* Supports two entity styles:
|
|
59
|
+
* - `"define-entity"` (default): Modern MikroORM v7 fluent `defineEntity()` schema API
|
|
60
|
+
* - `"decorators"`: Class-based entities with `@Entity()`, `@Property()`, `@PrimaryKey()`, `@ManyToOne()`
|
|
61
|
+
*/
|
|
62
|
+
declare function generateMikroOrmSchema(options: MikroOrmSchemaGeneratorOptions): DBAdapterSchemaCreation;
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/adapter/utils.d.ts
|
|
65
|
+
type EntityRecord = Record<string, unknown>;
|
|
66
|
+
type EntityManagerProvider = EntityManager | MikroORM | (() => EntityManager | MikroORM);
|
|
67
|
+
type DatabaseProvider = "postgresql" | "postgres" | "sqlite" | "mysql" | "mariadb" | "mongodb" | "sqlserver" | "libsql" | (string & {});
|
|
68
|
+
declare function getEntityManager(provider: EntityManagerProvider): EntityManager;
|
|
69
|
+
declare function resolveEntity(em: EntityManager, model: string): EntityMetadata<EntityRecord>;
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region src/adapter/adapter.d.ts
|
|
72
|
+
interface MikroOrmAdapterOptions {
|
|
73
|
+
/**
|
|
74
|
+
* Database provider (e.g. "postgresql", "sqlite", "mysql", "mongodb").
|
|
75
|
+
* Automatically detected from the EntityManager platform if omitted.
|
|
76
|
+
*/
|
|
77
|
+
provider?: DatabaseProvider;
|
|
78
|
+
/**
|
|
79
|
+
* Enable debug logs for the adapter.
|
|
80
|
+
*
|
|
81
|
+
* @default false
|
|
82
|
+
*/
|
|
83
|
+
debugLogs?: DBAdapterDebugLogOption;
|
|
84
|
+
/**
|
|
85
|
+
* Use plural table names for generated entities and queries.
|
|
86
|
+
*
|
|
87
|
+
* @default false
|
|
88
|
+
*/
|
|
89
|
+
usePlural?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Whether the database platform supports native JSON fields.
|
|
92
|
+
*
|
|
93
|
+
* @default true
|
|
94
|
+
*/
|
|
95
|
+
supportsJSON?: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Whether the database platform supports Date types.
|
|
98
|
+
*
|
|
99
|
+
* @default true
|
|
100
|
+
*/
|
|
101
|
+
supportsDates?: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Whether the database platform supports native boolean types.
|
|
104
|
+
*
|
|
105
|
+
* @default true
|
|
106
|
+
*/
|
|
107
|
+
supportsBooleans?: boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Whether the database platform supports array types.
|
|
110
|
+
*
|
|
111
|
+
* @default false
|
|
112
|
+
*/
|
|
113
|
+
supportsArrays?: boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Whether the database platform supports numeric/serial IDs.
|
|
116
|
+
*
|
|
117
|
+
* @default true
|
|
118
|
+
*/
|
|
119
|
+
supportsNumericIds?: boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Whether to execute multiple operations in a transaction.
|
|
122
|
+
*
|
|
123
|
+
* If the database doesn't support transactions, set this to `false`.
|
|
124
|
+
* @default true
|
|
125
|
+
*/
|
|
126
|
+
transactions?: boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Default output file path used by the Better Auth CLI schema generator.
|
|
129
|
+
*
|
|
130
|
+
* @default "src/entities/auth.ts"
|
|
131
|
+
*/
|
|
132
|
+
schemaFile?: string;
|
|
133
|
+
/**
|
|
134
|
+
* Default output directory used by the package CLI.
|
|
135
|
+
*
|
|
136
|
+
* @default "src/entities/auth"
|
|
137
|
+
*/
|
|
138
|
+
directory?: string;
|
|
139
|
+
/**
|
|
140
|
+
* Field and column naming convention for the schema generator:
|
|
141
|
+
* - `"snake_case"`: Convert column field names to snake_case (e.g. `user_id`, `created_at`)
|
|
142
|
+
* - `"camelCase"` (default): Keep default Better Auth field names (e.g. `userId`, `createdAt`)
|
|
143
|
+
*
|
|
144
|
+
* @default "camelCase"
|
|
145
|
+
*/
|
|
146
|
+
casing?: SchemaCasing;
|
|
147
|
+
/**
|
|
148
|
+
* Entity definition style for the schema generator:
|
|
149
|
+
* - `"define-entity"` (default): Modern MikroORM v7 fluent `defineEntity()` schema API with `InferEntity`
|
|
150
|
+
* - `"decorators"`: Class-based entities with `@Entity()`, `@Property()`, `@PrimaryKey()`, `@ManyToOne()`
|
|
151
|
+
*
|
|
152
|
+
* @default "define-entity"
|
|
153
|
+
*/
|
|
154
|
+
entityStyle?: EntityStyle;
|
|
155
|
+
/**
|
|
156
|
+
* Optional suffix for generated entity file names (e.g. `".entity"` or `".model"`).
|
|
157
|
+
* When set to `".entity"`, generates `user.entity.ts`, `session.entity.ts`, etc.
|
|
158
|
+
*
|
|
159
|
+
* @default ""
|
|
160
|
+
*/
|
|
161
|
+
fileSuffix?: string;
|
|
162
|
+
}
|
|
163
|
+
declare function mikroOrmAdapter(em: EntityManagerProvider, options?: MikroOrmAdapterOptions): (authOptions: BetterAuthOptions) => import("better-auth").DBAdapter<BetterAuthOptions>;
|
|
164
|
+
//#endregion
|
|
165
|
+
//#region src/adapter/options.d.ts
|
|
166
|
+
type AdapterFactory = (...arguments_: any[]) => unknown;
|
|
167
|
+
declare function attachGeneratorOptions<T extends AdapterFactory>(factory: T, options: MikroOrmAdapterOptions | undefined): T;
|
|
168
|
+
declare function readGeneratorOptions(value: unknown): MikroOrmAdapterOptions | undefined;
|
|
169
|
+
//#endregion
|
|
170
|
+
//#region src/cli/index.d.ts
|
|
171
|
+
interface CliIO {
|
|
172
|
+
cwd?: string;
|
|
173
|
+
stdout?: (message: string) => void;
|
|
174
|
+
}
|
|
175
|
+
declare function runCli(arguments_: string[], io?: CliIO): Promise<number>;
|
|
176
|
+
//#endregion
|
|
177
|
+
export { type CliIO, type DatabaseProvider, type EntityManagerProvider, type EntityRecord, type EntityStyle, type GeneratedSchemaDirectory, type GeneratedSchemaFile, type MikroOrmAdapterOptions, type MikroOrmSchemaGeneratorOptions, type SchemaCasing, attachGeneratorOptions, generateMikroOrmSchema, generateMikroOrmSchemaDirectory, getEntityManager, mikroOrmAdapter, readGeneratorOptions, resolveEntity, runCli, writeMikroOrmSchemaDirectory };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as getEntityManager, c as generateMikroOrmSchemaDirectory, i as readGeneratorOptions, l as writeMikroOrmSchemaDirectory, n as mikroOrmAdapter, o as resolveEntity, r as attachGeneratorOptions, s as generateMikroOrmSchema, t as runCli } from "./cli-cy61BGrg.mjs";
|
|
2
|
+
export { attachGeneratorOptions, generateMikroOrmSchema, generateMikroOrmSchemaDirectory, getEntityManager, mikroOrmAdapter, readGeneratorOptions, resolveEntity, runCli, writeMikroOrmSchemaDirectory };
|
package/package.json
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@a77ay/better-auth-mikro-orm",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "MikroORM database adapter and entity generator for Better Auth.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"adapter",
|
|
7
|
+
"auth",
|
|
8
|
+
"authentication",
|
|
9
|
+
"better-auth",
|
|
10
|
+
"better-auth-adapter",
|
|
11
|
+
"generator",
|
|
12
|
+
"mikro-orm",
|
|
13
|
+
"mikroorm",
|
|
14
|
+
"schema-generator"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://github.com/A77AY/better-auth-mikro-orm#readme",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/A77AY/better-auth-mikro-orm/issues"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"author": {
|
|
22
|
+
"name": "A77AY",
|
|
23
|
+
"url": "https://github.com/A77AY"
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/A77AY/better-auth-mikro-orm.git"
|
|
28
|
+
},
|
|
29
|
+
"bin": {
|
|
30
|
+
"better-auth-mikro-orm": "./dist/cli.mjs"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist"
|
|
34
|
+
],
|
|
35
|
+
"type": "module",
|
|
36
|
+
"types": "./dist/index.d.mts",
|
|
37
|
+
"exports": {
|
|
38
|
+
".": "./dist/index.mjs",
|
|
39
|
+
"./cli": "./dist/cli.mjs",
|
|
40
|
+
"./package.json": "./package.json"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"jiti": "^2.7.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@better-auth/test-utils": "^1.7.2",
|
|
50
|
+
"@changesets/changelog-github": "^1.0.0",
|
|
51
|
+
"@changesets/cli": "^3.0.1",
|
|
52
|
+
"@mikro-orm/core": "^7.1.14",
|
|
53
|
+
"@mikro-orm/mongodb": "^7.1.14",
|
|
54
|
+
"@mikro-orm/postgresql": "^7.1.14",
|
|
55
|
+
"@mikro-orm/sqlite": "^7.1.14",
|
|
56
|
+
"@types/node": "^26.4.0",
|
|
57
|
+
"@types/pg": "^8.23.1",
|
|
58
|
+
"@vitest/coverage-v8": "^4.1.11",
|
|
59
|
+
"better-auth": "^1.7.2",
|
|
60
|
+
"pg": "^8.23.0",
|
|
61
|
+
"typescript": "^7.0.2",
|
|
62
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@0.3.0",
|
|
63
|
+
"vite-plus": "0.3.0"
|
|
64
|
+
},
|
|
65
|
+
"peerDependencies": {
|
|
66
|
+
"@mikro-orm/core": "^7.0.0",
|
|
67
|
+
"better-auth": "^1.0.0"
|
|
68
|
+
},
|
|
69
|
+
"devEngines": {
|
|
70
|
+
"packageManager": {
|
|
71
|
+
"name": "pnpm",
|
|
72
|
+
"version": "11.24.0",
|
|
73
|
+
"onFail": "download"
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
"scripts": {
|
|
77
|
+
"build": "vp pack",
|
|
78
|
+
"dev": "vp pack --watch",
|
|
79
|
+
"test": "vp test",
|
|
80
|
+
"test:coverage": "vp test --coverage",
|
|
81
|
+
"check": "vp check",
|
|
82
|
+
"changeset": "changeset",
|
|
83
|
+
"version-packages": "changeset version",
|
|
84
|
+
"release": "changeset publish"
|
|
85
|
+
}
|
|
86
|
+
}
|