@riordanpawley/effect-prisma-generator 0.6.4 → 0.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +97 -24
- package/package.json +7 -6
package/dist/index.js
CHANGED
|
@@ -293,6 +293,7 @@ function generatePrismaInterface(models, customError) {
|
|
|
293
293
|
* This provides a type contract that the service implementation must satisfy.
|
|
294
294
|
*/
|
|
295
295
|
export interface IPrismaService {
|
|
296
|
+
client: BasePrismaClient
|
|
296
297
|
// Transaction operations
|
|
297
298
|
$transaction: <R, E, A>(
|
|
298
299
|
effect: Effect.Effect<A, E, R>
|
|
@@ -692,6 +693,41 @@ const clientOrTx = (client: BasePrismaClient) => Effect.map(
|
|
|
692
693
|
Option.getOrElse(() => client),
|
|
693
694
|
);
|
|
694
695
|
|
|
696
|
+
/**
|
|
697
|
+
* Like Effect.acquireUseRelease, but allows the release function to fail.
|
|
698
|
+
* Release errors are surfaced in the error channel instead of becoming defects.
|
|
699
|
+
*
|
|
700
|
+
* Key properties:
|
|
701
|
+
* - The release function is always called, even if use fails
|
|
702
|
+
* - The release function is uninterruptible to ensure cleanup completes
|
|
703
|
+
* - Release errors are surfaced in the error channel, not as defects
|
|
704
|
+
*/
|
|
705
|
+
const acquireUseReleaseWithErrors = <A, E, R, A2, E2, R2, X, E3, R3>(
|
|
706
|
+
acquire: Effect.Effect<A, E, R>,
|
|
707
|
+
use: (a: A) => Effect.Effect<A2, E2, R2>,
|
|
708
|
+
release: (a: A, exit: Exit.Exit<A2, E2>) => Effect.Effect<X, E3, R3>
|
|
709
|
+
): Effect.Effect<A2, E | E2 | E3, R | R2 | R3> =>
|
|
710
|
+
Effect.uninterruptibleMask((restore) =>
|
|
711
|
+
Effect.flatMap(acquire, (a) =>
|
|
712
|
+
Effect.flatMap(
|
|
713
|
+
Effect.exit(restore(use(a))),
|
|
714
|
+
(exit) =>
|
|
715
|
+
Effect.flatMap(
|
|
716
|
+
// Make release uninterruptible to ensure cleanup always completes
|
|
717
|
+
Effect.exit(release(a, exit)),
|
|
718
|
+
(releaseExit) => {
|
|
719
|
+
if (Exit.isFailure(releaseExit)) {
|
|
720
|
+
// Release failed - surface the release error
|
|
721
|
+
return releaseExit as any;
|
|
722
|
+
}
|
|
723
|
+
// Release succeeded - return the original use result
|
|
724
|
+
return exit as any;
|
|
725
|
+
}
|
|
726
|
+
)
|
|
727
|
+
)
|
|
728
|
+
)
|
|
729
|
+
);
|
|
730
|
+
|
|
695
731
|
${prismaInterface}
|
|
696
732
|
|
|
697
733
|
/**
|
|
@@ -766,6 +802,7 @@ const makePrismaService = Effect.gen(function* () {
|
|
|
766
802
|
const client = yield* PrismaClient;
|
|
767
803
|
|
|
768
804
|
const prismaService: IPrismaService = {
|
|
805
|
+
client,
|
|
769
806
|
/**
|
|
770
807
|
* Execute an effect within a database transaction.
|
|
771
808
|
* All operations within the effect will be atomic - they either all succeed or all fail.
|
|
@@ -802,7 +839,7 @@ const makePrismaService = Effect.gen(function* () {
|
|
|
802
839
|
}
|
|
803
840
|
|
|
804
841
|
// Otherwise, start a new transaction
|
|
805
|
-
return yield*
|
|
842
|
+
return yield* acquireUseReleaseWithErrors(
|
|
806
843
|
// Acquire: begin a new transaction with default options
|
|
807
844
|
$begin(client),
|
|
808
845
|
|
|
@@ -818,11 +855,11 @@ const makePrismaService = Effect.gen(function* () {
|
|
|
818
855
|
? Effect.tryPromise({
|
|
819
856
|
try: () => txClient.$commit(),
|
|
820
857
|
catch: (error) => mapError(error, "$commit", "Prisma")
|
|
821
|
-
}).pipe(Effect.withSpan("txClient.$
|
|
858
|
+
}).pipe(Effect.withSpan("txClient.$commit"))
|
|
822
859
|
: Effect.tryPromise({
|
|
823
860
|
try: () => txClient.$rollback(),
|
|
824
861
|
catch: (error) => mapError(error, "$rollback", "Prisma")
|
|
825
|
-
}).pipe(Effect.withSpan("txClient.$rollback")
|
|
862
|
+
}).pipe(Effect.withSpan("txClient.$rollback"))
|
|
826
863
|
);
|
|
827
864
|
}),
|
|
828
865
|
|
|
@@ -855,7 +892,7 @@ const makePrismaService = Effect.gen(function* () {
|
|
|
855
892
|
}
|
|
856
893
|
|
|
857
894
|
// Otherwise, start a new transaction
|
|
858
|
-
return yield*
|
|
895
|
+
return yield* acquireUseReleaseWithErrors(
|
|
859
896
|
// Acquire: begin a new transaction
|
|
860
897
|
// Prisma merges per-call options with constructor defaults internally
|
|
861
898
|
$begin(client, options),
|
|
@@ -872,11 +909,11 @@ const makePrismaService = Effect.gen(function* () {
|
|
|
872
909
|
? Effect.tryPromise({
|
|
873
910
|
try: () => txClient.$commit(),
|
|
874
911
|
catch: (error) => mapError(error, "$commit", "Prisma")
|
|
875
|
-
}).pipe(Effect.withSpan("txClient.$rollback")
|
|
912
|
+
}).pipe(Effect.withSpan("txClient.$rollback"))
|
|
876
913
|
: Effect.tryPromise({
|
|
877
914
|
try: () => txClient.$rollback(),
|
|
878
915
|
catch: (error) => mapError(error, "$rollback", "Prisma")
|
|
879
|
-
}).pipe(Effect.withSpan("txClient.$rollback")
|
|
916
|
+
}).pipe(Effect.withSpan("txClient.$rollback"))
|
|
880
917
|
);
|
|
881
918
|
}),
|
|
882
919
|
|
|
@@ -909,7 +946,7 @@ const makePrismaService = Effect.gen(function* () {
|
|
|
909
946
|
*/
|
|
910
947
|
$isolatedTransaction: ${enableTelemetry ? 'Effect.fn("Prisma.$isolatedTransaction")' : "Effect.fnUntraced"}(function* (effect) {
|
|
911
948
|
// Always create a fresh transaction
|
|
912
|
-
return yield*
|
|
949
|
+
return yield* acquireUseReleaseWithErrors(
|
|
913
950
|
$begin(client),
|
|
914
951
|
(txClient) =>
|
|
915
952
|
effect.pipe(
|
|
@@ -920,11 +957,11 @@ const makePrismaService = Effect.gen(function* () {
|
|
|
920
957
|
? Effect.tryPromise({
|
|
921
958
|
try: () => txClient.$commit(),
|
|
922
959
|
catch: (error) => mapError(error, "$commit", "Prisma")
|
|
923
|
-
}).pipe(Effect.withSpan("txClient.$rollback")
|
|
960
|
+
}).pipe(Effect.withSpan("txClient.$rollback"))
|
|
924
961
|
: Effect.tryPromise({
|
|
925
962
|
try: () => txClient.$rollback(),
|
|
926
963
|
catch: (error) => mapError(error, "$rollback", "Prisma")
|
|
927
|
-
}).pipe(Effect.withSpan("txClient.$rollback")
|
|
964
|
+
}).pipe(Effect.withSpan("txClient.$rollback"))
|
|
928
965
|
);
|
|
929
966
|
}),
|
|
930
967
|
|
|
@@ -957,7 +994,7 @@ const makePrismaService = Effect.gen(function* () {
|
|
|
957
994
|
*/
|
|
958
995
|
$isolatedTransactionWith: ${enableTelemetry ? 'Effect.fn("Prisma.$isolatedTransactionWith")' : "Effect.fnUntraced"}(function* (effect, options) {
|
|
959
996
|
// Always create a fresh transaction
|
|
960
|
-
return yield*
|
|
997
|
+
return yield* acquireUseReleaseWithErrors(
|
|
961
998
|
$begin(client, options),
|
|
962
999
|
(txClient) =>
|
|
963
1000
|
effect.pipe(
|
|
@@ -968,11 +1005,11 @@ const makePrismaService = Effect.gen(function* () {
|
|
|
968
1005
|
? Effect.tryPromise({
|
|
969
1006
|
try: () => txClient.$commit(),
|
|
970
1007
|
catch: (error) => mapError(error, "$commit", "Prisma")
|
|
971
|
-
}).pipe(Effect.withSpan("txClient.$rollback")
|
|
1008
|
+
}).pipe(Effect.withSpan("txClient.$rollback"))
|
|
972
1009
|
: Effect.tryPromise({
|
|
973
1010
|
try: () => txClient.$rollback(),
|
|
974
1011
|
catch: (error) => mapError(error, "$rollback", "Prisma")
|
|
975
|
-
}).pipe(Effect.withSpan("txClient.$rollback")
|
|
1012
|
+
}).pipe(Effect.withSpan("txClient.$rollback"))
|
|
976
1013
|
);
|
|
977
1014
|
}),
|
|
978
1015
|
${rawSqlOperations}
|
|
@@ -1557,6 +1594,41 @@ const clientOrTx = (client: BasePrismaClient) => Effect.map(
|
|
|
1557
1594
|
Option.getOrElse(() => client),
|
|
1558
1595
|
);
|
|
1559
1596
|
|
|
1597
|
+
/**
|
|
1598
|
+
* Like Effect.acquireUseRelease, but allows the release function to fail.
|
|
1599
|
+
* Release errors are surfaced in the error channel instead of becoming defects.
|
|
1600
|
+
*
|
|
1601
|
+
* Key properties:
|
|
1602
|
+
* - The release function is always called, even if use fails
|
|
1603
|
+
* - The release function is uninterruptible to ensure cleanup completes
|
|
1604
|
+
* - Release errors are surfaced in the error channel, not as defects
|
|
1605
|
+
*/
|
|
1606
|
+
const acquireUseReleaseWithErrors = <A, E, R, A2, E2, R2, X, E3, R3>(
|
|
1607
|
+
acquire: Effect.Effect<A, E, R>,
|
|
1608
|
+
use: (a: A) => Effect.Effect<A2, E2, R2>,
|
|
1609
|
+
release: (a: A, exit: Exit.Exit<A2, E2>) => Effect.Effect<X, E3, R3>
|
|
1610
|
+
): Effect.Effect<A2, E | E2 | E3, R | R2 | R3> =>
|
|
1611
|
+
Effect.uninterruptibleMask((restore) =>
|
|
1612
|
+
Effect.flatMap(acquire, (a) =>
|
|
1613
|
+
Effect.flatMap(
|
|
1614
|
+
Effect.exit(restore(use(a))),
|
|
1615
|
+
(exit) =>
|
|
1616
|
+
Effect.flatMap(
|
|
1617
|
+
// Make release uninterruptible to ensure cleanup always completes
|
|
1618
|
+
Effect.exit(Effect.uninterruptible(release(a, exit))),
|
|
1619
|
+
(releaseExit) => {
|
|
1620
|
+
if (Exit.isFailure(releaseExit)) {
|
|
1621
|
+
// Release failed - surface the release error
|
|
1622
|
+
return releaseExit as any;
|
|
1623
|
+
}
|
|
1624
|
+
// Release succeeded - return the original use result
|
|
1625
|
+
return exit as any;
|
|
1626
|
+
}
|
|
1627
|
+
)
|
|
1628
|
+
)
|
|
1629
|
+
)
|
|
1630
|
+
);
|
|
1631
|
+
|
|
1560
1632
|
${prismaInterface}
|
|
1561
1633
|
|
|
1562
1634
|
/**
|
|
@@ -1631,6 +1703,7 @@ const makePrismaService = Effect.gen(function* () {
|
|
|
1631
1703
|
const client = yield* PrismaClient;
|
|
1632
1704
|
|
|
1633
1705
|
const prismaService: IPrismaService = {
|
|
1706
|
+
client,
|
|
1634
1707
|
/**
|
|
1635
1708
|
* Execute an effect within a database transaction.
|
|
1636
1709
|
* All operations within the effect will be atomic - they either all succeed or all fail.
|
|
@@ -1666,7 +1739,7 @@ const makePrismaService = Effect.gen(function* () {
|
|
|
1666
1739
|
}
|
|
1667
1740
|
|
|
1668
1741
|
// Otherwise, start a new transaction
|
|
1669
|
-
return yield*
|
|
1742
|
+
return yield* acquireUseReleaseWithErrors(
|
|
1670
1743
|
// Acquire: begin a new transaction with default options
|
|
1671
1744
|
$begin(client),
|
|
1672
1745
|
|
|
@@ -1682,11 +1755,11 @@ const makePrismaService = Effect.gen(function* () {
|
|
|
1682
1755
|
? Effect.tryPromise({
|
|
1683
1756
|
try: () => txClient.$commit(),
|
|
1684
1757
|
catch: (error) => mapError(error, "$commit", "Prisma")
|
|
1685
|
-
}).pipe(Effect.withSpan("txClient.$rollback")
|
|
1758
|
+
}).pipe(Effect.withSpan("txClient.$rollback"))
|
|
1686
1759
|
: Effect.tryPromise({
|
|
1687
1760
|
try: () => txClient.$rollback(),
|
|
1688
1761
|
catch: (error) => mapError(error, "$rollback", "Prisma")
|
|
1689
|
-
}).pipe(Effect.withSpan("txClient.$rollback")
|
|
1762
|
+
}).pipe(Effect.withSpan("txClient.$rollback"))
|
|
1690
1763
|
);
|
|
1691
1764
|
}),
|
|
1692
1765
|
|
|
@@ -1719,7 +1792,7 @@ const makePrismaService = Effect.gen(function* () {
|
|
|
1719
1792
|
}
|
|
1720
1793
|
|
|
1721
1794
|
// Otherwise, start a new transaction
|
|
1722
|
-
return yield*
|
|
1795
|
+
return yield* acquireUseReleaseWithErrors(
|
|
1723
1796
|
// Acquire: begin a new transaction
|
|
1724
1797
|
// Prisma merges per-call options with constructor defaults internally
|
|
1725
1798
|
$begin(client, options),
|
|
@@ -1736,11 +1809,11 @@ const makePrismaService = Effect.gen(function* () {
|
|
|
1736
1809
|
? Effect.tryPromise({
|
|
1737
1810
|
try: () => txClient.$commit(),
|
|
1738
1811
|
catch: (error) => mapError(error, "$commit", "Prisma")
|
|
1739
|
-
}).pipe(Effect.withSpan("txClient.$rollback")
|
|
1812
|
+
}).pipe(Effect.withSpan("txClient.$rollback"))
|
|
1740
1813
|
: Effect.tryPromise({
|
|
1741
1814
|
try: () => txClient.$rollback(),
|
|
1742
1815
|
catch: (error) => mapError(error, "$rollback", "Prisma")
|
|
1743
|
-
}).pipe(Effect.withSpan("txClient.$rollback")
|
|
1816
|
+
}).pipe(Effect.withSpan("txClient.$rollback"))
|
|
1744
1817
|
);
|
|
1745
1818
|
}),
|
|
1746
1819
|
|
|
@@ -1773,7 +1846,7 @@ const makePrismaService = Effect.gen(function* () {
|
|
|
1773
1846
|
*/
|
|
1774
1847
|
$isolatedTransaction: ${enableTelemetry ? 'Effect.fn("Prisma.$isolatedTransaction")' : "Effect.fnUntraced"}(function* (effect) {
|
|
1775
1848
|
// Always create a fresh transaction
|
|
1776
|
-
return yield*
|
|
1849
|
+
return yield* acquireUseReleaseWithErrors(
|
|
1777
1850
|
$begin(client),
|
|
1778
1851
|
(txClient) =>
|
|
1779
1852
|
effect.pipe(
|
|
@@ -1784,11 +1857,11 @@ const makePrismaService = Effect.gen(function* () {
|
|
|
1784
1857
|
? Effect.tryPromise({
|
|
1785
1858
|
try: () => txClient.$commit(),
|
|
1786
1859
|
catch: (error) => mapError(error, "$commit", "Prisma")
|
|
1787
|
-
}).pipe(Effect.withSpan("txClient.$rollback")
|
|
1860
|
+
}).pipe(Effect.withSpan("txClient.$rollback"))
|
|
1788
1861
|
: Effect.tryPromise({
|
|
1789
1862
|
try: () => txClient.$rollback(),
|
|
1790
1863
|
catch: (error) => mapError(error, "$rollback", "Prisma")
|
|
1791
|
-
}).pipe(Effect.withSpan("txClient.$rollback")
|
|
1864
|
+
}).pipe(Effect.withSpan("txClient.$rollback"))
|
|
1792
1865
|
);
|
|
1793
1866
|
}),
|
|
1794
1867
|
|
|
@@ -1821,7 +1894,7 @@ const makePrismaService = Effect.gen(function* () {
|
|
|
1821
1894
|
*/
|
|
1822
1895
|
$isolatedTransactionWith: ${enableTelemetry ? 'Effect.fn("Prisma.$isolatedTransactionWith")' : "Effect.fnUntraced"}(function* (effect, options) {
|
|
1823
1896
|
// Always create a fresh transaction
|
|
1824
|
-
return yield*
|
|
1897
|
+
return yield* acquireUseReleaseWithErrors(
|
|
1825
1898
|
$begin(client, options),
|
|
1826
1899
|
(txClient) =>
|
|
1827
1900
|
effect.pipe(
|
|
@@ -1832,11 +1905,11 @@ const makePrismaService = Effect.gen(function* () {
|
|
|
1832
1905
|
? Effect.tryPromise({
|
|
1833
1906
|
try: () => txClient.$commit(),
|
|
1834
1907
|
catch: (error) => mapError(error, "$commit", "Prisma")
|
|
1835
|
-
}).pipe(Effect.withSpan("txClient.$rollback")
|
|
1908
|
+
}).pipe(Effect.withSpan("txClient.$rollback"))
|
|
1836
1909
|
: Effect.tryPromise({
|
|
1837
1910
|
try: () => txClient.$rollback(),
|
|
1838
1911
|
catch: (error) => mapError(error, "$rollback", "Prisma")
|
|
1839
|
-
}).pipe(Effect.withSpan("txClient.$rollback")
|
|
1912
|
+
}).pipe(Effect.withSpan("txClient.$rollback"))
|
|
1840
1913
|
);
|
|
1841
1914
|
}),
|
|
1842
1915
|
${rawSqlOperations}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riordanpawley/effect-prisma-generator",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.6",
|
|
4
4
|
"description": "Prisma generator for Effect (fork with Prisma 7 support)",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -10,6 +10,11 @@
|
|
|
10
10
|
"dist",
|
|
11
11
|
"README.md"
|
|
12
12
|
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc && chmod +x dist/index.js",
|
|
15
|
+
"test": "tsx scripts/runTests.ts",
|
|
16
|
+
"prepublishOnly": "pnpm run build"
|
|
17
|
+
},
|
|
13
18
|
"repository": {
|
|
14
19
|
"type": "git",
|
|
15
20
|
"url": "git+https://github.com/riordanpawley/effect-prisma-generator.git"
|
|
@@ -38,9 +43,5 @@
|
|
|
38
43
|
"prisma": "^6.19.0",
|
|
39
44
|
"tsx": "^4.20.6",
|
|
40
45
|
"vitest": "^3.0.7"
|
|
41
|
-
},
|
|
42
|
-
"scripts": {
|
|
43
|
-
"build": "tsc && chmod +x dist/index.js",
|
|
44
|
-
"test": "tsx scripts/runTests.ts"
|
|
45
46
|
}
|
|
46
|
-
}
|
|
47
|
+
}
|