@forklaunch/better-auth-mikro-orm-fork 0.4.21 → 0.4.101

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 CHANGED
@@ -222,30 +222,28 @@ var mikroOrmAdapter = (orm, { debugLogs, supportsJSON = true } = {}) => (0, impo
222
222
  } = createAdapterUtils(orm);
223
223
  return {
224
224
  async create({ model, data, select }) {
225
+ const em = orm.em.fork();
225
226
  const metadata = getEntityMetadata(model);
226
227
  const input = normalizeInput(metadata, data);
227
- if ((options.advanced?.generateId === false || options.advanced?.database?.generateId === false) && !options.advanced?.database) {
228
+ if (options.advanced?.generateId === false && !options.advanced?.database) {
228
229
  Reflect.deleteProperty(input, "id");
229
230
  }
230
- const entity = orm.em.create(metadata.class, input);
231
- try {
232
- await orm.em.persistAndFlush(entity);
233
- } catch (error) {
234
- await orm.em.removeAndFlush(entity);
235
- throw error;
236
- }
231
+ const entity = em.create(metadata.class, input);
232
+ await em.persistAndFlush(entity);
237
233
  return normalizeOutput(metadata, entity, select);
238
234
  },
239
235
  async count({ model, where }) {
236
+ const em = orm.em.fork();
240
237
  const metadata = getEntityMetadata(model);
241
- return orm.em.count(
238
+ return em.count(
242
239
  metadata.class,
243
240
  normalizeWhereClauses(metadata, where)
244
241
  );
245
242
  },
246
243
  async findOne({ model, where, select }) {
244
+ const em = orm.em.fork();
247
245
  const metadata = getEntityMetadata(model);
248
- const entity = await orm.em.findOne(
246
+ const entity = await em.findOne(
249
247
  metadata.class,
250
248
  normalizeWhereClauses(metadata, where)
251
249
  );
@@ -255,6 +253,7 @@ var mikroOrmAdapter = (orm, { debugLogs, supportsJSON = true } = {}) => (0, impo
255
253
  return normalizeOutput(metadata, entity, select);
256
254
  },
257
255
  async findMany({ model, where, limit, offset, sortBy }) {
256
+ const em = orm.em.fork();
258
257
  const metadata = getEntityMetadata(model);
259
258
  const options2 = {
260
259
  limit,
@@ -264,7 +263,7 @@ var mikroOrmAdapter = (orm, { debugLogs, supportsJSON = true } = {}) => (0, impo
264
263
  const path = getFieldPath(metadata, sortBy.field);
265
264
  (0, import_dset2.dset)(options2, ["orderBy", ...path], sortBy.direction);
266
265
  }
267
- const rows = await orm.em.find(
266
+ const rows = await em.find(
268
267
  metadata.class,
269
268
  normalizeWhereClauses(metadata, where),
270
269
  options2
@@ -272,36 +271,33 @@ var mikroOrmAdapter = (orm, { debugLogs, supportsJSON = true } = {}) => (0, impo
272
271
  return rows.map((row) => normalizeOutput(metadata, row));
273
272
  },
274
273
  async update({ model, where, update }) {
274
+ const em = orm.em.fork();
275
275
  const metadata = getEntityMetadata(model);
276
- const entity = await orm.em.findOne(
276
+ const entity = await em.findOne(
277
277
  metadata.class,
278
278
  normalizeWhereClauses(metadata, where)
279
279
  );
280
280
  if (!entity) {
281
281
  return null;
282
282
  }
283
- orm.em.assign(entity, normalizeInput(metadata, update));
284
- try {
285
- await orm.em.flush();
286
- } catch (error) {
287
- await orm.em.removeAndFlush(entity);
288
- throw error;
289
- }
283
+ em.assign(entity, normalizeInput(metadata, update));
284
+ await em.flush();
290
285
  return normalizeOutput(metadata, entity);
291
286
  },
292
287
  async updateMany({ model, where, update }) {
288
+ const em = orm.em.fork();
293
289
  const metadata = getEntityMetadata(model);
294
- const affected = await orm.em.nativeUpdate(
290
+ const affected = await em.nativeUpdate(
295
291
  metadata.class,
296
292
  normalizeWhereClauses(metadata, where),
297
293
  normalizeInput(metadata, update)
298
294
  );
299
- orm.em.clear();
300
295
  return affected;
301
296
  },
302
297
  async delete({ model, where }) {
298
+ const em = orm.em.fork();
303
299
  const metadata = getEntityMetadata(model);
304
- const entity = await orm.em.findOne(
300
+ const entity = await em.findOne(
305
301
  metadata.class,
306
302
  normalizeWhereClauses(metadata, where),
307
303
  {
@@ -309,19 +305,20 @@ var mikroOrmAdapter = (orm, { debugLogs, supportsJSON = true } = {}) => (0, impo
309
305
  }
310
306
  );
311
307
  if (entity) {
312
- await orm.em.removeAndFlush(entity);
308
+ await em.removeAndFlush(entity);
313
309
  }
314
310
  },
315
311
  async deleteMany({ model, where }) {
312
+ const em = orm.em.fork();
316
313
  const metadata = getEntityMetadata(model);
317
- const [rows, count] = await orm.em.findAndCount(
314
+ const [rows, count] = await em.findAndCount(
318
315
  metadata.class,
319
316
  normalizeWhereClauses(metadata, where),
320
317
  {
321
318
  fields: ["id"]
322
319
  }
323
320
  );
324
- await orm.em.removeAndFlush(rows);
321
+ await em.removeAndFlush(rows);
325
322
  return count;
326
323
  }
327
324
  };
package/lib/adapter.js CHANGED
@@ -196,30 +196,28 @@ var mikroOrmAdapter = (orm, { debugLogs, supportsJSON = true } = {}) => createAd
196
196
  } = createAdapterUtils(orm);
197
197
  return {
198
198
  async create({ model, data, select }) {
199
+ const em = orm.em.fork();
199
200
  const metadata = getEntityMetadata(model);
200
201
  const input = normalizeInput(metadata, data);
201
- if ((options.advanced?.generateId === false || options.advanced?.database?.generateId === false) && !options.advanced?.database) {
202
+ if (options.advanced?.generateId === false && !options.advanced?.database) {
202
203
  Reflect.deleteProperty(input, "id");
203
204
  }
204
- const entity = orm.em.create(metadata.class, input);
205
- try {
206
- await orm.em.persistAndFlush(entity);
207
- } catch (error) {
208
- await orm.em.removeAndFlush(entity);
209
- throw error;
210
- }
205
+ const entity = em.create(metadata.class, input);
206
+ await em.persistAndFlush(entity);
211
207
  return normalizeOutput(metadata, entity, select);
212
208
  },
213
209
  async count({ model, where }) {
210
+ const em = orm.em.fork();
214
211
  const metadata = getEntityMetadata(model);
215
- return orm.em.count(
212
+ return em.count(
216
213
  metadata.class,
217
214
  normalizeWhereClauses(metadata, where)
218
215
  );
219
216
  },
220
217
  async findOne({ model, where, select }) {
218
+ const em = orm.em.fork();
221
219
  const metadata = getEntityMetadata(model);
222
- const entity = await orm.em.findOne(
220
+ const entity = await em.findOne(
223
221
  metadata.class,
224
222
  normalizeWhereClauses(metadata, where)
225
223
  );
@@ -229,6 +227,7 @@ var mikroOrmAdapter = (orm, { debugLogs, supportsJSON = true } = {}) => createAd
229
227
  return normalizeOutput(metadata, entity, select);
230
228
  },
231
229
  async findMany({ model, where, limit, offset, sortBy }) {
230
+ const em = orm.em.fork();
232
231
  const metadata = getEntityMetadata(model);
233
232
  const options2 = {
234
233
  limit,
@@ -238,7 +237,7 @@ var mikroOrmAdapter = (orm, { debugLogs, supportsJSON = true } = {}) => createAd
238
237
  const path = getFieldPath(metadata, sortBy.field);
239
238
  dset2(options2, ["orderBy", ...path], sortBy.direction);
240
239
  }
241
- const rows = await orm.em.find(
240
+ const rows = await em.find(
242
241
  metadata.class,
243
242
  normalizeWhereClauses(metadata, where),
244
243
  options2
@@ -246,36 +245,33 @@ var mikroOrmAdapter = (orm, { debugLogs, supportsJSON = true } = {}) => createAd
246
245
  return rows.map((row) => normalizeOutput(metadata, row));
247
246
  },
248
247
  async update({ model, where, update }) {
248
+ const em = orm.em.fork();
249
249
  const metadata = getEntityMetadata(model);
250
- const entity = await orm.em.findOne(
250
+ const entity = await em.findOne(
251
251
  metadata.class,
252
252
  normalizeWhereClauses(metadata, where)
253
253
  );
254
254
  if (!entity) {
255
255
  return null;
256
256
  }
257
- orm.em.assign(entity, normalizeInput(metadata, update));
258
- try {
259
- await orm.em.flush();
260
- } catch (error) {
261
- await orm.em.removeAndFlush(entity);
262
- throw error;
263
- }
257
+ em.assign(entity, normalizeInput(metadata, update));
258
+ await em.flush();
264
259
  return normalizeOutput(metadata, entity);
265
260
  },
266
261
  async updateMany({ model, where, update }) {
262
+ const em = orm.em.fork();
267
263
  const metadata = getEntityMetadata(model);
268
- const affected = await orm.em.nativeUpdate(
264
+ const affected = await em.nativeUpdate(
269
265
  metadata.class,
270
266
  normalizeWhereClauses(metadata, where),
271
267
  normalizeInput(metadata, update)
272
268
  );
273
- orm.em.clear();
274
269
  return affected;
275
270
  },
276
271
  async delete({ model, where }) {
272
+ const em = orm.em.fork();
277
273
  const metadata = getEntityMetadata(model);
278
- const entity = await orm.em.findOne(
274
+ const entity = await em.findOne(
279
275
  metadata.class,
280
276
  normalizeWhereClauses(metadata, where),
281
277
  {
@@ -283,19 +279,20 @@ var mikroOrmAdapter = (orm, { debugLogs, supportsJSON = true } = {}) => createAd
283
279
  }
284
280
  );
285
281
  if (entity) {
286
- await orm.em.removeAndFlush(entity);
282
+ await em.removeAndFlush(entity);
287
283
  }
288
284
  },
289
285
  async deleteMany({ model, where }) {
286
+ const em = orm.em.fork();
290
287
  const metadata = getEntityMetadata(model);
291
- const [rows, count] = await orm.em.findAndCount(
288
+ const [rows, count] = await em.findAndCount(
292
289
  metadata.class,
293
290
  normalizeWhereClauses(metadata, where),
294
291
  {
295
292
  fields: ["id"]
296
293
  }
297
294
  );
298
- await orm.em.removeAndFlush(rows);
295
+ await em.removeAndFlush(rows);
299
296
  return count;
300
297
  }
301
298
  };
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.21",
5
+ "version": "0.4.101",
6
6
  "description": "Mikro ORM Adapter for Better Auth",
7
7
  "keywords": [
8
8
  "auth",