@shivaedev/effect-prisma 0.0.0 → 0.2.0

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 (104) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/LICENSE +21 -0
  3. package/README.md +150 -2
  4. package/dist/database.d.ts +35 -0
  5. package/dist/database.d.ts.map +1 -0
  6. package/dist/database.js +83 -0
  7. package/dist/database.js.map +1 -0
  8. package/dist/error.d.ts +52 -0
  9. package/dist/error.d.ts.map +1 -0
  10. package/dist/error.js +48 -0
  11. package/dist/error.js.map +1 -0
  12. package/dist/index.d.ts +4 -0
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +3 -0
  15. package/dist/index.js.map +1 -0
  16. package/dist/internal/client-lifecycle.d.ts +7 -0
  17. package/dist/internal/client-lifecycle.d.ts.map +1 -0
  18. package/dist/internal/client-lifecycle.js +19 -0
  19. package/dist/internal/client-lifecycle.js.map +1 -0
  20. package/dist/internal/executor.d.ts +16 -0
  21. package/dist/internal/executor.d.ts.map +1 -0
  22. package/dist/internal/executor.js +2 -0
  23. package/dist/internal/executor.js.map +1 -0
  24. package/dist/internal/promise.d.ts +4 -0
  25. package/dist/internal/promise.d.ts.map +1 -0
  26. package/dist/internal/promise.js +9 -0
  27. package/dist/internal/promise.js.map +1 -0
  28. package/dist/internal/recipe.d.ts +13 -0
  29. package/dist/internal/recipe.d.ts.map +1 -0
  30. package/dist/internal/recipe.js +92 -0
  31. package/dist/internal/recipe.js.map +1 -0
  32. package/dist/internal/relation-plan.d.ts +8 -0
  33. package/dist/internal/relation-plan.d.ts.map +1 -0
  34. package/dist/internal/relation-plan.js +10 -0
  35. package/dist/internal/relation-plan.js.map +1 -0
  36. package/dist/internal/relation-runtime.d.ts +5 -0
  37. package/dist/internal/relation-runtime.d.ts.map +1 -0
  38. package/dist/internal/relation-runtime.js +106 -0
  39. package/dist/internal/relation-runtime.js.map +1 -0
  40. package/dist/internal/testing.d.ts +11 -0
  41. package/dist/internal/testing.d.ts.map +1 -0
  42. package/dist/internal/testing.js +9 -0
  43. package/dist/internal/testing.js.map +1 -0
  44. package/dist/internal/transaction.d.ts +14 -0
  45. package/dist/internal/transaction.d.ts.map +1 -0
  46. package/dist/internal/transaction.js +79 -0
  47. package/dist/internal/transaction.js.map +1 -0
  48. package/dist/internal/vitest-database.d.ts +18 -0
  49. package/dist/internal/vitest-database.d.ts.map +1 -0
  50. package/dist/internal/vitest-database.js +73 -0
  51. package/dist/internal/vitest-database.js.map +1 -0
  52. package/dist/relation/include-metadata.d.ts +34 -0
  53. package/dist/relation/include-metadata.d.ts.map +1 -0
  54. package/dist/relation/include-metadata.js +2 -0
  55. package/dist/relation/include-metadata.js.map +1 -0
  56. package/dist/relation/include.d.ts +25 -0
  57. package/dist/relation/include.d.ts.map +1 -0
  58. package/dist/relation/include.js +2 -0
  59. package/dist/relation/include.js.map +1 -0
  60. package/dist/relation/prisma-methods.d.ts +56 -0
  61. package/dist/relation/prisma-methods.d.ts.map +1 -0
  62. package/dist/relation/prisma-methods.js +2 -0
  63. package/dist/relation/prisma-methods.js.map +1 -0
  64. package/dist/relation.d.ts +34 -0
  65. package/dist/relation.d.ts.map +1 -0
  66. package/dist/relation.js +2 -0
  67. package/dist/relation.js.map +1 -0
  68. package/dist/testing/transaction.d.ts +10 -0
  69. package/dist/testing/transaction.d.ts.map +1 -0
  70. package/dist/testing/transaction.js +6 -0
  71. package/dist/testing/transaction.js.map +1 -0
  72. package/dist/testing/types.d.ts +29 -0
  73. package/dist/testing/types.d.ts.map +1 -0
  74. package/dist/testing/types.js +2 -0
  75. package/dist/testing/types.js.map +1 -0
  76. package/dist/testing/vitest.d.ts +6 -0
  77. package/dist/testing/vitest.d.ts.map +1 -0
  78. package/dist/testing/vitest.js +28 -0
  79. package/dist/testing/vitest.js.map +1 -0
  80. package/dist/testing.d.ts +4 -0
  81. package/dist/testing.d.ts.map +1 -0
  82. package/dist/testing.js +3 -0
  83. package/dist/testing.js.map +1 -0
  84. package/package.json +69 -4
  85. package/src/database.ts +232 -0
  86. package/src/error.ts +89 -0
  87. package/src/index.ts +14 -0
  88. package/src/internal/client-lifecycle.ts +31 -0
  89. package/src/internal/executor.ts +28 -0
  90. package/src/internal/promise.ts +16 -0
  91. package/src/internal/recipe.ts +148 -0
  92. package/src/internal/relation-plan.ts +22 -0
  93. package/src/internal/relation-runtime.ts +249 -0
  94. package/src/internal/testing.ts +32 -0
  95. package/src/internal/transaction.ts +149 -0
  96. package/src/internal/vitest-database.ts +210 -0
  97. package/src/relation/include-metadata.ts +102 -0
  98. package/src/relation/include.ts +169 -0
  99. package/src/relation/prisma-methods.ts +196 -0
  100. package/src/relation.ts +118 -0
  101. package/src/testing/transaction.ts +28 -0
  102. package/src/testing/types.ts +67 -0
  103. package/src/testing/vitest.ts +67 -0
  104. package/src/testing.ts +8 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,22 @@
