prisma-flare 1.1.4 → 1.1.6

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.
@@ -349,6 +349,11 @@ function resolvePrismaClientPath(rootDir, output) {
349
349
  }
350
350
  const schemaDir = path4.join(rootDir, "prisma");
351
351
  const absolutePath = path4.resolve(schemaDir, output);
352
+ const clientEntryPath = path4.join(absolutePath, "client.ts");
353
+ const clientEntryPathJs = path4.join(absolutePath, "client.js");
354
+ if (fs4.existsSync(clientEntryPath) || fs4.existsSync(clientEntryPathJs)) {
355
+ return path4.join(absolutePath, "client");
356
+ }
352
357
  return absolutePath;
353
358
  }
354
359
  function getPrismaClientPath(rootDir) {
@@ -371,6 +376,25 @@ function hasCustomPrismaOutput(rootDir) {
371
376
  }
372
377
 
373
378
  // src/cli/generate-client.ts
379
+ function createSymlinkSafe(target, linkPath) {
380
+ try {
381
+ if (fs5.existsSync(linkPath)) {
382
+ const stats = fs5.lstatSync(linkPath);
383
+ if (stats.isSymbolicLink()) {
384
+ fs5.unlinkSync(linkPath);
385
+ } else if (stats.isDirectory()) {
386
+ fs5.rmSync(linkPath, { recursive: true });
387
+ } else {
388
+ fs5.unlinkSync(linkPath);
389
+ }
390
+ }
391
+ const linkType = process.platform === "win32" ? "junction" : "dir";
392
+ fs5.symlinkSync(target, linkPath, linkType);
393
+ return true;
394
+ } catch (error) {
395
+ return false;
396
+ }
397
+ }
374
398
  function generateClient() {
375
399
  const rootDir = findProjectRoot(process.cwd());
376
400
  const config = loadConfig(rootDir);
@@ -386,14 +410,27 @@ function generateClient() {
386
410
  fs5.mkdirSync(prismaFlareDir, { recursive: true });
387
411
  }
388
412
  let resolvedImport;
413
+ let useSymlink = false;
389
414
  if (prismaClientImport === "@prisma/client") {
390
415
  resolvedImport = "@prisma/client";
391
416
  } else {
392
- resolvedImport = path5.relative(prismaFlareDir, prismaClientImport);
393
- if (!resolvedImport.startsWith(".")) {
394
- resolvedImport = "./" + resolvedImport;
417
+ const symlinkPath = path5.join(prismaFlareDir, "prisma-client");
418
+ let targetDir = prismaClientImport;
419
+ if (targetDir.endsWith("/client") || targetDir.endsWith("\\client")) {
420
+ targetDir = path5.dirname(targetDir);
421
+ }
422
+ if (createSymlinkSafe(targetDir, symlinkPath)) {
423
+ useSymlink = true;
424
+ const hasClientEntry = fs5.existsSync(path5.join(targetDir, "client.ts")) || fs5.existsSync(path5.join(targetDir, "client.js"));
425
+ resolvedImport = hasClientEntry ? "./prisma-client/client" : "./prisma-client";
426
+ } else {
427
+ console.warn("\u26A0\uFE0F Could not create symlink. Some bundlers may have issues with the generated import path.");
428
+ resolvedImport = path5.relative(prismaFlareDir, prismaClientImport);
429
+ if (!resolvedImport.startsWith(".")) {
430
+ resolvedImport = "./" + resolvedImport;
431
+ }
432
+ resolvedImport = resolvedImport.replace(/\\/g, "/");
395
433
  }
396
- resolvedImport = resolvedImport.replace(/\\/g, "/");
397
434
  }
398
435
  const isCustomOutput = hasCustomPrismaOutput(rootDir);
399
436
  const esmContent = `// Generated by prisma-flare - DO NOT EDIT
@@ -483,12 +520,15 @@ export declare class FlareClient extends BasePrismaClient {
483
520
  );
484
521
  if (isCustomOutput) {
485
522
  console.log(`\u2705 Generated prisma-flare client with custom Prisma output: ${prismaClientImport}`);
523
+ if (useSymlink) {
524
+ console.log(` Using symlink for bundler compatibility`);
525
+ }
486
526
  } else {
487
527
  console.log(`\u2705 Generated prisma-flare client using @prisma/client`);
488
528
  }
489
529
  console.log(` Location: ${prismaFlareDir}`);
490
530
  console.log(`
491
- Import: import { FlareClient } from 'prisma-flare/client';`);
531
+ Import: import { FlareClient } from 'prisma-flare';`);
492
532
  }
493
533
 
494
534
  // src/cli/index.ts
package/dist/cli/index.js CHANGED
@@ -326,6 +326,11 @@ function resolvePrismaClientPath(rootDir, output) {
326
326
  }
327
327
  const schemaDir = path4.join(rootDir, "prisma");
328
328
  const absolutePath = path4.resolve(schemaDir, output);
329
+ const clientEntryPath = path4.join(absolutePath, "client.ts");
330
+ const clientEntryPathJs = path4.join(absolutePath, "client.js");
331
+ if (fs4.existsSync(clientEntryPath) || fs4.existsSync(clientEntryPathJs)) {
332
+ return path4.join(absolutePath, "client");
333
+ }
329
334
  return absolutePath;
330
335
  }
