prisma-flare 1.3.0 → 1.3.2
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/db-migrate.cjs +119 -49
- package/dist/cli/db-migrate.js +125 -49
- package/dist/cli/db-reset.cjs +119 -49
- package/dist/cli/db-reset.js +125 -49
- package/dist/cli/index.cjs +119 -49
- package/dist/cli/index.js +125 -49
- package/dist/core/flareBuilder.d.cts +17 -45
- package/dist/core/flareBuilder.d.ts +17 -45
- package/dist/core/hooks.cjs +44 -22
- package/dist/core/hooks.d.cts +8 -8
- package/dist/core/hooks.d.ts +8 -8
- package/dist/core/hooks.js +44 -22
- package/dist/{hookRegistry-CjujesJK.d.cts → hookRegistry-B8oyCNJ9.d.cts} +14 -2
- package/dist/{hookRegistry--2l0ARPy.d.ts → hookRegistry-C2bTS4YN.d.ts} +14 -2
- package/dist/hooks.cjs +44 -22
- package/dist/hooks.d.cts +2 -2
- package/dist/hooks.d.ts +2 -2
- package/dist/hooks.js +44 -22
- package/dist/index.cjs +30 -8
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +30 -8
- package/dist/{prisma.types-CIEFXVL-.d.cts → prisma.types-WBv5kOSl.d.cts} +18 -1
- package/dist/{prisma.types-CIEFXVL-.d.ts → prisma.types-WBv5kOSl.d.ts} +18 -1
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Prisma } from '@prisma/client';
|
|
2
|
-
import { M as ModelName, b as ModelDelegate, Q as QueryArgs, W as WhereInput, O as OrderByInput, R as RecordType, D as DistinctInput, S as SelectInput, I as IncludeKey, G as GroupByInput, c as HavingInput, d as PaginatedResult, e as CreateData, f as CreateManyData, g as DeleteArgs, h as DeleteManyArgs, U as UpdateData, i as UpdateManyData, j as UpsertArgs, k as SumFields, l as AvgFields, m as MinFields, n as MaxFields } from '../prisma.types-
|
|
2
|
+
import { M as ModelName, b as ModelDelegate, Q as QueryArgs, W as WhereInput, O as OrderByInput, R as RecordType, D as DistinctInput, S as SelectInput, I as IncludeKey, G as GroupByInput, c as HavingInput, d as PaginatedResult, e as CreateData, f as CreateManyData, g as DeleteArgs, h as DeleteManyArgs, U as UpdateData, i as UpdateManyData, j as UpsertArgs, k as SumFields, l as AvgFields, m as MinFields, n as MaxFields } from '../prisma.types-WBv5kOSl.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Global interface for relation-to-model mapping.
|
|
@@ -42,9 +42,7 @@ declare class FlareBuilder<T extends ModelName, Args extends Record<string, any>
|
|
|
42
42
|
* .findMany()
|
|
43
43
|
* // Equivalent to: { AND: [{ published: true }, { authorId: 1 }] }
|
|
44
44
|
*/
|
|
45
|
-
where(condition: WhereInput<T>):
|
|
46
|
-
where: WhereInput<T>;
|
|
47
|
-
}>;
|
|
45
|
+
where(condition: WhereInput<T>): this;
|
|
48
46
|
/**
|
|
49
47
|
* Adds a where condition using AND logic (explicit alias for where())
|
|
50
48
|
* @param condition - Where filter matching your Prisma model
|
|
@@ -55,9 +53,7 @@ declare class FlareBuilder<T extends ModelName, Args extends Record<string, any>
|
|
|
55
53
|
* .andWhere({ createdAt: { gte: new Date('2024-01-01') } })
|
|
56
54
|
* .findMany()
|
|
57
55
|
*/
|
|
58
|
-
andWhere(condition: WhereInput<T>):
|
|
59
|
-
where: WhereInput<T>;
|
|
60
|
-
}>;
|
|
56
|
+
andWhere(condition: WhereInput<T>): this;
|
|
61
57
|
/**
|
|
62
58
|
* Adds a where condition using OR logic.
|
|
63
59
|
*
|
|
@@ -91,9 +87,7 @@ declare class FlareBuilder<T extends ModelName, Args extends Record<string, any>
|
|
|
91
87
|
* .findMany()
|
|
92
88
|
* // Result: published AND (category='news' OR category='tech')
|
|
93
89
|
*/
|
|
94
|
-
orWhere(condition: WhereInput<T>):
|
|
95
|
-
where: WhereInput<T>;
|
|
96
|
-
}>;
|
|
90
|
+
orWhere(condition: WhereInput<T>): this;
|
|
97
91
|
/**
|
|
98
92
|
* Creates a grouped where condition using a callback.
|
|
99
93
|
* Use this for explicit control over boolean logic grouping.
|
|
@@ -122,9 +116,7 @@ declare class FlareBuilder<T extends ModelName, Args extends Record<string, any>
|
|
|
122
116
|
* , 'OR')
|
|
123
117
|
* .findMany()
|
|
124
118
|
*/
|
|
125
|
-
whereGroup(callback: (builder: FlareBuilder<T, Record<string, never>>) => FlareBuilder<T, any>, mode?: 'AND' | 'OR'):
|
|
126
|
-
where: WhereInput<T>;
|
|
127
|
-
}>;
|
|
119
|
+
whereGroup(callback: (builder: FlareBuilder<T, Record<string, never>>) => FlareBuilder<T, any>, mode?: 'AND' | 'OR'): this;
|
|
128
120
|
/**
|
|
129
121
|
* Alias for whereGroup with OR mode.
|
|
130
122
|
* Creates a grouped condition that's OR-ed with existing where.
|
|
@@ -141,56 +133,38 @@ declare class FlareBuilder<T extends ModelName, Args extends Record<string, any>
|
|
|
141
133
|
* )
|
|
142
134
|
* .findMany()
|
|
143
135
|
*/
|
|
144
|
-
orWhereGroup(callback: (builder: FlareBuilder<T, Record<string, never>>) => FlareBuilder<T, any>):
|
|
145
|
-
where: WhereInput<T>;
|
|
146
|
-
}>;
|
|
136
|
+
orWhereGroup(callback: (builder: FlareBuilder<T, Record<string, never>>) => FlareBuilder<T, any>): this;
|
|
147
137
|
/**
|
|
148
138
|
* Adds a where condition to the query for the specified id.
|
|
149
139
|
* Uses the same AND composition as where() for consistency.
|
|
150
140
|
* @param id - The id to search for
|
|
151
141
|
*/
|
|
152
|
-
withId(id: number | string):
|
|
153
|
-
where: {
|
|
154
|
-
id: number | string;
|
|
155
|
-
};
|
|
156
|
-
}>;
|
|
142
|
+
withId(id: number | string): this;
|
|
157
143
|
/**
|
|
158
144
|
* Adds an order by condition to the query
|
|
159
145
|
* @param orderBy - OrderBy object matching your Prisma model
|
|
160
146
|
*/
|
|
161
|
-
order(orderBy: OrderByInput<T>):
|
|
162
|
-
orderBy: OrderByInput<T>;
|
|
163
|
-
}>;
|
|
147
|
+
order(orderBy: OrderByInput<T>): this;
|
|
164
148
|
/**
|
|
165
149
|
* Gets the last record sorted by the specified field
|
|
166
150
|
* @param key - Field to sort by (defaults to 'createdAt')
|
|
167
151
|
*/
|
|
168
|
-
last(key?: keyof RecordType<T> | string):
|
|
169
|
-
orderBy: any;
|
|
170
|
-
take: number;
|
|
171
|
-
}>;
|
|
152
|
+
last(key?: keyof RecordType<T> | string): this;
|
|
172
153
|
/**
|
|
173
154
|
* Gets the first record sorted by the specified field
|
|
174
155
|
* @param key - Field to sort by (defaults to 'createdAt')
|
|
175
156
|
*/
|
|
176
|
-
first(key?: keyof RecordType<T> | string):
|
|
177
|
-
orderBy: any;
|
|
178
|
-
take: number;
|
|
179
|
-
}>;
|
|
157
|
+
first(key?: keyof RecordType<T> | string): this;
|
|
180
158
|
/**
|
|
181
159
|
* Sets a limit on the number of records to retrieve
|
|
182
160
|
* @param limit - Maximum number of records
|
|
183
161
|
*/
|
|
184
|
-
limit(limit: number):
|
|
185
|
-
take: number;
|
|
186
|
-
}>;
|
|
162
|
+
limit(limit: number): this;
|
|
187
163
|
/**
|
|
188
164
|
* Sets distinct fields for the query
|
|
189
165
|
* @param distinct - Fields to be distinct
|
|
190
166
|
*/
|
|
191
|
-
distinct(distinct: DistinctInput<T>):
|
|
192
|
-
distinct: DistinctInput<T>;
|
|
193
|
-
}>;
|
|
167
|
+
distinct(distinct: DistinctInput<T>): this;
|
|
194
168
|
/**
|
|
195
169
|
* Selects specific fields to retrieve
|
|
196
170
|
* @param fields - Select object matching your Prisma model
|
|
@@ -248,9 +222,7 @@ declare class FlareBuilder<T extends ModelName, Args extends Record<string, any>
|
|
|
248
222
|
* Skips the specified number of records
|
|
249
223
|
* @param offset - Number of records to skip
|
|
250
224
|
*/
|
|
251
|
-
skip(offset: number):
|
|
252
|
-
skip: number;
|
|
253
|
-
}>;
|
|
225
|
+
skip(offset: number): this;
|
|
254
226
|
/**
|
|
255
227
|
* Checks if any record exists matching the current query
|
|
256
228
|
* @param existenceKey - Key to check for existence (defaults to 'id')
|
|
@@ -261,7 +233,7 @@ declare class FlareBuilder<T extends ModelName, Args extends Record<string, any>
|
|
|
261
233
|
* @param page - Page number (1-based)
|
|
262
234
|
* @param perPage - Number of records per page
|
|
263
235
|
*/
|
|
264
|
-
paginate(page?: number, perPage?: number): Promise<PaginatedResult<
|
|
236
|
+
paginate(page?: number, perPage?: number): Promise<PaginatedResult<Prisma.Result<ModelDelegate<T>, Args, 'findFirstOrThrow'>>>;
|
|
265
237
|
/**
|
|
266
238
|
* Conditionally executes a callback on the query builder
|
|
267
239
|
* @param condition - Boolean or function returning boolean
|
|
@@ -273,7 +245,7 @@ declare class FlareBuilder<T extends ModelName, Args extends Record<string, any>
|
|
|
273
245
|
* @param size - Size of each chunk
|
|
274
246
|
* @param callback - Function to process each chunk
|
|
275
247
|
*/
|
|
276
|
-
chunk(size: number, callback: (results:
|
|
248
|
+
chunk(size: number, callback: (results: Prisma.Result<ModelDelegate<T>, Args, 'findMany'>) => Promise<void> | void): Promise<void>;
|
|
277
249
|
/**
|
|
278
250
|
* Clones the current query builder instance.
|
|
279
251
|
* Uses structuredClone for proper handling of Date, BigInt, etc.
|
|
@@ -285,7 +257,7 @@ declare class FlareBuilder<T extends ModelName, Args extends Record<string, any>
|
|
|
285
257
|
* @throws {Prisma.NotFoundError} When no record matches the query
|
|
286
258
|
* @returns Promise resolving to the found record
|
|
287
259
|
*/
|
|
288
|
-
findFirstOrThrow(): Promise<
|
|
260
|
+
findFirstOrThrow(): Promise<Prisma.Result<ModelDelegate<T>, Args, 'findFirstOrThrow'>>;
|
|
289
261
|
/**
|
|
290
262
|
* Finds a unique record by primary key or throws an error if not found
|
|
291
263
|
* Requires a unique constraint (typically the id field)
|
|
@@ -293,7 +265,7 @@ declare class FlareBuilder<T extends ModelName, Args extends Record<string, any>
|
|
|
293
265
|
* @throws {Prisma.NotFoundError} When no record is found
|
|
294
266
|
* @returns Promise resolving to the found record
|
|
295
267
|
*/
|
|
296
|
-
findUniqueOrThrow(): Promise<
|
|
268
|
+
findUniqueOrThrow(): Promise<Prisma.Result<ModelDelegate<T>, Args, 'findUniqueOrThrow'>>;
|
|
297
269
|
/**
|
|
298
270
|
* Finds all records matching the query
|
|
299
271
|
* Respects all previously set query conditions (where, orderBy, take, skip, include, select, distinct)
|
package/dist/core/hooks.cjs
CHANGED
|
@@ -71,6 +71,7 @@ var HookRegistry = class {
|
|
|
71
71
|
this.fieldCache = {};
|
|
72
72
|
this.modelsWithColumnHooks = /* @__PURE__ */ new Set();
|
|
73
73
|
this.config = { ...DEFAULT_CONFIG };
|
|
74
|
+
this.disabledTags = /* @__PURE__ */ new Set();
|
|
74
75
|
}
|
|
75
76
|
/**
|
|
76
77
|
* Configure the hook system.
|
|
@@ -97,30 +98,48 @@ var HookRegistry = class {
|
|
|
97
98
|
getConfig() {
|
|
98
99
|
return this.config;
|
|
99
100
|
}
|
|
100
|
-
addHook(model, action, timing, fn) {
|
|
101
|
+
addHook(model, action, timing, fn, tag) {
|
|
101
102
|
const key = `${model}:${action}`;
|
|
102
103
|
if (!this.hooks[timing][key]) {
|
|
103
104
|
this.hooks[timing][key] = [];
|
|
104
105
|
}
|
|
105
|
-
this.hooks[timing][key].push(fn);
|
|
106
|
+
this.hooks[timing][key].push({ callback: fn, tag });
|
|
106
107
|
}
|
|
107
108
|
addColumnHook(model, column, fn, options) {
|
|
108
109
|
const key = `${model}:${column}`;
|
|
109
110
|
if (!this.columnHooks.afterChange[key]) {
|
|
110
111
|
this.columnHooks.afterChange[key] = [];
|
|
111
112
|
}
|
|
112
|
-
this.columnHooks.afterChange[key].push({ callback: fn, options });
|
|
113
|
+
this.columnHooks.afterChange[key].push({ callback: fn, options, tag: options?.tag });
|
|
113
114
|
this.modelsWithColumnHooks.add(model);
|
|
114
115
|
delete this.fieldCache[model];
|
|
115
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* Disable all hooks with the given tag.
|
|
119
|
+
* @example hookRegistry.disable('changelog');
|
|
120
|
+
*/
|
|
121
|
+
disable(tag) {
|
|
122
|
+
this.disabledTags.add(tag);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Re-enable hooks with the given tag.
|
|
126
|
+
* @example hookRegistry.enable('changelog');
|
|
127
|
+
*/
|
|
128
|
+
enable(tag) {
|
|
129
|
+
this.disabledTags.delete(tag);
|
|
130
|
+
}
|
|
131
|
+
isEnabled(tag) {
|
|
132
|
+
return !tag || !this.disabledTags.has(tag);
|
|
133
|
+
}
|
|
116
134
|
async runHooks(timing, model, action, args, prisma) {
|
|
117
135
|
const key = `${model}:${action}`;
|
|
118
|
-
const
|
|
136
|
+
const entries = this.hooks[timing]?.[key] ?? [];
|
|
137
|
+
const active = entries.filter((e) => this.isEnabled(e.tag));
|
|
119
138
|
if (timing === "after") {
|
|
120
|
-
await Promise.all(
|
|
139
|
+
await Promise.all(active.map((e) => e.callback(...args, prisma)));
|
|
121
140
|
} else {
|
|
122
|
-
for (const
|
|
123
|
-
await
|
|
141
|
+
for (const entry of active) {
|
|
142
|
+
await entry.callback(...args, prisma);
|
|
124
143
|
}
|
|
125
144
|
}
|
|
126
145
|
}
|
|
@@ -131,7 +150,9 @@ var HookRegistry = class {
|
|
|
131
150
|
const entries = this.columnHooks.afterChange[key];
|
|
132
151
|
if (entries && !valuesEqual(newData[column], prevData[column])) {
|
|
133
152
|
for (const entry of entries) {
|
|
134
|
-
|
|
153
|
+
if (this.isEnabled(entry.tag)) {
|
|
154
|
+
promises.push(entry.callback(prevData[column], newData[column], newData, prisma));
|
|
155
|
+
}
|
|
135
156
|
}
|
|
136
157
|
}
|
|
137
158
|
}
|
|
@@ -206,6 +227,7 @@ var HookRegistry = class {
|
|
|
206
227
|
this.fieldCache = {};
|
|
207
228
|
this.modelsWithColumnHooks.clear();
|
|
208
229
|
this.config = { ...DEFAULT_CONFIG };
|
|
230
|
+
this.disabledTags.clear();
|
|
209
231
|
}
|
|
210
232
|
};
|
|
211
233
|
var HOOK_REGISTRY_SYMBOL = /* @__PURE__ */ Symbol.for("prisma-flare.hookRegistry");
|
|
@@ -220,29 +242,29 @@ var hookRegistry_default = hookRegistry;
|
|
|
220
242
|
function normalizeModelName(model) {
|
|
221
243
|
return model.toLowerCase();
|
|
222
244
|
}
|
|
223
|
-
function beforeCreate(model, callback) {
|
|
224
|
-
hookRegistry_default.addHook(normalizeModelName(model), "create", "before", callback);
|
|
245
|
+
function beforeCreate(model, callback, options) {
|
|
246
|
+
hookRegistry_default.addHook(normalizeModelName(model), "create", "before", callback, options?.tag);
|
|
225
247
|
}
|
|
226
|
-
function beforeDelete(model, callback) {
|
|
227
|
-
hookRegistry_default.addHook(normalizeModelName(model), "delete", "before", callback);
|
|
248
|
+
function beforeDelete(model, callback, options) {
|
|
249
|
+
hookRegistry_default.addHook(normalizeModelName(model), "delete", "before", callback, options?.tag);
|
|
228
250
|
}
|
|
229
|
-
function afterCreate(model, callback) {
|
|
230
|
-
hookRegistry_default.addHook(normalizeModelName(model), "create", "after", callback);
|
|
251
|
+
function afterCreate(model, callback, options) {
|
|
252
|
+
hookRegistry_default.addHook(normalizeModelName(model), "create", "after", callback, options?.tag);
|
|
231
253
|
}
|
|
232
|
-
function afterDelete(model, callback) {
|
|
233
|
-
hookRegistry_default.addHook(normalizeModelName(model), "delete", "after", callback);
|
|
254
|
+
function afterDelete(model, callback, options) {
|
|
255
|
+
hookRegistry_default.addHook(normalizeModelName(model), "delete", "after", callback, options?.tag);
|
|
234
256
|
}
|
|
235
|
-
function beforeUpdate(model, callback) {
|
|
236
|
-
hookRegistry_default.addHook(normalizeModelName(model), "update", "before", callback);
|
|
257
|
+
function beforeUpdate(model, callback, options) {
|
|
258
|
+
hookRegistry_default.addHook(normalizeModelName(model), "update", "before", callback, options?.tag);
|
|
237
259
|
}
|
|
238
|
-
function afterUpdate(model, callback) {
|
|
239
|
-
hookRegistry_default.addHook(normalizeModelName(model), "update", "after", callback);
|
|
260
|
+
function afterUpdate(model, callback, options) {
|
|
261
|
+
hookRegistry_default.addHook(normalizeModelName(model), "update", "after", callback, options?.tag);
|
|
240
262
|
}
|
|
241
263
|
function afterChange(model, column, callback, options) {
|
|
242
264
|
hookRegistry_default.addColumnHook(normalizeModelName(model), column, callback, options);
|
|
243
265
|
}
|
|
244
|
-
function afterUpsert(model, callback) {
|
|
245
|
-
hookRegistry_default.addHook(normalizeModelName(model), "upsert", "after", callback);
|
|
266
|
+
function afterUpsert(model, callback, options) {
|
|
267
|
+
hookRegistry_default.addHook(normalizeModelName(model), "upsert", "after", callback, options?.tag);
|
|
246
268
|
}
|
|
247
269
|
// Annotate the CommonJS export names for ESM import in node:
|
|
248
270
|
0 && (module.exports = {
|
package/dist/core/hooks.d.cts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { M as ModelName, B as BeforeHookCallback, A as AfterHookCallback, F as FieldName, C as ColumnChangeCallback, a as ColumnChangeOptions } from '../prisma.types-
|
|
1
|
+
import { M as ModelName, B as BeforeHookCallback, o as HookOptions, A as AfterHookCallback, F as FieldName, C as ColumnChangeCallback, a as ColumnChangeOptions } from '../prisma.types-WBv5kOSl.cjs';
|
|
2
2
|
import '@prisma/client';
|
|
3
3
|
|
|
4
|
-
declare function beforeCreate<T extends ModelName>(model: T, callback: BeforeHookCallback<T
|
|
5
|
-
declare function beforeDelete<T extends ModelName>(model: T, callback: BeforeHookCallback<T
|
|
6
|
-
declare function afterCreate<T extends ModelName>(model: T, callback: AfterHookCallback<T
|
|
7
|
-
declare function afterDelete<T extends ModelName>(model: T, callback: AfterHookCallback<T
|
|
8
|
-
declare function beforeUpdate<T extends ModelName>(model: T, callback: BeforeHookCallback<T
|
|
9
|
-
declare function afterUpdate<T extends ModelName>(model: T, callback: AfterHookCallback<T
|
|
4
|
+
declare function beforeCreate<T extends ModelName>(model: T, callback: BeforeHookCallback<T>, options?: HookOptions): void;
|
|
5
|
+
declare function beforeDelete<T extends ModelName>(model: T, callback: BeforeHookCallback<T>, options?: HookOptions): void;
|
|
6
|
+
declare function afterCreate<T extends ModelName>(model: T, callback: AfterHookCallback<T>, options?: HookOptions): void;
|
|
7
|
+
declare function afterDelete<T extends ModelName>(model: T, callback: AfterHookCallback<T>, options?: HookOptions): void;
|
|
8
|
+
declare function beforeUpdate<T extends ModelName>(model: T, callback: BeforeHookCallback<T>, options?: HookOptions): void;
|
|
9
|
+
declare function afterUpdate<T extends ModelName>(model: T, callback: AfterHookCallback<T>, options?: HookOptions): void;
|
|
10
10
|
declare function afterChange<T extends ModelName>(model: T, column: FieldName<T>, callback: ColumnChangeCallback<T>, options?: ColumnChangeOptions<T>): void;
|
|
11
|
-
declare function afterUpsert<T extends ModelName>(model: T, callback: AfterHookCallback<T
|
|
11
|
+
declare function afterUpsert<T extends ModelName>(model: T, callback: AfterHookCallback<T>, options?: HookOptions): void;
|
|
12
12
|
|
|
13
13
|
export { afterChange, afterCreate, afterDelete, afterUpdate, afterUpsert, beforeCreate, beforeDelete, beforeUpdate };
|
package/dist/core/hooks.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { M as ModelName, B as BeforeHookCallback, A as AfterHookCallback, F as FieldName, C as ColumnChangeCallback, a as ColumnChangeOptions } from '../prisma.types-
|
|
1
|
+
import { M as ModelName, B as BeforeHookCallback, o as HookOptions, A as AfterHookCallback, F as FieldName, C as ColumnChangeCallback, a as ColumnChangeOptions } from '../prisma.types-WBv5kOSl.js';
|
|
2
2
|
import '@prisma/client';
|
|
3
3
|
|
|
4
|
-
declare function beforeCreate<T extends ModelName>(model: T, callback: BeforeHookCallback<T
|
|
5
|
-
declare function beforeDelete<T extends ModelName>(model: T, callback: BeforeHookCallback<T
|
|
6
|
-
declare function afterCreate<T extends ModelName>(model: T, callback: AfterHookCallback<T
|
|
7
|
-
declare function afterDelete<T extends ModelName>(model: T, callback: AfterHookCallback<T
|
|
8
|
-
declare function beforeUpdate<T extends ModelName>(model: T, callback: BeforeHookCallback<T
|
|
9
|
-
declare function afterUpdate<T extends ModelName>(model: T, callback: AfterHookCallback<T
|
|
4
|
+
declare function beforeCreate<T extends ModelName>(model: T, callback: BeforeHookCallback<T>, options?: HookOptions): void;
|
|
5
|
+
declare function beforeDelete<T extends ModelName>(model: T, callback: BeforeHookCallback<T>, options?: HookOptions): void;
|
|
6
|
+
declare function afterCreate<T extends ModelName>(model: T, callback: AfterHookCallback<T>, options?: HookOptions): void;
|
|
7
|
+
declare function afterDelete<T extends ModelName>(model: T, callback: AfterHookCallback<T>, options?: HookOptions): void;
|
|
8
|
+
declare function beforeUpdate<T extends ModelName>(model: T, callback: BeforeHookCallback<T>, options?: HookOptions): void;
|
|
9
|
+
declare function afterUpdate<T extends ModelName>(model: T, callback: AfterHookCallback<T>, options?: HookOptions): void;
|
|
10
10
|
declare function afterChange<T extends ModelName>(model: T, column: FieldName<T>, callback: ColumnChangeCallback<T>, options?: ColumnChangeOptions<T>): void;
|
|
11
|
-
declare function afterUpsert<T extends ModelName>(model: T, callback: AfterHookCallback<T
|
|
11
|
+
declare function afterUpsert<T extends ModelName>(model: T, callback: AfterHookCallback<T>, options?: HookOptions): void;
|
|
12
12
|
|
|
13
13
|
export { afterChange, afterCreate, afterDelete, afterUpdate, afterUpsert, beforeCreate, beforeDelete, beforeUpdate };
|
package/dist/core/hooks.js
CHANGED
|
@@ -38,6 +38,7 @@ var HookRegistry = class {
|
|
|
38
38
|
this.fieldCache = {};
|
|
39
39
|
this.modelsWithColumnHooks = /* @__PURE__ */ new Set();
|
|
40
40
|
this.config = { ...DEFAULT_CONFIG };
|
|
41
|
+
this.disabledTags = /* @__PURE__ */ new Set();
|
|
41
42
|
}
|
|
42
43
|
/**
|
|
43
44
|
* Configure the hook system.
|
|
@@ -64,30 +65,48 @@ var HookRegistry = class {
|
|
|
64
65
|
getConfig() {
|
|
65
66
|
return this.config;
|
|
66
67
|
}
|
|
67
|
-
addHook(model, action, timing, fn) {
|
|
68
|
+
addHook(model, action, timing, fn, tag) {
|
|
68
69
|
const key = `${model}:${action}`;
|
|
69
70
|
if (!this.hooks[timing][key]) {
|
|
70
71
|
this.hooks[timing][key] = [];
|
|
71
72
|
}
|
|
72
|
-
this.hooks[timing][key].push(fn);
|
|
73
|
+
this.hooks[timing][key].push({ callback: fn, tag });
|
|
73
74
|
}
|
|
74
75
|
addColumnHook(model, column, fn, options) {
|
|
75
76
|
const key = `${model}:${column}`;
|
|
76
77
|
if (!this.columnHooks.afterChange[key]) {
|
|
77
78
|
this.columnHooks.afterChange[key] = [];
|
|
78
79
|
}
|
|
79
|
-
this.columnHooks.afterChange[key].push({ callback: fn, options });
|
|
80
|
+
this.columnHooks.afterChange[key].push({ callback: fn, options, tag: options?.tag });
|
|
80
81
|
this.modelsWithColumnHooks.add(model);
|
|
81
82
|
delete this.fieldCache[model];
|
|
82
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Disable all hooks with the given tag.
|
|
86
|
+
* @example hookRegistry.disable('changelog');
|
|
87
|
+
*/
|
|
88
|
+
disable(tag) {
|
|
89
|
+
this.disabledTags.add(tag);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Re-enable hooks with the given tag.
|
|
93
|
+
* @example hookRegistry.enable('changelog');
|
|
94
|
+
*/
|
|
95
|
+
enable(tag) {
|
|
96
|
+
this.disabledTags.delete(tag);
|
|
97
|
+
}
|
|
98
|
+
isEnabled(tag) {
|
|
99
|
+
return !tag || !this.disabledTags.has(tag);
|
|
100
|
+
}
|
|
83
101
|
async runHooks(timing, model, action, args, prisma) {
|
|
84
102
|
const key = `${model}:${action}`;
|
|
85
|
-
const
|
|
103
|
+
const entries = this.hooks[timing]?.[key] ?? [];
|
|
104
|
+
const active = entries.filter((e) => this.isEnabled(e.tag));
|
|
86
105
|
if (timing === "after") {
|
|
87
|
-
await Promise.all(
|
|
106
|
+
await Promise.all(active.map((e) => e.callback(...args, prisma)));
|
|
88
107
|
} else {
|
|
89
|
-
for (const
|
|
90
|
-
await
|
|
108
|
+
for (const entry of active) {
|
|
109
|
+
await entry.callback(...args, prisma);
|
|
91
110
|
}
|
|
92
111
|
}
|
|
93
112
|
}
|
|
@@ -98,7 +117,9 @@ var HookRegistry = class {
|
|
|
98
117
|
const entries = this.columnHooks.afterChange[key];
|
|
99
118
|
if (entries && !valuesEqual(newData[column], prevData[column])) {
|
|
100
119
|
for (const entry of entries) {
|
|
101
|
-
|
|
120
|
+
if (this.isEnabled(entry.tag)) {
|
|
121
|
+
promises.push(entry.callback(prevData[column], newData[column], newData, prisma));
|
|
122
|
+
}
|
|
102
123
|
}
|
|
103
124
|
}
|
|
104
125
|
}
|
|
@@ -173,6 +194,7 @@ var HookRegistry = class {
|
|
|
173
194
|
this.fieldCache = {};
|
|
174
195
|
this.modelsWithColumnHooks.clear();
|
|
175
196
|
this.config = { ...DEFAULT_CONFIG };
|
|
197
|
+
this.disabledTags.clear();
|
|
176
198
|
}
|
|
177
199
|
};
|
|
178
200
|
var HOOK_REGISTRY_SYMBOL = /* @__PURE__ */ Symbol.for("prisma-flare.hookRegistry");
|
|
@@ -187,29 +209,29 @@ var hookRegistry_default = hookRegistry;
|
|
|
187
209
|
function normalizeModelName(model) {
|
|
188
210
|
return model.toLowerCase();
|
|
189
211
|
}
|
|
190
|
-
function beforeCreate(model, callback) {
|
|
191
|
-
hookRegistry_default.addHook(normalizeModelName(model), "create", "before", callback);
|
|
212
|
+
function beforeCreate(model, callback, options) {
|
|
213
|
+
hookRegistry_default.addHook(normalizeModelName(model), "create", "before", callback, options?.tag);
|
|
192
214
|
}
|
|
193
|
-
function beforeDelete(model, callback) {
|
|
194
|
-
hookRegistry_default.addHook(normalizeModelName(model), "delete", "before", callback);
|
|
215
|
+
function beforeDelete(model, callback, options) {
|
|
216
|
+
hookRegistry_default.addHook(normalizeModelName(model), "delete", "before", callback, options?.tag);
|
|
195
217
|
}
|
|
196
|
-
function afterCreate(model, callback) {
|
|
197
|
-
hookRegistry_default.addHook(normalizeModelName(model), "create", "after", callback);
|
|
218
|
+
function afterCreate(model, callback, options) {
|
|
219
|
+
hookRegistry_default.addHook(normalizeModelName(model), "create", "after", callback, options?.tag);
|
|
198
220
|
}
|
|
199
|
-
function afterDelete(model, callback) {
|
|
200
|
-
hookRegistry_default.addHook(normalizeModelName(model), "delete", "after", callback);
|
|
221
|
+
function afterDelete(model, callback, options) {
|
|
222
|
+
hookRegistry_default.addHook(normalizeModelName(model), "delete", "after", callback, options?.tag);
|
|
201
223
|
}
|
|
202
|
-
function beforeUpdate(model, callback) {
|
|
203
|
-
hookRegistry_default.addHook(normalizeModelName(model), "update", "before", callback);
|
|
224
|
+
function beforeUpdate(model, callback, options) {
|
|
225
|
+
hookRegistry_default.addHook(normalizeModelName(model), "update", "before", callback, options?.tag);
|
|
204
226
|
}
|
|
205
|
-
function afterUpdate(model, callback) {
|
|
206
|
-
hookRegistry_default.addHook(normalizeModelName(model), "update", "after", callback);
|
|
227
|
+
function afterUpdate(model, callback, options) {
|
|
228
|
+
hookRegistry_default.addHook(normalizeModelName(model), "update", "after", callback, options?.tag);
|
|
207
229
|
}
|
|
208
230
|
function afterChange(model, column, callback, options) {
|
|
209
231
|
hookRegistry_default.addColumnHook(normalizeModelName(model), column, callback, options);
|
|
210
232
|
}
|
|
211
|
-
function afterUpsert(model, callback) {
|
|
212
|
-
hookRegistry_default.addHook(normalizeModelName(model), "upsert", "after", callback);
|
|
233
|
+
function afterUpsert(model, callback, options) {
|
|
234
|
+
hookRegistry_default.addHook(normalizeModelName(model), "upsert", "after", callback, options?.tag);
|
|
213
235
|
}
|
|
214
236
|
export {
|
|
215
237
|
afterChange,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { M as ModelName, P as PrismaOperation, H as HookTiming, B as BeforeHookCallback, A as AfterHookCallback, C as ColumnChangeCallback, a as ColumnChangeOptions } from './prisma.types-
|
|
1
|
+
import { M as ModelName, P as PrismaOperation, H as HookTiming, B as BeforeHookCallback, A as AfterHookCallback, C as ColumnChangeCallback, a as ColumnChangeOptions } from './prisma.types-WBv5kOSl.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Configuration options for the hook system.
|
|
@@ -30,6 +30,7 @@ declare class HookRegistry {
|
|
|
30
30
|
private fieldCache;
|
|
31
31
|
private modelsWithColumnHooks;
|
|
32
32
|
private config;
|
|
33
|
+
private disabledTags;
|
|
33
34
|
constructor();
|
|
34
35
|
/**
|
|
35
36
|
* Configure the hook system.
|
|
@@ -52,8 +53,19 @@ declare class HookRegistry {
|
|
|
52
53
|
* Get current configuration.
|
|
53
54
|
*/
|
|
54
55
|
getConfig(): Readonly<HookConfig>;
|
|
55
|
-
addHook(model: ModelName, action: PrismaOperation, timing: HookTiming, fn: BeforeHookCallback | AfterHookCallback): void;
|
|
56
|
+
addHook(model: ModelName, action: PrismaOperation, timing: HookTiming, fn: BeforeHookCallback | AfterHookCallback, tag?: string): void;
|
|
56
57
|
addColumnHook(model: ModelName, column: string, fn: ColumnChangeCallback<any>, options?: ColumnChangeOptions<any>): void;
|
|
58
|
+
/**
|
|
59
|
+
* Disable all hooks with the given tag.
|
|
60
|
+
* @example hookRegistry.disable('changelog');
|
|
61
|
+
*/
|
|
62
|
+
disable(tag: string): void;
|
|
63
|
+
/**
|
|
64
|
+
* Re-enable hooks with the given tag.
|
|
65
|
+
* @example hookRegistry.enable('changelog');
|
|
66
|
+
*/
|
|
67
|
+
enable(tag: string): void;
|
|
68
|
+
private isEnabled;
|
|
57
69
|
runHooks(timing: HookTiming, model: ModelName, action: PrismaOperation, args: any[], prisma: any): Promise<void>;
|
|
58
70
|
runColumnHooks(model: ModelName, newData: any, prevData: any, prisma: any): Promise<void>;
|
|
59
71
|
hasColumnHooks(model: ModelName): boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { M as ModelName, P as PrismaOperation, H as HookTiming, B as BeforeHookCallback, A as AfterHookCallback, C as ColumnChangeCallback, a as ColumnChangeOptions } from './prisma.types-
|
|
1
|
+
import { M as ModelName, P as PrismaOperation, H as HookTiming, B as BeforeHookCallback, A as AfterHookCallback, C as ColumnChangeCallback, a as ColumnChangeOptions } from './prisma.types-WBv5kOSl.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Configuration options for the hook system.
|
|
@@ -30,6 +30,7 @@ declare class HookRegistry {
|
|
|
30
30
|
private fieldCache;
|
|
31
31
|
private modelsWithColumnHooks;
|
|
32
32
|
private config;
|
|
33
|
+
private disabledTags;
|
|
33
34
|
constructor();
|
|
34
35
|
/**
|
|
35
36
|
* Configure the hook system.
|
|
@@ -52,8 +53,19 @@ declare class HookRegistry {
|
|
|
52
53
|
* Get current configuration.
|
|
53
54
|
*/
|
|
54
55
|
getConfig(): Readonly<HookConfig>;
|
|
55
|
-
addHook(model: ModelName, action: PrismaOperation, timing: HookTiming, fn: BeforeHookCallback | AfterHookCallback): void;
|
|
56
|
+
addHook(model: ModelName, action: PrismaOperation, timing: HookTiming, fn: BeforeHookCallback | AfterHookCallback, tag?: string): void;
|
|
56
57
|
addColumnHook(model: ModelName, column: string, fn: ColumnChangeCallback<any>, options?: ColumnChangeOptions<any>): void;
|
|
58
|
+
/**
|
|
59
|
+
* Disable all hooks with the given tag.
|
|
60
|
+
* @example hookRegistry.disable('changelog');
|
|
61
|
+
*/
|
|
62
|
+
disable(tag: string): void;
|
|
63
|
+
/**
|
|
64
|
+
* Re-enable hooks with the given tag.
|
|
65
|
+
* @example hookRegistry.enable('changelog');
|
|
66
|
+
*/
|
|
67
|
+
enable(tag: string): void;
|
|
68
|
+
private isEnabled;
|
|
57
69
|
runHooks(timing: HookTiming, model: ModelName, action: PrismaOperation, args: any[], prisma: any): Promise<void>;
|
|
58
70
|
runColumnHooks(model: ModelName, newData: any, prevData: any, prisma: any): Promise<void>;
|
|
59
71
|
hasColumnHooks(model: ModelName): boolean;
|
package/dist/hooks.cjs
CHANGED
|
@@ -72,6 +72,7 @@ var HookRegistry = class {
|
|
|
72
72
|
this.fieldCache = {};
|
|
73
73
|
this.modelsWithColumnHooks = /* @__PURE__ */ new Set();
|
|
74
74
|
this.config = { ...DEFAULT_CONFIG };
|
|
75
|
+
this.disabledTags = /* @__PURE__ */ new Set();
|
|
75
76
|
}
|
|
76
77
|
/**
|
|
77
78
|
* Configure the hook system.
|
|
@@ -98,30 +99,48 @@ var HookRegistry = class {
|
|
|
98
99
|
getConfig() {
|
|
99
100
|
return this.config;
|
|
100
101
|
}
|
|
101
|
-
addHook(model, action, timing, fn) {
|
|
102
|
+
addHook(model, action, timing, fn, tag) {
|
|
102
103
|
const key = `${model}:${action}`;
|
|
103
104
|
if (!this.hooks[timing][key]) {
|
|
104
105
|
this.hooks[timing][key] = [];
|
|
105
106
|
}
|
|
106
|
-
this.hooks[timing][key].push(fn);
|
|
107
|
+
this.hooks[timing][key].push({ callback: fn, tag });
|
|
107
108
|
}
|
|
108
109
|
addColumnHook(model, column, fn, options) {
|
|
109
110
|
const key = `${model}:${column}`;
|
|
110
111
|
if (!this.columnHooks.afterChange[key]) {
|
|
111
112
|
this.columnHooks.afterChange[key] = [];
|
|
112
113
|
}
|
|
113
|
-
this.columnHooks.afterChange[key].push({ callback: fn, options });
|
|
114
|
+
this.columnHooks.afterChange[key].push({ callback: fn, options, tag: options?.tag });
|
|
114
115
|
this.modelsWithColumnHooks.add(model);
|
|
115
116
|
delete this.fieldCache[model];
|
|
116
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Disable all hooks with the given tag.
|
|
120
|
+
* @example hookRegistry.disable('changelog');
|
|
121
|
+
*/
|
|
122
|
+
disable(tag) {
|
|
123
|
+
this.disabledTags.add(tag);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Re-enable hooks with the given tag.
|
|
127
|
+
* @example hookRegistry.enable('changelog');
|
|
128
|
+
*/
|
|
129
|
+
enable(tag) {
|
|
130
|
+
this.disabledTags.delete(tag);
|
|
131
|
+
}
|
|
132
|
+
isEnabled(tag) {
|
|
133
|
+
return !tag || !this.disabledTags.has(tag);
|
|
134
|
+
}
|
|
117
135
|
async runHooks(timing, model, action, args, prisma) {
|
|
118
136
|
const key = `${model}:${action}`;
|
|
119
|
-
const
|
|
137
|
+
const entries = this.hooks[timing]?.[key] ?? [];
|
|
138
|
+
const active = entries.filter((e) => this.isEnabled(e.tag));
|
|
120
139
|
if (timing === "after") {
|
|
121
|
-
await Promise.all(
|
|
140
|
+
await Promise.all(active.map((e) => e.callback(...args, prisma)));
|
|
122
141
|
} else {
|
|
123
|
-
for (const
|
|
124
|
-
await
|
|
142
|
+
for (const entry of active) {
|
|
143
|
+
await entry.callback(...args, prisma);
|
|
125
144
|
}
|
|
126
145
|
}
|
|
127
146
|
}
|
|
@@ -132,7 +151,9 @@ var HookRegistry = class {
|
|
|
132
151
|
const entries = this.columnHooks.afterChange[key];
|
|
133
152
|
if (entries && !valuesEqual(newData[column], prevData[column])) {
|
|
134
153
|
for (const entry of entries) {
|
|
135
|
-
|
|
154
|
+
if (this.isEnabled(entry.tag)) {
|
|
155
|
+
promises.push(entry.callback(prevData[column], newData[column], newData, prisma));
|
|
156
|
+
}
|
|
136
157
|
}
|
|
137
158
|
}
|
|
138
159
|
}
|
|
@@ -207,6 +228,7 @@ var HookRegistry = class {
|
|
|
207
228
|
this.fieldCache = {};
|
|
208
229
|
this.modelsWithColumnHooks.clear();
|
|
209
230
|
this.config = { ...DEFAULT_CONFIG };
|
|
231
|
+
this.disabledTags.clear();
|
|
210
232
|
}
|
|
211
233
|
};
|
|
212
234
|
var HOOK_REGISTRY_SYMBOL = /* @__PURE__ */ Symbol.for("prisma-flare.hookRegistry");
|
|
@@ -221,29 +243,29 @@ var hookRegistry_default = hookRegistry;
|
|
|
221
243
|
function normalizeModelName(model) {
|
|
222
244
|
return model.toLowerCase();
|
|
223
245
|
}
|
|
224
|
-
function beforeCreate(model, callback) {
|
|
225
|
-
hookRegistry_default.addHook(normalizeModelName(model), "create", "before", callback);
|
|
246
|
+
function beforeCreate(model, callback, options) {
|
|
247
|
+
hookRegistry_default.addHook(normalizeModelName(model), "create", "before", callback, options?.tag);
|
|
226
248
|
}
|
|
227
|
-
function beforeDelete(model, callback) {
|
|
228
|
-
hookRegistry_default.addHook(normalizeModelName(model), "delete", "before", callback);
|
|
249
|
+
function beforeDelete(model, callback, options) {
|
|
250
|
+
hookRegistry_default.addHook(normalizeModelName(model), "delete", "before", callback, options?.tag);
|
|
229
251
|
}
|
|
230
|
-
function afterCreate(model, callback) {
|
|
231
|
-
hookRegistry_default.addHook(normalizeModelName(model), "create", "after", callback);
|
|
252
|
+
function afterCreate(model, callback, options) {
|
|
253
|
+
hookRegistry_default.addHook(normalizeModelName(model), "create", "after", callback, options?.tag);
|
|
232
254
|
}
|
|
233
|
-
function afterDelete(model, callback) {
|
|
234
|
-
hookRegistry_default.addHook(normalizeModelName(model), "delete", "after", callback);
|
|
255
|
+
function afterDelete(model, callback, options) {
|
|
256
|
+
hookRegistry_default.addHook(normalizeModelName(model), "delete", "after", callback, options?.tag);
|
|
235
257
|
}
|
|
236
|
-
function beforeUpdate(model, callback) {
|
|
237
|
-
hookRegistry_default.addHook(normalizeModelName(model), "update", "before", callback);
|
|
258
|
+
function beforeUpdate(model, callback, options) {
|
|
259
|
+
hookRegistry_default.addHook(normalizeModelName(model), "update", "before", callback, options?.tag);
|
|
238
260
|
}
|
|
239
|
-
function afterUpdate(model, callback) {
|
|
240
|
-
hookRegistry_default.addHook(normalizeModelName(model), "update", "after", callback);
|
|
261
|
+
function afterUpdate(model, callback, options) {
|
|
262
|
+
hookRegistry_default.addHook(normalizeModelName(model), "update", "after", callback, options?.tag);
|
|
241
263
|
}
|
|
242
264
|
function afterChange(model, column, callback, options) {
|
|
243
265
|
hookRegistry_default.addColumnHook(normalizeModelName(model), column, callback, options);
|
|
244
266
|
}
|
|
245
|
-
function afterUpsert(model, callback) {
|
|
246
|
-
hookRegistry_default.addHook(normalizeModelName(model), "upsert", "after", callback);
|
|
267
|
+
function afterUpsert(model, callback, options) {
|
|
268
|
+
hookRegistry_default.addHook(normalizeModelName(model), "upsert", "after", callback, options?.tag);
|
|
247
269
|
}
|
|
248
270
|
// Annotate the CommonJS export names for ESM import in node:
|
|
249
271
|
0 && (module.exports = {
|