prisma-flare 1.3.1 → 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 +106 -36
- package/dist/cli/db-migrate.js +112 -36
- package/dist/cli/db-reset.cjs +106 -36
- package/dist/cli/db-reset.js +112 -36
- package/dist/cli/index.cjs +106 -36
- package/dist/cli/index.js +112 -36
- package/dist/core/flareBuilder.d.cts +5 -5
- package/dist/core/flareBuilder.d.ts +5 -5
- 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 +1 -1
package/dist/cli/index.cjs
CHANGED
|
@@ -230,11 +230,32 @@ function getPrismaProvider(rootDir) {
|
|
|
230
230
|
}
|
|
231
231
|
function parseModelRelations(schemaContent) {
|
|
232
232
|
const models = [];
|
|
233
|
-
const
|
|
233
|
+
const modelStartRegex = /model\s+(\w+)\s*\{/g;
|
|
234
234
|
let modelMatch;
|
|
235
|
-
while ((modelMatch =
|
|
235
|
+
while ((modelMatch = modelStartRegex.exec(schemaContent)) !== null) {
|
|
236
236
|
const modelName = modelMatch[1];
|
|
237
|
-
const
|
|
237
|
+
const bodyStart = modelMatch.index + modelMatch[0].length;
|
|
238
|
+
let depth = 1;
|
|
239
|
+
let i = bodyStart;
|
|
240
|
+
let inString = false;
|
|
241
|
+
let stringChar = "";
|
|
242
|
+
while (i < schemaContent.length && depth > 0) {
|
|
243
|
+
const ch = schemaContent[i];
|
|
244
|
+
if (inString) {
|
|
245
|
+
if (ch === stringChar && schemaContent[i - 1] !== "\\") inString = false;
|
|
246
|
+
} else {
|
|
247
|
+
if (ch === '"' || ch === "'") {
|
|
248
|
+
inString = true;
|
|
249
|
+
stringChar = ch;
|
|
250
|
+
} else if (ch === "{") {
|
|
251
|
+
depth++;
|
|
252
|
+
} else if (ch === "}") {
|
|
253
|
+
depth--;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
i++;
|
|
257
|
+
}
|
|
258
|
+
const modelBody = schemaContent.slice(bodyStart, i - 1);
|
|
238
259
|
const relations = [];
|
|
239
260
|
const lines = modelBody.split("\n");
|
|
240
261
|
for (const line of lines) {
|
|
@@ -294,13 +315,33 @@ ${entries.join(",\n")}
|
|
|
294
315
|
};`;
|
|
295
316
|
}
|
|
296
317
|
function getRelationModelMap(rootDir) {
|
|
318
|
+
const dmmfResult = getRelationModelMapFromDMMF(rootDir);
|
|
319
|
+
if (dmmfResult) return dmmfResult;
|
|
297
320
|
const resolution = resolveSchemaPath(rootDir);
|
|
298
|
-
if (!resolution)
|
|
299
|
-
return null;
|
|
300
|
-
}
|
|
321
|
+
if (!resolution) return null;
|
|
301
322
|
const models = parseModelRelations(resolution.content);
|
|
302
323
|
return generateRelationModelMap(models);
|
|
303
324
|
}
|
|
325
|
+
function getRelationModelMapFromDMMF(rootDir) {
|
|
326
|
+
try {
|
|
327
|
+
const clientPath = getPrismaClientPath(rootDir);
|
|
328
|
+
const resolvedPath = clientPath.startsWith("/") ? clientPath : require.resolve(clientPath, { paths: [rootDir] });
|
|
329
|
+
const prismaModule = require(resolvedPath);
|
|
330
|
+
const dmmf = prismaModule?.Prisma?.dmmf ?? prismaModule?.dmmf;
|
|
331
|
+
if (!dmmf?.datamodel?.models) return null;
|
|
332
|
+
const models = dmmf.datamodel.models.map((model) => ({
|
|
333
|
+
name: model.name,
|
|
334
|
+
relations: model.fields.filter((f) => f.kind === "object").map((f) => ({
|
|
335
|
+
fieldName: f.name,
|
|
336
|
+
targetModel: f.type,
|
|
337
|
+
isArray: f.isList
|
|
338
|
+
}))
|
|
339
|
+
}));
|
|
340
|
+
return generateRelationModelMap(models);
|
|
341
|
+
} catch {
|
|
342
|
+
return null;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
304
345
|
|
|
305
346
|
// src/cli/generate-queries.ts
|
|
306
347
|
function toCamelCase(str) {
|
|
@@ -811,6 +852,11 @@ ${exportKeyword}type ColumnChangeCallback<T extends ModelName = ModelName> = (
|
|
|
811
852
|
/**
|
|
812
853
|
* Options for column change hooks (afterChange)
|
|
813
854
|
*/
|
|
855
|
+
${exportKeyword}interface HookOptions {
|
|
856
|
+
/** Tag to group hooks. Tagged hooks can be disabled/enabled via hookRegistry.disable(tag)/enable(tag). */
|
|
857
|
+
tag?: string;
|
|
858
|
+
}
|
|
859
|
+
|
|
814
860
|
${exportKeyword}interface ColumnChangeOptions<T extends ModelName = ModelName> {
|
|
815
861
|
/**
|
|
816
862
|
* Additional fields to include when fetching records for this hook.
|
|
@@ -818,6 +864,8 @@ ${exportKeyword}interface ColumnChangeOptions<T extends ModelName = ModelName> {
|
|
|
818
864
|
* Use this when your callback needs access to other fields.
|
|
819
865
|
*/
|
|
820
866
|
includeFields?: FieldName<T>[];
|
|
867
|
+
/** Tag to group hooks. Tagged hooks can be disabled/enabled via hookRegistry.disable(tag)/enable(tag). */
|
|
868
|
+
tag?: string;
|
|
821
869
|
}
|
|
822
870
|
`.trimStart();
|
|
823
871
|
}
|
|
@@ -985,7 +1033,7 @@ var FLARE_BUILDER_METHODS = {
|
|
|
985
1033
|
pagination: [
|
|
986
1034
|
{
|
|
987
1035
|
name: "paginate",
|
|
988
|
-
signature:
|
|
1036
|
+
signature: (ns, useFlareResult) => useFlareResult ? `(page?: number, perPage?: number): Promise<PaginatedResult<FlareResult<T, Args>>>` : `(page?: number, perPage?: number): Promise<PaginatedResult<${ns}.Result<ModelDelegate<T>, Args, 'findFirstOrThrow'>>>`
|
|
989
1037
|
}
|
|
990
1038
|
],
|
|
991
1039
|
existence: [
|
|
@@ -1001,7 +1049,7 @@ var FLARE_BUILDER_METHODS = {
|
|
|
1001
1049
|
},
|
|
1002
1050
|
{
|
|
1003
1051
|
name: "chunk",
|
|
1004
|
-
signature:
|
|
1052
|
+
signature: (ns, useFlareResult) => useFlareResult ? `(size: number, callback: (results: FlareResultMany<T, Args>) => Promise<void> | void): Promise<void>` : `(size: number, callback: (results: ${ns}.Result<ModelDelegate<T>, Args, 'findMany'>) => Promise<void> | void): Promise<void>`
|
|
1005
1053
|
},
|
|
1006
1054
|
{
|
|
1007
1055
|
name: "clone",
|
|
@@ -1200,9 +1248,10 @@ import {
|
|
|
1200
1248
|
*/
|
|
1201
1249
|
export function beforeCreate<T extends ModelName>(
|
|
1202
1250
|
model: T,
|
|
1203
|
-
callback: BeforeHookCallback<T
|
|
1251
|
+
callback: BeforeHookCallback<T>,
|
|
1252
|
+
options?: HookOptions
|
|
1204
1253
|
): void {
|
|
1205
|
-
_beforeCreate(model as any, callback as any);
|
|
1254
|
+
_beforeCreate(model as any, callback as any, options);
|
|
1206
1255
|
}
|
|
1207
1256
|
|
|
1208
1257
|
/**
|
|
@@ -1210,9 +1259,10 @@ export function beforeCreate<T extends ModelName>(
|
|
|
1210
1259
|
*/
|
|
1211
1260
|
export function afterCreate<T extends ModelName>(
|
|
1212
1261
|
model: T,
|
|
1213
|
-
callback: AfterHookCallback<T
|
|
1262
|
+
callback: AfterHookCallback<T>,
|
|
1263
|
+
options?: HookOptions
|
|
1214
1264
|
): void {
|
|
1215
|
-
_afterCreate(model as any, callback as any);
|
|
1265
|
+
_afterCreate(model as any, callback as any, options);
|
|
1216
1266
|
}
|
|
1217
1267
|
|
|
1218
1268
|
/**
|
|
@@ -1220,9 +1270,10 @@ export function afterCreate<T extends ModelName>(
|
|
|
1220
1270
|
*/
|
|
1221
1271
|
export function beforeUpdate<T extends ModelName>(
|
|
1222
1272
|
model: T,
|
|
1223
|
-
callback: BeforeHookCallback<T
|
|
1273
|
+
callback: BeforeHookCallback<T>,
|
|
1274
|
+
options?: HookOptions
|
|
1224
1275
|
): void {
|
|
1225
|
-
_beforeUpdate(model as any, callback as any);
|
|
1276
|
+
_beforeUpdate(model as any, callback as any, options);
|
|
1226
1277
|
}
|
|
1227
1278
|
|
|
1228
1279
|
/**
|
|
@@ -1230,9 +1281,10 @@ export function beforeUpdate<T extends ModelName>(
|
|
|
1230
1281
|
*/
|
|
1231
1282
|
export function afterUpdate<T extends ModelName>(
|
|
1232
1283
|
model: T,
|
|
1233
|
-
callback: AfterHookCallback<T
|
|
1284
|
+
callback: AfterHookCallback<T>,
|
|
1285
|
+
options?: HookOptions
|
|
1234
1286
|
): void {
|
|
1235
|
-
_afterUpdate(model as any, callback as any);
|
|
1287
|
+
_afterUpdate(model as any, callback as any, options);
|
|
1236
1288
|
}
|
|
1237
1289
|
|
|
1238
1290
|
/**
|
|
@@ -1240,9 +1292,10 @@ export function afterUpdate<T extends ModelName>(
|
|
|
1240
1292
|
*/
|
|
1241
1293
|
export function beforeDelete<T extends ModelName>(
|
|
1242
1294
|
model: T,
|
|
1243
|
-
callback: BeforeHookCallback<T
|
|
1295
|
+
callback: BeforeHookCallback<T>,
|
|
1296
|
+
options?: HookOptions
|
|
1244
1297
|
): void {
|
|
1245
|
-
_beforeDelete(model as any, callback as any);
|
|
1298
|
+
_beforeDelete(model as any, callback as any, options);
|
|
1246
1299
|
}
|
|
1247
1300
|
|
|
1248
1301
|
/**
|
|
@@ -1250,9 +1303,10 @@ export function beforeDelete<T extends ModelName>(
|
|
|
1250
1303
|
*/
|
|
1251
1304
|
export function afterDelete<T extends ModelName>(
|
|
1252
1305
|
model: T,
|
|
1253
|
-
callback: AfterHookCallback<T
|
|
1306
|
+
callback: AfterHookCallback<T>,
|
|
1307
|
+
options?: HookOptions
|
|
1254
1308
|
): void {
|
|
1255
|
-
_afterDelete(model as any, callback as any);
|
|
1309
|
+
_afterDelete(model as any, callback as any, options);
|
|
1256
1310
|
}
|
|
1257
1311
|
|
|
1258
1312
|
/**
|
|
@@ -1272,9 +1326,10 @@ export function afterChange<T extends ModelName>(
|
|
|
1272
1326
|
*/
|
|
1273
1327
|
export function afterUpsert<T extends ModelName>(
|
|
1274
1328
|
model: T,
|
|
1275
|
-
callback: AfterHookCallback<T
|
|
1329
|
+
callback: AfterHookCallback<T>,
|
|
1330
|
+
options?: HookOptions
|
|
1276
1331
|
): void {
|
|
1277
|
-
_afterUpsert(model as any, callback as any);
|
|
1332
|
+
_afterUpsert(model as any, callback as any, options);
|
|
1278
1333
|
}
|
|
1279
1334
|
|
|
1280
1335
|
// Re-export hookRegistry for advanced use cases
|
|
@@ -1354,7 +1409,8 @@ import {
|
|
|
1354
1409
|
*/
|
|
1355
1410
|
export declare function beforeCreate<T extends ModelName>(
|
|
1356
1411
|
model: T,
|
|
1357
|
-
callback: BeforeHookCallback<T
|
|
1412
|
+
callback: BeforeHookCallback<T>,
|
|
1413
|
+
options?: HookOptions
|
|
1358
1414
|
): void;
|
|
1359
1415
|
|
|
1360
1416
|
/**
|
|
@@ -1362,7 +1418,8 @@ export declare function beforeCreate<T extends ModelName>(
|
|
|
1362
1418
|
*/
|
|
1363
1419
|
export declare function afterCreate<T extends ModelName>(
|
|
1364
1420
|
model: T,
|
|
1365
|
-
callback: AfterHookCallback<T
|
|
1421
|
+
callback: AfterHookCallback<T>,
|
|
1422
|
+
options?: HookOptions
|
|
1366
1423
|
): void;
|
|
1367
1424
|
|
|
1368
1425
|
/**
|
|
@@ -1370,7 +1427,8 @@ export declare function afterCreate<T extends ModelName>(
|
|
|
1370
1427
|
*/
|
|
1371
1428
|
export declare function beforeUpdate<T extends ModelName>(
|
|
1372
1429
|
model: T,
|
|
1373
|
-
callback: BeforeHookCallback<T
|
|
1430
|
+
callback: BeforeHookCallback<T>,
|
|
1431
|
+
options?: HookOptions
|
|
1374
1432
|
): void;
|
|
1375
1433
|
|
|
1376
1434
|
/**
|
|
@@ -1378,7 +1436,8 @@ export declare function beforeUpdate<T extends ModelName>(
|
|
|
1378
1436
|
*/
|
|
1379
1437
|
export declare function afterUpdate<T extends ModelName>(
|
|
1380
1438
|
model: T,
|
|
1381
|
-
callback: AfterHookCallback<T
|
|
1439
|
+
callback: AfterHookCallback<T>,
|
|
1440
|
+
options?: HookOptions
|
|
1382
1441
|
): void;
|
|
1383
1442
|
|
|
1384
1443
|
/**
|
|
@@ -1386,7 +1445,8 @@ export declare function afterUpdate<T extends ModelName>(
|
|
|
1386
1445
|
*/
|
|
1387
1446
|
export declare function beforeDelete<T extends ModelName>(
|
|
1388
1447
|
model: T,
|
|
1389
|
-
callback: BeforeHookCallback<T
|
|
1448
|
+
callback: BeforeHookCallback<T>,
|
|
1449
|
+
options?: HookOptions
|
|
1390
1450
|
): void;
|
|
1391
1451
|
|
|
1392
1452
|
/**
|
|
@@ -1394,7 +1454,8 @@ export declare function beforeDelete<T extends ModelName>(
|
|
|
1394
1454
|
*/
|
|
1395
1455
|
export declare function afterDelete<T extends ModelName>(
|
|
1396
1456
|
model: T,
|
|
1397
|
-
callback: AfterHookCallback<T
|
|
1457
|
+
callback: AfterHookCallback<T>,
|
|
1458
|
+
options?: HookOptions
|
|
1398
1459
|
): void;
|
|
1399
1460
|
|
|
1400
1461
|
/**
|
|
@@ -1412,7 +1473,8 @@ export declare function afterChange<T extends ModelName>(
|
|
|
1412
1473
|
*/
|
|
1413
1474
|
export declare function afterUpsert<T extends ModelName>(
|
|
1414
1475
|
model: T,
|
|
1415
|
-
callback: AfterHookCallback<T
|
|
1476
|
+
callback: AfterHookCallback<T>,
|
|
1477
|
+
options?: HookOptions
|
|
1416
1478
|
): void;
|
|
1417
1479
|
|
|
1418
1480
|
// Re-export hookRegistry for advanced use cases
|
|
@@ -1536,6 +1598,7 @@ import type {
|
|
|
1536
1598
|
AfterHookCallback,
|
|
1537
1599
|
ColumnChangeCallback,
|
|
1538
1600
|
ColumnChangeOptions,
|
|
1601
|
+
HookOptions,
|
|
1539
1602
|
FieldName,
|
|
1540
1603
|
HookConfig
|
|
1541
1604
|
} from 'prisma-flare';
|
|
@@ -1584,7 +1647,8 @@ export declare class FlareClient extends BasePrismaClient {
|
|
|
1584
1647
|
*/
|
|
1585
1648
|
export declare function beforeCreate<T extends ModelName>(
|
|
1586
1649
|
model: T,
|
|
1587
|
-
callback: BeforeHookCallback<T
|
|
1650
|
+
callback: BeforeHookCallback<T>,
|
|
1651
|
+
options?: HookOptions
|
|
1588
1652
|
): void;
|
|
1589
1653
|
|
|
1590
1654
|
/**
|
|
@@ -1592,7 +1656,8 @@ export declare function beforeCreate<T extends ModelName>(
|
|
|
1592
1656
|
*/
|
|
1593
1657
|
export declare function afterCreate<T extends ModelName>(
|
|
1594
1658
|
model: T,
|
|
1595
|
-
callback: AfterHookCallback<T
|
|
1659
|
+
callback: AfterHookCallback<T>,
|
|
1660
|
+
options?: HookOptions
|
|
1596
1661
|
): void;
|
|
1597
1662
|
|
|
1598
1663
|
/**
|
|
@@ -1600,7 +1665,8 @@ export declare function afterCreate<T extends ModelName>(
|
|
|
1600
1665
|
*/
|
|
1601
1666
|
export declare function beforeUpdate<T extends ModelName>(
|
|
1602
1667
|
model: T,
|
|
1603
|
-
callback: BeforeHookCallback<T
|
|
1668
|
+
callback: BeforeHookCallback<T>,
|
|
1669
|
+
options?: HookOptions
|
|
1604
1670
|
): void;
|
|
1605
1671
|
|
|
1606
1672
|
/**
|
|
@@ -1608,7 +1674,8 @@ export declare function beforeUpdate<T extends ModelName>(
|
|
|
1608
1674
|
*/
|
|
1609
1675
|
export declare function afterUpdate<T extends ModelName>(
|
|
1610
1676
|
model: T,
|
|
1611
|
-
callback: AfterHookCallback<T
|
|
1677
|
+
callback: AfterHookCallback<T>,
|
|
1678
|
+
options?: HookOptions
|
|
1612
1679
|
): void;
|
|
1613
1680
|
|
|
1614
1681
|
/**
|
|
@@ -1616,7 +1683,8 @@ export declare function afterUpdate<T extends ModelName>(
|
|
|
1616
1683
|
*/
|
|
1617
1684
|
export declare function beforeDelete<T extends ModelName>(
|
|
1618
1685
|
model: T,
|
|
1619
|
-
callback: BeforeHookCallback<T
|
|
1686
|
+
callback: BeforeHookCallback<T>,
|
|
1687
|
+
options?: HookOptions
|
|
1620
1688
|
): void;
|
|
1621
1689
|
|
|
1622
1690
|
/**
|
|
@@ -1624,7 +1692,8 @@ export declare function beforeDelete<T extends ModelName>(
|
|
|
1624
1692
|
*/
|
|
1625
1693
|
export declare function afterDelete<T extends ModelName>(
|
|
1626
1694
|
model: T,
|
|
1627
|
-
callback: AfterHookCallback<T
|
|
1695
|
+
callback: AfterHookCallback<T>,
|
|
1696
|
+
options?: HookOptions
|
|
1628
1697
|
): void;
|
|
1629
1698
|
|
|
1630
1699
|
/**
|
|
@@ -1642,7 +1711,8 @@ export declare function afterChange<T extends ModelName>(
|
|
|
1642
1711
|
*/
|
|
1643
1712
|
export declare function afterUpsert<T extends ModelName>(
|
|
1644
1713
|
model: T,
|
|
1645
|
-
callback: AfterHookCallback<T
|
|
1714
|
+
callback: AfterHookCallback<T>,
|
|
1715
|
+
options?: HookOptions
|
|
1646
1716
|
): void;
|
|
1647
1717
|
|
|
1648
1718
|
// Re-export hookRegistry for advanced use cases
|
package/dist/cli/index.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
3
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
4
|
+
}) : x)(function(x) {
|
|
5
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
6
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
+
});
|
|
2
8
|
|
|
3
9
|
// src/cli/generate-queries.ts
|
|
4
10
|
import * as fs3 from "fs";
|
|
@@ -207,11 +213,32 @@ function getPrismaProvider(rootDir) {
|
|
|
207
213
|
}
|
|
208
214
|
function parseModelRelations(schemaContent) {
|
|
209
215
|
const models = [];
|
|
210
|
-
const
|
|
216
|
+
const modelStartRegex = /model\s+(\w+)\s*\{/g;
|
|
211
217
|
let modelMatch;
|
|
212
|
-
while ((modelMatch =
|
|
218
|
+
while ((modelMatch = modelStartRegex.exec(schemaContent)) !== null) {
|
|
213
219
|
const modelName = modelMatch[1];
|
|
214
|
-
const
|
|
220
|
+
const bodyStart = modelMatch.index + modelMatch[0].length;
|
|
221
|
+
let depth = 1;
|
|
222
|
+
let i = bodyStart;
|
|
223
|
+
let inString = false;
|
|
224
|
+
let stringChar = "";
|
|
225
|
+
while (i < schemaContent.length && depth > 0) {
|
|
226
|
+
const ch = schemaContent[i];
|
|
227
|
+
if (inString) {
|
|
228
|
+
if (ch === stringChar && schemaContent[i - 1] !== "\\") inString = false;
|
|
229
|
+
} else {
|
|
230
|
+
if (ch === '"' || ch === "'") {
|
|
231
|
+
inString = true;
|
|
232
|
+
stringChar = ch;
|
|
233
|
+
} else if (ch === "{") {
|
|
234
|
+
depth++;
|
|
235
|
+
} else if (ch === "}") {
|
|
236
|
+
depth--;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
i++;
|
|
240
|
+
}
|
|
241
|
+
const modelBody = schemaContent.slice(bodyStart, i - 1);
|
|
215
242
|
const relations = [];
|
|
216
243
|
const lines = modelBody.split("\n");
|
|
217
244
|
for (const line of lines) {
|
|
@@ -271,13 +298,33 @@ ${entries.join(",\n")}
|
|
|
271
298
|
};`;
|
|
272
299
|
}
|
|
273
300
|
function getRelationModelMap(rootDir) {
|
|
301
|
+
const dmmfResult = getRelationModelMapFromDMMF(rootDir);
|
|
302
|
+
if (dmmfResult) return dmmfResult;
|
|
274
303
|
const resolution = resolveSchemaPath(rootDir);
|
|
275
|
-
if (!resolution)
|
|
276
|
-
return null;
|
|
277
|
-
}
|
|
304
|
+
if (!resolution) return null;
|
|
278
305
|
const models = parseModelRelations(resolution.content);
|
|
279
306
|
return generateRelationModelMap(models);
|
|
280
307
|
}
|
|
308
|
+
function getRelationModelMapFromDMMF(rootDir) {
|
|
309
|
+
try {
|
|
310
|
+
const clientPath = getPrismaClientPath(rootDir);
|
|
311
|
+
const resolvedPath = clientPath.startsWith("/") ? clientPath : __require.resolve(clientPath, { paths: [rootDir] });
|
|
312
|
+
const prismaModule = __require(resolvedPath);
|
|
313
|
+
const dmmf = prismaModule?.Prisma?.dmmf ?? prismaModule?.dmmf;
|
|
314
|
+
if (!dmmf?.datamodel?.models) return null;
|
|
315
|
+
const models = dmmf.datamodel.models.map((model) => ({
|
|
316
|
+
name: model.name,
|
|
317
|
+
relations: model.fields.filter((f) => f.kind === "object").map((f) => ({
|
|
318
|
+
fieldName: f.name,
|
|
319
|
+
targetModel: f.type,
|
|
320
|
+
isArray: f.isList
|
|
321
|
+
}))
|
|
322
|
+
}));
|
|
323
|
+
return generateRelationModelMap(models);
|
|
324
|
+
} catch {
|
|
325
|
+
return null;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
281
328
|
|
|
282
329
|
// src/cli/generate-queries.ts
|
|
283
330
|
function toCamelCase(str) {
|
|
@@ -788,6 +835,11 @@ ${exportKeyword}type ColumnChangeCallback<T extends ModelName = ModelName> = (
|
|
|
788
835
|
/**
|
|
789
836
|
* Options for column change hooks (afterChange)
|
|
790
837
|
*/
|
|
838
|
+
${exportKeyword}interface HookOptions {
|
|
839
|
+
/** Tag to group hooks. Tagged hooks can be disabled/enabled via hookRegistry.disable(tag)/enable(tag). */
|
|
840
|
+
tag?: string;
|
|
841
|
+
}
|
|
842
|
+
|
|
791
843
|
${exportKeyword}interface ColumnChangeOptions<T extends ModelName = ModelName> {
|
|
792
844
|
/**
|
|
793
845
|
* Additional fields to include when fetching records for this hook.
|
|
@@ -795,6 +847,8 @@ ${exportKeyword}interface ColumnChangeOptions<T extends ModelName = ModelName> {
|
|
|
795
847
|
* Use this when your callback needs access to other fields.
|
|
796
848
|
*/
|
|
797
849
|
includeFields?: FieldName<T>[];
|
|
850
|
+
/** Tag to group hooks. Tagged hooks can be disabled/enabled via hookRegistry.disable(tag)/enable(tag). */
|
|
851
|
+
tag?: string;
|
|
798
852
|
}
|
|
799
853
|
`.trimStart();
|
|
800
854
|
}
|
|
@@ -962,7 +1016,7 @@ var FLARE_BUILDER_METHODS = {
|
|
|
962
1016
|
pagination: [
|
|
963
1017
|
{
|
|
964
1018
|
name: "paginate",
|
|
965
|
-
signature:
|
|
1019
|
+
signature: (ns, useFlareResult) => useFlareResult ? `(page?: number, perPage?: number): Promise<PaginatedResult<FlareResult<T, Args>>>` : `(page?: number, perPage?: number): Promise<PaginatedResult<${ns}.Result<ModelDelegate<T>, Args, 'findFirstOrThrow'>>>`
|
|
966
1020
|
}
|
|
967
1021
|
],
|
|
968
1022
|
existence: [
|
|
@@ -978,7 +1032,7 @@ var FLARE_BUILDER_METHODS = {
|
|
|
978
1032
|
},
|
|
979
1033
|
{
|
|
980
1034
|
name: "chunk",
|
|
981
|
-
signature:
|
|
1035
|
+
signature: (ns, useFlareResult) => useFlareResult ? `(size: number, callback: (results: FlareResultMany<T, Args>) => Promise<void> | void): Promise<void>` : `(size: number, callback: (results: ${ns}.Result<ModelDelegate<T>, Args, 'findMany'>) => Promise<void> | void): Promise<void>`
|
|
982
1036
|
},
|
|
983
1037
|
{
|
|
984
1038
|
name: "clone",
|
|
@@ -1177,9 +1231,10 @@ import {
|
|
|
1177
1231
|
*/
|
|
1178
1232
|
export function beforeCreate<T extends ModelName>(
|
|
1179
1233
|
model: T,
|
|
1180
|
-
callback: BeforeHookCallback<T
|
|
1234
|
+
callback: BeforeHookCallback<T>,
|
|
1235
|
+
options?: HookOptions
|
|
1181
1236
|
): void {
|
|
1182
|
-
_beforeCreate(model as any, callback as any);
|
|
1237
|
+
_beforeCreate(model as any, callback as any, options);
|
|
1183
1238
|
}
|
|
1184
1239
|
|
|
1185
1240
|
/**
|
|
@@ -1187,9 +1242,10 @@ export function beforeCreate<T extends ModelName>(
|
|
|
1187
1242
|
*/
|
|
1188
1243
|
export function afterCreate<T extends ModelName>(
|
|
1189
1244
|
model: T,
|
|
1190
|
-
callback: AfterHookCallback<T
|
|
1245
|
+
callback: AfterHookCallback<T>,
|
|
1246
|
+
options?: HookOptions
|
|
1191
1247
|
): void {
|
|
1192
|
-
_afterCreate(model as any, callback as any);
|
|
1248
|
+
_afterCreate(model as any, callback as any, options);
|
|
1193
1249
|
}
|
|
1194
1250
|
|
|
1195
1251
|
/**
|
|
@@ -1197,9 +1253,10 @@ export function afterCreate<T extends ModelName>(
|
|
|
1197
1253
|
*/
|
|
1198
1254
|
export function beforeUpdate<T extends ModelName>(
|
|
1199
1255
|
model: T,
|
|
1200
|
-
callback: BeforeHookCallback<T
|
|
1256
|
+
callback: BeforeHookCallback<T>,
|
|
1257
|
+
options?: HookOptions
|
|
1201
1258
|
): void {
|
|
1202
|
-
_beforeUpdate(model as any, callback as any);
|
|
1259
|
+
_beforeUpdate(model as any, callback as any, options);
|
|
1203
1260
|
}
|
|
1204
1261
|
|
|
1205
1262
|
/**
|
|
@@ -1207,9 +1264,10 @@ export function beforeUpdate<T extends ModelName>(
|
|
|
1207
1264
|
*/
|
|
1208
1265
|
export function afterUpdate<T extends ModelName>(
|
|
1209
1266
|
model: T,
|
|
1210
|
-
callback: AfterHookCallback<T
|
|
1267
|
+
callback: AfterHookCallback<T>,
|
|
1268
|
+
options?: HookOptions
|
|
1211
1269
|
): void {
|
|
1212
|
-
_afterUpdate(model as any, callback as any);
|
|
1270
|
+
_afterUpdate(model as any, callback as any, options);
|
|
1213
1271
|
}
|
|
1214
1272
|
|
|
1215
1273
|
/**
|
|
@@ -1217,9 +1275,10 @@ export function afterUpdate<T extends ModelName>(
|
|
|
1217
1275
|
*/
|
|
1218
1276
|
export function beforeDelete<T extends ModelName>(
|
|
1219
1277
|
model: T,
|
|
1220
|
-
callback: BeforeHookCallback<T
|
|
1278
|
+
callback: BeforeHookCallback<T>,
|
|
1279
|
+
options?: HookOptions
|
|
1221
1280
|
): void {
|
|
1222
|
-
_beforeDelete(model as any, callback as any);
|
|
1281
|
+
_beforeDelete(model as any, callback as any, options);
|
|
1223
1282
|
}
|
|
1224
1283
|
|
|
1225
1284
|
/**
|
|
@@ -1227,9 +1286,10 @@ export function beforeDelete<T extends ModelName>(
|
|
|
1227
1286
|
*/
|
|
1228
1287
|
export function afterDelete<T extends ModelName>(
|
|
1229
1288
|
model: T,
|
|
1230
|
-
callback: AfterHookCallback<T
|
|
1289
|
+
callback: AfterHookCallback<T>,
|
|
1290
|
+
options?: HookOptions
|
|
1231
1291
|
): void {
|
|
1232
|
-
_afterDelete(model as any, callback as any);
|
|
1292
|
+
_afterDelete(model as any, callback as any, options);
|
|
1233
1293
|
}
|
|
1234
1294
|
|
|
1235
1295
|
/**
|
|
@@ -1249,9 +1309,10 @@ export function afterChange<T extends ModelName>(
|
|
|
1249
1309
|
*/
|
|
1250
1310
|
export function afterUpsert<T extends ModelName>(
|
|
1251
1311
|
model: T,
|
|
1252
|
-
callback: AfterHookCallback<T
|
|
1312
|
+
callback: AfterHookCallback<T>,
|
|
1313
|
+
options?: HookOptions
|
|
1253
1314
|
): void {
|
|
1254
|
-
_afterUpsert(model as any, callback as any);
|
|
1315
|
+
_afterUpsert(model as any, callback as any, options);
|
|
1255
1316
|
}
|
|
1256
1317
|
|
|
1257
1318
|
// Re-export hookRegistry for advanced use cases
|
|
@@ -1331,7 +1392,8 @@ import {
|
|
|
1331
1392
|
*/
|
|
1332
1393
|
export declare function beforeCreate<T extends ModelName>(
|
|
1333
1394
|
model: T,
|
|
1334
|
-
callback: BeforeHookCallback<T
|
|
1395
|
+
callback: BeforeHookCallback<T>,
|
|
1396
|
+
options?: HookOptions
|
|
1335
1397
|
): void;
|
|
1336
1398
|
|
|
1337
1399
|
/**
|
|
@@ -1339,7 +1401,8 @@ export declare function beforeCreate<T extends ModelName>(
|
|
|
1339
1401
|
*/
|
|
1340
1402
|
export declare function afterCreate<T extends ModelName>(
|
|
1341
1403
|
model: T,
|
|
1342
|
-
callback: AfterHookCallback<T
|
|
1404
|
+
callback: AfterHookCallback<T>,
|
|
1405
|
+
options?: HookOptions
|
|
1343
1406
|
): void;
|
|
1344
1407
|
|
|
1345
1408
|
/**
|
|
@@ -1347,7 +1410,8 @@ export declare function afterCreate<T extends ModelName>(
|
|
|
1347
1410
|
*/
|
|
1348
1411
|
export declare function beforeUpdate<T extends ModelName>(
|
|
1349
1412
|
model: T,
|
|
1350
|
-
callback: BeforeHookCallback<T
|
|
1413
|
+
callback: BeforeHookCallback<T>,
|
|
1414
|
+
options?: HookOptions
|
|
1351
1415
|
): void;
|
|
1352
1416
|
|
|
1353
1417
|
/**
|
|
@@ -1355,7 +1419,8 @@ export declare function beforeUpdate<T extends ModelName>(
|
|
|
1355
1419
|
*/
|
|
1356
1420
|
export declare function afterUpdate<T extends ModelName>(
|
|
1357
1421
|
model: T,
|
|
1358
|
-
callback: AfterHookCallback<T
|
|
1422
|
+
callback: AfterHookCallback<T>,
|
|
1423
|
+
options?: HookOptions
|
|
1359
1424
|
): void;
|
|
1360
1425
|
|
|
1361
1426
|
/**
|
|
@@ -1363,7 +1428,8 @@ export declare function afterUpdate<T extends ModelName>(
|
|
|
1363
1428
|
*/
|
|
1364
1429
|
export declare function beforeDelete<T extends ModelName>(
|
|
1365
1430
|
model: T,
|
|
1366
|
-
callback: BeforeHookCallback<T
|
|
1431
|
+
callback: BeforeHookCallback<T>,
|
|
1432
|
+
options?: HookOptions
|
|
1367
1433
|
): void;
|
|
1368
1434
|
|
|
1369
1435
|
/**
|
|
@@ -1371,7 +1437,8 @@ export declare function beforeDelete<T extends ModelName>(
|
|
|
1371
1437
|
*/
|
|
1372
1438
|
export declare function afterDelete<T extends ModelName>(
|
|
1373
1439
|
model: T,
|
|
1374
|
-
callback: AfterHookCallback<T
|
|
1440
|
+
callback: AfterHookCallback<T>,
|
|
1441
|
+
options?: HookOptions
|
|
1375
1442
|
): void;
|
|
1376
1443
|
|
|
1377
1444
|
/**
|
|
@@ -1389,7 +1456,8 @@ export declare function afterChange<T extends ModelName>(
|
|
|
1389
1456
|
*/
|
|
1390
1457
|
export declare function afterUpsert<T extends ModelName>(
|
|
1391
1458
|
model: T,
|
|
1392
|
-
callback: AfterHookCallback<T
|
|
1459
|
+
callback: AfterHookCallback<T>,
|
|
1460
|
+
options?: HookOptions
|
|
1393
1461
|
): void;
|
|
1394
1462
|
|
|
1395
1463
|
// Re-export hookRegistry for advanced use cases
|
|
@@ -1513,6 +1581,7 @@ import type {
|
|
|
1513
1581
|
AfterHookCallback,
|
|
1514
1582
|
ColumnChangeCallback,
|
|
1515
1583
|
ColumnChangeOptions,
|
|
1584
|
+
HookOptions,
|
|
1516
1585
|
FieldName,
|
|
1517
1586
|
HookConfig
|
|
1518
1587
|
} from 'prisma-flare';
|
|
@@ -1561,7 +1630,8 @@ export declare class FlareClient extends BasePrismaClient {
|
|
|
1561
1630
|
*/
|
|
1562
1631
|
export declare function beforeCreate<T extends ModelName>(
|
|
1563
1632
|
model: T,
|
|
1564
|
-
callback: BeforeHookCallback<T
|
|
1633
|
+
callback: BeforeHookCallback<T>,
|
|
1634
|
+
options?: HookOptions
|
|
1565
1635
|
): void;
|
|
1566
1636
|
|
|
1567
1637
|
/**
|
|
@@ -1569,7 +1639,8 @@ export declare function beforeCreate<T extends ModelName>(
|
|
|
1569
1639
|
*/
|
|
1570
1640
|
export declare function afterCreate<T extends ModelName>(
|
|
1571
1641
|
model: T,
|
|
1572
|
-
callback: AfterHookCallback<T
|
|
1642
|
+
callback: AfterHookCallback<T>,
|
|
1643
|
+
options?: HookOptions
|
|
1573
1644
|
): void;
|
|
1574
1645
|
|
|
1575
1646
|
/**
|
|
@@ -1577,7 +1648,8 @@ export declare function afterCreate<T extends ModelName>(
|
|
|
1577
1648
|
*/
|
|
1578
1649
|
export declare function beforeUpdate<T extends ModelName>(
|
|
1579
1650
|
model: T,
|
|
1580
|
-
callback: BeforeHookCallback<T
|
|
1651
|
+
callback: BeforeHookCallback<T>,
|
|
1652
|
+
options?: HookOptions
|
|
1581
1653
|
): void;
|
|
1582
1654
|
|
|
1583
1655
|
/**
|
|
@@ -1585,7 +1657,8 @@ export declare function beforeUpdate<T extends ModelName>(
|
|
|
1585
1657
|
*/
|
|
1586
1658
|
export declare function afterUpdate<T extends ModelName>(
|
|
1587
1659
|
model: T,
|
|
1588
|
-
callback: AfterHookCallback<T
|
|
1660
|
+
callback: AfterHookCallback<T>,
|
|
1661
|
+
options?: HookOptions
|
|
1589
1662
|
): void;
|
|
1590
1663
|
|
|
1591
1664
|
/**
|
|
@@ -1593,7 +1666,8 @@ export declare function afterUpdate<T extends ModelName>(
|
|
|
1593
1666
|
*/
|
|
1594
1667
|
export declare function beforeDelete<T extends ModelName>(
|
|
1595
1668
|
model: T,
|
|
1596
|
-
callback: BeforeHookCallback<T
|
|
1669
|
+
callback: BeforeHookCallback<T>,
|
|
1670
|
+
options?: HookOptions
|
|
1597
1671
|
): void;
|
|
1598
1672
|
|
|
1599
1673
|
/**
|
|
@@ -1601,7 +1675,8 @@ export declare function beforeDelete<T extends ModelName>(
|
|
|
1601
1675
|
*/
|
|
1602
1676
|
export declare function afterDelete<T extends ModelName>(
|
|
1603
1677
|
model: T,
|
|
1604
|
-
callback: AfterHookCallback<T
|
|
1678
|
+
callback: AfterHookCallback<T>,
|
|
1679
|
+
options?: HookOptions
|
|
1605
1680
|
): void;
|
|
1606
1681
|
|
|
1607
1682
|
/**
|
|
@@ -1619,7 +1694,8 @@ export declare function afterChange<T extends ModelName>(
|
|
|
1619
1694
|
*/
|
|
1620
1695
|
export declare function afterUpsert<T extends ModelName>(
|
|
1621
1696
|
model: T,
|
|
1622
|
-
callback: AfterHookCallback<T
|
|
1697
|
+
callback: AfterHookCallback<T>,
|
|
1698
|
+
options?: HookOptions
|
|
1623
1699
|
): void;
|
|
1624
1700
|
|
|
1625
1701
|
// Re-export hookRegistry for advanced use cases
|