@effectify/prisma 0.1.2 → 1.0.1
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/src/cli.d.ts +1 -1
- package/dist/src/cli.js +9 -9
- package/dist/src/commands/init.d.ts +1 -1
- package/dist/src/commands/init.js +0 -2
- package/dist/src/commands/prisma.d.ts +5 -0
- package/dist/src/commands/prisma.js +35 -0
- package/dist/src/generators/sql-schema-generator.d.ts +9 -0
- package/dist/src/generators/sql-schema-generator.js +50 -58
- package/dist/src/services/generator-context.d.ts +6 -0
- package/dist/src/services/generator-context.js +3 -0
- package/dist/src/services/generator-service.d.ts +14 -0
- package/dist/src/services/generator-service.js +121 -0
- package/dist/src/services/render-service.d.ts +10 -0
- package/dist/src/services/render-service.js +23 -0
- package/{src → dist/src}/templates/index-default.eta +1 -1
- package/dist/src/templates/model.eta +8 -0
- package/{src → dist/src}/templates/prisma-repository.eta +7 -7
- package/package.json +15 -11
- package/dist/src/commands/generate-effect.d.ts +0 -2
- package/dist/src/commands/generate-effect.js +0 -73
- package/dist/src/commands/generate-sql-schema.d.ts +0 -2
- package/dist/src/commands/generate-sql-schema.js +0 -72
- package/dist/src/effect-prisma.d.ts +0 -2
- package/dist/src/effect-prisma.js +0 -1771
- package/dist/src/generators/prisma-effect-generator.d.ts +0 -1
- package/dist/src/generators/prisma-effect-generator.js +0 -446
- package/prisma/dev.db +0 -0
- package/prisma/generated/client.d.ts +0 -1
- package/prisma/generated/client.js +0 -5
- package/prisma/generated/default.d.ts +0 -1
- package/prisma/generated/default.js +0 -5
- package/prisma/generated/edge.d.ts +0 -1
- package/prisma/generated/edge.js +0 -141
- package/prisma/generated/effect/index.ts +0 -392
- package/prisma/generated/effect/models/Todo.ts +0 -6
- package/prisma/generated/effect/prisma-repository.ts +0 -954
- package/prisma/generated/effect/prisma-schema.ts +0 -94
- package/prisma/generated/effect/schemas/enums.ts +0 -6
- package/prisma/generated/effect/schemas/index.ts +0 -2
- package/prisma/generated/effect/schemas/types.ts +0 -40
- package/prisma/generated/index-browser.js +0 -172
- package/prisma/generated/index.d.ts +0 -2376
- package/prisma/generated/index.js +0 -141
- package/prisma/generated/package.json +0 -144
- package/prisma/generated/query_compiler_bg.js +0 -2
- package/prisma/generated/query_compiler_bg.wasm +0 -0
- package/prisma/generated/query_compiler_bg.wasm-base64.js +0 -2
- package/prisma/generated/runtime/client.d.ts +0 -3180
- package/prisma/generated/runtime/client.js +0 -86
- package/prisma/generated/runtime/index-browser.d.ts +0 -87
- package/prisma/generated/runtime/index-browser.js +0 -6
- package/prisma/generated/runtime/wasm-compiler-edge.js +0 -76
- package/prisma/generated/schema.prisma +0 -31
- package/prisma/generated/wasm-edge-light-loader.mjs +0 -5
- package/prisma/generated/wasm-worker-loader.mjs +0 -5
- package/prisma/migrations/20250721164420_init/migration.sql +0 -9
- package/prisma/migrations/20250721191716_dumb/migration.sql +0 -49
- package/prisma/migrations/migration_lock.toml +0 -3
- package/prisma/schema.prisma +0 -31
- package/prisma.config.ts +0 -8
- package/project.json +0 -48
- package/scripts/cleanup-tests.ts +0 -26
- package/scripts/generate-test-files.ts +0 -93
- package/setup-tests.ts +0 -10
- package/src/cli.ts +0 -22
- package/src/commands/init.ts +0 -153
- package/src/commands/prisma.ts +0 -50
- package/src/generators/sql-schema-generator.ts +0 -66
- package/src/services/generator-context.ts +0 -4
- package/src/services/generator-service.ts +0 -178
- package/src/services/render-service.ts +0 -32
- package/src/templates/model.eta +0 -6
- package/test/prisma-model.test.ts +0 -340
- package/test/utils.ts +0 -10
- package/tsconfig.json +0 -20
- package/tsconfig.lib.json +0 -24
- package/tsconfig.spec.json +0 -15
- package/vitest.config.ts +0 -24
- /package/{src → dist/src}/templates/index-custom-error.eta +0 -0
- /package/{src → dist/src}/templates/prisma-raw-sql.eta +0 -0
- /package/{src → dist/src}/templates/prisma-schema.eta +0 -0
|
@@ -1,954 +0,0 @@
|
|
|
1
|
-
/** biome-ignore-all lint/suspicious/noExplicitAny: <todo> */
|
|
2
|
-
/** biome-ignore-all lint/style/useDefaultSwitchClause: <todo> */
|
|
3
|
-
|
|
4
|
-
import * as VariantSchema from '@effect/experimental/VariantSchema'
|
|
5
|
-
import { type PrismaClient as BasePrismaClient, Prisma as PrismaNamespace } from '@prisma/client'
|
|
6
|
-
import { PrismaClient } from './index.js'
|
|
7
|
-
import * as Data from 'effect/Data'
|
|
8
|
-
import * as Effect from 'effect/Effect'
|
|
9
|
-
import type * as Option from 'effect/Option'
|
|
10
|
-
import * as Schema from 'effect/Schema'
|
|
11
|
-
import * as SqlSchema from './prisma-schema.js'
|
|
12
|
-
|
|
13
|
-
export class PrismaUniqueConstraintError extends Data.TaggedError('PrismaUniqueConstraintError')<{
|
|
14
|
-
cause: PrismaNamespace.PrismaClientKnownRequestError
|
|
15
|
-
operation: string
|
|
16
|
-
model: string
|
|
17
|
-
}> {}
|
|
18
|
-
|
|
19
|
-
export class PrismaForeignKeyConstraintError extends Data.TaggedError('PrismaForeignKeyConstraintError')<{
|
|
20
|
-
cause: PrismaNamespace.PrismaClientKnownRequestError
|
|
21
|
-
operation: string
|
|
22
|
-
model: string
|
|
23
|
-
}> {}
|
|
24
|
-
|
|
25
|
-
export class PrismaRecordNotFoundError extends Data.TaggedError('PrismaRecordNotFoundError')<{
|
|
26
|
-
cause: PrismaNamespace.PrismaClientKnownRequestError
|
|
27
|
-
operation: string
|
|
28
|
-
model: string
|
|
29
|
-
}> {}
|
|
30
|
-
|
|
31
|
-
export class PrismaRelationViolationError extends Data.TaggedError('PrismaRelationViolationError')<{
|
|
32
|
-
cause: PrismaNamespace.PrismaClientKnownRequestError
|
|
33
|
-
operation: string
|
|
34
|
-
model: string
|
|
35
|
-
}> {}
|
|
36
|
-
|
|
37
|
-
export class PrismaRelatedRecordNotFoundError extends Data.TaggedError('PrismaRelatedRecordNotFoundError')<{
|
|
38
|
-
cause: PrismaNamespace.PrismaClientKnownRequestError
|
|
39
|
-
operation: string
|
|
40
|
-
model: string
|
|
41
|
-
}> {}
|
|
42
|
-
|
|
43
|
-
export class PrismaTransactionConflictError extends Data.TaggedError('PrismaTransactionConflictError')<{
|
|
44
|
-
cause: PrismaNamespace.PrismaClientKnownRequestError
|
|
45
|
-
operation: string
|
|
46
|
-
model: string
|
|
47
|
-
}> {}
|
|
48
|
-
|
|
49
|
-
export class PrismaValueTooLongError extends Data.TaggedError('PrismaValueTooLongError')<{
|
|
50
|
-
cause: PrismaNamespace.PrismaClientKnownRequestError
|
|
51
|
-
operation: string
|
|
52
|
-
model: string
|
|
53
|
-
}> {}
|
|
54
|
-
|
|
55
|
-
export class PrismaValueOutOfRangeError extends Data.TaggedError('PrismaValueOutOfRangeError')<{
|
|
56
|
-
cause: PrismaNamespace.PrismaClientKnownRequestError
|
|
57
|
-
operation: string
|
|
58
|
-
model: string
|
|
59
|
-
}> {}
|
|
60
|
-
|
|
61
|
-
export class PrismaDbConstraintError extends Data.TaggedError('PrismaDbConstraintError')<{
|
|
62
|
-
cause: PrismaNamespace.PrismaClientKnownRequestError
|
|
63
|
-
operation: string
|
|
64
|
-
model: string
|
|
65
|
-
}> {}
|
|
66
|
-
|
|
67
|
-
export class PrismaConnectionError extends Data.TaggedError('PrismaConnectionError')<{
|
|
68
|
-
cause: PrismaNamespace.PrismaClientKnownRequestError
|
|
69
|
-
operation: string
|
|
70
|
-
model: string
|
|
71
|
-
}> {}
|
|
72
|
-
|
|
73
|
-
export class PrismaMissingRequiredValueError extends Data.TaggedError('PrismaMissingRequiredValueError')<{
|
|
74
|
-
cause: PrismaNamespace.PrismaClientKnownRequestError
|
|
75
|
-
operation: string
|
|
76
|
-
model: string
|
|
77
|
-
}> {}
|
|
78
|
-
|
|
79
|
-
export class PrismaInputValidationError extends Data.TaggedError('PrismaInputValidationError')<{
|
|
80
|
-
cause: PrismaNamespace.PrismaClientKnownRequestError
|
|
81
|
-
operation: string
|
|
82
|
-
model: string
|
|
83
|
-
}> {}
|
|
84
|
-
|
|
85
|
-
export type PrismaCreateError =
|
|
86
|
-
| PrismaValueTooLongError
|
|
87
|
-
| PrismaUniqueConstraintError
|
|
88
|
-
| PrismaForeignKeyConstraintError
|
|
89
|
-
| PrismaDbConstraintError
|
|
90
|
-
| PrismaInputValidationError
|
|
91
|
-
| PrismaMissingRequiredValueError
|
|
92
|
-
| PrismaRelatedRecordNotFoundError
|
|
93
|
-
| PrismaValueOutOfRangeError
|
|
94
|
-
| PrismaConnectionError
|
|
95
|
-
| PrismaTransactionConflictError
|
|
96
|
-
|
|
97
|
-
export type PrismaUpdateError =
|
|
98
|
-
| PrismaValueTooLongError
|
|
99
|
-
| PrismaUniqueConstraintError
|
|
100
|
-
| PrismaForeignKeyConstraintError
|
|
101
|
-
| PrismaDbConstraintError
|
|
102
|
-
| PrismaInputValidationError
|
|
103
|
-
| PrismaMissingRequiredValueError
|
|
104
|
-
| PrismaRelationViolationError
|
|
105
|
-
| PrismaRelatedRecordNotFoundError
|
|
106
|
-
| PrismaValueOutOfRangeError
|
|
107
|
-
| PrismaConnectionError
|
|
108
|
-
| PrismaRecordNotFoundError
|
|
109
|
-
| PrismaTransactionConflictError
|
|
110
|
-
|
|
111
|
-
export type PrismaDeleteError =
|
|
112
|
-
| PrismaForeignKeyConstraintError
|
|
113
|
-
| PrismaRelationViolationError
|
|
114
|
-
| PrismaConnectionError
|
|
115
|
-
| PrismaRecordNotFoundError
|
|
116
|
-
| PrismaTransactionConflictError
|
|
117
|
-
|
|
118
|
-
export type PrismaFindOrThrowError =
|
|
119
|
-
| PrismaConnectionError
|
|
120
|
-
| PrismaRecordNotFoundError
|
|
121
|
-
|
|
122
|
-
export type PrismaFindError =
|
|
123
|
-
| PrismaConnectionError
|
|
124
|
-
|
|
125
|
-
export type PrismaDeleteManyError =
|
|
126
|
-
| PrismaForeignKeyConstraintError
|
|
127
|
-
| PrismaRelationViolationError
|
|
128
|
-
| PrismaConnectionError
|
|
129
|
-
| PrismaTransactionConflictError
|
|
130
|
-
|
|
131
|
-
export type PrismaUpdateManyError =
|
|
132
|
-
| PrismaValueTooLongError
|
|
133
|
-
| PrismaUniqueConstraintError
|
|
134
|
-
| PrismaForeignKeyConstraintError
|
|
135
|
-
| PrismaDbConstraintError
|
|
136
|
-
| PrismaInputValidationError
|
|
137
|
-
| PrismaMissingRequiredValueError
|
|
138
|
-
| PrismaValueOutOfRangeError
|
|
139
|
-
| PrismaConnectionError
|
|
140
|
-
| PrismaTransactionConflictError
|
|
141
|
-
|
|
142
|
-
// Create, Upsert
|
|
143
|
-
export const mapCreateError = (error: unknown, operation: string, model: string): PrismaCreateError => {
|
|
144
|
-
if (error instanceof PrismaNamespace.PrismaClientKnownRequestError) {
|
|
145
|
-
switch (error.code) {
|
|
146
|
-
case 'P2000':
|
|
147
|
-
return new PrismaValueTooLongError({ cause: error, operation, model })
|
|
148
|
-
case 'P2002':
|
|
149
|
-
return new PrismaUniqueConstraintError({ cause: error, operation, model })
|
|
150
|
-
case 'P2003':
|
|
151
|
-
return new PrismaForeignKeyConstraintError({ cause: error, operation, model })
|
|
152
|
-
case 'P2004':
|
|
153
|
-
return new PrismaDbConstraintError({ cause: error, operation, model })
|
|
154
|
-
case 'P2005':
|
|
155
|
-
case 'P2006':
|
|
156
|
-
case 'P2019':
|
|
157
|
-
return new PrismaInputValidationError({ cause: error, operation, model })
|
|
158
|
-
case 'P2011':
|
|
159
|
-
case 'P2012':
|
|
160
|
-
return new PrismaMissingRequiredValueError({ cause: error, operation, model })
|
|
161
|
-
case 'P2015':
|
|
162
|
-
case 'P2018':
|
|
163
|
-
return new PrismaRelatedRecordNotFoundError({ cause: error, operation, model })
|
|
164
|
-
case 'P2020':
|
|
165
|
-
return new PrismaValueOutOfRangeError({ cause: error, operation, model })
|
|
166
|
-
case 'P2024':
|
|
167
|
-
return new PrismaConnectionError({ cause: error, operation, model })
|
|
168
|
-
case 'P2034':
|
|
169
|
-
return new PrismaTransactionConflictError({ cause: error, operation, model })
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
throw error
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// Update
|
|
176
|
-
export const mapUpdateError = (error: unknown, operation: string, model: string): PrismaUpdateError => {
|
|
177
|
-
if (error instanceof PrismaNamespace.PrismaClientKnownRequestError) {
|
|
178
|
-
switch (error.code) {
|
|
179
|
-
case "P2000":
|
|
180
|
-
return new PrismaValueTooLongError({ cause: error, operation, model });
|
|
181
|
-
case "P2002":
|
|
182
|
-
return new PrismaUniqueConstraintError({ cause: error, operation, model });
|
|
183
|
-
case "P2003":
|
|
184
|
-
return new PrismaForeignKeyConstraintError({ cause: error, operation, model });
|
|
185
|
-
case "P2004":
|
|
186
|
-
return new PrismaDbConstraintError({ cause: error, operation, model });
|
|
187
|
-
case "P2005":
|
|
188
|
-
case "P2006":
|
|
189
|
-
case "P2019":
|
|
190
|
-
return new PrismaInputValidationError({ cause: error, operation, model });
|
|
191
|
-
case "P2011":
|
|
192
|
-
case "P2012":
|
|
193
|
-
return new PrismaMissingRequiredValueError({ cause: error, operation, model });
|
|
194
|
-
case "P2014":
|
|
195
|
-
return new PrismaRelationViolationError({ cause: error, operation, model });
|
|
196
|
-
case "P2015":
|
|
197
|
-
case "P2018":
|
|
198
|
-
return new PrismaRelatedRecordNotFoundError({ cause: error, operation, model });
|
|
199
|
-
case "P2020":
|
|
200
|
-
return new PrismaValueOutOfRangeError({ cause: error, operation, model });
|
|
201
|
-
case "P2024":
|
|
202
|
-
return new PrismaConnectionError({ cause: error, operation, model });
|
|
203
|
-
case "P2025":
|
|
204
|
-
return new PrismaRecordNotFoundError({ cause: error, operation, model });
|
|
205
|
-
case "P2034":
|
|
206
|
-
return new PrismaTransactionConflictError({ cause: error, operation, model });
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
throw error;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
// Delete
|
|
213
|
-
export const mapDeleteError = (error: unknown, operation: string, model: string): PrismaDeleteError => {
|
|
214
|
-
if (error instanceof PrismaNamespace.PrismaClientKnownRequestError) {
|
|
215
|
-
switch (error.code) {
|
|
216
|
-
case "P2003":
|
|
217
|
-
return new PrismaForeignKeyConstraintError({ cause: error, operation, model });
|
|
218
|
-
case "P2014":
|
|
219
|
-
return new PrismaRelationViolationError({ cause: error, operation, model });
|
|
220
|
-
case "P2024":
|
|
221
|
-
return new PrismaConnectionError({ cause: error, operation, model });
|
|
222
|
-
case "P2025":
|
|
223
|
-
return new PrismaRecordNotFoundError({ cause: error, operation, model });
|
|
224
|
-
case "P2034":
|
|
225
|
-
return new PrismaTransactionConflictError({ cause: error, operation, model });
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
throw error;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// FindOrThrow
|
|
232
|
-
export const mapFindOrThrowError = (error: unknown, operation: string, model: string): PrismaFindOrThrowError => {
|
|
233
|
-
if (error instanceof PrismaNamespace.PrismaClientKnownRequestError) {
|
|
234
|
-
switch (error.code) {
|
|
235
|
-
case "P2024":
|
|
236
|
-
return new PrismaConnectionError({ cause: error, operation, model });
|
|
237
|
-
case "P2025":
|
|
238
|
-
return new PrismaRecordNotFoundError({ cause: error, operation, model });
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
throw error;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
// Find
|
|
245
|
-
export const mapFindError = (error: unknown, operation: string, model: string): PrismaFindError => {
|
|
246
|
-
if (error instanceof PrismaNamespace.PrismaClientKnownRequestError) {
|
|
247
|
-
switch (error.code) {
|
|
248
|
-
case "P2024":
|
|
249
|
-
return new PrismaConnectionError({ cause: error, operation, model });
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
throw error;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// DeleteMany
|
|
256
|
-
export const mapDeleteManyError = (error: unknown, operation: string, model: string): PrismaDeleteManyError => {
|
|
257
|
-
if (error instanceof PrismaNamespace.PrismaClientKnownRequestError) {
|
|
258
|
-
switch (error.code) {
|
|
259
|
-
case "P2003":
|
|
260
|
-
return new PrismaForeignKeyConstraintError({ cause: error, operation, model });
|
|
261
|
-
case "P2014":
|
|
262
|
-
return new PrismaRelationViolationError({ cause: error, operation, model });
|
|
263
|
-
case "P2024":
|
|
264
|
-
return new PrismaConnectionError({ cause: error, operation, model });
|
|
265
|
-
case "P2034":
|
|
266
|
-
return new PrismaTransactionConflictError({ cause: error, operation, model });
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
throw error;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
// UpdateMany
|
|
273
|
-
export const mapUpdateManyError = (error: unknown, operation: string, model: string): PrismaUpdateManyError => {
|
|
274
|
-
if (error instanceof PrismaNamespace.PrismaClientKnownRequestError) {
|
|
275
|
-
switch (error.code) {
|
|
276
|
-
case "P2000":
|
|
277
|
-
return new PrismaValueTooLongError({ cause: error, operation, model });
|
|
278
|
-
case "P2002":
|
|
279
|
-
return new PrismaUniqueConstraintError({ cause: error, operation, model });
|
|
280
|
-
case "P2003":
|
|
281
|
-
return new PrismaForeignKeyConstraintError({ cause: error, operation, model });
|
|
282
|
-
case "P2004":
|
|
283
|
-
return new PrismaDbConstraintError({ cause: error, operation, model });
|
|
284
|
-
case "P2005":
|
|
285
|
-
case "P2006":
|
|
286
|
-
case "P2019":
|
|
287
|
-
return new PrismaInputValidationError({ cause: error, operation, model });
|
|
288
|
-
case "P2011":
|
|
289
|
-
case "P2012":
|
|
290
|
-
return new PrismaMissingRequiredValueError({ cause: error, operation, model });
|
|
291
|
-
case "P2020":
|
|
292
|
-
return new PrismaValueOutOfRangeError({ cause: error, operation, model });
|
|
293
|
-
case "P2024":
|
|
294
|
-
return new PrismaConnectionError({ cause: error, operation, model });
|
|
295
|
-
case "P2034":
|
|
296
|
-
return new PrismaTransactionConflictError({ cause: error, operation, model });
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
throw error;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
const { Class, Field, FieldExcept, FieldOnly, Struct, Union, extract, fieldEvolve, fieldFromKey } = VariantSchema.make({
|
|
303
|
-
variants: [
|
|
304
|
-
'findUnique',
|
|
305
|
-
'findUniqueOrThrow',
|
|
306
|
-
'findFirst',
|
|
307
|
-
'findFirstOrThrow',
|
|
308
|
-
'findMany',
|
|
309
|
-
'create',
|
|
310
|
-
'createMany',
|
|
311
|
-
'createManyAndReturn',
|
|
312
|
-
'update',
|
|
313
|
-
'json',
|
|
314
|
-
'jsonCreate',
|
|
315
|
-
'jsonUpdate',
|
|
316
|
-
],
|
|
317
|
-
defaultVariant: 'findUnique',
|
|
318
|
-
})
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* @since 1.0.0
|
|
322
|
-
* @category models
|
|
323
|
-
*/
|
|
324
|
-
export type Any = Schema.Schema.Any & {
|
|
325
|
-
readonly fields: Schema.Struct.Fields
|
|
326
|
-
readonly findUnique: Schema.Schema.Any
|
|
327
|
-
readonly findUniqueOrThrow: Schema.Schema.Any
|
|
328
|
-
readonly findFirst: Schema.Schema.Any
|
|
329
|
-
readonly findFirstOrThrow: Schema.Schema.Any
|
|
330
|
-
readonly findMany: Schema.Schema.Any
|
|
331
|
-
readonly create: Schema.Schema.Any
|
|
332
|
-
readonly createMany: Schema.Schema.Any
|
|
333
|
-
readonly createManyAndReturn: Schema.Schema.Any
|
|
334
|
-
readonly update: Schema.Schema.Any
|
|
335
|
-
readonly json: Schema.Schema.Any
|
|
336
|
-
readonly jsonCreate: Schema.Schema.Any
|
|
337
|
-
readonly jsonUpdate: Schema.Schema.Any
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
* @since 1.0.0
|
|
342
|
-
* @category models
|
|
343
|
-
*/
|
|
344
|
-
export type AnyNoContext = Schema.Schema.AnyNoContext & {
|
|
345
|
-
readonly fields: Schema.Struct.Fields
|
|
346
|
-
readonly findUnique: Schema.Schema.AnyNoContext
|
|
347
|
-
readonly findUniqueOrThrow: Schema.Schema.AnyNoContext
|
|
348
|
-
readonly findFirst: Schema.Schema.AnyNoContext
|
|
349
|
-
readonly findFirstOrThrow: Schema.Schema.AnyNoContext
|
|
350
|
-
readonly findMany: Schema.Schema.AnyNoContext
|
|
351
|
-
readonly create: Schema.Schema.AnyNoContext
|
|
352
|
-
readonly createMany: Schema.Schema.AnyNoContext
|
|
353
|
-
readonly createManyAndReturn: Schema.Schema.AnyNoContext
|
|
354
|
-
readonly update: Schema.Schema.AnyNoContext
|
|
355
|
-
readonly json: Schema.Schema.AnyNoContext
|
|
356
|
-
readonly jsonCreate: Schema.Schema.AnyNoContext
|
|
357
|
-
readonly jsonUpdate: Schema.Schema.AnyNoContext
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
/**
|
|
361
|
-
* @since 1.0.0
|
|
362
|
-
* @category models
|
|
363
|
-
*/
|
|
364
|
-
export type VariantsDatabase =
|
|
365
|
-
| 'findUnique'
|
|
366
|
-
| 'findUniqueOrThrow'
|
|
367
|
-
| 'findFirst'
|
|
368
|
-
| 'findFirstOrThrow'
|
|
369
|
-
| 'findMany'
|
|
370
|
-
| 'create'
|
|
371
|
-
| 'createMany'
|
|
372
|
-
| 'createManyAndReturn'
|
|
373
|
-
| 'update'
|
|
374
|
-
|
|
375
|
-
/**
|
|
376
|
-
* @since 1.0.0
|
|
377
|
-
* @category models
|
|
378
|
-
*/
|
|
379
|
-
export type VariantsJson = 'json' | 'jsonCreate' | 'jsonUpdate'
|
|
380
|
-
|
|
381
|
-
export {
|
|
382
|
-
/**
|
|
383
|
-
* A base class used for creating domain model schemas.
|
|
384
|
-
*
|
|
385
|
-
* It supports common variants for database and JSON apis.
|
|
386
|
-
*
|
|
387
|
-
* @since 1.0.0
|
|
388
|
-
* @category constructors
|
|
389
|
-
* @example
|
|
390
|
-
* \`\`\`ts
|
|
391
|
-
* import { Schema } from "effect"
|
|
392
|
-
* import { Model } from "@effect/sql"
|
|
393
|
-
*
|
|
394
|
-
* export const GroupId = Schema.Number.pipe(Schema.brand("GroupId"))
|
|
395
|
-
*
|
|
396
|
-
* export class Group extends Model.Class<Group>("Group")({
|
|
397
|
-
* id: Model.Generated(GroupId),
|
|
398
|
-
* name: Schema.NonEmptyTrimmedString,
|
|
399
|
-
* createdAt: Model.DateTimeInsertFromDate,
|
|
400
|
-
* updatedAt: Model.DateTimeUpdateFromDate
|
|
401
|
-
* }) {}
|
|
402
|
-
*
|
|
403
|
-
* // schema used for selects
|
|
404
|
-
* Group
|
|
405
|
-
*
|
|
406
|
-
* // schema used for inserts
|
|
407
|
-
* Group.insert
|
|
408
|
-
*
|
|
409
|
-
* // schema used for updates
|
|
410
|
-
* Group.update
|
|
411
|
-
*
|
|
412
|
-
* // schema used for json api
|
|
413
|
-
* Group.json
|
|
414
|
-
* Group.jsonCreate
|
|
415
|
-
* Group.jsonUpdate
|
|
416
|
-
*
|
|
417
|
-
* // you can also turn them into classes
|
|
418
|
-
* class GroupJson extends Schema.Class<GroupJson>("GroupJson")(Group.json) {
|
|
419
|
-
* get upperName() {
|
|
420
|
-
* return this.name.toUpperCase()
|
|
421
|
-
* }
|
|
422
|
-
* }
|
|
423
|
-
* \`\`\`
|
|
424
|
-
*/
|
|
425
|
-
Class,
|
|
426
|
-
/**
|
|
427
|
-
* @since 1.0.0
|
|
428
|
-
* @category extraction
|
|
429
|
-
*/
|
|
430
|
-
extract,
|
|
431
|
-
/**
|
|
432
|
-
* @since 1.0.0
|
|
433
|
-
* @category fields
|
|
434
|
-
*/
|
|
435
|
-
Field,
|
|
436
|
-
/**
|
|
437
|
-
* @since 1.0.0
|
|
438
|
-
* @category fields
|
|
439
|
-
*/
|
|
440
|
-
fieldEvolve,
|
|
441
|
-
/**
|
|
442
|
-
* @since 1.0.0
|
|
443
|
-
* @category fields
|
|
444
|
-
*/
|
|
445
|
-
FieldExcept,
|
|
446
|
-
/**
|
|
447
|
-
* @since 1.0.0
|
|
448
|
-
* @category fields
|
|
449
|
-
*/
|
|
450
|
-
fieldFromKey,
|
|
451
|
-
/**
|
|
452
|
-
* @since 1.0.0
|
|
453
|
-
* @category fields
|
|
454
|
-
*/
|
|
455
|
-
FieldOnly,
|
|
456
|
-
/**
|
|
457
|
-
* @since 1.0.0
|
|
458
|
-
* @category constructors
|
|
459
|
-
*/
|
|
460
|
-
Struct,
|
|
461
|
-
/**
|
|
462
|
-
* @since 1.0.0
|
|
463
|
-
* @category constructors
|
|
464
|
-
*/
|
|
465
|
-
Union,
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
/**
|
|
469
|
-
* Create a simple CRUD repository from a model.
|
|
470
|
-
*
|
|
471
|
-
* @since 1.0.0
|
|
472
|
-
* @category repository
|
|
473
|
-
*/
|
|
474
|
-
export const make = <S extends Any, M extends keyof BasePrismaClient>(
|
|
475
|
-
Model: S,
|
|
476
|
-
options: {
|
|
477
|
-
readonly modelName: M extends string ? M : string
|
|
478
|
-
readonly spanPrefix: string
|
|
479
|
-
readonly uniqueKey?: string | ReadonlyArray<string>
|
|
480
|
-
},
|
|
481
|
-
): Effect.Effect<
|
|
482
|
-
{
|
|
483
|
-
readonly findUnique: <A extends PrismaNamespace.Args<BasePrismaClient[M], 'findUnique'>>(
|
|
484
|
-
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'findUnique'>>,
|
|
485
|
-
) => Effect.Effect<Option.Option<S['Type']>, PrismaFindError, S['Context'] | S['findUnique']['Context']>
|
|
486
|
-
|
|
487
|
-
readonly findUniqueOrThrow: <A extends PrismaNamespace.Args<BasePrismaClient[M], 'findUnique'>>(
|
|
488
|
-
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'findUnique'>>,
|
|
489
|
-
) => Effect.Effect<S['Type'], PrismaFindOrThrowError, S['Context'] | S['findUniqueOrThrow']['Context']>
|
|
490
|
-
|
|
491
|
-
readonly findFirst: <A extends PrismaNamespace.Args<BasePrismaClient[M], 'findFirst'>>(
|
|
492
|
-
args?: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'findFirst'>>
|
|
493
|
-
) => Effect.Effect<Option.Option<S['Type']>, PrismaFindError, S['Context'] | S['findFirst']['Context']>
|
|
494
|
-
|
|
495
|
-
readonly findFirstOrThrow: <A extends PrismaNamespace.Args<BasePrismaClient[M], 'findFirstOrThrow'>>(
|
|
496
|
-
args?: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'findFirstOrThrow'>>
|
|
497
|
-
) => Effect.Effect<S['Type'], PrismaFindOrThrowError, S['Context'] | S['findFirstOrThrow']['Context']>
|
|
498
|
-
|
|
499
|
-
readonly findMany: <A extends PrismaNamespace.Args<BasePrismaClient[M], 'findMany'>>(
|
|
500
|
-
args?: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'findMany'>>
|
|
501
|
-
) => Effect.Effect<Array<S['Type']>, PrismaFindError, S['Context'] | S['findMany']['Context']>
|
|
502
|
-
|
|
503
|
-
readonly create: <A extends PrismaNamespace.Args<BasePrismaClient[M], 'create'>>(
|
|
504
|
-
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'create'>>,
|
|
505
|
-
) => Effect.Effect<S['Type'], PrismaCreateError, S['Context'] | S['create']['Context']>
|
|
506
|
-
|
|
507
|
-
readonly createMany: <A extends PrismaNamespace.Args<BasePrismaClient[M], 'createMany'>>(
|
|
508
|
-
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'createMany'>>,
|
|
509
|
-
) => Effect.Effect<PrismaNamespace.BatchPayload, PrismaCreateError, S['Context'] | S['createMany']['Context']>
|
|
510
|
-
|
|
511
|
-
readonly createManyAndReturn: <A extends PrismaNamespace.Args<BasePrismaClient[M], 'createManyAndReturn'>>(
|
|
512
|
-
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'createManyAndReturn'>>,
|
|
513
|
-
) => Effect.Effect<Array<S['Type']>, PrismaCreateError, S['Context'] | S['createManyAndReturn']['Context']>
|
|
514
|
-
|
|
515
|
-
readonly update: <A extends PrismaNamespace.Args<BasePrismaClient[M], 'update'>>(
|
|
516
|
-
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'update'>>
|
|
517
|
-
) => Effect.Effect<S['Type'], PrismaUpdateError, S['Context'] | S['update']['Context']>
|
|
518
|
-
|
|
519
|
-
readonly updateMany: <A extends PrismaNamespace.Args<BasePrismaClient[M], 'updateMany'>>(
|
|
520
|
-
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'updateMany'>>
|
|
521
|
-
) => Effect.Effect<PrismaNamespace.BatchPayload, PrismaUpdateManyError, S['Context'] | S['update']['Context']>
|
|
522
|
-
|
|
523
|
-
readonly delete: <A extends PrismaNamespace.Args<BasePrismaClient[M], 'delete'>>(
|
|
524
|
-
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'delete'>>
|
|
525
|
-
) => Effect.Effect<S['Type'], PrismaDeleteError, S['Context']>
|
|
526
|
-
|
|
527
|
-
readonly deleteMany: <A extends PrismaNamespace.Args<BasePrismaClient[M], 'deleteMany'>>(
|
|
528
|
-
args?: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'deleteMany'>>
|
|
529
|
-
) => Effect.Effect<PrismaNamespace.BatchPayload, PrismaDeleteManyError, S['Context']>
|
|
530
|
-
|
|
531
|
-
readonly upsert: <A extends PrismaNamespace.Args<BasePrismaClient[M], 'upsert'>>(
|
|
532
|
-
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'upsert'>>
|
|
533
|
-
) => Effect.Effect<S['Type'], PrismaCreateError, S['Context']>
|
|
534
|
-
|
|
535
|
-
readonly count: <A extends PrismaNamespace.Args<BasePrismaClient[M], 'count'>>(
|
|
536
|
-
args?: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'count'>>
|
|
537
|
-
) => Effect.Effect<unknown, PrismaFindError, S['Context']>
|
|
538
|
-
|
|
539
|
-
readonly aggregate: <A extends PrismaNamespace.Args<BasePrismaClient[M], 'aggregate'>>(
|
|
540
|
-
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'aggregate'>>
|
|
541
|
-
) => Effect.Effect<unknown, PrismaFindError, S['Context']>
|
|
542
|
-
|
|
543
|
-
readonly groupBy: <A extends PrismaNamespace.Args<BasePrismaClient[M], 'groupBy'>>(
|
|
544
|
-
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'groupBy'>>
|
|
545
|
-
) => Effect.Effect<unknown, PrismaFindError, S['Context']>
|
|
546
|
-
},
|
|
547
|
-
never,
|
|
548
|
-
PrismaClient
|
|
549
|
-
> =>
|
|
550
|
-
Effect.gen(function* () {
|
|
551
|
-
const prisma = yield* PrismaClient
|
|
552
|
-
|
|
553
|
-
// Construye el schema del where para findUnique usando uniqueKey en modo builder
|
|
554
|
-
let findUniqueRequestSchema: Schema.Schema<any, any, any> = Schema.Unknown
|
|
555
|
-
if (options.uniqueKey) {
|
|
556
|
-
const keys = Array.isArray(options.uniqueKey) ? options.uniqueKey : [options.uniqueKey]
|
|
557
|
-
const shape: Record<string, Schema.Schema.Any> = {}
|
|
558
|
-
let valid = true
|
|
559
|
-
for (const key of keys) {
|
|
560
|
-
const field = (Model as any).fields?.[key]
|
|
561
|
-
if (!field) {
|
|
562
|
-
valid = false
|
|
563
|
-
break
|
|
564
|
-
}
|
|
565
|
-
shape[key] = field
|
|
566
|
-
}
|
|
567
|
-
if (valid) {
|
|
568
|
-
findUniqueRequestSchema = Schema.Struct(shape as any)
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
const findUniqueSchema = SqlSchema.findOne({
|
|
573
|
-
Request: findUniqueRequestSchema,
|
|
574
|
-
Result: Model,
|
|
575
|
-
execute: (request) =>
|
|
576
|
-
Effect.tryPromise({
|
|
577
|
-
try: () =>
|
|
578
|
-
((prisma.tx as BasePrismaClient)[options.modelName as M] as any).findUnique({ where: request }) as any,
|
|
579
|
-
catch: (error) => mapFindError(error, 'findUnique', options.modelName),
|
|
580
|
-
}).pipe(Effect.map((result) => (result ? [result] : []))),
|
|
581
|
-
})
|
|
582
|
-
|
|
583
|
-
const findUnique = <A extends PrismaNamespace.Args<BasePrismaClient[M], 'findUnique'>>(
|
|
584
|
-
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'findUnique'>>,
|
|
585
|
-
): Effect.Effect<Option.Option<S['Type']>, never, S['Context'] | S['findUnique']['Context']> =>
|
|
586
|
-
findUniqueSchema((args as any).where).pipe(
|
|
587
|
-
Effect.catchTag('ParseError', Effect.die),
|
|
588
|
-
Effect.withSpan(`\${options.spanPrefix}.findUnique`, {
|
|
589
|
-
captureStackTrace: false,
|
|
590
|
-
attributes: { ...(args as any).where },
|
|
591
|
-
}),
|
|
592
|
-
) as any
|
|
593
|
-
|
|
594
|
-
const findUniqueOrThrowSchema = SqlSchema.single({
|
|
595
|
-
Request: findUniqueRequestSchema,
|
|
596
|
-
Result: Model,
|
|
597
|
-
execute: (request) =>
|
|
598
|
-
Effect.tryPromise({
|
|
599
|
-
try: () =>
|
|
600
|
-
((prisma.tx as BasePrismaClient)[options.modelName as M] as any).findUniqueOrThrow({
|
|
601
|
-
where: request,
|
|
602
|
-
}) as any,
|
|
603
|
-
catch: (error) => mapFindOrThrowError(error, 'findUniqueOrThrow', options.modelName),
|
|
604
|
-
}).pipe(Effect.map((result) => [result] as any)),
|
|
605
|
-
})
|
|
606
|
-
|
|
607
|
-
const findUniqueOrThrow = <A extends PrismaNamespace.Args<BasePrismaClient[M], 'findUnique'>>(
|
|
608
|
-
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'findUnique'>>,
|
|
609
|
-
): Effect.Effect<S['Type'], never, S['Context'] | S['findUniqueOrThrow']['Context']> =>
|
|
610
|
-
findUniqueOrThrowSchema((args as any).where).pipe(
|
|
611
|
-
Effect.map((result) => result as S['Type']),
|
|
612
|
-
Effect.catchTag('ParseError', Effect.die),
|
|
613
|
-
Effect.catchTag('NoSuchElementException', Effect.die),
|
|
614
|
-
Effect.withSpan(`\${options.spanPrefix}.findUniqueOrThrow`, {
|
|
615
|
-
captureStackTrace: false,
|
|
616
|
-
attributes: { ...(args as any).where },
|
|
617
|
-
}),
|
|
618
|
-
) as any
|
|
619
|
-
|
|
620
|
-
const findFirstSchema = SqlSchema.findOne({
|
|
621
|
-
Request: Schema.Unknown,
|
|
622
|
-
Result: Model,
|
|
623
|
-
execute: (request) =>
|
|
624
|
-
Effect.tryPromise({
|
|
625
|
-
try: () =>
|
|
626
|
-
((prisma.tx as BasePrismaClient)[options.modelName as M] as any).findFirst(request) as any,
|
|
627
|
-
catch: (error) => mapFindError(error, 'findFirst', options.modelName),
|
|
628
|
-
}).pipe(Effect.map((result) => (result ? [result] : []))),
|
|
629
|
-
})
|
|
630
|
-
|
|
631
|
-
const findFirst = <A extends PrismaNamespace.Args<BasePrismaClient[M], 'findFirst'>>(
|
|
632
|
-
args?: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'findFirst'>>
|
|
633
|
-
): Effect.Effect<Option.Option<S['Type']>, never, S['Context'] | S['findFirst']['Context']> =>
|
|
634
|
-
findFirstSchema(args).pipe(
|
|
635
|
-
Effect.catchTag('ParseError', Effect.die),
|
|
636
|
-
Effect.withSpan(`\${options.spanPrefix}.findFirst`, {
|
|
637
|
-
captureStackTrace: false,
|
|
638
|
-
attributes: { ...(args as any) },
|
|
639
|
-
}),
|
|
640
|
-
) as any
|
|
641
|
-
|
|
642
|
-
const findFirstOrThrowSchema = SqlSchema.single({
|
|
643
|
-
Request: Schema.Unknown,
|
|
644
|
-
Result: Model,
|
|
645
|
-
execute: (request) =>
|
|
646
|
-
Effect.tryPromise({
|
|
647
|
-
try: () =>
|
|
648
|
-
((prisma.tx as BasePrismaClient)[options.modelName as M] as any).findFirstOrThrow(request) as any,
|
|
649
|
-
catch: (error) => mapFindOrThrowError(error, 'findFirstOrThrow', options.modelName),
|
|
650
|
-
}).pipe(Effect.map((result) => [result] as any)),
|
|
651
|
-
})
|
|
652
|
-
|
|
653
|
-
const findFirstOrThrow = <A extends PrismaNamespace.Args<BasePrismaClient[M], 'findFirstOrThrow'>>(
|
|
654
|
-
args?: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'findFirstOrThrow'>>
|
|
655
|
-
): Effect.Effect<S['Type'], never, S['Context'] | S['findFirstOrThrow']['Context']> =>
|
|
656
|
-
findFirstOrThrowSchema(args).pipe(
|
|
657
|
-
Effect.map((result) => result as S['Type']),
|
|
658
|
-
Effect.catchTag('ParseError', Effect.die),
|
|
659
|
-
Effect.catchTag('NoSuchElementException', Effect.die),
|
|
660
|
-
Effect.withSpan(`\${options.spanPrefix}.findFirstOrThrow`, {
|
|
661
|
-
captureStackTrace: false,
|
|
662
|
-
attributes: { ...(args as any) },
|
|
663
|
-
}),
|
|
664
|
-
) as any
|
|
665
|
-
|
|
666
|
-
const findManySchema = SqlSchema.many({
|
|
667
|
-
Request: Schema.Unknown,
|
|
668
|
-
Result: Model,
|
|
669
|
-
execute: (request) =>
|
|
670
|
-
Effect.tryPromise({
|
|
671
|
-
try: () =>
|
|
672
|
-
((prisma.tx as BasePrismaClient)[options.modelName as M] as any).findMany(request) as any,
|
|
673
|
-
catch: (error) => mapFindError(error, 'findMany', options.modelName),
|
|
674
|
-
}).pipe(Effect.map((result) => result as any)),
|
|
675
|
-
})
|
|
676
|
-
|
|
677
|
-
const findMany = <A extends PrismaNamespace.Args<BasePrismaClient[M], 'findMany'>>(
|
|
678
|
-
args?: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'findMany'>>
|
|
679
|
-
): Effect.Effect<Array<S['Type']>, never, S['Context'] | S['findMany']['Context']> =>
|
|
680
|
-
findManySchema(args).pipe(
|
|
681
|
-
Effect.catchTag('ParseError', Effect.die),
|
|
682
|
-
Effect.withSpan(`\${options.spanPrefix}.findMany`, {
|
|
683
|
-
captureStackTrace: false,
|
|
684
|
-
attributes: { ...(args as any) },
|
|
685
|
-
}),
|
|
686
|
-
) as any
|
|
687
|
-
|
|
688
|
-
const createSchema = SqlSchema.single({
|
|
689
|
-
Request: Model.create,
|
|
690
|
-
Result: Model,
|
|
691
|
-
execute: (request) =>
|
|
692
|
-
Effect.tryPromise({
|
|
693
|
-
try: () => ((prisma.tx as BasePrismaClient)[options.modelName as M] as any).create({ data: request }),
|
|
694
|
-
catch: (error) => mapCreateError(error, 'create', options.modelName),
|
|
695
|
-
}).pipe(Effect.map((result) => [result] as any)),
|
|
696
|
-
})
|
|
697
|
-
|
|
698
|
-
const create = <A extends PrismaNamespace.Args<BasePrismaClient[M], 'create'>>(
|
|
699
|
-
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'create'>>,
|
|
700
|
-
): Effect.Effect<S['Type'], never, S['Context'] | S['create']['Context']> =>
|
|
701
|
-
createSchema((args as any).data).pipe(
|
|
702
|
-
Effect.catchTag('ParseError', Effect.die),
|
|
703
|
-
Effect.catchTag('NoSuchElementException', Effect.die),
|
|
704
|
-
Effect.withSpan(`\${options.spanPrefix}.create`, {
|
|
705
|
-
captureStackTrace: false,
|
|
706
|
-
attributes: { ...(args as any).data },
|
|
707
|
-
}),
|
|
708
|
-
) as any
|
|
709
|
-
|
|
710
|
-
const createManySchema = SqlSchema.single({
|
|
711
|
-
Request: Schema.Array(Model.createMany),
|
|
712
|
-
Result: Schema.Unknown,
|
|
713
|
-
execute: (request) =>
|
|
714
|
-
Effect.tryPromise({
|
|
715
|
-
try: () =>
|
|
716
|
-
((prisma.tx as BasePrismaClient)[options.modelName as M] as any).createMany({ data: request as any }),
|
|
717
|
-
catch: (error) => mapCreateError(error, 'createMany', options.modelName),
|
|
718
|
-
}).pipe(Effect.map((result) => [result] as any)),
|
|
719
|
-
})
|
|
720
|
-
|
|
721
|
-
const createMany = <A extends PrismaNamespace.Args<BasePrismaClient[M], 'createMany'>>(
|
|
722
|
-
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'createMany'>>,
|
|
723
|
-
): Effect.Effect<PrismaNamespace.BatchPayload, never, S['Context'] | S['createMany']['Context']> =>
|
|
724
|
-
createManySchema((args as any).data).pipe(
|
|
725
|
-
Effect.map((res) => res as unknown as PrismaNamespace.BatchPayload),
|
|
726
|
-
Effect.catchTag('ParseError', Effect.die),
|
|
727
|
-
Effect.catchTag('NoSuchElementException', Effect.die),
|
|
728
|
-
Effect.withSpan(`\${options.spanPrefix}.createMany`, {
|
|
729
|
-
captureStackTrace: false,
|
|
730
|
-
attributes: { ...(args as any).data },
|
|
731
|
-
}),
|
|
732
|
-
) as any
|
|
733
|
-
|
|
734
|
-
const createManyAndReturnSchema = SqlSchema.many({
|
|
735
|
-
Request: Schema.Array(Model.createMany),
|
|
736
|
-
Result: Model,
|
|
737
|
-
execute: (request) =>
|
|
738
|
-
Effect.tryPromise({
|
|
739
|
-
try: () =>
|
|
740
|
-
((prisma.tx as BasePrismaClient)[options.modelName as M] as any).createManyAndReturn({
|
|
741
|
-
data: request as any,
|
|
742
|
-
}),
|
|
743
|
-
catch: (error) => mapCreateError(error, 'createManyAndReturn', options.modelName),
|
|
744
|
-
}),
|
|
745
|
-
})
|
|
746
|
-
|
|
747
|
-
const createManyAndReturn = <A extends PrismaNamespace.Args<BasePrismaClient[M], 'createManyAndReturn'>>(
|
|
748
|
-
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'createManyAndReturn'>>,
|
|
749
|
-
): Effect.Effect<Array<S['Type']>, never, S['Context'] | S['createManyAndReturn']['Context']> =>
|
|
750
|
-
createManyAndReturnSchema((args as any).data).pipe(
|
|
751
|
-
Effect.catchTag('ParseError', Effect.die),
|
|
752
|
-
Effect.withSpan(`\${options.spanPrefix}.createManyAndReturn`, {
|
|
753
|
-
captureStackTrace: false,
|
|
754
|
-
attributes: { ...(args as any).data },
|
|
755
|
-
}),
|
|
756
|
-
) as any
|
|
757
|
-
|
|
758
|
-
const countSchema = SqlSchema.single({
|
|
759
|
-
Request: Schema.Unknown,
|
|
760
|
-
Result: Schema.Unknown,
|
|
761
|
-
execute: (request) =>
|
|
762
|
-
Effect.tryPromise({
|
|
763
|
-
try: () => ((prisma.tx as BasePrismaClient)[options.modelName as M] as any).count(request),
|
|
764
|
-
catch: (error) => mapFindError(error, 'count', options.modelName),
|
|
765
|
-
}).pipe(Effect.map((result) => [result] as any)),
|
|
766
|
-
})
|
|
767
|
-
|
|
768
|
-
const count = <A extends PrismaNamespace.Args<BasePrismaClient[M], 'count'>>(
|
|
769
|
-
args?: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'count'>>
|
|
770
|
-
): Effect.Effect<unknown, never, S['Context']> =>
|
|
771
|
-
countSchema(args).pipe(
|
|
772
|
-
Effect.catchTag('ParseError', Effect.die),
|
|
773
|
-
Effect.catchTag('NoSuchElementException', Effect.die),
|
|
774
|
-
Effect.withSpan(`\${options.spanPrefix}.count`, {
|
|
775
|
-
captureStackTrace: false,
|
|
776
|
-
attributes: { ...(args as any) },
|
|
777
|
-
}),
|
|
778
|
-
) as any
|
|
779
|
-
|
|
780
|
-
const updateSchema = SqlSchema.single({
|
|
781
|
-
Request: Schema.Unknown,
|
|
782
|
-
Result: Model,
|
|
783
|
-
execute: (request) =>
|
|
784
|
-
Effect.tryPromise({
|
|
785
|
-
try: () => ((prisma.tx as BasePrismaClient)[options.modelName as M] as any).update(request),
|
|
786
|
-
catch: (error) => mapUpdateError(error, 'update', options.modelName),
|
|
787
|
-
}).pipe(Effect.map((result) => [result] as any)),
|
|
788
|
-
})
|
|
789
|
-
|
|
790
|
-
const update = <A extends PrismaNamespace.Args<BasePrismaClient[M], 'update'>>(
|
|
791
|
-
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'update'>>
|
|
792
|
-
): Effect.Effect<S['Type'], never, S['Context'] | S['update']['Context']> =>
|
|
793
|
-
updateSchema(args).pipe(
|
|
794
|
-
Effect.catchTag('ParseError', Effect.die),
|
|
795
|
-
Effect.catchTag('NoSuchElementException', Effect.die),
|
|
796
|
-
Effect.withSpan(`\${options.spanPrefix}.update`, {
|
|
797
|
-
captureStackTrace: false,
|
|
798
|
-
attributes: { ...(args as any) },
|
|
799
|
-
}),
|
|
800
|
-
) as any
|
|
801
|
-
|
|
802
|
-
const deleteSchema = SqlSchema.single({
|
|
803
|
-
Request: Schema.Unknown,
|
|
804
|
-
Result: Model,
|
|
805
|
-
execute: (request) =>
|
|
806
|
-
Effect.tryPromise({
|
|
807
|
-
try: () => ((prisma.tx as BasePrismaClient)[options.modelName as M] as any).delete(request),
|
|
808
|
-
catch: (error) => mapDeleteError(error, 'delete', options.modelName),
|
|
809
|
-
}).pipe(Effect.map((result) => [result] as any)),
|
|
810
|
-
})
|
|
811
|
-
|
|
812
|
-
const delete_ = <A extends PrismaNamespace.Args<BasePrismaClient[M], 'delete'>>(
|
|
813
|
-
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'delete'>>
|
|
814
|
-
): Effect.Effect<S['Type'], never, S['Context']> =>
|
|
815
|
-
deleteSchema(args).pipe(
|
|
816
|
-
Effect.catchTag('ParseError', Effect.die),
|
|
817
|
-
Effect.catchTag('NoSuchElementException', Effect.die),
|
|
818
|
-
Effect.withSpan(`\${options.spanPrefix}.delete`, {
|
|
819
|
-
captureStackTrace: false,
|
|
820
|
-
attributes: { ...(args as any) },
|
|
821
|
-
}),
|
|
822
|
-
) as any
|
|
823
|
-
|
|
824
|
-
const upsertSchema = SqlSchema.single({
|
|
825
|
-
Request: Schema.Unknown,
|
|
826
|
-
Result: Model,
|
|
827
|
-
execute: (request) =>
|
|
828
|
-
Effect.tryPromise({
|
|
829
|
-
try: () => ((prisma.tx as BasePrismaClient)[options.modelName as M] as any).upsert(request),
|
|
830
|
-
catch: (error) => mapCreateError(error, 'upsert', options.modelName),
|
|
831
|
-
}).pipe(Effect.map((result) => [result] as any)),
|
|
832
|
-
})
|
|
833
|
-
|
|
834
|
-
const upsert = <A extends PrismaNamespace.Args<BasePrismaClient[M], 'upsert'>>(
|
|
835
|
-
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'upsert'>>
|
|
836
|
-
): Effect.Effect<S['Type'], never, S['Context']> =>
|
|
837
|
-
upsertSchema(args).pipe(
|
|
838
|
-
Effect.catchTag('ParseError', Effect.die),
|
|
839
|
-
Effect.catchTag('NoSuchElementException', Effect.die),
|
|
840
|
-
Effect.withSpan(`\${options.spanPrefix}.upsert`, {
|
|
841
|
-
captureStackTrace: false,
|
|
842
|
-
attributes: { ...(args as any) },
|
|
843
|
-
}),
|
|
844
|
-
) as any
|
|
845
|
-
|
|
846
|
-
const aggregateSchema = SqlSchema.single({
|
|
847
|
-
Request: Schema.Unknown,
|
|
848
|
-
Result: Schema.Unknown,
|
|
849
|
-
execute: (request) =>
|
|
850
|
-
Effect.tryPromise({
|
|
851
|
-
try: () => ((prisma.tx as BasePrismaClient)[options.modelName as M] as any).aggregate(request),
|
|
852
|
-
catch: (error) => mapFindError(error, 'aggregate', options.modelName),
|
|
853
|
-
}).pipe(Effect.map((result) => [result] as any)),
|
|
854
|
-
})
|
|
855
|
-
|
|
856
|
-
const aggregate = <A extends PrismaNamespace.Args<BasePrismaClient[M], 'aggregate'>>(
|
|
857
|
-
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'aggregate'>>
|
|
858
|
-
): Effect.Effect<unknown, never, S['Context']> =>
|
|
859
|
-
aggregateSchema(args).pipe(
|
|
860
|
-
Effect.catchTag('ParseError', Effect.die),
|
|
861
|
-
Effect.catchTag('NoSuchElementException', Effect.die),
|
|
862
|
-
Effect.withSpan(`\${options.spanPrefix}.aggregate`, {
|
|
863
|
-
captureStackTrace: false,
|
|
864
|
-
attributes: { ...(args as any) },
|
|
865
|
-
}),
|
|
866
|
-
) as any
|
|
867
|
-
|
|
868
|
-
const groupBySchema = SqlSchema.many({
|
|
869
|
-
Request: Schema.Unknown,
|
|
870
|
-
Result: Schema.Unknown,
|
|
871
|
-
execute: (request) =>
|
|
872
|
-
Effect.tryPromise({
|
|
873
|
-
try: () => ((prisma.tx as BasePrismaClient)[options.modelName as M] as any).groupBy(request),
|
|
874
|
-
catch: (error) => mapFindError(error, 'groupBy', options.modelName),
|
|
875
|
-
}).pipe(Effect.map((result) => result as any)),
|
|
876
|
-
})
|
|
877
|
-
|
|
878
|
-
const groupBy = <A extends PrismaNamespace.Args<BasePrismaClient[M], 'groupBy'>>(
|
|
879
|
-
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'groupBy'>>
|
|
880
|
-
): Effect.Effect<unknown, never, S['Context']> =>
|
|
881
|
-
groupBySchema(args).pipe(
|
|
882
|
-
Effect.catchTag('ParseError', Effect.die),
|
|
883
|
-
Effect.withSpan(`\${options.spanPrefix}.groupBy`, {
|
|
884
|
-
captureStackTrace: false,
|
|
885
|
-
attributes: { ...(args as any) },
|
|
886
|
-
}),
|
|
887
|
-
) as any
|
|
888
|
-
|
|
889
|
-
const updateManySchema = SqlSchema.single({
|
|
890
|
-
Request: Schema.Unknown,
|
|
891
|
-
Result: Schema.Unknown,
|
|
892
|
-
execute: (request) =>
|
|
893
|
-
Effect.tryPromise({
|
|
894
|
-
try: () => ((prisma.tx as BasePrismaClient)[options.modelName as M] as any).updateMany(request),
|
|
895
|
-
catch: (error) => mapUpdateManyError(error, 'updateMany', options.modelName),
|
|
896
|
-
}).pipe(Effect.map((result) => [result] as any)),
|
|
897
|
-
})
|
|
898
|
-
|
|
899
|
-
const updateMany = <A extends PrismaNamespace.Args<BasePrismaClient[M], 'updateMany'>>(
|
|
900
|
-
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'updateMany'>>
|
|
901
|
-
): Effect.Effect<PrismaNamespace.BatchPayload, never, S['Context'] | S['update']['Context']> =>
|
|
902
|
-
updateManySchema(args).pipe(
|
|
903
|
-
Effect.map((res) => res as unknown as PrismaNamespace.BatchPayload),
|
|
904
|
-
Effect.catchTag('ParseError', Effect.die),
|
|
905
|
-
Effect.catchTag('NoSuchElementException', Effect.die),
|
|
906
|
-
Effect.withSpan(`\${options.spanPrefix}.updateMany`, {
|
|
907
|
-
captureStackTrace: false,
|
|
908
|
-
attributes: { ...(args as any) },
|
|
909
|
-
}),
|
|
910
|
-
) as any
|
|
911
|
-
|
|
912
|
-
const deleteManySchema = SqlSchema.single({
|
|
913
|
-
Request: Schema.Unknown,
|
|
914
|
-
Result: Schema.Unknown,
|
|
915
|
-
execute: (request) =>
|
|
916
|
-
Effect.tryPromise({
|
|
917
|
-
try: () => ((prisma.tx as BasePrismaClient)[options.modelName as M] as any).deleteMany(request),
|
|
918
|
-
catch: (error) => mapDeleteManyError(error, 'deleteMany', options.modelName),
|
|
919
|
-
}).pipe(Effect.map((result) => [result] as any)),
|
|
920
|
-
})
|
|
921
|
-
|
|
922
|
-
const deleteMany = <A extends PrismaNamespace.Args<BasePrismaClient[M], 'deleteMany'>>(
|
|
923
|
-
args?: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'deleteMany'>>
|
|
924
|
-
): Effect.Effect<PrismaNamespace.BatchPayload, never, S['Context']> =>
|
|
925
|
-
deleteManySchema(args).pipe(
|
|
926
|
-
Effect.map((res) => res as unknown as PrismaNamespace.BatchPayload),
|
|
927
|
-
Effect.catchTag('ParseError', Effect.die),
|
|
928
|
-
Effect.catchTag('NoSuchElementException', Effect.die),
|
|
929
|
-
Effect.withSpan(`\${options.spanPrefix}.deleteMany`, {
|
|
930
|
-
captureStackTrace: false,
|
|
931
|
-
attributes: { ...(args as any) },
|
|
932
|
-
}),
|
|
933
|
-
) as any
|
|
934
|
-
|
|
935
|
-
return {
|
|
936
|
-
findUnique,
|
|
937
|
-
findUniqueOrThrow,
|
|
938
|
-
findFirst,
|
|
939
|
-
findFirstOrThrow,
|
|
940
|
-
findMany,
|
|
941
|
-
create,
|
|
942
|
-
createMany,
|
|
943
|
-
createManyAndReturn,
|
|
944
|
-
update,
|
|
945
|
-
updateMany,
|
|
946
|
-
delete: delete_,
|
|
947
|
-
deleteMany,
|
|
948
|
-
upsert,
|
|
949
|
-
count,
|
|
950
|
-
aggregate,
|
|
951
|
-
groupBy
|
|
952
|
-
} as const
|
|
953
|
-
|
|
954
|
-
})
|