@forklaunch/better-auth-mikro-orm-fork 0.4.102 → 0.4.103
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 +11 -12
- package/lib/adapter.js +11 -12
- package/package.json +2 -1
- package/readme.md +4 -0
package/lib/adapter.cjs
CHANGED
|
@@ -114,6 +114,12 @@ function createAdapterUtils(orm) {
|
|
|
114
114
|
`Cannot normalize "${fieldName}" field name into path for "${metadata2.className}" entity.`
|
|
115
115
|
);
|
|
116
116
|
};
|
|
117
|
+
const normalizePropertyValue = (property, value) => {
|
|
118
|
+
if (!property.targetMeta || property.kind === import_core.ReferenceKind.SCALAR || property.kind === import_core.ReferenceKind.EMBEDDED) {
|
|
119
|
+
return value;
|
|
120
|
+
}
|
|
121
|
+
return orm.em.getReference(property.targetMeta.class, value);
|
|
122
|
+
};
|
|
117
123
|
const normalizeInput = (metadata2, input) => {
|
|
118
124
|
const fields = {};
|
|
119
125
|
Object.entries(input).forEach(([key, value]) => {
|
|
@@ -126,7 +132,7 @@ function createAdapterUtils(orm) {
|
|
|
126
132
|
});
|
|
127
133
|
return fields;
|
|
128
134
|
};
|
|
129
|
-
const normalizeOutput = (metadata2, output
|
|
135
|
+
const normalizeOutput = (metadata2, output) => {
|
|
130
136
|
output = (0, import_core.serialize)(output);
|
|
131
137
|
const result = {};
|
|
132
138
|
Object.entries(output).map(([key, value]) => ({
|
|
@@ -135,7 +141,7 @@ function createAdapterUtils(orm) {
|
|
|
135
141
|
getPropertyMetadata(metadata2, key)
|
|
136
142
|
),
|
|
137
143
|
value
|
|
138
|
-
})).
|
|
144
|
+
})).forEach(({ path, value }) => (0, import_dset.dset)(result, path, value));
|
|
139
145
|
return result;
|
|
140
146
|
};
|
|
141
147
|
function createWhereClause(path, value, op, target = {}) {
|
|
@@ -291,13 +297,11 @@ var mikroOrmAdapter = (orm, { debugLogs, supportsJSON = true } = {}) => (0, impo
|
|
|
291
297
|
},
|
|
292
298
|
async updateMany({ model, where, update }) {
|
|
293
299
|
const metadata = getEntityMetadata(model);
|
|
294
|
-
|
|
300
|
+
return orm.em.nativeUpdate(
|
|
295
301
|
metadata.class,
|
|
296
302
|
normalizeWhereClauses(metadata, where),
|
|
297
303
|
normalizeInput(metadata, update)
|
|
298
304
|
);
|
|
299
|
-
orm.em.clear();
|
|
300
|
-
return affected;
|
|
301
305
|
},
|
|
302
306
|
async delete({ model, where }) {
|
|
303
307
|
const metadata = getEntityMetadata(model);
|
|
@@ -314,15 +318,10 @@ var mikroOrmAdapter = (orm, { debugLogs, supportsJSON = true } = {}) => (0, impo
|
|
|
314
318
|
},
|
|
315
319
|
async deleteMany({ model, where }) {
|
|
316
320
|
const metadata = getEntityMetadata(model);
|
|
317
|
-
|
|
321
|
+
return orm.em.nativeDelete(
|
|
318
322
|
metadata.class,
|
|
319
|
-
normalizeWhereClauses(metadata, where)
|
|
320
|
-
{
|
|
321
|
-
fields: ["id"]
|
|
322
|
-
}
|
|
323
|
+
normalizeWhereClauses(metadata, where)
|
|
323
324
|
);
|
|
324
|
-
await orm.em.removeAndFlush(rows);
|
|
325
|
-
return count;
|
|
326
325
|
}
|
|
327
326
|
};
|
|
328
327
|
}
|
package/lib/adapter.js
CHANGED
|
@@ -88,6 +88,12 @@ function createAdapterUtils(orm) {
|
|
|
88
88
|
`Cannot normalize "${fieldName}" field name into path for "${metadata2.className}" entity.`
|
|
89
89
|
);
|
|
90
90
|
};
|
|
91
|
+
const normalizePropertyValue = (property, value) => {
|
|
92
|
+
if (!property.targetMeta || property.kind === ReferenceKind.SCALAR || property.kind === ReferenceKind.EMBEDDED) {
|
|
93
|
+
return value;
|
|
94
|
+
}
|
|
95
|
+
return orm.em.getReference(property.targetMeta.class, value);
|
|
96
|
+
};
|
|
91
97
|
const normalizeInput = (metadata2, input) => {
|
|
92
98
|
const fields = {};
|
|
93
99
|
Object.entries(input).forEach(([key, value]) => {
|
|
@@ -100,7 +106,7 @@ function createAdapterUtils(orm) {
|
|
|
100
106
|
});
|
|
101
107
|
return fields;
|
|
102
108
|
};
|
|
103
|
-
const normalizeOutput = (metadata2, output
|
|
109
|
+
const normalizeOutput = (metadata2, output) => {
|
|
104
110
|
output = serialize(output);
|
|
105
111
|
const result = {};
|
|
106
112
|
Object.entries(output).map(([key, value]) => ({
|
|
@@ -109,7 +115,7 @@ function createAdapterUtils(orm) {
|
|
|
109
115
|
getPropertyMetadata(metadata2, key)
|
|
110
116
|
),
|
|
111
117
|
value
|
|
112
|
-
})).
|
|
118
|
+
})).forEach(({ path, value }) => dset(result, path, value));
|
|
113
119
|
return result;
|
|
114
120
|
};
|
|
115
121
|
function createWhereClause(path, value, op, target = {}) {
|
|
@@ -265,13 +271,11 @@ var mikroOrmAdapter = (orm, { debugLogs, supportsJSON = true } = {}) => createAd
|
|
|
265
271
|
},
|
|
266
272
|
async updateMany({ model, where, update }) {
|
|
267
273
|
const metadata = getEntityMetadata(model);
|
|
268
|
-
|
|
274
|
+
return orm.em.nativeUpdate(
|
|
269
275
|
metadata.class,
|
|
270
276
|
normalizeWhereClauses(metadata, where),
|
|
271
277
|
normalizeInput(metadata, update)
|
|
272
278
|
);
|
|
273
|
-
orm.em.clear();
|
|
274
|
-
return affected;
|
|
275
279
|
},
|
|
276
280
|
async delete({ model, where }) {
|
|
277
281
|
const metadata = getEntityMetadata(model);
|
|
@@ -288,15 +292,10 @@ var mikroOrmAdapter = (orm, { debugLogs, supportsJSON = true } = {}) => createAd
|
|
|
288
292
|
},
|
|
289
293
|
async deleteMany({ model, where }) {
|
|
290
294
|
const metadata = getEntityMetadata(model);
|
|
291
|
-
|
|
295
|
+
return orm.em.nativeDelete(
|
|
292
296
|
metadata.class,
|
|
293
|
-
normalizeWhereClauses(metadata, where)
|
|
294
|
-
{
|
|
295
|
-
fields: ["id"]
|
|
296
|
-
}
|
|
297
|
+
normalizeWhereClauses(metadata, where)
|
|
297
298
|
);
|
|
298
|
-
await orm.em.removeAndFlush(rows);
|
|
299
|
-
return count;
|
|
300
299
|
}
|
|
301
300
|
};
|
|
302
301
|
}
|
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.103",
|
|
6
6
|
"description": "Mikro ORM Adapter for Better Auth",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"auth",
|
|
@@ -61,6 +61,7 @@
|
|
|
61
61
|
"@vitest/ui": "3.1.1",
|
|
62
62
|
"better-auth": "1.2.9",
|
|
63
63
|
"del-cli": "6.0.0",
|
|
64
|
+
"es-toolkit": "1.39.7",
|
|
64
65
|
"husky": "9.1.7",
|
|
65
66
|
"is-in-ci": "1.0.0",
|
|
66
67
|
"tsup": "8.4.0",
|
package/readme.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
[Mikro ORM](https://mikro-orm.io/) adapter for [Better Auth](https://www.better-auth.com/)
|
|
4
4
|
|
|
5
|
+
|
|
6
|
+
[](https://github.com/octet-stream/better-auth-mikro-orm/actions/workflows/ci.yaml)
|
|
7
|
+
[](https://codecov.io/gh/octet-stream/better-auth-mikro-orm)
|
|
8
|
+
|
|
5
9
|
## Installation
|
|
6
10
|
|
|
7
11
|
pnpm:
|