prisma-flare 1.1.3 → 1.1.4

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.
@@ -1,2 +1 @@
1
1
  #!/usr/bin/env node
2
- import '.prisma-flare';
@@ -1,2 +1 @@
1
1
  #!/usr/bin/env node
2
- import '.prisma-flare';
package/dist/index.cjs CHANGED
@@ -30,9 +30,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
- ExtendedPrismaClient: () => ExtendedPrismaClient,
34
33
  FlareBuilder: () => FlareBuilder,
35
- FlareClient: () => FlareClient,
34
+ FlareClient: () => import__.FlareClient,
35
+ Prisma: () => import__.Prisma,
36
+ PrismaClient: () => import__.PrismaClient,
36
37
  afterChange: () => afterChange,
37
38
  afterCreate: () => afterCreate,
38
39
  afterDelete: () => afterDelete,
@@ -41,7 +42,6 @@ __export(index_exports, {
41
42
  beforeCreate: () => beforeCreate,
42
43
  beforeDelete: () => beforeDelete,
43
44
  beforeUpdate: () => beforeUpdate,
44
- createFlareClient: () => createFlareClient,
45
45
  createHooksExtension: () => createHooksExtension,
46
46
  dbAdapterRegistry: () => registry,
47
47
  hookRegistry: () => hookRegistry_default,
@@ -51,9 +51,7 @@ __export(index_exports, {
51
51
  registerHooksLegacy: () => registerHooksLegacy
52
52
  });
53
53
  module.exports = __toCommonJS(index_exports);
54
-
55
- // src/core/extendedPrismaClient.ts
56
- var import_client2 = require("@prisma/client");
54
+ var import__ = require(".prisma-flare");
57
55
 
58
56
  // src/core/modelRegistry.ts
59
57
  var ModelRegistry = class {
@@ -892,10 +890,39 @@ if (!globalObj2[HOOK_REGISTRY_SYMBOL]) {
892
890
  var hookRegistry = globalObj2[HOOK_REGISTRY_SYMBOL];
893
891
  var hookRegistry_default = hookRegistry;
894
892
 
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
+
895
922
  // src/core/hookMiddleware.ts
896
- var import_client = require("@prisma/client");
897
923
  var import_fs = __toESM(require("fs"), 1);
898
924
  var import_path = __toESM(require("path"), 1);
925
+ var _Prisma = null;
899
926
  function supportsTypeScriptImports() {
900
927
  if (process.env.TS_NODE || /* @__PURE__ */ Symbol.for("ts-node.register.instance") in process) {
901
928
  return true;
@@ -992,7 +1019,12 @@ function supportsPrisma6Middleware(prisma) {
992
1019
  return typeof prisma.$use === "function";
993
1020
  }
994
1021
  function createHooksExtension(basePrisma) {
995
- return import_client.Prisma.defineExtension({
1022
+ if (!_Prisma) {
1023
+ throw new Error(
1024
+ "Prisma namespace not initialized. Make sure to run `npx prisma-flare generate` first."
1025
+ );
1026
+ }
1027
+ return _Prisma.defineExtension({
996
1028
  name: "prisma-flare-hooks",
997
1029
  query: {
998
1030
  $allModels: {
@@ -1025,155 +1057,6 @@ function registerHooks(prisma) {
1025
1057
  }
1026
1058
  }
1027
1059
 
1028
- // src/core/extendedPrismaClient.ts
1029
- function supportsPrisma6Middleware2(prisma) {
1030
- return typeof prisma.$use === "function";
1031
- }
1032
- var FlareClient = class extends import_client2.PrismaClient {
1033
- constructor(options = {}) {
1034
- const { callbacks = true, ...prismaOptions } = options;
1035
- super(prismaOptions);
1036
- if (callbacks) {
1037
- if (supportsPrisma6Middleware2(this)) {
1038
- registerHooksLegacy(this);
1039
- } else {
1040
- const extension = createHooksExtension(this);
1041
- return this.$extends(extension);
1042
- }
1043
- }
1044
- }
1045
- /**
1046
- * Creates a new FlareBuilder instance for the specified model.
1047
- * @param modelName - The name of the model.
1048
- * @returns FlareBuilder instance
1049
- */
1050
- from(modelName) {
1051
- const key = modelName.charAt(0).toLowerCase() + modelName.slice(1);
1052
- const model = this[key];
1053
- if (!model) {
1054
- throw new Error(`Model ${modelName} does not exist on PrismaClient.`);
1055
- }
1056
- return new FlareBuilder(model);
1057
- }
1058
- /**
1059
- * Executes a transaction with the FlareClient capabilities.
1060
- * @param fn - The transaction function.
1061
- * @param options - Transaction options.
1062
- * @returns The result of the transaction.
1063
- */
1064
- async transaction(fn, options) {
1065
- return super.$transaction(async (tx) => {
1066
- const extendedTx = new Proxy(tx, {
1067
- get: (target, prop, receiver) => {
1068
- if (prop === "from") {
1069
- return (modelName) => {
1070
- const key = modelName.charAt(0).toLowerCase() + modelName.slice(1);
1071
- const model = target[key];
1072
- if (!model) {
1073
- throw new Error(`Model ${modelName} does not exist on TransactionClient.`);
1074
- }
1075
- return new FlareBuilder(model);
1076
- };
1077
- }
1078
- return Reflect.get(target, prop, receiver);
1079
- }
1080
- });
1081
- return fn(extendedTx);
1082
- }, options);
1083
- }
1084
- };
1085
- var ExtendedPrismaClient = FlareClient;
1086
-
1087
- // src/core/createFlareClient.ts
1088
- function supportsPrisma6Middleware3(prisma) {
1089
- return typeof prisma.$use === "function";
1090
- }
1091
- function createFlareClient(BasePrismaClient, _PrismaNamespace) {
1092
- const FlareClientImpl = class extends BasePrismaClient {
1093
- constructor(options = {}) {
1094
- const { callbacks = true, ...prismaOptions } = options;
1095
- super(prismaOptions);
1096
- if (callbacks) {
1097
- if (supportsPrisma6Middleware3(this)) {
1098
- registerHooksLegacy(this);
1099
- } else {
1100
- const extension = createHooksExtension(this);
1101
- return this.$extends(extension);
1102
- }
1103
- }
1104
- }
1105
- /**
1106
- * Creates a new FlareBuilder instance for the specified model.
1107
- * @param modelName - The name of the model.
1108
- * @returns FlareBuilder instance
1109
- */
1110
- from(modelName) {
1111
- const key = modelName.charAt(0).toLowerCase() + modelName.slice(1);
1112
- const model = this[key];
1113
- if (!model) {
1114
- throw new Error(`Model ${modelName} does not exist on PrismaClient.`);
1115
- }
1116
- return new FlareBuilder(model);
1117
- }
1118
- /**
1119
- * Executes a transaction with the FlareClient capabilities.
1120
- * @param fn - The transaction function.
1121
- * @param options - Transaction options.
1122
- * @returns The result of the transaction.
1123
- */
1124
- async transaction(fn, options) {
1125
- return this.$transaction(async (tx) => {
1126
- const extendedTx = new Proxy(tx, {
1127
- get: (target, prop, receiver) => {
1128
- if (prop === "from") {
1129
- return (modelName) => {
1130
- const key = modelName.charAt(0).toLowerCase() + modelName.slice(1);
1131
- const model = target[key];
1132
- if (!model) {
1133
- throw new Error(`Model ${modelName} does not exist on TransactionClient.`);
1134
- }
1135
- return new FlareBuilder(model);
1136
- };
1137
- }
1138
- return Reflect.get(target, prop, receiver);
1139
- }
1140
- });
1141
- return fn(extendedTx);
1142
- }, options);
1143
- }
1144
- };
1145
- return FlareClientImpl;
1146
- }
1147
-
1148
- // src/core/hooks.ts
1149
- function normalizeModelName(model) {
1150
- return model.toLowerCase();
1151
- }
1152
- function beforeCreate(model, callback) {
1153
- hookRegistry_default.addHook(normalizeModelName(model), "create", "before", callback);
1154
- }
1155
- function beforeDelete(model, callback) {
1156
- hookRegistry_default.addHook(normalizeModelName(model), "delete", "before", callback);
1157
- }
1158
- function afterCreate(model, callback) {
1159
- hookRegistry_default.addHook(normalizeModelName(model), "create", "after", callback);
1160
- }
1161
- function afterDelete(model, callback) {
1162
- hookRegistry_default.addHook(normalizeModelName(model), "delete", "after", callback);
1163
- }
1164
- function beforeUpdate(model, callback) {
1165
- hookRegistry_default.addHook(normalizeModelName(model), "update", "before", callback);
1166
- }
1167
- function afterUpdate(model, callback) {
1168
- hookRegistry_default.addHook(normalizeModelName(model), "update", "after", callback);
1169
- }
1170
- function afterChange(model, column, callback) {
1171
- hookRegistry_default.addColumnHook(normalizeModelName(model), column, callback);
1172
- }
1173
- function afterUpsert(model, callback) {
1174
- hookRegistry_default.addHook(normalizeModelName(model), "upsert", "after", callback);
1175
- }
1176
-
1177
1060
  // src/core/adapters/postgres.ts
1178
1061
  var PostgresAdapter = {
1179
1062
  name: "postgres",
@@ -1332,9 +1215,10 @@ registry.register(PostgresAdapter);
1332
1215
  registry.register(SqliteAdapter);
1333
1216
  // Annotate the CommonJS export names for ESM import in node:
1334
1217
  0 && (module.exports = {
1335
- ExtendedPrismaClient,
1336
1218
  FlareBuilder,
1337
1219
  FlareClient,
1220
+ Prisma,
1221
+ PrismaClient,
1338
1222
  afterChange,
1339
1223
  afterCreate,
1340
1224
  afterDelete,
@@ -1343,7 +1227,6 @@ registry.register(SqliteAdapter);
1343
1227
  beforeCreate,
1344
1228
  beforeDelete,
1345
1229
  beforeUpdate,
1346
- createFlareClient,
1347
1230
  createHooksExtension,
1348
1231
  dbAdapterRegistry,
1349
1232
  hookRegistry,
package/dist/index.d.cts CHANGED
@@ -1,52 +1,13 @@
1
- import * as _prisma_client from '@prisma/client';
2
- import { PrismaClient } from '@prisma/client';
1
+ export { FlareClient, Prisma, PrismaClient } from '.prisma-flare';
3
2
  import * as _prisma_client_runtime_library from '@prisma/client/runtime/library';
4
- import { PrismaClientOptions, DriverAdapter } from '@prisma/client/runtime/library';
3
+ import { DriverAdapter } from '@prisma/client/runtime/library';
5
4
  import FlareBuilder from './core/flareBuilder.cjs';
6
5
  export { RelationModelMap } from './core/flareBuilder.cjs';
7
6
  import { M as ModelName, l as PrismaOperation, m as HookTiming, B as BeforeHookCallback, j as AfterHookCallback, k as ColumnChangeCallback } from './prisma.types-nGNe1CG8.cjs';
8
7
  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';
9
8
  export { afterChange, afterCreate, afterDelete, afterUpdate, afterUpsert, beforeCreate, beforeDelete, beforeUpdate } from './core/hooks.cjs';
10
-
11
- interface FlareClientOptions extends PrismaClientOptions {
12
- /**
13
- * Enable callbacks/hooks middleware. When true (default), the middleware
14
- * that executes your registered callbacks (beforeCreate, afterUpdate, etc.)
15
- * is automatically attached.
16
- *
17
- * @default true
18
- */
19
- callbacks?: boolean;
20
- /**
21
- * Driver adapter for serverless/edge environments.
22
- * Pass an adapter instance (e.g., from @prisma/adapter-pg, @prisma/adapter-d1, etc.)
23
- */
24
- adapter?: DriverAdapter;
25
- }
26
- declare class FlareClient extends PrismaClient {
27
- constructor(options?: FlareClientOptions);
28
- /**
29
- * Creates a new FlareBuilder instance for the specified model.
30
- * @param modelName - The name of the model.
31
- * @returns FlareBuilder instance
32
- */
33
- from<T extends ModelName>(modelName: T): FlareBuilder<T>;
34
- /**
35
- * Executes a transaction with the FlareClient capabilities.
36
- * @param fn - The transaction function.
37
- * @param options - Transaction options.
38
- * @returns The result of the transaction.
39
- */
40
- transaction<R>(fn: (tx: FlareClient) => Promise<R>, options?: {
41
- maxWait?: number;
42
- timeout?: number;
43
- isolationLevel?: any;
44
- }): Promise<R>;
45
- }
46
- /**
47
- * @deprecated Use `FlareClient` instead. This alias will be removed in a future version.
48
- */
49
- declare const ExtendedPrismaClient: typeof FlareClient;
9
+ import * as _prisma_client from '@prisma/client';
10
+ import { PrismaClient } from '@prisma/client';
50
11
 
51
12
  /**
52
13
  * Options for FlareClient created via the factory.
@@ -71,53 +32,6 @@ interface FactoryFlareClientOptions {
71
32
  */
72
33
  [key: string]: unknown;
73
34
  }
74
- /**
75
- * Type for the Prisma namespace (contains Result, defineExtension, etc.)
76
- */
77
- type PrismaNamespace = {
78
- defineExtension: (extension: any) => any;
79
- [key: string]: unknown;
80
- };
81
- /**
82
- * Type for a PrismaClient-like constructor
83
- */
84
- interface PrismaClientLike {
85
- new (options?: Record<string, unknown>): PrismaClient;
86
- }
87
- /**
88
- * The shape of a FlareClient class created by the factory
89
- */
90
- interface FlareClientClass {
91
- new (options?: FactoryFlareClientOptions): FlareClientInstance;
92
- }
93
- /**
94
- * Instance type for FlareClient
95
- */
96
- interface FlareClientInstance extends PrismaClient {
97
- from<M extends ModelName>(modelName: M): FlareBuilder<M>;
98
- transaction<R>(fn: (tx: FlareClientInstance) => Promise<R>, options?: {
99
- maxWait?: number;
100
- timeout?: number;
101
- isolationLevel?: unknown;
102
- }): Promise<R>;
103
- }
104
- /**
105
- * Creates a FlareClient class that extends the provided PrismaClient.
106
- * This factory enables support for custom Prisma client output paths.
107
- *
108
- * @param BasePrismaClient - The PrismaClient class to extend
109
- * @param _PrismaNamespace - The Prisma namespace (optional, for future type inference)
110
- * @returns A FlareClient class that extends BasePrismaClient
111
- *
112
- * @example
113
- * // For custom Prisma output paths:
114
- * import { PrismaClient, Prisma } from './generated/client';
115
- * import { createFlareClient } from 'prisma-flare';
116
- *
117
- * const FlareClient = createFlareClient(PrismaClient, Prisma);
118
- * export const db = new FlareClient();
119
- */
120
- declare function createFlareClient(BasePrismaClient: PrismaClientLike, _PrismaNamespace?: PrismaNamespace): FlareClientClass;
121
35
 
122
36
  type ModelClass<T extends ModelName = any> = new () => FlareBuilder<T, any>;
123
37
  /**
@@ -319,4 +233,4 @@ declare class AdapterRegistry {
319
233
  }
320
234
  declare const registry: AdapterRegistry;
321
235
 
322
- export { AfterHookCallback, BeforeHookCallback, ColumnChangeCallback, type DatabaseAdapter, ExtendedPrismaClient, type FactoryFlareClientOptions, FlareBuilder, FlareClient, type FlareClientClass, type FlareClientInstance, type FlareClientOptions, type HookConfig, HookTiming, ModelName, type PrismaClientLike, type PrismaNamespace, PrismaOperation, createFlareClient, createHooksExtension, registry as dbAdapterRegistry, hookRegistry, loadCallbacks, modelRegistry, registerHooks, registerHooksLegacy };
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 };
package/dist/index.d.ts CHANGED
@@ -1,52 +1,13 @@
1
- import * as _prisma_client from '@prisma/client';
2
- import { PrismaClient } from '@prisma/client';
1
+ export { FlareClient, Prisma, PrismaClient } from '.prisma-flare';
3
2
  import * as _prisma_client_runtime_library from '@prisma/client/runtime/library';
4
- import { PrismaClientOptions, DriverAdapter } from '@prisma/client/runtime/library';
3
+ import { DriverAdapter } from '@prisma/client/runtime/library';
5
4
  import FlareBuilder from './core/flareBuilder.js';
6
5
  export { RelationModelMap } from './core/flareBuilder.js';
7
6
  import { M as ModelName, l as PrismaOperation, m as HookTiming, B as BeforeHookCallback, j as AfterHookCallback, k as ColumnChangeCallback } from './prisma.types-nGNe1CG8.js';
8
7
  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';
9
8
  export { afterChange, afterCreate, afterDelete, afterUpdate, afterUpsert, beforeCreate, beforeDelete, beforeUpdate } from './core/hooks.js';
10
-
11
- interface FlareClientOptions extends PrismaClientOptions {
12
- /**
13
- * Enable callbacks/hooks middleware. When true (default), the middleware
14
- * that executes your registered callbacks (beforeCreate, afterUpdate, etc.)
15
- * is automatically attached.
16
- *
17
- * @default true
18
- */
19
- callbacks?: boolean;
20
- /**
21
- * Driver adapter for serverless/edge environments.
22
- * Pass an adapter instance (e.g., from @prisma/adapter-pg, @prisma/adapter-d1, etc.)
23
- */
24
- adapter?: DriverAdapter;
25
- }
26
- declare class FlareClient extends PrismaClient {
27
- constructor(options?: FlareClientOptions);
28
- /**
29
- * Creates a new FlareBuilder instance for the specified model.
30
- * @param modelName - The name of the model.
31
- * @returns FlareBuilder instance
32
- */
33
- from<T extends ModelName>(modelName: T): FlareBuilder<T>;
34
- /**
35
- * Executes a transaction with the FlareClient capabilities.
36
- * @param fn - The transaction function.
37
- * @param options - Transaction options.
38
- * @returns The result of the transaction.
39
- */
40
- transaction<R>(fn: (tx: FlareClient) => Promise<R>, options?: {
41
- maxWait?: number;
42
- timeout?: number;
43
- isolationLevel?: any;
44
- }): Promise<R>;
45
- }
46
- /**
47
- * @deprecated Use `FlareClient` instead. This alias will be removed in a future version.
48
- */
49
- declare const ExtendedPrismaClient: typeof FlareClient;
9
+ import * as _prisma_client from '@prisma/client';
10
+ import { PrismaClient } from '@prisma/client';
50
11
 
51
12
  /**
52
13
  * Options for FlareClient created via the factory.
@@ -71,53 +32,6 @@ interface FactoryFlareClientOptions {
71
32
  */
72
33
  [key: string]: unknown;
73
34
  }
74
- /**
75
- * Type for the Prisma namespace (contains Result, defineExtension, etc.)
76
- */
77
- type PrismaNamespace = {
78
- defineExtension: (extension: any) => any;
79
- [key: string]: unknown;
80
- };
81
- /**
82
- * Type for a PrismaClient-like constructor
83
- */
84
- interface PrismaClientLike {
85
- new (options?: Record<string, unknown>): PrismaClient;
86
- }
87
- /**
88
- * The shape of a FlareClient class created by the factory
89
- */
90
- interface FlareClientClass {
91
- new (options?: FactoryFlareClientOptions): FlareClientInstance;
92
- }
93
- /**
94
- * Instance type for FlareClient
95
- */
96
- interface FlareClientInstance extends PrismaClient {
97
- from<M extends ModelName>(modelName: M): FlareBuilder<M>;
98
- transaction<R>(fn: (tx: FlareClientInstance) => Promise<R>, options?: {
99
- maxWait?: number;
100
- timeout?: number;
101
- isolationLevel?: unknown;
102
- }): Promise<R>;
103
- }
104
- /**
105
- * Creates a FlareClient class that extends the provided PrismaClient.
106
- * This factory enables support for custom Prisma client output paths.
107
- *
108
- * @param BasePrismaClient - The PrismaClient class to extend
109
- * @param _PrismaNamespace - The Prisma namespace (optional, for future type inference)
110
- * @returns A FlareClient class that extends BasePrismaClient
111
- *
112
- * @example
113
- * // For custom Prisma output paths:
114
- * import { PrismaClient, Prisma } from './generated/client';
115
- * import { createFlareClient } from 'prisma-flare';
116
- *
117
- * const FlareClient = createFlareClient(PrismaClient, Prisma);
118
- * export const db = new FlareClient();
119
- */
120
- declare function createFlareClient(BasePrismaClient: PrismaClientLike, _PrismaNamespace?: PrismaNamespace): FlareClientClass;
121
35
 
122
36
  type ModelClass<T extends ModelName = any> = new () => FlareBuilder<T, any>;
123
37
  /**
@@ -319,4 +233,4 @@ declare class AdapterRegistry {
319
233
  }
320
234
  declare const registry: AdapterRegistry;
321
235
 
322
- export { AfterHookCallback, BeforeHookCallback, ColumnChangeCallback, type DatabaseAdapter, ExtendedPrismaClient, type FactoryFlareClientOptions, FlareBuilder, FlareClient, type FlareClientClass, type FlareClientInstance, type FlareClientOptions, type HookConfig, HookTiming, ModelName, type PrismaClientLike, type PrismaNamespace, PrismaOperation, createFlareClient, createHooksExtension, registry as dbAdapterRegistry, hookRegistry, loadCallbacks, modelRegistry, registerHooks, registerHooksLegacy };
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 };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- // src/core/extendedPrismaClient.ts
2
- import { PrismaClient as PrismaClient2 } from "@prisma/client";
1
+ // src/index.ts
2
+ import { FlareClient, Prisma, PrismaClient } from ".prisma-flare";
3
3
 
4
4
  // src/core/modelRegistry.ts
5
5
  var ModelRegistry = class {
@@ -838,10 +838,39 @@ 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
+
841
870
  // src/core/hookMiddleware.ts
842
- import { Prisma } from "@prisma/client";
843
871
  import fs from "fs";
844
872
  import path from "path";
873
+ var _Prisma = null;
845
874
  function supportsTypeScriptImports() {
846
875
  if (process.env.TS_NODE || /* @__PURE__ */ Symbol.for("ts-node.register.instance") in process) {
847
876
  return true;
@@ -938,7 +967,12 @@ function supportsPrisma6Middleware(prisma) {
938
967
  return typeof prisma.$use === "function";
939
968
  }
940
969
  function createHooksExtension(basePrisma) {
941
- return Prisma.defineExtension({
970
+ if (!_Prisma) {
971
+ throw new Error(
972
+ "Prisma namespace not initialized. Make sure to run `npx prisma-flare generate` first."
973
+ );
974
+ }
975
+ return _Prisma.defineExtension({
942
976
  name: "prisma-flare-hooks",
943
977
  query: {
944
978
  $allModels: {
@@ -971,155 +1005,6 @@ function registerHooks(prisma) {
971
1005
  }
972
1006
  }
973
1007
 
974
- // src/core/extendedPrismaClient.ts
975
- function supportsPrisma6Middleware2(prisma) {
976
- return typeof prisma.$use === "function";
977
- }
978
- var FlareClient = class extends PrismaClient2 {
979
- constructor(options = {}) {
980
- const { callbacks = true, ...prismaOptions } = options;
981
- super(prismaOptions);
982
- if (callbacks) {
983
- if (supportsPrisma6Middleware2(this)) {
984
- registerHooksLegacy(this);
985
- } else {
986
- const extension = createHooksExtension(this);
987
- return this.$extends(extension);
988
- }
989
- }
990
- }
991
- /**
992
- * Creates a new FlareBuilder instance for the specified model.
993
- * @param modelName - The name of the model.
994
- * @returns FlareBuilder instance
995
- */
996
- from(modelName) {
997
- const key = modelName.charAt(0).toLowerCase() + modelName.slice(1);
998
- const model = this[key];
999
- if (!model) {
1000
- throw new Error(`Model ${modelName} does not exist on PrismaClient.`);
1001
- }
1002
- return new FlareBuilder(model);
1003
- }
1004
- /**
1005
- * Executes a transaction with the FlareClient capabilities.
1006
- * @param fn - The transaction function.
1007
- * @param options - Transaction options.
1008
- * @returns The result of the transaction.
1009
- */
1010
- async transaction(fn, options) {
1011
- return super.$transaction(async (tx) => {
1012
- const extendedTx = new Proxy(tx, {
1013
- get: (target, prop, receiver) => {
1014
- if (prop === "from") {
1015
- return (modelName) => {
1016
- const key = modelName.charAt(0).toLowerCase() + modelName.slice(1);
1017
- const model = target[key];
1018
- if (!model) {
1019
- throw new Error(`Model ${modelName} does not exist on TransactionClient.`);
1020
- }
1021
- return new FlareBuilder(model);
1022
- };
1023
- }
1024
- return Reflect.get(target, prop, receiver);
1025
- }
1026
- });
1027
- return fn(extendedTx);
1028
- }, options);
1029
- }
1030
- };
1031
- var ExtendedPrismaClient = FlareClient;
1032
-
1033
- // src/core/createFlareClient.ts
1034
- function supportsPrisma6Middleware3(prisma) {
1035
- return typeof prisma.$use === "function";
1036
- }
1037
- function createFlareClient(BasePrismaClient, _PrismaNamespace) {
1038
- const FlareClientImpl = class extends BasePrismaClient {
1039
- constructor(options = {}) {
1040
- const { callbacks = true, ...prismaOptions } = options;
1041
- super(prismaOptions);
1042
- if (callbacks) {
1043
- if (supportsPrisma6Middleware3(this)) {
1044
- registerHooksLegacy(this);
1045
- } else {
1046
- const extension = createHooksExtension(this);
1047
- return this.$extends(extension);
1048
- }
1049
- }
1050
- }
1051
- /**
1052
- * Creates a new FlareBuilder instance for the specified model.
1053
- * @param modelName - The name of the model.
1054
- * @returns FlareBuilder instance
1055
- */
1056
- from(modelName) {
1057
- const key = modelName.charAt(0).toLowerCase() + modelName.slice(1);
1058
- const model = this[key];
1059
- if (!model) {
1060
- throw new Error(`Model ${modelName} does not exist on PrismaClient.`);
1061
- }
1062
- return new FlareBuilder(model);
1063
- }
1064
- /**
1065
- * Executes a transaction with the FlareClient capabilities.
1066
- * @param fn - The transaction function.
1067
- * @param options - Transaction options.
1068
- * @returns The result of the transaction.
1069
- */
1070
- async transaction(fn, options) {
1071
- return this.$transaction(async (tx) => {
1072
- const extendedTx = new Proxy(tx, {
1073
- get: (target, prop, receiver) => {
1074
- if (prop === "from") {
1075
- return (modelName) => {
1076
- const key = modelName.charAt(0).toLowerCase() + modelName.slice(1);
1077
- const model = target[key];
1078
- if (!model) {
1079
- throw new Error(`Model ${modelName} does not exist on TransactionClient.`);
1080
- }
1081
- return new FlareBuilder(model);
1082
- };
1083
- }
1084
- return Reflect.get(target, prop, receiver);
1085
- }
1086
- });
1087
- return fn(extendedTx);
1088
- }, options);
1089
- }
1090
- };
1091
- return FlareClientImpl;
1092
- }
1093
-
1094
- // src/core/hooks.ts
1095
- function normalizeModelName(model) {
1096
- return model.toLowerCase();
1097
- }
1098
- function beforeCreate(model, callback) {
1099
- hookRegistry_default.addHook(normalizeModelName(model), "create", "before", callback);
1100
- }
1101
- function beforeDelete(model, callback) {
1102
- hookRegistry_default.addHook(normalizeModelName(model), "delete", "before", callback);
1103
- }
1104
- function afterCreate(model, callback) {
1105
- hookRegistry_default.addHook(normalizeModelName(model), "create", "after", callback);
1106
- }
1107
- function afterDelete(model, callback) {
1108
- hookRegistry_default.addHook(normalizeModelName(model), "delete", "after", callback);
1109
- }
1110
- function beforeUpdate(model, callback) {
1111
- hookRegistry_default.addHook(normalizeModelName(model), "update", "before", callback);
1112
- }
1113
- function afterUpdate(model, callback) {
1114
- hookRegistry_default.addHook(normalizeModelName(model), "update", "after", callback);
1115
- }
1116
- function afterChange(model, column, callback) {
1117
- hookRegistry_default.addColumnHook(normalizeModelName(model), column, callback);
1118
- }
1119
- function afterUpsert(model, callback) {
1120
- hookRegistry_default.addHook(normalizeModelName(model), "upsert", "after", callback);
1121
- }
1122
-
1123
1008
  // src/core/adapters/postgres.ts
1124
1009
  var PostgresAdapter = {
1125
1010
  name: "postgres",
@@ -1277,9 +1162,10 @@ var registry = new AdapterRegistry();
1277
1162
  registry.register(PostgresAdapter);
1278
1163
  registry.register(SqliteAdapter);
1279
1164
  export {
1280
- ExtendedPrismaClient,
1281
1165
  FlareBuilder,
1282
1166
  FlareClient,
1167
+ Prisma,
1168
+ PrismaClient,
1283
1169
  afterChange,
1284
1170
  afterCreate,
1285
1171
  afterDelete,
@@ -1288,7 +1174,6 @@ export {
1288
1174
  beforeCreate,
1289
1175
  beforeDelete,
1290
1176
  beforeUpdate,
1291
- createFlareClient,
1292
1177
  createHooksExtension,
1293
1178
  registry as dbAdapterRegistry,
1294
1179
  hookRegistry_default as hookRegistry,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prisma-flare",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
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",
@@ -78,11 +78,6 @@
78
78
  "import": "./dist/index.js",
79
79
  "require": "./dist/index.cjs"
80
80
  },
81
- "./client": {
82
- "types": "./dist/client/index.d.ts",
83
- "import": "./dist/client/index.js",
84
- "require": "./dist/client/index.cjs"
85
- },
86
81
  "./generated": {
87
82
  "types": "./dist/generated.d.ts",
88
83
  "import": "./dist/generated.js",
@@ -101,9 +96,6 @@
101
96
  },
102
97
  "typesVersions": {
103
98
  "*": {
104
- "client": [
105
- "./dist/client/index.d.ts"
106
- ],
107
99
  "generated": [
108
100
  "./dist/generated.d.ts"
109
101
  ],
package/readme.md CHANGED
@@ -75,13 +75,11 @@ Replace your standard `PrismaClient` with `FlareClient` in your database setup f
75
75
  ```typescript
76
76
  // prisma/db.ts
77
77
  import './callbacks'; // Import generated index to register all hooks
78
- import { FlareClient } from 'prisma-flare/client';
78
+ import { FlareClient } from 'prisma-flare';
79
79
 
80
80
  export const db = new FlareClient();
81
81
  ```
82
82
 
83
- **Note:** Always import `FlareClient` from `prisma-flare/client` - this ensures compatibility with custom Prisma output paths (see [Custom Prisma Output Path](#custom-prisma-output-path) below).
84
-
85
83
  `FlareClient` automatically attaches the callbacks middleware (using the appropriate API for your Prisma version). The callbacks import loads a generated barrel file that registers all your hooks - this pattern works in all environments (bundlers, Node.js, serverless, etc.).
86
84
 
87
85
  **With Prisma adapters:**
@@ -89,7 +87,7 @@ export const db = new FlareClient();
89
87
  ```typescript
90
88
  import './callbacks';
91
89
  import { PrismaPg } from '@prisma/adapter-pg';
92
- import { FlareClient } from 'prisma-flare/client';
90
+ import { FlareClient } from 'prisma-flare';
93
91
 
94
92
  const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL });
95
93
 
@@ -99,7 +97,7 @@ export const db = new FlareClient({ adapter });
99
97
  **Disable callbacks middleware:**
100
98
 
101
99
  ```typescript
102
- import { FlareClient } from 'prisma-flare/client';
100
+ import { FlareClient } from 'prisma-flare';
103
101
 
104
102
  // If you don't use callbacks, disable the middleware for slightly less overhead
105
103
  export const db = new FlareClient({ callbacks: false });
@@ -161,21 +159,9 @@ generator client {
161
159
  }
162
160
  ```
163
161
 
164
- The `prisma-flare generate` command:
165
- 1. Parses your `schema.prisma` to detect custom output paths
166
- 2. Generates `node_modules/.prisma-flare/` with the correct import path
167
- 3. `prisma-flare/client` automatically uses this generated client
168
-
169
- **That's it!** Just import from `prisma-flare/client` and it works:
170
-
171
- ```typescript
172
- import { FlareClient } from 'prisma-flare/client'; // Works with any Prisma output path
173
- import { hookRegistry } from 'prisma-flare'; // Hooks/utilities from main package
174
-
175
- export const db = new FlareClient();
176
- ```
162
+ Just run `npx prisma-flare generate` - it parses your `schema.prisma` and configures everything automatically. No extra configuration needed.
177
163
 
178
- **Manual override:** If auto-detection doesn't work for your setup, you can explicitly configure the path:
164
+ **Manual override:** If auto-detection doesn't work, add to `prisma-flare.config.json`:
179
165
 
180
166
  ```json
181
167
  {
@@ -183,18 +169,6 @@ export const db = new FlareClient();
183
169
  }
184
170
  ```
185
171
 
186
- **Advanced: Factory function**
187
-
188
- For full control, use `createFlareClient` to create a FlareClient from any PrismaClient:
189
-
190
- ```typescript
191
- import { createFlareClient } from 'prisma-flare';
192
- import { PrismaClient, Prisma } from './my/custom/prisma/path';
193
-
194
- const FlareClient = createFlareClient(PrismaClient, Prisma);
195
- export const db = new FlareClient();
196
- ```
197
-
198
172
  ## Usage
199
173
 
200
174
  ### Flare Builder
@@ -1,34 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/client/index.ts
21
- var client_exports = {};
22
- __export(client_exports, {
23
- FlareClient: () => import__.FlareClient,
24
- Prisma: () => import__.Prisma,
25
- PrismaClient: () => import__.PrismaClient
26
- });
27
- module.exports = __toCommonJS(client_exports);
28
- var import__ = require(".prisma-flare");
29
- // Annotate the CommonJS export names for ESM import in node:
30
- 0 && (module.exports = {
31
- FlareClient,
32
- Prisma,
33
- PrismaClient
34
- });
@@ -1 +0,0 @@
1
- export { FlareClient, Prisma, PrismaClient } from '.prisma-flare';
@@ -1 +0,0 @@
1
- export { FlareClient, Prisma, PrismaClient } from '.prisma-flare';
@@ -1,7 +0,0 @@
1
- // src/client/index.ts
2
- import { FlareClient, Prisma, PrismaClient } from ".prisma-flare";
3
- export {
4
- FlareClient,
5
- Prisma,
6
- PrismaClient
7
- };