prisma-flare 1.1.4 → 1.1.5
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/dist/cli/index.cjs +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/index.cjs +98 -29
- package/dist/index.d.cts +50 -3
- package/dist/index.d.ts +50 -3
- package/dist/index.js +97 -29
- package/package.json +1 -1
package/dist/cli/index.cjs
CHANGED
|
@@ -488,7 +488,7 @@ export declare class FlareClient extends BasePrismaClient {
|
|
|
488
488
|
}
|
|
489
489
|
console.log(` Location: ${prismaFlareDir}`);
|
|
490
490
|
console.log(`
|
|
491
|
-
Import: import { FlareClient } from 'prisma-flare
|
|
491
|
+
Import: import { FlareClient } from 'prisma-flare';`);
|
|
492
492
|
}
|
|
493
493
|
|
|
494
494
|
// src/cli/index.ts
|
package/dist/cli/index.js
CHANGED
|
@@ -465,7 +465,7 @@ export declare class FlareClient extends BasePrismaClient {
|
|
|
465
465
|
}
|
|
466
466
|
console.log(` Location: ${prismaFlareDir}`);
|
|
467
467
|
console.log(`
|
|
468
|
-
Import: import { FlareClient } from 'prisma-flare
|
|
468
|
+
Import: import { FlareClient } from 'prisma-flare';`);
|
|
469
469
|
}
|
|
470
470
|
|
|
471
471
|
// 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