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