@riordanpawley/effect-prisma-generator 0.6.5 → 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.
Files changed (2) hide show
  1. package/dist/index.js +94 -24
  2. package/package.json +7 -6
package/dist/index.js CHANGED
@@ -693,6 +693,41 @@ const clientOrTx = (client: BasePrismaClient) => Effect.map(
693
693
  Option.getOrElse(() => client),
694
694
  );
695
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
+
696
731
  ${prismaInterface}
697
732
 
698
733
  /**
@@ -804,7 +839,7 @@ const makePrismaService = Effect.gen(function* () {
804
839
  }
805
840
 
806
841
  // Otherwise, start a new transaction
807
- return yield* Effect.acquireUseRelease(
842
+ return yield* acquireUseReleaseWithErrors(
808
843
  // Acquire: begin a new transaction with default options
809
844
  $begin(client),
810
845
 
@@ -820,11 +855,11 @@ const makePrismaService = Effect.gen(function* () {
820
855
  ? Effect.tryPromise({
821
856
  try: () => txClient.$commit(),
822
857
  catch: (error) => mapError(error, "$commit", "Prisma")
823
- }).pipe(Effect.withSpan("txClient.$rollback"), Effect.orDie)
858
+ }).pipe(Effect.withSpan("txClient.$commit"))
824
859
  : Effect.tryPromise({
825
860
  try: () => txClient.$rollback(),
826
861
  catch: (error) => mapError(error, "$rollback", "Prisma")
827
- }).pipe(Effect.withSpan("txClient.$rollback"), Effect.orDie)
862
+ }).pipe(Effect.withSpan("txClient.$rollback"))
828
863
  );
829
864
  }),
830
865
 
@@ -857,7 +892,7 @@ const makePrismaService = Effect.gen(function* () {
857
892
  }
858
893
 
859
894
  // Otherwise, start a new transaction
860
- return yield* Effect.acquireUseRelease(
895
+ return yield* acquireUseReleaseWithErrors(
861
896
  // Acquire: begin a new transaction
862
897
  // Prisma merges per-call options with constructor defaults internally
863
898
  $begin(client, options),
@@ -874,11 +909,11 @@ const makePrismaService = Effect.gen(function* () {
874
909
  ? Effect.tryPromise({
875
910
  try: () => txClient.$commit(),
876
911
  catch: (error) => mapError(error, "$commit", "Prisma")
877
- }).pipe(Effect.withSpan("txClient.$rollback"), Effect.orDie)
912
+ }).pipe(Effect.withSpan("txClient.$rollback"))
878
913
  : Effect.tryPromise({
879
914
  try: () => txClient.$rollback(),
880
915
  catch: (error) => mapError(error, "$rollback", "Prisma")
881
- }).pipe(Effect.withSpan("txClient.$rollback"), Effect.orDie)
916
+ }).pipe(Effect.withSpan("txClient.$rollback"))
882
917
  );
883
918
  }),
884
919
 
@@ -911,7 +946,7 @@ const makePrismaService = Effect.gen(function* () {
911
946
  */
912
947
  $isolatedTransaction: ${enableTelemetry ? 'Effect.fn("Prisma.$isolatedTransaction")' : "Effect.fnUntraced"}(function* (effect) {
913
948
  // Always create a fresh transaction
914
- return yield* Effect.acquireUseRelease(
949
+ return yield* acquireUseReleaseWithErrors(
915
950
  $begin(client),
916
951
  (txClient) =>
917
952
  effect.pipe(
@@ -922,11 +957,11 @@ const makePrismaService = Effect.gen(function* () {
922
957
  ? Effect.tryPromise({
923
958
  try: () => txClient.$commit(),
924
959
  catch: (error) => mapError(error, "$commit", "Prisma")
925
- }).pipe(Effect.withSpan("txClient.$rollback"), Effect.orDie)
960
+ }).pipe(Effect.withSpan("txClient.$rollback"))
926
961
  : Effect.tryPromise({
927
962
  try: () => txClient.$rollback(),
928
963
  catch: (error) => mapError(error, "$rollback", "Prisma")
929
- }).pipe(Effect.withSpan("txClient.$rollback"), Effect.orDie)
964
+ }).pipe(Effect.withSpan("txClient.$rollback"))
930
965
  );
931
966
  }),