331
336
  function getPrismaClientPath(rootDir) {
@@ -348,6 +353,25 @@ function hasCustomPrismaOutput(rootDir) {
348
353
  }
349
354
 
350
355
  // src/cli/generate-client.ts
356
+ function createSymlinkSafe(target, linkPath) {
357
+ try {
358
+ if (fs5.existsSync(linkPath)) {
359
+ const stats = fs5.lstatSync(linkPath);
360
+ if (stats.isSymbolicLink()) {
361
+ fs5.unlinkSync(linkPath);
362
+ } else if (stats.isDirectory()) {
363
+ fs5.rmSync(linkPath, { recursive: true });
364
+ } else {
365
+ fs5.unlinkSync(linkPath);
366
+ }
367
+ }
368
+ const linkType = process.platform === "win32" ? "junction" : "dir";
369
+ fs5.symlinkSync(target, linkPath, linkType);
370
+ return true;
371
+ } catch (error) {
372
+ return false;
373
+ }
374
+ }
351
375
  function generateClient() {
352
376
  const rootDir = findProjectRoot(process.cwd());
353
377
  const config = loadConfig(rootDir);
@@ -363,14 +387,27 @@ function generateClient() {
363
387
  fs5.mkdirSync(prismaFlareDir, { recursive: true });
364
388
  }
365
389
  let resolvedImport;
390
+ let useSymlink = false;
366
391
  if (prismaClientImport === "@prisma/client") {
367
392
  resolvedImport = "@prisma/client";
368
393
  } else {
369
- resolvedImport = path5.relative(prismaFlareDir, prismaClientImport);
370
- if (!resolvedImport.startsWith(".")) {
371
- resolvedImport = "./" + resolvedImport;
394
+ const symlinkPath = path5.join(prismaFlareDir, "prisma-client");
395
+ let targetDir = prismaClientImport;
396
+ if (targetDir.endsWith("/client") || targetDir.endsWith("\\client")) {
397
+ targetDir = path5.dirname(targetDir);
398
+ }
399
+ if (createSymlinkSafe(targetDir, symlinkPath)) {
400
+ useSymlink = true;
401
+ const hasClientEntry = fs5.existsSync(path5.join(targetDir, "client.ts")) || fs5.existsSync(path5.join(targetDir, "client.js"));
402
+ resolvedImport = hasClientEntry ? "./prisma-client/client" : "./prisma-client";
403
+ } else {
404
+ console.warn("\u26A0\uFE0F Could not create symlink. Some bundlers may have issues with the generated import path.");
405
+ resolvedImport = path5.relative(prismaFlareDir, prismaClientImport);
406
+ if (!resolvedImport.startsWith(".")) {
407
+ resolvedImport = "./" + resolvedImport;
408
+ }
409
+ resolvedImport = resolvedImport.replace(/\\/g, "/");
372
410
  }
373
- resolvedImport = resolvedImport.replace(/\\/g, "/");
374
411
  }
375
412
  const isCustomOutput = hasCustomPrismaOutput(rootDir);
376
413
  const esmContent = `// Generated by prisma-flare - DO NOT EDIT
@@ -460,12 +497,15 @@ export declare class FlareClient extends BasePrismaClient {
460
497
  );
461
498
  if (isCustomOutput) {
462
499
  console.log(`\u2705 Generated prisma-flare client with custom Prisma output: ${prismaClientImport}`);
500
+ if (useSymlink) {
501
+ console.log(` Using symlink for bundler compatibility`);
502
+ }
463
503
  } else {
464
504
  console.log(`\u2705 Generated prisma-flare client using @prisma/client`);
465
505
  }
466
506
  console.log(` Location: ${prismaFlareDir}`);
467
507
  console.log(`
468
- Import: import { FlareClient } from 'prisma-flare/client';`);
508
+ Import: import { FlareClient } from 'prisma-flare';`);
469
509
  }
470
510
 
471
511
  // src/cli/index.ts
package/dist/index.cjs CHANGED
@@ -42,6 +42,7 @@ __export(index_exports, {
42
42
  beforeCreate: () => beforeCreate,
43
43
  beforeDelete: () => beforeDelete,
44
44
  beforeUpdate: () => beforeUpdate,
45
+ createFlareClient: () => createFlareClient,
45
46
  createHooksExtension: () => createHooksExtension,
46
47
  dbAdapterRegistry: () => registry,
47
48
  hookRegistry: () => hookRegistry_default,
@@ -890,39 +891,13 @@ if (!globalObj2[HOOK_REGISTRY_SYMBOL]) {
890
891
  var hookRegistry = globalObj2[HOOK_REGISTRY_SYMBOL];
891
892
  var hookRegistry_default = hookRegistry;
892
893
 
893
- // src/core/hooks.ts
894
- function normalizeModelName(model) {
895
- return model.toLowerCase();
896
- }
897
- function beforeCreate(model, callback) {
898
- hookRegistry_default.addHook(normalizeModelName(model), "create", "before", callback);
899
- }
900
- function beforeDelete(model, callback) {
901
- hookRegistry_default.addHook(normalizeModelName(model), "delete", "before", callback);
902
- }
903
- function afterCreate(model, callback) {
904
- hookRegistry_default.addHook(normalizeModelName(model), "create", "after", callback);
905
- }
906
- function afterDelete(model, callback) {
907
- hookRegistry_default.addHook(normalizeModelName(model), "delete", "after", callback);
908
- }
909
- function beforeUpdate(model, callback) {
910
- hookRegistry_default.addHook(normalizeModelName(model), "update", "before", callback);
911
- }
912
- function afterUpdate(model, callback) {
913
- hookRegistry_default.addHook(normalizeModelName(model), "update", "after", callback);
914
- }
915
- function afterChange(model, column, callback) {
916
- hookRegistry_default.addColumnHook(normalizeModelName(model), column, callback);
917
- }
918
- function afterUpsert(model, callback) {
919
- hookRegistry_default.addHook(normalizeModelName(model), "upsert", "after", callback);
920
- }
921
-
922
894
  // src/core/hookMiddleware.ts
923
895
  var import_fs = __toESM(require("fs"), 1);
924
896
  var import_path = __toESM(require("path"), 1);
925
897
  var _Prisma = null;
898
+ function setPrismaNamespace(prisma) {
899
+ _Prisma = prisma;
900
+ }
926
901
  function supportsTypeScriptImports() {
927
902
  if (process.env.TS_NODE || /* @__PURE__ */ Symbol.for("ts-node.register.instance") in process) {
928
903
  return true;
@@ -1057,6 +1032,99 @@ function registerHooks(prisma) {
1057
1032
  }
1058
1033
  }
1059
1034
 
1035
+ // src/core/createFlareClient.ts
1036
+ function supportsPrisma6Middleware2(prisma) {
1037
+ return typeof prisma.$use === "function";
1038
+ }
1039
+ function createFlareClient(BasePrismaClient, PrismaNamespaceArg) {
1040
+ if (PrismaNamespaceArg) {
1041
+ setPrismaNamespace(PrismaNamespaceArg);
1042
+ }
1043
+ const FlareClientImpl = class extends BasePrismaClient {
1044
+ constructor(options = {}) {
1045
+ const { callbacks = true, ...prismaOptions } = options;
1046
+ super(prismaOptions);
1047
+ if (callbacks) {
1048
+ if (supportsPrisma6Middleware2(this)) {
1049
+ registerHooksLegacy(this);
1050
+ } else {
1051
+ const extension = createHooksExtension(this);
1052
+ return this.$extends(extension);
1053
+ }
1054
+ }
1055
+ }
1056
+ /**
1057
+ * Creates a new FlareBuilder instance for the specified model.
1058
+ * @param modelName - The name of the model.
1059
+ * @returns FlareBuilder instance
1060
+ */
1061
+ from(modelName) {
1062
+ const key = modelName.charAt(0).toLowerCase() + modelName.slice(1);
1063
+ const model = this[key];
1064
+ if (!model) {
1065
+ throw new Error(`Model ${modelName} does not exist on PrismaClient.`);
1066
+ }
1067
+ return new FlareBuilder(model);
1068
+ }
1069
+ /**
1070
+ * Executes a transaction with the FlareClient capabilities.
1071
+ * @param fn - The transaction function.
1072
+ * @param options - Transaction options.
1073
+ * @returns The result of the transaction.
1074
+ */
1075
+ async transaction(fn, options) {
1076
+ return this.$transaction(async (tx) => {
1077
+ const extendedTx = new Proxy(tx, {
1078
+ get: (target, prop, receiver) => {
1079
+ if (prop === "from") {
1080
+ return (modelName) => {
1081
+ const key = modelName.charAt(0).toLowerCase() + modelName.slice(1);
1082
+ const model = target[key];
1083
+ if (!model) {
1084
+ throw new Error(`Model ${modelName} does not exist on TransactionClient.`);
1085
+ }
1086
+ return new FlareBuilder(model);
1087
+ };
1088
+ }
1089
+ return Reflect.get(target, prop, receiver);
1090
+ }
1091
+ });
1092
+ return fn(extendedTx);
1093
+ }, options);
1094
+ }
1095
+ };
1096
+ return FlareClientImpl;
1097
+ }
1098
+
1099
+ // src/core/hooks.ts
1100
+ function normalizeModelName(model) {
1101
+ return model.toLowerCase();
1102
+ }
1103
+ function beforeCreate(model, callback) {
1104
+ hookRegistry_default.addHook(normalizeModelName(model), "create", "before", callback);
1105
+ }
1106
+ function beforeDelete(model, callback) {
1107
+ hookRegistry_default.addHook(normalizeModelName(model), "delete", "before", callback);
1108
+ }
1109
+ function afterCreate(model, callback) {
1110
+ hookRegistry_default.addHook(normalizeModelName(model), "create", "after", callback);
1111
+ }
1112
+ function afterDelete(model, callback) {
1113
+ hookRegistry_default.addHook(normalizeModelName(model), "delete", "after", callback);
1114
+ }
1115
+ function beforeUpdate(model, callback) {
1116
+ hookRegistry_default.addHook(normalizeModelName(model), "update", "before", callback);
1117
+ }
1118
+ function afterUpdate(model, callback) {
1119
+ hookRegistry_default.addHook(normalizeModelName(model), "update", "after", callback);
1120
+ }
1121
+ function afterChange(model, column, callback) {
1122
+ hookRegistry_default.addColumnHook(normalizeModelName(model), column, callback);
1123
+ }
1124
+ function afterUpsert(model, callback) {
1125
+ hookRegistry_default.addHook(normalizeModelName(model), "upsert", "after", callback);
1126
+ }
1127
+
1060
1128
  // src/core/adapters/postgres.ts
1061
1129
  var PostgresAdapter = {
1062
1130
  name: "postgres",
@@ -1227,6 +1295,7 @@ registry.register(SqliteAdapter);
1227
1295
  beforeCreate,
1228
1296
  beforeDelete,
1229
1297
  beforeUpdate,
1298
+ createFlareClient,
1230
1299
  createHooksExtension,
1231
1300
  dbAdapterRegistry,
1232
1301
  hookRegistry,
package/dist/index.d.cts CHANGED
@@ -1,4 +1,6 @@
1
1
  export { FlareClient, Prisma, PrismaClient } from '.prisma-flare';
2
+ import * as _prisma_client from '@prisma/client';
3
+ import { PrismaClient } from '@prisma/client';
2
4
  import * as _prisma_client_runtime_library from '@prisma/client/runtime/library';
3
5
  import { DriverAdapter } from '@prisma/client/runtime/library';
4
6
  import FlareBuilder from './core/flareBuilder.cjs';
@@ -6,8 +8,6 @@ export { RelationModelMap } from './core/flareBuilder.cjs';
6
8
  import { M as ModelName, l as PrismaOperation, m as HookTiming, B as BeforeHookCallback, j as AfterHookCallback, k as ColumnChangeCallback } from './prisma.types-nGNe1CG8.cjs';
7
9
  export { r as AggregateResult, o as CreateArgs, C as CreateData, p as CreateManyArgs, b as CreateManyData, c as DeleteArgs, n as FindFirstArgs, F as FindManyArgs, a as ModelDelegate, R as RecordType, q as UpdateArgs, f as UpsertArgs } from './prisma.types-nGNe1CG8.cjs';
8
10
  export { afterChange, afterCreate, afterDelete, afterUpdate, afterUpsert, beforeCreate, beforeDelete, beforeUpdate } from './core/hooks.cjs';
9
- import * as _prisma_client from '@prisma/client';
10
- import { PrismaClient } from '@prisma/client';
11
11
 
12
12
  /**
13
13
  * Options for FlareClient created via the factory.
@@ -32,6 +32,53 @@ interface FactoryFlareClientOptions {
32
32
  */
33
33
  [key: string]: unknown;
34
34
  }
35
+ /**
36
+ * Type for the Prisma namespace (contains Result, defineExtension, etc.)
37
+ */
38
+ type PrismaNamespace = {
39
+ defineExtension: (extension: any) => any;
40
+ [key: string]: unknown;
41
+ };
42
+ /**
43
+ * Type for a PrismaClient-like constructor
44
+ */
45
+ interface PrismaClientLike {
46
+ new (options?: Record<string, unknown>): PrismaClient;
47
+ }
48
+ /**
49
+ * The shape of a FlareClient class created by the factory
50
+ */
51
+ interface FlareClientClass {
52
+ new (options?: FactoryFlareClientOptions): FlareClientInstance;
53
+ }
54
+ /**
55
+ * Instance type for FlareClient
56
+ */
57
+ interface FlareClientInstance extends PrismaClient {
58
+ from<M extends ModelName>(modelName: M): FlareBuilder<M>;
59
+ transaction<R>(fn: (tx: FlareClientInstance) => Promise<R>, options?: {
60
+ maxWait?: number;
61
+ timeout?: number;
62
+ isolationLevel?: unknown;
63
+ }): Promise<R>;
64
+ }
65
+ /**
66
+ * Creates a FlareClient class that extends the provided PrismaClient.
67
+ * This factory enables support for custom Prisma client output paths.
68
+ *
69
+ * @param BasePrismaClient - The PrismaClient class to extend
70
+ * @param _PrismaNamespace - The Prisma namespace (optional, for future type inference)
71
+ * @returns A FlareClient class that extends BasePrismaClient
72
+ *
73
+ * @example
74
+ * // For custom Prisma output paths:
75
+ * import { PrismaClient, Prisma } from './generated/client';
76
+ * import { createFlareClient } from 'prisma-flare';
77
+ *
78
+ * const FlareClient = createFlareClient(PrismaClient, Prisma);
79
+ * export const db = new FlareClient();
80
+ */
81
+ declare function createFlareClient(BasePrismaClient: PrismaClientLike, PrismaNamespaceArg?: PrismaNamespace): FlareClientClass;
35
82
 
36
83
  type ModelClass<T extends ModelName = any> = new () => FlareBuilder<T, any>;
37
84
  /**
@@ -233,4 +280,4 @@ declare class AdapterRegistry {
233
280
  }
234
281
  declare const registry: AdapterRegistry;
235
282
 
236
- export { AfterHookCallback, BeforeHookCallback, ColumnChangeCallback, type DatabaseAdapter, FlareBuilder, type FactoryFlareClientOptions as FlareClientOptions, type HookConfig, HookTiming, ModelName, PrismaOperation, createHooksExtension, registry as dbAdapterRegistry, hookRegistry, loadCallbacks, modelRegistry, registerHooks, registerHooksLegacy };
283
+ export { AfterHookCallback, BeforeHookCallback, ColumnChangeCallback, type DatabaseAdapter, FlareBuilder, type FactoryFlareClientOptions as FlareClientOptions, type HookConfig, HookTiming, ModelName, PrismaOperation, createFlareClient, createHooksExtension, registry as dbAdapterRegistry, hookRegistry, loadCallbacks, modelRegistry, registerHooks, registerHooksLegacy };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  export { FlareClient, Prisma, PrismaClient } from '.prisma-flare';
2
+ import * as _prisma_client from '@prisma/client';
3
+ import { PrismaClient } from '@prisma/client';
2
4
  import * as _prisma_client_runtime_library from '@prisma/client/runtime/library';
3
5
  import { DriverAdapter } from '@prisma/client/runtime/library';
4
6
  import FlareBuilder from './core/flareBuilder.js';
@@ -6,8 +8,6 @@ export { RelationModelMap } from './core/flareBuilder.js';
6
8
  import { M as ModelName, l as PrismaOperation, m as HookTiming, B as BeforeHookCallback, j as AfterHookCallback, k as ColumnChangeCallback } from './prisma.types-nGNe1CG8.js';
7
9
  export { r as AggregateResult, o as CreateArgs, C as CreateData, p as CreateManyArgs, b as CreateManyData, c as DeleteArgs, n as FindFirstArgs, F as FindManyArgs, a as ModelDelegate, R as RecordType, q as UpdateArgs, f as UpsertArgs } from './prisma.types-nGNe1CG8.js';
8
10
  export { afterChange, afterCreate, afterDelete, afterUpdate, afterUpsert, beforeCreate, beforeDelete, beforeUpdate } from './core/hooks.js';
9
- import * as _prisma_client from '@prisma/client';
10
- import { PrismaClient } from '@prisma/client';
11
11
 
12
12
  /**
13
13
  * Options for FlareClient created via the factory.
@@ -32,6 +32,53 @@ interface FactoryFlareClientOptions {
32
32
  */
33
33
  [key: string]: unknown;
34
34
  }
35
+ /**
36
+ * Type for the Prisma namespace (contains Result, defineExtension, etc.)
37
+ */
38
+ type PrismaNamespace = {
39
+ defineExtension: (extension: any) => any;
40
+ [key: string]: unknown;
41
+ };
42
+ /**
43
+ * Type for a PrismaClient-like constructor
44
+ */
45
+ interface PrismaClientLike {
46
+ new (options?: Record<string, unknown>): PrismaClient;
47
+ }
48
+ /**
49
+ * The shape of a FlareClient class created by the factory
50
+ */
51
+ interface FlareClientClass {
52
+ new (options?: FactoryFlareClientOptions): FlareClientInstance;
53
+ }
54
+ /**
55
+ * Instance type for FlareClient
56
+ */
57
+ interface FlareClientInstance extends PrismaClient {
58
+ from<M extends ModelName>(modelName: M): FlareBuilder<M>;
59
+ transaction<R>(fn: (tx: FlareClientInstance) => Promise<R>, options?: {
60
+ maxWait?: number;
61
+ timeout?: number;
62
+ isolationLevel?: unknown;
63
+ }): Promise<R>;
64
+ }
65
+ /**
66
+ * Creates a FlareClient class that extends the provided PrismaClient.
67
+ * This factory enables support for custom Prisma client output paths.
68
+ *
69
+ * @param BasePrismaClient - The PrismaClient class to extend
70
+ * @param _PrismaNamespace - The Prisma namespace (optional, for future type inference)
71
+ * @returns A FlareClient class that extends BasePrismaClient
72
+ *
73
+ * @example
74
+ * // For custom Prisma output paths:
75
+ * import { PrismaClient, Prisma } from './generated/client';
76
+ * import { createFlareClient } from 'prisma-flare';
77
+ *
78
+ * const FlareClient = createFlareClient(PrismaClient, Prisma);
79
+ * export const db = new FlareClient();
80
+ */
81
+ declare function createFlareClient(BasePrismaClient: PrismaClientLike, PrismaNamespaceArg?: PrismaNamespace): FlareClientClass;
35
82
 
36
83
  type ModelClass<T extends ModelName = any> = new () => FlareBuilder<T, any>;
37
84
  /**
@@ -233,4 +280,4 @@ declare class AdapterRegistry {
233
280
  }
234
281
  declare const registry: AdapterRegistry;
235
282
 
236
- export { AfterHookCallback, BeforeHookCallback, ColumnChangeCallback, type DatabaseAdapter, FlareBuilder, type FactoryFlareClientOptions as FlareClientOptions, type HookConfig, HookTiming, ModelName, PrismaOperation, createHooksExtension, registry as dbAdapterRegistry, hookRegistry, loadCallbacks, modelRegistry, registerHooks, registerHooksLegacy };
283
+ export { AfterHookCallback, BeforeHookCallback, ColumnChangeCallback, type DatabaseAdapter, FlareBuilder, type FactoryFlareClientOptions as FlareClientOptions, type HookConfig, HookTiming, ModelName, PrismaOperation, createFlareClient, createHooksExtension, registry as dbAdapterRegistry, hookRegistry, loadCallbacks, modelRegistry, registerHooks, registerHooksLegacy };
package/dist/index.js CHANGED
@@ -838,39 +838,13 @@ if (!globalObj2[HOOK_REGISTRY_SYMBOL]) {
838
838
  var hookRegistry = globalObj2[HOOK_REGISTRY_SYMBOL];
839
839
  var hookRegistry_default = hookRegistry;
840
840
 
841
- // src/core/hooks.ts
842
- function normalizeModelName(model) {
843
- return model.toLowerCase();
844
- }
845
- function beforeCreate(model, callback) {
846
- hookRegistry_default.addHook(normalizeModelName(model), "create", "before", callback);
847
- }
848
- function beforeDelete(model, callback) {
849
- hookRegistry_default.addHook(normalizeModelName(model), "delete", "before", callback);
850
- }
851
- function afterCreate(model, callback) {
852
- hookRegistry_default.addHook(normalizeModelName(model), "create", "after", callback);
853
- }
854
- function afterDelete(model, callback) {
855
- hookRegistry_default.addHook(normalizeModelName(model), "delete", "after", callback);
856
- }
857
- function beforeUpdate(model, callback) {
858
- hookRegistry_default.addHook(normalizeModelName(model), "update", "before", callback);
859
- }
860
- function afterUpdate(model, callback) {
861
- hookRegistry_default.addHook(normalizeModelName(model), "update", "after", callback);
862
- }
863
- function afterChange(model, column, callback) {
864
- hookRegistry_default.addColumnHook(normalizeModelName(model), column, callback);
865
- }
866
- function afterUpsert(model, callback) {
867
- hookRegistry_default.addHook(normalizeModelName(model), "upsert", "after", callback);
868
- }
869
-
870
841
  // src/core/hookMiddleware.ts
871
842
  import fs from "fs";
872
843
  import path from "path";
873
844
  var _Prisma = null;
845
+ function setPrismaNamespace(prisma) {
846
+ _Prisma = prisma;
847
+ }
874
848
  function supportsTypeScriptImports() {
875
849
  if (process.env.TS_NODE || /* @__PURE__ */ Symbol.for("ts-node.register.instance") in process) {
876
850
  return true;
@@ -1005,6 +979,99 @@ function registerHooks(prisma) {
1005
979
  }
1006
980
  }
1007
981
 
982
+ // src/core/createFlareClient.ts
983
+ function supportsPrisma6Middleware2(prisma) {
984
+ return typeof prisma.$use === "function";
985
+ }
986
+ function createFlareClient(BasePrismaClient, PrismaNamespaceArg) {
987
+ if (PrismaNamespaceArg) {
988
+ setPrismaNamespace(PrismaNamespaceArg);
989
+ }
990
+ const FlareClientImpl = class extends BasePrismaClient {
991
+ constructor(options = {}) {
992
+ const { callbacks = true, ...prismaOptions } = options;
993
+ super(prismaOptions);
994
+ if (callbacks) {
995
+ if (supportsPrisma6Middleware2(this)) {
996
+ registerHooksLegacy(this);
997
+ } else {
998
+ const extension = createHooksExtension(this);
999
+ return this.$extends(extension);
1000
+ }
1001
+ }
1002
+ }
1003
+ /**
1004
+ * Creates a new FlareBuilder instance for the specified model.
1005
+ * @param modelName - The name of the model.
1006
+ * @returns FlareBuilder instance
1007
+ */
1008
+ from(modelName) {
1009
+ const key = modelName.charAt(0).toLowerCase() + modelName.slice(1);
1010
+ const model = this[key];
1011
+ if (!model) {
1012
+ throw new Error(`Model ${modelName} does not exist on PrismaClient.`);
1013
+ }
1014
+ return new FlareBuilder(model);
1015
+ }
1016
+ /**
1017
+ * Executes a transaction with the FlareClient capabilities.
1018
+ * @param fn - The transaction function.
1019
+ * @param options - Transaction options.
1020
+ * @returns The result of the transaction.
1021
+ */
1022
+ async transaction(fn, options) {
1023
+ return this.$transaction(async (tx) => {
1024
+ const extendedTx = new Proxy(tx, {
1025
+ get: (target, prop, receiver) => {
1026
+ if (prop === "from") {
1027
+ return (modelName) => {
1028
+ const key = modelName.charAt(0).toLowerCase() + modelName.slice(1);
1029
+ const model = target[key];
1030
+ if (!model) {
1031
+ throw new Error(`Model ${modelName} does not exist on TransactionClient.`);
1032
+ }
1033
+ return new FlareBuilder(model);
1034
+ };
1035
+ }
1036
+ return Reflect.get(target, prop, receiver);
1037
+ }
1038
+ });
1039
+ return fn(extendedTx);
1040
+ }, options);
1041
+ }
1042
+ };
1043
+ return FlareClientImpl;
1044
+ }
1045
+
1046
+ // src/core/hooks.ts
1047
+ function normalizeModelName(model) {
1048
+ return model.toLowerCase();
1049
+ }
1050
+ function beforeCreate(model, callback) {
1051
+ hookRegistry_default.addHook(normalizeModelName(model), "create", "before", callback);
1052
+ }
1053
+ function beforeDelete(model, callback) {
1054
+ hookRegistry_default.addHook(normalizeModelName(model), "delete", "before", callback);
1055
+ }
1056
+ function afterCreate(model, callback) {
1057
+ hookRegistry_default.addHook(normalizeModelName(model), "create", "after", callback);
1058
+ }
1059
+ function afterDelete(model, callback) {
1060
+ hookRegistry_default.addHook(normalizeModelName(model), "delete", "after", callback);
1061
+ }
1062
+ function beforeUpdate(model, callback) {
1063
+ hookRegistry_default.addHook(normalizeModelName(model), "update", "before", callback);
1064
+ }
1065
+ function afterUpdate(model, callback) {
1066
+ hookRegistry_default.addHook(normalizeModelName(model), "update", "after", callback);
1067
+ }
1068
+ function afterChange(model, column, callback) {
1069
+ hookRegistry_default.addColumnHook(normalizeModelName(model), column, callback);
1070
+ }
1071
+ function afterUpsert(model, callback) {
1072
+ hookRegistry_default.addHook(normalizeModelName(model), "upsert", "after", callback);
1073
+ }
1074
+
1008
1075
  // src/core/adapters/postgres.ts
1009
1076
  var PostgresAdapter = {
1010
1077
  name: "postgres",
@@ -1174,6 +1241,7 @@ export {
1174
1241
  beforeCreate,
1175
1242
  beforeDelete,
1176
1243
  beforeUpdate,
1244
+ createFlareClient,
1177
1245
  createHooksExtension,
1178
1246
  registry as dbAdapterRegistry,
1179
1247
  hookRegistry_default as hookRegistry,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prisma-flare",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "description": "Prisma utilities package with callback system and query builder for chained operations",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",