1
+ # Changelog
2
+
3
+ ## Unreleased
4
+
5
+ ## 0.2.0 - 2026-07-26
6
+
7
+ ### Added
8
+
9
+ - Load typed to-one and to-many relations, including nested and refined
10
+ relations and relation counts.
11
+ - Count any filtered relation directly without building an aggregate result.
12
+
13
+ ## 0.1.0 - 2026-07-26
14
+
15
+ ### Added
16
+
17
+ - Effect-native, immutable Prisma relations with typed filtering, ordering,
18
+ pagination, aggregates, grouping, and mutation operations.
19
+ - Implicitly scoped transactions that preserve the same database service inside
20
+ and outside a transaction.
21
+ - Vitest helpers for typed database tests that automatically roll back their
22
+ changes.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ShivaeDev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,4 +1,152 @@
1
1
  # `@shivaedev/effect-prisma`
2
2
 
3
- Bootstrap placeholder for the package's automated release flow. Use version
4
- `0.1.0` or later.
3
+ Effect-native PostgreSQL queries and transactions backed by Prisma Next.
4
+
5
+ This package currently targets exact early-access versions of Effect v4 and
6
+ Prisma Next. It is built for ShivaeDev applications and may change without a
7
+ deprecation period.
8
+
9
+ ## Install
10
+
11
+ ```sh
12
+ pnpm add @shivaedev/effect-prisma effect
13
+ ```
14
+
15
+ Generate a Prisma Next contract in the application, then create its database
16
+ service:
17
+
18
+ ```ts
19
+ import { makeDatabase } from "@shivaedev/effect-prisma"
20
+ import { contractJson, type Contract } from "./generated/contract.js"
21
+
22
+ export const Database = makeDatabase<Contract>("@app/Database", {
23
+ contractJson,
24
+ })
25
+
26
+ export const DatabaseLive = Database.layer({
27
+ url: process.env.DATABASE_URL!,
28
+ })
29
+ ```
30
+
31
+ The Layer owns the PostgreSQL client and closes it with its Effect scope.
32
+
33
+ ## Queries
34
+
35
+ Yield the database service once and use generated models directly:
36
+
37
+ ```ts
38
+ import { Effect } from "effect"
39
+
40
+ const program = Effect.gen(function* () {
41
+ const db = yield* Database
42
+
43
+ const active = db.User.where({ active: true })
44
+ const newest = active.orderBy((user) => user.createdAt.desc())
45
+
46
+ const users = yield* newest.take(20)
47
+ const first = yield* active.first()
48
+ const exists = yield* active.exists()
49
+ const count = yield* active.count()
50
+
51
+ return { users, first, exists, count }
52
+ })
53
+ ```
54
+
55
+ Relations are lazy and immutable. Reusing or branching a Relation never changes
56
+ the original, and each execution resolves the active database context again.
57
+
58
+ Relations can be loaded directly or refined with another immutable Relation:
59
+
60
+ ```ts
61
+ const recentPosts = db.Post
62
+ .orderBy((post) => post.createdAt.desc())
63
+ .take(5)
64
+
65
+ const usersWithPosts = yield* db.User.include("posts", recentPosts)
66
+
67
+ const usersWithPostCounts = yield* db.User.include("posts", db.Post.count())
68
+ ```
69
+
70
+ Includes can be chained and nested. Loaded to-many relations are arrays, and
71
+ nullable to-one relations remain nullable in the result type.
72
+
73
+ Named query records return several projections of the same relation:
74
+
75
+ ```ts
76
+ const publishedPosts = db.Post.where({ published: true })
77
+ const recentPublishedPosts = publishedPosts
78
+ .orderBy((post) => post.createdAt.desc())
79
+ .take(5)
80
+
81
+ const usersWithPostOverview = yield* db.User.include("posts", {
82
+ items: recentPublishedPosts,
83
+ fullCount: publishedPosts.count(),
84
+ })
85
+ ```
86
+
87
+ Collections are also cold Effect Streams:
88
+
89
+ ```ts
90
+ const stream = db.User.where({ active: true }).stream
91
+ ```
92
+
93
+ The package covers scalar models, filtering, selection, relation loading,
94
+ ordering, pagination, distinct queries, aggregates, grouping, and
95
+ create/update/delete terminals. Model variants are deliberately deferred rather
96
+ than exposed with weakened types.
97
+
98
+ ## Transactions
99
+
100
+ Transactions keep the same database API and are implicitly scoped:
101
+
102
+ ```ts
103
+ yield* db.transaction(
104
+ Effect.gen(function* () {
105
+ const db = yield* Database
106
+ yield* db.User.create({
107
+ id,
108
+ email,
109
+ name,
110
+ })
111
+ }),
112
+ )
113
+ ```
114
+
115
+ Nested package transactions reuse the active transaction. Successful programs
116
+ commit; failure, defect, and interruption roll back.
117
+
118
+ ## Vitest
119
+
120
+ Install `@effect/vitest` to use the optional testing entrypoint:
121
+
122
+ ```sh
123
+ pnpm add --save-dev @effect/vitest vitest
124
+ ```
125
+
126
+ Configure the database once in the application's test support:
127
+
128
+ ```ts
129
+ import { makeDatabaseIt } from "@shivaedev/effect-prisma/testing"
130
+
131
+ export const it = makeDatabaseIt({
132
+ database: Database,
133
+ layer: DatabaseTest,
134
+ })
135
+ ```
136
+
137
+ Tests receive the typed database facade and always roll back:
138
+
139
+ ```ts
140
+ it.effectDB("creates a user", function* (db) {
141
+ const user = yield* db.User.create({
142
+ id,
143
+ email,
144
+ name,
145
+ })
146
+
147
+ expect(user.email).toBe(email)
148
+ })
149
+ ```
150
+
151
+ `effectDB` supports the usual `skip`, `skipIf`, `runIf`, `only`, `each`, and
152
+ `fails` variants. `withTestTransaction` is also exported for custom harnesses.
@@ -0,0 +1,35 @@
1
+ import { type PostgresClient, type PostgresOptionsBase } from "@prisma-next/postgres/runtime";
2
+ import { Context, Effect, Layer, Redacted } from "effect";
3
+ import type { PrismaError } from "./error.js";
4
+ import type { AnyPostgresContract, ExecutorIdentifier } from "./internal/executor.js";
5
+ import type { Relation } from "./relation.js";
6
+ type ClientFor<Contract extends AnyPostgresContract> = PostgresClient<Contract>;
7
+ type OrmFor<Contract extends AnyPostgresContract> = ClientFor<Contract>["orm"];
8
+ type DefaultNamespaceId<Contract extends AnyPostgresContract> = "__unbound__" extends keyof OrmFor<Contract> ? "__unbound__" : "public" extends keyof OrmFor<Contract> ? "public" : keyof OrmFor<Contract>;
9
+ type DefaultModels<Contract extends AnyPostgresContract> = OrmFor<Contract>[DefaultNamespaceId<Contract>] extends infer Models extends object ? Models : never;
10
+ interface DatabaseIdentifier<Contract extends AnyPostgresContract> {
11
+ readonly _contract: Contract;
12
+ readonly _databaseIdentifier: unique symbol;
13
+ }
14
+ type DatabaseModels<Contract extends AnyPostgresContract, Requirement> = {
15
+ readonly [Model in keyof DefaultModels<Contract>]: Relation<DefaultModels<Contract>[Model], Requirement, Contract, Model & string>;
16
+ };
17
+ export type DatabaseService<Contract extends AnyPostgresContract, Requirement> = DatabaseModels<Contract, Requirement> & {
18
+ transaction<A, E, R>(program: Effect.Effect<A, E, R>): Effect.Effect<A, E | PrismaError, R | Requirement>;
19
+ };
20
+ export interface DatabaseLayerOptions extends PostgresOptionsBase {
21
+ readonly url: string | Redacted.Redacted<string>;
22
+ }
23
+ type DatabaseFactoryOptions<Contract extends AnyPostgresContract> = {
24
+ readonly contract: Contract;
25
+ readonly contractJson?: never;
26
+ } | {
27
+ readonly contractJson: unknown;
28
+ readonly contract?: never;
29
+ };
30
+ export interface DatabaseDefinition<Contract extends AnyPostgresContract, Requirement = ExecutorIdentifier<DefaultModels<Contract>>> extends Context.Service<DatabaseIdentifier<Contract>, DatabaseService<Contract, Requirement>> {
31
+ readonly layer: (options: DatabaseLayerOptions) => Layer.Layer<DatabaseIdentifier<Contract> | Requirement, PrismaError>;
32
+ }
33
+ export declare const makeDatabase: <const Contract extends AnyPostgresContract>(identifier: string, options: DatabaseFactoryOptions<Contract>) => DatabaseDefinition<Contract>;
34
+ export {};
35
+ //# sourceMappingURL=database.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":"AAAA,OAAiB,EAChB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAK9C,OAAO,KAAK,EACX,mBAAmB,EAEnB,kBAAkB,EAClB,MAAM,wBAAwB,CAAC;AAShC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,KAAK,SAAS,CAAC,QAAQ,SAAS,mBAAmB,IAAI,cAAc,CAAC,QAAQ,CAAC,CAAC;AAChF,K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ACtD,CAAC;AAEF,MAAM,WAAW,oBAAqB,SAAQ,mBAAmB;IAChE,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;CACjD;AAED,KAAK,sBAAsB,CAAC,QAAQ,SAAS,mBAAmB,IAC7D;IACA,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,YAAY,CAAC,EAAE,KAAK,CAAC;CAC7B,GACD;IACA,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAC/B,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC;CACzB,CAAC;AAEL,MAAM,WAAW,kBAAkB,CAClC,QAAQ,SAAS,mBAAmB,EACpC,WAAW,GAAG,kBAAkB,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CACxD,SAAQ,OAAO,CAAC,OAAO,CACvB,kBAAkB,CAAC,QAAQ,CAAC,EAC5B,eAAe,CAAC,QAAQ,EAAE,WAAW,CAAC,CACtC;IACD,QAAQ,CAAC,KAAK,EAAE,CACf,OAAO,EAAE,oBAAoB,KACzB,KAAK,CAAC,KAAK,CAAC,kBAAkB,CAAC,QAAQ,CAAC,GAAG,WAAW,EAAE,WAAW,CAAC,CAAC;CAC1E;AAoBD,eAAO,MAAM,YAAY,GAAI,KAAK,CAAC,QAAQ,SAAS,mBAAmB,EACtE,YAAY,MAAM,EAClB,SAAS,sBAAsB,CAAC,QAAQ,CAAC,KACvC,kBAAkB,CAAC,QAAQ,CA0H7B,CAAC"}
@@ -0,0 +1,83 @@
1
+ import postgres, {} from "@prisma-next/postgres/runtime";
2
+ import { Context, Effect, Layer, Redacted } from "effect";
3
+ import { acquireConnectedClient, assertAvailableModelNames, } from "./internal/client-lifecycle.js";
4
+ import { fromPrismaPromise } from "./internal/promise.js";
5
+ import { makeModelRelation } from "./internal/relation-runtime.js";
6
+ import { DatabaseTestingTypeId } from "./internal/testing.js";
7
+ import { acquireTransaction, releaseTestTransaction, releaseTransaction, } from "./internal/transaction.js";
8
+ const defaultModels = (client) => {
9
+ const namespaces = Object.keys(client.contract.domain.namespaces);
10
+ if (namespaces.length !== 1 || namespaces[0] === undefined) {
11
+ throw new TypeError("Effect Prisma currently requires exactly one domain namespace");
12
+ }
13
+ assertAvailableModelNames(Object.keys(client.contract.domain.namespaces[namespaces[0]].models));
14
+ return Reflect.get(client.orm, namespaces[0]);
15
+ };
16
+ export const makeDatabase = (identifier, options) => {
17
+ const Executor = Context.Service(`${identifier}/Executor`);
18
+ const Service = Context.Service(identifier);
19
+ const transaction = (program) => Effect.flatMap(Executor, (current) => {
20
+ if (current.transactional) {
21
+ return program;
22
+ }
23
+ return Effect.acquireUseRelease(acquireTransaction(current, (transactionOrm) => defaultModels({
24
+ contract: current.client.contract,
25
+ orm: transactionOrm,
26
+ })), (resource) => program.pipe(Effect.provideService(Executor, resource.executor)), releaseTransaction).pipe(Effect.withSpan("prisma.transaction", { kind: "client" }));
27
+ });
28
+ const withTestTransaction = (program) => Effect.flatMap(Executor, (current) => {
29
+ if (current.transactional) {
30
+ return program;
31
+ }
32
+ return Effect.acquireUseRelease(acquireTransaction(current, (transactionOrm) => defaultModels({
33
+ contract: current.client.contract,
34
+ orm: transactionOrm,
35
+ })), (resource) => program.pipe(Effect.provideService(Executor, resource.executor)), releaseTestTransaction).pipe(Effect.withSpan("prisma.testTransaction", { kind: "client" }));
36
+ });
37
+ const facade = new Proxy(Object.assign(Object.create(null), {
38
+ transaction,
39
+ }), {
40
+ get(target, property, receiver) {
41
+ if (Reflect.has(target, property)) {
42
+ return Reflect.get(target, property, receiver);
43
+ }
44
+ if (typeof property !== "string") {
45
+ return undefined;
46
+ }
47
+ return makeModelRelation(Executor, property);
48
+ },
49
+ });
50
+ const layer = (layerOptions) => {
51
+ const acquire = Effect.acquireRelease(Effect.suspend(() => {
52
+ const clientOptions = {
53
+ url: typeof layerOptions.url === "string"
54
+ ? layerOptions.url
55
+ : Redacted.value(layerOptions.url),
56
+ extensions: layerOptions.extensions,
57
+ middleware: layerOptions.middleware,
58
+ poolOptions: layerOptions.poolOptions,
59
+ verifyMarker: layerOptions.verifyMarker,
60
+ };
61
+ const client = options.contract === undefined
62
+ ? postgres({
63
+ ...clientOptions,
64
+ contractJson: options.contractJson,
65
+ })
66
+ : postgres({
67
+ ...clientOptions,
68
+ contract: options.contract,
69
+ });
70
+ return fromPrismaPromise(() => acquireConnectedClient(client, () => ({
71
+ client,
72
+ models: defaultModels(client),
73
+ transactional: false,
74
+ })));
75
+ }), (executor) => Effect.promise(() => executor.client.close()).pipe(Effect.orDie));
76
+ return Layer.effectContext(Effect.map(acquire, (executor) => Context.make(Executor, executor).pipe(Context.add(Service, facade))));
77
+ };
78
+ return Object.assign(Service, {
79
+ layer,
80
+ [DatabaseTestingTypeId]: { withTestTransaction },
81
+ });
82
+ };
83
+ //# sourceMappingURL=database.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database.js","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,EAAE,EAGhB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAE1D,OAAO,EACN,sBAAsB,EACtB,yBAAyB,GACzB,MAAM,gCAAgC,CAAC;AAMxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EACN,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,GAClB,MAAM,2BAA2B,CAAC;AAkEnC,MAAM,aAAa,GAAG,CAIrB,MAA0D,EACjD,EAAE;IACX,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,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AC,CACjE,CAAC;QAEF,OAAO,KAAK,CAAC,aAAa,CACzB,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,EAAE,CAChC,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CACnE,CACD,CAAC;IACH,CAAC,CAAC;IAEF,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE;QAC7B,KAAK;QACL,CAAC,qBAAqB,CAAC,EAAE,EAAE,mBAAmB,EAAE;KAChD,CAAiC,CAAC;AACpC,CAAC,CAAC"}
@@ -0,0 +1,52 @@
1
+ import { Redacted } from "effect";
2
+ declare const PrismaRuntimeFailure_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => Readonly<A> & {
3
+ readonly _tag: "PrismaRuntimeFailure";
4
+ } & import("effect/Pipeable").Pipeable;
5
+ export declare class PrismaRuntimeFailure extends PrismaRuntimeFailure_base<{
6
+ readonly code: string;
7
+ readonly original: Redacted.Redacted<unknown>;
8
+ }> {
9
+ }
10
+ declare const PrismaQueryFailure_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => Readonly<A> & {
11
+ readonly _tag: "PrismaQueryFailure";
12
+ } & import("effect/Pipeable").Pipeable;
13
+ export declare class PrismaQueryFailure extends PrismaQueryFailure_base<{
14
+ readonly sqlState?: string;
15
+ readonly constraint?: string;
16
+ readonly table?: string;
17
+ readonly column?: string;
18
+ readonly original: Redacted.Redacted<unknown>;
19
+ }> {
20
+ }
21
+ declare const PrismaConnectionFailure_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => Readonly<A> & {
22
+ readonly _tag: "PrismaConnectionFailure";
23
+ } & import("effect/Pipeable").Pipeable;
24
+ export declare class PrismaConnectionFailure extends PrismaConnectionFailure_base<{
25
+ readonly transient?: boolean;
26
+ readonly original: Redacted.Redacted<unknown>;
27
+ }> {
28
+ }
29
+ export type PrismaErrorReason = PrismaRuntimeFailure | PrismaQueryFailure | PrismaConnectionFailure;
30
+ declare const PrismaError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
31
+ readonly _tag: "PrismaError";
32
+ } & Readonly<A>;
33
+ export declare class PrismaError extends PrismaError_base<{
34
+ readonly reason: PrismaErrorReason;
35
+ }> {
36
+ }
37
+ type PrismaFailure = {
38
+ readonly code: string;
39
+ } | {
40
+ readonly kind: "sql_query";
41
+ readonly sqlState?: string;
42
+ readonly constraint?: string;
43
+ readonly table?: string;
44
+ readonly column?: string;
45
+ } | {
46
+ readonly kind: "sql_connection";
47
+ readonly transient?: boolean;
48
+ };
49
+ export declare const isPrismaFailure: (error: unknown) => error is PrismaFailure;
50
+ export declare const toPrismaError: (error: PrismaFailure) => PrismaError;
51
+ export {};
52
+ //# sourceMappingURL=error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,QAAQ,EAAE,MAAM,QAAQ,CAAC;;;;AAExC,qBAAa,oBAAqB,SAAQ,0BAExC;IACD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;CAC9C,CAAC;CAAG;;;;AAEL,qBAAa,kBAAmB,SAAQ,wBAAuC;IAC9E,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM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Data.TaggedClass("PrismaRuntimeFailure") {
3
+ }
4
+ export class PrismaQueryFailure extends Data.TaggedClass("PrismaQueryFailure") {
5
+ }
6
+ export class PrismaConnectionFailure extends Data.TaggedClass("PrismaConnectionFailure") {
7
+ }
8
+ export class PrismaError extends Data.TaggedError("PrismaError") {
9
+ }
10
+ export const isPrismaFailure = (error) => {
11
+ if (typeof error !== "object" || error === null) {
12
+ return false;
13
+ }
14
+ if ("code" in error && typeof error.code === "string") {
15
+ return true;
16
+ }
17
+ return ("kind" in error &&
18
+ (error.kind === "sql_query" || error.kind === "sql_connection"));
19
+ };
20
+ export const toPrismaError = (error) => {
21
+ const original = Redacted.make(error);
22
+ if ("kind" in error && error.kind === "sql_query") {
23
+ return new PrismaError({
24
+ reason: new PrismaQueryFailure({
25
+ sqlState: error.sqlState,
26
+ constraint: error.constraint,
27
+ table: error.table,
28
+ column: error.column,
29
+ original,
30
+ }),
31
+ });
32
+ }
33
+ if ("kind" in error && error.kind === "sql_connection") {
34
+ return new PrismaError({
35
+ reason: new PrismaConnectionFailure({
36
+ transient: error.transient,
37
+ original,
38
+ }),
39
+ });
40
+ }
41
+ return new PrismaError({
42
+ reason: new PrismaRuntimeFailure({
43
+ code: error.code,
44
+ original,
45
+ }),
46
+ });
47
+ };
48
+ //# sourceMappingURL=error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAExC,MAAM,OAAO,oBAAqB,SAAQ,IAAI,CAAC,WAAW,CACzD,sBAAsB,CAIrB;CAAG;AAEL,MAAM,OAAO,kBAAmB,SAAQ,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAM3E;CAAG;AAEL,MAAM,OAAO,uBAAwB,SAAQ,IAAI,CAAC,WAAW,CAC5D,yBAAyB,CAIxB;CAAG;AAOL,MAAM,OAAO,WAAY,SAAQ,IAAI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;QACtB,MAAM,EAAE,IAAI,oBAAoB,CAAC;YAChC,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,QAAQ;SACR,CAAC;KACF,CAAC,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { type DatabaseDefinition, type DatabaseLayerOptions, type DatabaseService, makeDatabase, } from "./database.js";
2
+ export { PrismaConnectionFailure, PrismaError, type PrismaErrorReason, PrismaQueryFailure, PrismaRuntimeFailure, } from "./error.js";
3
+ export type { Relation } from "./relation.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,YAAY,GACZ,MAAM,eAAe,CAAC;AACvB,OAAO,EACN,uBAAuB,EACvB,WAAW,EACX,KAAK,iBAAiB,EACtB,kBAAkB,EAClB,oBAAoB,GACpB,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { makeDatabase, } from "./database.js";
2
+ export { PrismaConnectionFailure, PrismaError, PrismaQueryFailure, PrismaRuntimeFailure, } from "./error.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,YAAY,GACZ,MAAM,eAAe,CAAC;AACvB,OAAO,EACN,uBAAuB,EACvB,WAAW,EAEX,kBAAkB,EAClB,oBAAoB,GACpB,MAAM,YAAY,CAAC"}
@@ -0,0 +1,7 @@
1
+ export interface ClientLifecycle {
2
+ readonly connect: () => PromiseLike<unknown>;
3
+ readonly close: () => PromiseLike<void>;
4
+ }
5
+ export declare const acquireConnectedClient: <A>(client: ClientLifecycle, initialize: () => A) => Promise<A>;
6
+ export declare const assertAvailableModelNames: (modelNames: ReadonlyArray<string>) => void;
7
+ //# sourceMappingURL=client-lifecycle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-lifecycle.d.ts","sourceRoot":"","sources":["../../src/internal/client-lifecycle.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,OAAO,EAAE,MAAM,WAAW,CAAC,OAAO,CAAC,CAAC;IAC7C,QAAQ,CAAC,KAAK,EAAE,MAAM,WAAW,CAAC,IAAI,CAAC,CAAC;CACxC;AAED,eAAO,MAAM,sBAAsB,GAAU,CAAC,EAC7C,QAAQ,eAAe,EACvB,YAAY,MAAM,CAAC,KACjB,OAAO,CAAC,CAAC,CAQX,CAAC;AAIF,eAAO,MAAM,yBAAyB,GACrC,YAAY,aAAa,CAAC,MAAM,CAAC,KAC/B,IAQF,CAAC"}
@@ -0,0 +1,19 @@
1
+ export const acquireConnectedClient = async (client, initialize) => {
2
+ try {
3
+ await client.connect();
4
+ return initialize();
5
+ }
6
+ catch (error) {
7
+ await Promise.resolve(client.close()).catch(() => undefined);
8
+ throw error;
9
+ }
10
+ };
11
+ const reservedModelNames = new Set(["transaction"]);
12
+ export const assertAvailableModelNames = (modelNames) => {
13
+ for (const modelName of modelNames) {
14
+ if (reservedModelNames.has(modelName)) {
15
+ throw new TypeError(`Prisma model name conflicts with the database facade: ${modelName}`);
16
+ }
17
+ }
18
+ };
19
+ //# sourceMappingURL=client-lifecycle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-lifecycle.js","sourceRoot":"","sources":["../../src/internal/client-lifecycle.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,EAC1C,MAAuB,EACvB,UAAmB,EACN,EAAE;IACf,IAAI,CAAC;QACJ,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;QACvB,OAAO,UAAU,EAAE,CAAC;IACrB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,MAAM,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC7D,MAAM,KAAK,CAAC;IACb,CAAC;AACF,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC;AAEpD,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACxC,UAAiC,EAC1B,EAAE;IACT,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACpC,IAAI,kBAAkB,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;YACvC,MAAM,IAAI,SAAS,CAClB,yDAAyD,SAAS,EAAE,CACpE,CAAC;QACH,CAAC;IACF,CAAC;AACF,CAAC,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { Contract as PrismaContract } from "@prisma-next/contract/types";
2
+ import type { PostgresClient } from "@prisma-next/postgres/runtime";
3
+ import type { SqlStorage } from "@prisma-next/sql-contract/types";
4
+ import type { Context } from "effect";
5
+ export type AnyPostgresContract = PrismaContract<SqlStorage>;
6
+ export interface DatabaseExecutor<Models extends object, Contract extends AnyPostgresContract = AnyPostgresContract> {
7
+ readonly client: PostgresClient<Contract>;
8
+ readonly models: Models;
9
+ readonly transactional: boolean;
10
+ }
11
+ export type ExecutorService<Models extends object, Contract extends AnyPostgresContract = AnyPostgresContract> = Context.Service<ExecutorIdentifier<Models>, DatabaseExecutor<Models, Contract>>;
12
+ export interface ExecutorIdentifier<Models extends object> {
13
+ readonly _models: Models;
14
+ readonly _executorIdentifier: unique symbol;
15
+ }
16
+ //# sourceMappingURL=executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../src/internal/executor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,IAAI,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC9E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEtC,MAAM,MAAM,mBAAmB,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;AAE7D,MAAM,WAAW,gBAAgB,CAChC,MAAM,SAAS,MAAM,EACrB,QAAQ,SAAS,mBAAmB,GAAG,mBAAmB;IAE1D,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAC;IAC1C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;CAChC;AAED,MAAM,MAAM,eAAe,CAC1B,MAAM,SAAS,MAAM,EACrB,QAAQ,SAAS,mBAAmB,GAAG,mBAAmB,IACvD,OAAO,CAAC,OAAO,CAClB,kBAAkB,CAAC,MAAM,CAAC,EAC1B,gBAAgB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAClC,CAAC;AAEF,MAAM,WAAW,kBAAkB,CAAC,MAAM,SAAS,MAAM;IACxD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,mBAAmB,EAAE,OAAO,MAAM,CAAC;CAC5C"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=executor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.js","sourceRoot":"","sources":["../../src/internal/executor.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import { Effect } from "effect";
2
+ import { type PrismaError } from "../error.js";
3
+ export declare const fromPrismaPromise: <A>(evaluate: (signal: AbortSignal) => PromiseLike<A>) => Effect.Effect<A, PrismaError>;
4
+ //# sourceMappingURL=promise.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../../src/internal/promise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAmB,KAAK,WAAW,EAAiB,MAAM,aAAa,CAAC;AAE/E,eAAO,MAAM,iBAAiB,GAAI,CAAC,EAClC,UAAU,CAAC,MAAM,EAAE,WAAW,KAAK,WAAW,CAAC,CAAC,CAAC,KAC/C,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,WAAW,CAU7B,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { Effect } from "effect";
2
+ import { isPrismaFailure, toPrismaError } from "../error.js";
3
+ export const fromPrismaPromise = (evaluate) => Effect.tryPromise({
4
+ try: (signal) => Promise.resolve(evaluate(signal)),
5
+ catch: (error) => error,
6
+ }).pipe(Effect.catch((error) => isPrismaFailure(error)
7
+ ? Effect.fail(toPrismaError(error))
8
+ : Effect.die(error)));
9
+ //# sourceMappingURL=promise.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"promise.js","sourceRoot":"","sources":["../../src/internal/promise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,eAAe,EAAoB,aAAa,EAAE,MAAM,aAAa,CAAC;AAE/E,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAChC,QAAiD,EACjB,EAAE,CAClC,MAAM,CAAC,UAAU,CAAC;IACjB,GAAG,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAClD,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK;CACvB,CAAC,CAAC,IAAI,CACN,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CACtB,eAAe,CAAC,KAAK,CAAC;IACrB,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CACpB,CACD,CAAC"}
@@ -0,0 +1,13 @@
1
+ export interface RelationOperation {
2
+ readonly name: PropertyKey;
3
+ readonly arguments: ReadonlyArray<unknown>;
4
+ }
5
+ export interface RelationRecipe {
6
+ readonly model: string;
7
+ readonly parent?: RelationRecipe;
8
+ readonly operation?: RelationOperation;
9
+ }
10
+ export declare const rootRecipe: (model: string) => RelationRecipe;
11
+ export declare const appendOperation: (parent: RelationRecipe, name: PropertyKey, arguments_: ReadonlyArray<unknown>) => RelationRecipe;
12
+ export declare const replayRecipe: (models: object, recipe: RelationRecipe) => unknown;
13
+ //# sourceMappingURL=recipe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recipe.d.ts","sourceRoot":"","sources":["../../src/internal/recipe.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,iBAAiB;IACjC,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;CAC3C;AAED,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,CAAC,EAAE,cAAc,CAAC;IACjC,QAAQ,CAAC,SAAS,CAAC,EAAE,iBAAiB,CAAC;CACvC;AAED,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,KAAG,cAA6B,CAAC;AAEzE,eAAO,MAAM,eAAe,GAC3B,QAAQ,cAAc,EACtB,MAAM,WAAW,EACjB,YAAY,aAAa,CAAC,OAAO,CAAC,KAChC,cAOD,CAAC;AA8GH,eAAO,MAAM,YAAY,GACxB,QAAQ,MAAM,EACd,QAAQ,cAAc,KACpB,OAQF,CAAC"}