932
967
 
@@ -959,7 +994,7 @@ const makePrismaService = Effect.gen(function* () {
959
994
  */
960
995
  $isolatedTransactionWith: ${enableTelemetry ? 'Effect.fn("Prisma.$isolatedTransactionWith")' : "Effect.fnUntraced"}(function* (effect, options) {
961
996
  // Always create a fresh transaction
962
- return yield* Effect.acquireUseRelease(
997
+ return yield* acquireUseReleaseWithErrors(
963
998
  $begin(client, options),
964
999
  (txClient) =>
965
1000
  effect.pipe(
@@ -970,11 +1005,11 @@ const makePrismaService = Effect.gen(function* () {
970
1005
  ? Effect.tryPromise({
971
1006
  try: () => txClient.$commit(),
972
1007
  catch: (error) => mapError(error, "$commit", "Prisma")
973
- }).pipe(Effect.withSpan("txClient.$rollback"), Effect.orDie)
1008
+ }).pipe(Effect.withSpan("txClient.$rollback"))
974
1009
  : Effect.tryPromise({
975
1010
  try: () => txClient.$rollback(),
976
1011
  catch: (error) => mapError(error, "$rollback", "Prisma")
977
- }).pipe(Effect.withSpan("txClient.$rollback"), Effect.orDie)
1012
+ }).pipe(Effect.withSpan("txClient.$rollback"))
978
1013
  );
979
1014
  }),
980
1015
  ${rawSqlOperations}
@@ -1559,6 +1594,41 @@ const clientOrTx = (client: BasePrismaClient) => Effect.map(
1559
1594
  Option.getOrElse(() => client),
1560
1595
  );
1561
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
+
1562
1632
  ${prismaInterface}
1563
1633
 
1564
1634
  /**
@@ -1669,7 +1739,7 @@ const makePrismaService = Effect.gen(function* () {
1669
1739
  }
1670
1740
 
1671
1741
  // Otherwise, start a new transaction
1672
- return yield* Effect.acquireUseRelease(
1742
+ return yield* acquireUseReleaseWithErrors(
1673
1743
  // Acquire: begin a new transaction with default options
1674
1744
  $begin(client),
1675
1745
 
@@ -1685,11 +1755,11 @@ const makePrismaService = Effect.gen(function* () {
1685
1755
  ? Effect.tryPromise({
1686
1756
  try: () => txClient.$commit(),
1687
1757
  catch: (error) => mapError(error, "$commit", "Prisma")
1688
- }).pipe(Effect.withSpan("txClient.$rollback"), Effect.orDie)
1758
+ }).pipe(Effect.withSpan("txClient.$rollback"))
1689
1759
  : Effect.tryPromise({
1690
1760
  try: () => txClient.$rollback(),
1691
1761
  catch: (error) => mapError(error, "$rollback", "Prisma")
1692
- }).pipe(Effect.withSpan("txClient.$rollback"), Effect.orDie)
1762
+ }).pipe(Effect.withSpan("txClient.$rollback"))
1693
1763
  );
1694
1764
  }),
1695
1765
 
@@ -1722,7 +1792,7 @@ const makePrismaService = Effect.gen(function* () {
1722
1792
  }
1723
1793
 
1724
1794
  // Otherwise, start a new transaction
1725
- return yield* Effect.acquireUseRelease(
1795
+ return yield* acquireUseReleaseWithErrors(
1726
1796
  // Acquire: begin a new transaction
1727
1797
  // Prisma merges per-call options with constructor defaults internally
1728
1798
  $begin(client, options),
@@ -1739,11 +1809,11 @@ const makePrismaService = Effect.gen(function* () {
1739
1809
  ? Effect.tryPromise({
1740
1810
  try: () => txClient.$commit(),
1741
1811
  catch: (error) => mapError(error, "$commit", "Prisma")
1742
- }).pipe(Effect.withSpan("txClient.$rollback"), Effect.orDie)
1812
+ }).pipe(Effect.withSpan("txClient.$rollback"))
1743
1813
  : Effect.tryPromise({
1744
1814
  try: () => txClient.$rollback(),
1745
1815
  catch: (error) => mapError(error, "$rollback", "Prisma")
1746
- }).pipe(Effect.withSpan("txClient.$rollback"), Effect.orDie)
1816
+ }).pipe(Effect.withSpan("txClient.$rollback"))
1747
1817
  );
1748
1818
  }),
1749
1819
 
@@ -1776,7 +1846,7 @@ const makePrismaService = Effect.gen(function* () {
1776
1846
  */
1777
1847
  $isolatedTransaction: ${enableTelemetry ? 'Effect.fn("Prisma.$isolatedTransaction")' : "Effect.fnUntraced"}(function* (effect) {
1778
1848
  // Always create a fresh transaction
1779
- return yield* Effect.acquireUseRelease(
1849
+ return yield* acquireUseReleaseWithErrors(
1780
1850
  $begin(client),
1781
1851
  (txClient) =>
1782
1852
  effect.pipe(
@@ -1787,11 +1857,11 @@ const makePrismaService = Effect.gen(function* () {
1787
1857
  ? Effect.tryPromise({
1788
1858
  try: () => txClient.$commit(),
1789
1859
  catch: (error) => mapError(error, "$commit", "Prisma")
1790
- }).pipe(Effect.withSpan("txClient.$rollback"), Effect.orDie)
1860
+ }).pipe(Effect.withSpan("txClient.$rollback"))
1791
1861
  : Effect.tryPromise({
1792
1862
  try: () => txClient.$rollback(),
1793
1863
  catch: (error) => mapError(error, "$rollback", "Prisma")
1794
- }).pipe(Effect.withSpan("txClient.$rollback"), Effect.orDie)
1864
+ }).pipe(Effect.withSpan("txClient.$rollback"))
1795
1865
  );
1796
1866
  }),
1797
1867
 
@@ -1824,7 +1894,7 @@ const makePrismaService = Effect.gen(function* () {
1824
1894
  */
1825
1895
  $isolatedTransactionWith: ${enableTelemetry ? 'Effect.fn("Prisma.$isolatedTransactionWith")' : "Effect.fnUntraced"}(function* (effect, options) {
1826
1896
  // Always create a fresh transaction
1827
- return yield* Effect.acquireUseRelease(
1897
+ return yield* acquireUseReleaseWithErrors(
1828
1898
  $begin(client, options),
1829
1899
  (txClient) =>
1830
1900
  effect.pipe(
@@ -1835,11 +1905,11 @@ const makePrismaService = Effect.gen(function* () {
1835
1905
  ? Effect.tryPromise({
1836
1906
  try: () => txClient.$commit(),
1837
1907
  catch: (error) => mapError(error, "$commit", "Prisma")
1838
- }).pipe(Effect.withSpan("txClient.$rollback"), Effect.orDie)
1908
+ }).pipe(Effect.withSpan("txClient.$rollback"))
1839
1909
  : Effect.tryPromise({
1840
1910
  try: () => txClient.$rollback(),
1841
1911
  catch: (error) => mapError(error, "$rollback", "Prisma")
1842
- }).pipe(Effect.withSpan("txClient.$rollback"), Effect.orDie)
1912
+ }).pipe(Effect.withSpan("txClient.$rollback"))
1843
1913
  );
1844
1914
  }),
1845
1915
  ${rawSqlOperations}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riordanpawley/effect-prisma-generator",
3
- "version": "0.6.5",
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
+ }