@effectify/prisma 1.0.0 → 1.1.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.
- package/README.md +33 -38
- package/dist/src/cli.d.ts +1 -1
- package/dist/src/cli.js +15 -14
- package/dist/src/commands/init.d.ts +1 -1
- package/dist/src/commands/init.js +36 -47
- package/dist/src/commands/prisma.d.ts +4 -4
- package/dist/src/commands/prisma.js +12 -12
- package/dist/src/generators/sql-schema-generator.js +15 -16
- package/dist/src/runtime/index.d.ts +303 -0
- package/dist/src/runtime/index.js +216 -0
- package/dist/src/schema-generator/effect/enum.d.ts +12 -0
- package/dist/src/schema-generator/effect/enum.js +18 -0
- package/dist/src/schema-generator/effect/generator.d.ts +16 -0
- package/dist/src/schema-generator/effect/generator.js +42 -0
- package/dist/src/schema-generator/effect/join-table.d.ts +12 -0
- package/dist/src/schema-generator/effect/join-table.js +28 -0
- package/dist/src/schema-generator/effect/type.d.ts +18 -0
- package/dist/src/schema-generator/effect/type.js +82 -0
- package/dist/src/schema-generator/index.d.ts +11 -0
- package/dist/src/schema-generator/index.js +83 -0
- package/dist/src/schema-generator/kysely/generator.d.ts +11 -0
- package/dist/src/schema-generator/kysely/generator.js +7 -0
- package/dist/src/schema-generator/kysely/type.d.ts +14 -0
- package/dist/src/schema-generator/kysely/type.js +44 -0
- package/dist/src/schema-generator/prisma/enum.d.ts +19 -0
- package/dist/src/schema-generator/prisma/enum.js +19 -0
- package/dist/src/schema-generator/prisma/generator.d.ts +53 -0
- package/dist/src/schema-generator/prisma/generator.js +29 -0
- package/dist/src/schema-generator/prisma/relation.d.ts +83 -0
- package/dist/src/schema-generator/prisma/relation.js +165 -0
- package/dist/src/schema-generator/prisma/type.d.ts +108 -0
- package/dist/src/schema-generator/prisma/type.js +85 -0
- package/dist/src/schema-generator/utils/annotations.d.ts +32 -0
- package/dist/src/schema-generator/utils/annotations.js +79 -0
- package/dist/src/schema-generator/utils/codegen.d.ts +9 -0
- package/dist/src/schema-generator/utils/codegen.js +14 -0
- package/dist/src/schema-generator/utils/naming.d.ts +29 -0
- package/dist/src/schema-generator/utils/naming.js +68 -0
- package/dist/src/schema-generator/utils/type-mappings.d.ts +62 -0
- package/dist/src/schema-generator/utils/type-mappings.js +70 -0
- package/dist/src/services/formatter-service.d.ts +10 -0
- package/dist/src/services/formatter-service.js +18 -0
- package/dist/src/services/generator-context.d.ts +2 -2
- package/dist/src/services/generator-context.js +2 -2
- package/dist/src/services/generator-service.d.ts +9 -8
- package/dist/src/services/generator-service.js +39 -43
- package/dist/src/services/render-service.d.ts +3 -3
- package/dist/src/services/render-service.js +8 -8
- package/dist/src/templates/effect-branded-id.eta +2 -0
- package/dist/src/templates/effect-enums.eta +9 -0
- package/dist/src/templates/effect-index.eta +4 -0
- package/dist/src/templates/effect-join-table.eta +8 -0
- package/dist/src/templates/effect-model.eta +6 -0
- package/dist/src/templates/effect-types-header.eta +7 -0
- package/dist/src/templates/index-default.eta +2 -1
- package/dist/src/templates/kysely-db-interface.eta +6 -0
- package/dist/src/templates/prisma-repository.eta +57 -32
- package/package.json +11 -6
|
@@ -1,20 +1,25 @@
|
|
|
1
|
-
import * as FileSystem from
|
|
2
|
-
import * as Path from
|
|
3
|
-
import * as Context from
|
|
4
|
-
import * as Effect from
|
|
5
|
-
import * as Layer from
|
|
6
|
-
import { GeneratorContext } from
|
|
7
|
-
import { RenderService } from
|
|
8
|
-
|
|
1
|
+
import * as FileSystem from "@effect/platform/FileSystem";
|
|
2
|
+
import * as Path from "@effect/platform/Path";
|
|
3
|
+
import * as Context from "effect/Context";
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
5
|
+
import * as Layer from "effect/Layer";
|
|
6
|
+
import { GeneratorContext } from "./generator-context.js";
|
|
7
|
+
import { RenderService } from "./render-service.js";
|
|
8
|
+
import { FormatterService } from "./formatter-service.js";
|
|
9
|
+
import { generateSchemas } from "../schema-generator/index.js";
|
|
10
|
+
export class GeneratorService extends Context.Tag("GeneratorService")() {
|
|
9
11
|
static Live = Layer.effect(GeneratorService, Effect.gen(function* () {
|
|
10
12
|
const fs = yield* FileSystem.FileSystem;
|
|
11
13
|
const path = yield* Path.Path;
|
|
12
|
-
const
|
|
14
|
+
const renderService = yield* RenderService;
|
|
15
|
+
const formatterService = yield* FormatterService;
|
|
16
|
+
const { render } = renderService;
|
|
17
|
+
const { format } = formatterService;
|
|
13
18
|
const parseErrorImportPath = (errorImportPath) => {
|
|
14
19
|
if (!errorImportPath) {
|
|
15
20
|
return null;
|
|
16
21
|
}
|
|
17
|
-
const [modulePath, className] = errorImportPath.split(
|
|
22
|
+
const [modulePath, className] = errorImportPath.split("#");
|
|
18
23
|
if (!(modulePath && className)) {
|
|
19
24
|
throw new Error(`Invalid errorImportPath format: "${errorImportPath}". Expected "path/to/module#ErrorClassName"`);
|
|
20
25
|
}
|
|
@@ -30,36 +35,21 @@ export class GeneratorService extends Context.Tag('GeneratorService')() {
|
|
|
30
35
|
}
|
|
31
36
|
return `${filePath}.${extension}`;
|
|
32
37
|
};
|
|
33
|
-
const fixSchemaImports = (outputDir) => Effect.gen(function* () {
|
|
34
|
-
const schemasDir = path.join(outputDir, 'schemas');
|
|
35
|
-
const indexFile = path.join(schemasDir, 'index.ts');
|
|
36
|
-
const exists = yield* fs.exists(indexFile);
|
|
37
|
-
if (!exists) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
const content = yield* fs.readFileString(indexFile);
|
|
41
|
-
const fixedContent = content
|
|
42
|
-
.replace(/export \* from '\.\/enums'/g, "export * from './enums.js'")
|
|
43
|
-
.replace(/export \* from '\.\/types'/g, "export * from './types.js'");
|
|
44
|
-
if (content !== fixedContent) {
|
|
45
|
-
yield* fs.writeFileString(indexFile, fixedContent);
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
38
|
const getClientImportPath = (config) => Array.isArray(config.clientImportPath)
|
|
49
39
|
? config.clientImportPath[0]
|
|
50
|
-
: (config.clientImportPath ??
|
|
40
|
+
: (config.clientImportPath ?? "@prisma/client");
|
|
51
41
|
const getErrorImportPath = (config) => Array.isArray(config.errorImportPath) ? config.errorImportPath[0] : config.errorImportPath;
|
|
52
|
-
const getImportFileExtension = (config) => Array.isArray(config.importFileExtension) ? config.importFileExtension[0] : (config.importFileExtension ??
|
|
42
|
+
const getImportFileExtension = (config) => Array.isArray(config.importFileExtension) ? config.importFileExtension[0] : (config.importFileExtension ?? "");
|
|
53
43
|
const getCustomError = (config, options, schemaDir) => {
|
|
54
44
|
const errorImportPathRaw = getErrorImportPath(config);
|
|
55
45
|
const importFileExtension = getImportFileExtension(config);
|
|
56
46
|
let customError = parseErrorImportPath(errorImportPathRaw);
|
|
57
|
-
if (customError?.path.startsWith(
|
|
47
|
+
if (customError?.path.startsWith(".")) {
|
|
58
48
|
const outputDir = options.generator.output?.value;
|
|
59
49
|
if (outputDir) {
|
|
60
50
|
const absoluteErrorPath = path.resolve(schemaDir, customError.path);
|
|
61
51
|
const relativeToOutput = path.relative(outputDir, absoluteErrorPath);
|
|
62
|
-
const normalizedPath = relativeToOutput.startsWith(
|
|
52
|
+
const normalizedPath = relativeToOutput.startsWith(".") ? relativeToOutput : `./${relativeToOutput}`;
|
|
63
53
|
const pathWithExtension = addExtension(normalizedPath, importFileExtension);
|
|
64
54
|
customError = { ...customError, path: pathWithExtension };
|
|
65
55
|
}
|
|
@@ -73,32 +63,36 @@ export class GeneratorService extends Context.Tag('GeneratorService')() {
|
|
|
73
63
|
return { clientImportPath, customError };
|
|
74
64
|
};
|
|
75
65
|
const generatePrismaSchema = (outputDir) => Effect.gen(function* () {
|
|
76
|
-
const content = yield* render(
|
|
77
|
-
yield*
|
|
66
|
+
const content = yield* render("prisma-schema", {});
|
|
67
|
+
const formatted = yield* format(content);
|
|
68
|
+
yield* fs.writeFileString(path.join(outputDir, "prisma-schema.ts"), formatted);
|
|
78
69
|
});
|
|
79
70
|
const generatePrismaRepository = (outputDir, clientImportPath) => Effect.gen(function* () {
|
|
80
|
-
const content = yield* render(
|
|
81
|
-
yield*
|
|
71
|
+
const content = yield* render("prisma-repository", { clientImportPath });
|
|
72
|
+
const formatted = yield* format(content);
|
|
73
|
+
yield* fs.writeFileString(path.join(outputDir, "prisma-repository.ts"), formatted);
|
|
82
74
|
});
|
|
83
75
|
const generateModels = (outputDir, models) => Effect.gen(function* () {
|
|
84
|
-
yield* fs.makeDirectory(path.join(outputDir,
|
|
76
|
+
yield* fs.makeDirectory(path.join(outputDir, "models"), { recursive: true });
|
|
85
77
|
for (const model of models) {
|
|
86
|
-
const content = yield* render(
|
|
87
|
-
yield*
|
|
78
|
+
const content = yield* render("model", { model });
|
|
79
|
+
const formatted = yield* format(content);
|
|
80
|
+
yield* fs.writeFileString(path.join(outputDir, "models", `${model.name}.ts`), formatted);
|
|
88
81
|
}
|
|
89
82
|
});
|
|
90
83
|
const generateIndex = (outputDir, models, clientImportPath, customError) => Effect.gen(function* () {
|
|
91
|
-
const errorType = customError ? customError.className :
|
|
92
|
-
const rawSqlOperations = yield* render(
|
|
93
|
-
const modelExports = models.map((m) => `export * from "./models/${m.name}.js"`).join(
|
|
94
|
-
const templateName = customError ?
|
|
84
|
+
const errorType = customError ? customError.className : "PrismaError";
|
|
85
|
+
const rawSqlOperations = yield* render("prisma-raw-sql", { errorType });
|
|
86
|
+
const modelExports = models.map((m) => `export * from "./models/${m.name}.js"`).join("\n");
|
|
87
|
+
const templateName = customError ? "index-custom-error" : "index-default";
|
|
95
88
|
const content = yield* render(templateName, {
|
|
96
89
|
clientImportPath,
|
|
97
90
|
customError,
|
|
98
91
|
rawSqlOperations,
|
|
99
92
|
modelExports,
|
|
100
93
|
});
|
|
101
|
-
yield*
|
|
94
|
+
const formatted = yield* format(content);
|
|
95
|
+
yield* fs.writeFileString(path.join(outputDir, "index.ts"), formatted);
|
|
102
96
|
});
|
|
103
97
|
const generate = Effect.gen(function* () {
|
|
104
98
|
const options = yield* GeneratorContext;
|
|
@@ -106,15 +100,17 @@ export class GeneratorService extends Context.Tag('GeneratorService')() {
|
|
|
106
100
|
const outputDir = options.generator.output?.value;
|
|
107
101
|
const schemaDir = path.dirname(options.schemaPath);
|
|
108
102
|
if (!outputDir) {
|
|
109
|
-
return yield* Effect.fail(new Error(
|
|
103
|
+
return yield* Effect.fail(new Error("No output directory specified"));
|
|
110
104
|
}
|
|
111
105
|
const { clientImportPath, customError } = getGeneratorConfig(options, schemaDir);
|
|
112
106
|
yield* fs.makeDirectory(outputDir, { recursive: true });
|
|
107
|
+
// Generate Effect/Kysely Schemas (enums.ts, types.ts, schemas/index.ts)
|
|
108
|
+
const schemasDir = path.join(outputDir, "schemas");
|
|
109
|
+
yield* generateSchemas(options.dmmf, schemasDir).pipe(Effect.provideService(FileSystem.FileSystem, fs), Effect.provideService(Path.Path, path), Effect.provideService(RenderService, renderService), Effect.provideService(FormatterService, formatterService));
|
|
113
110
|
yield* generatePrismaSchema(outputDir);
|
|
114
111
|
yield* generatePrismaRepository(outputDir, clientImportPath);
|
|
115
112
|
yield* generateModels(outputDir, models);
|
|
116
113
|
yield* generateIndex(outputDir, models, clientImportPath, customError);
|
|
117
|
-
yield* fixSchemaImports(outputDir);
|
|
118
114
|
});
|
|
119
115
|
return { generate };
|
|
120
116
|
}));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as Context from
|
|
2
|
-
import * as Effect from
|
|
3
|
-
import * as Layer from
|
|
1
|
+
import * as Context from "effect/Context";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Layer from "effect/Layer";
|
|
4
4
|
declare const RenderService_base: Context.TagClass<RenderService, "RenderService", {
|
|
5
5
|
readonly render: (templateName: string, data: Record<string, unknown>) => Effect.Effect<string, Error>;
|
|
6
6
|
}>;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import
|
|
3
|
-
import * as
|
|
4
|
-
import
|
|
5
|
-
import * as
|
|
6
|
-
import {
|
|
7
|
-
export class RenderService extends Context.Tag(
|
|
1
|
+
import * as Context from "effect/Context";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Layer from "effect/Layer";
|
|
4
|
+
import { Eta } from "eta";
|
|
5
|
+
import * as path from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
export class RenderService extends Context.Tag("RenderService")() {
|
|
8
8
|
static Live = Layer.sync(RenderService, () => {
|
|
9
9
|
const __filename = fileURLToPath(import.meta.url);
|
|
10
10
|
const __dirname = path.dirname(__filename);
|
|
11
|
-
const templatesDir = path.resolve(__dirname,
|
|
11
|
+
const templatesDir = path.resolve(__dirname, "../templates");
|
|
12
12
|
const eta = new Eta({
|
|
13
13
|
views: templatesDir,
|
|
14
14
|
autoEscape: false,
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// <%= it.tableName %> Join Table Schema (Prisma implicit many-to-many)
|
|
2
|
+
// Database columns: A (<%= it.modelA %>), B (<%= it.modelB %>)
|
|
3
|
+
// TypeScript fields: <%= it.columnAFieldName %>, <%= it.columnBFieldName %>
|
|
4
|
+
export const <%= it.name %> = Schema.Struct({
|
|
5
|
+
<%~ it.columnAField %>,
|
|
6
|
+
<%~ it.columnBField %>,
|
|
7
|
+
});
|
|
8
|
+
export type <%= it.name %> = typeof <%= it.name %>;
|
|
@@ -201,7 +201,8 @@ export type PrismaError =
|
|
|
201
201
|
// Generic mapper for raw operations and fallback
|
|
202
202
|
const mapError = (error: unknown, operation: string, model: string): PrismaError => {
|
|
203
203
|
if (error instanceof PrismaNamespace.PrismaClientKnownRequestError) {
|
|
204
|
-
|
|
204
|
+
const prismaError = error as PrismaNamespace.PrismaClientKnownRequestError;
|
|
205
|
+
switch (prismaError.code) {
|
|
205
206
|
case "P2000":
|
|
206
207
|
return new PrismaValueTooLongError({ cause: error, operation, model });
|
|
207
208
|
case "P2002":
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/** biome-ignore-all lint/suspicious/noExplicitAny: <todo> */
|
|
2
|
-
/** biome-ignore-all lint/style/useDefaultSwitchClause: <todo> */
|
|
3
|
-
|
|
4
1
|
import * as VariantSchema from '@effect/experimental/VariantSchema'
|
|
5
2
|
import { type PrismaClient as BasePrismaClient, Prisma as PrismaNamespace } from '<%= it.clientImportPath %>'
|
|
6
3
|
import { PrismaClient } from './index.js'
|
|
@@ -9,6 +6,7 @@ import * as Effect from 'effect/Effect'
|
|
|
9
6
|
import type * as Option from 'effect/Option'
|
|
10
7
|
import * as Schema from 'effect/Schema'
|
|
11
8
|
import * as SqlSchema from './prisma-schema.js'
|
|
9
|
+
import { Insertable, Updateable } from '@effectify/prisma'
|
|
12
10
|
|
|
13
11
|
export class PrismaUniqueConstraintError extends Data.TaggedError('PrismaUniqueConstraintError')<{
|
|
14
12
|
cause: PrismaNamespace.PrismaClientKnownRequestError
|
|
@@ -142,7 +140,8 @@ export type PrismaUpdateManyError =
|
|
|
142
140
|
// Create, Upsert
|
|
143
141
|
export const mapCreateError = (error: unknown, operation: string, model: string): PrismaCreateError => {
|
|
144
142
|
if (error instanceof PrismaNamespace.PrismaClientKnownRequestError) {
|
|
145
|
-
|
|
143
|
+
const prismaError = error as PrismaNamespace.PrismaClientKnownRequestError;
|
|
144
|
+
switch (prismaError.code) {
|
|
146
145
|
case 'P2000':
|
|
147
146
|
return new PrismaValueTooLongError({ cause: error, operation, model })
|
|
148
147
|
case 'P2002':
|
|
@@ -175,7 +174,8 @@ export const mapCreateError = (error: unknown, operation: string, model: string)
|
|
|
175
174
|
// Update
|
|
176
175
|
export const mapUpdateError = (error: unknown, operation: string, model: string): PrismaUpdateError => {
|
|
177
176
|
if (error instanceof PrismaNamespace.PrismaClientKnownRequestError) {
|
|
178
|
-
|
|
177
|
+
const prismaError = error as PrismaNamespace.PrismaClientKnownRequestError;
|
|
178
|
+
switch (prismaError.code) {
|
|
179
179
|
case "P2000":
|
|
180
180
|
return new PrismaValueTooLongError({ cause: error, operation, model });
|
|
181
181
|
case "P2002":
|
|
@@ -212,7 +212,8 @@ export const mapUpdateError = (error: unknown, operation: string, model: string)
|
|
|
212
212
|
// Delete
|
|
213
213
|
export const mapDeleteError = (error: unknown, operation: string, model: string): PrismaDeleteError => {
|
|
214
214
|
if (error instanceof PrismaNamespace.PrismaClientKnownRequestError) {
|
|
215
|
-
|
|
215
|
+
const prismaError = error as PrismaNamespace.PrismaClientKnownRequestError;
|
|
216
|
+
switch (prismaError.code) {
|
|
216
217
|
case "P2003":
|
|
217
218
|
return new PrismaForeignKeyConstraintError({ cause: error, operation, model });
|
|
218
219
|
case "P2014":
|
|
@@ -231,7 +232,8 @@ export const mapDeleteError = (error: unknown, operation: string, model: string)
|
|
|
231
232
|
// FindOrThrow
|
|
232
233
|
export const mapFindOrThrowError = (error: unknown, operation: string, model: string): PrismaFindOrThrowError => {
|
|
233
234
|
if (error instanceof PrismaNamespace.PrismaClientKnownRequestError) {
|
|
234
|
-
|
|
235
|
+
const prismaError = error as PrismaNamespace.PrismaClientKnownRequestError;
|
|
236
|
+
switch (prismaError.code) {
|
|
235
237
|
case "P2024":
|
|
236
238
|
return new PrismaConnectionError({ cause: error, operation, model });
|
|
237
239
|
case "P2025":
|
|
@@ -244,7 +246,8 @@ export const mapFindOrThrowError = (error: unknown, operation: string, model: st
|
|
|
244
246
|
// Find
|
|
245
247
|
export const mapFindError = (error: unknown, operation: string, model: string): PrismaFindError => {
|
|
246
248
|
if (error instanceof PrismaNamespace.PrismaClientKnownRequestError) {
|
|
247
|
-
|
|
249
|
+
const prismaError = error as PrismaNamespace.PrismaClientKnownRequestError;
|
|
250
|
+
switch (prismaError.code) {
|
|
248
251
|
case "P2024":
|
|
249
252
|
return new PrismaConnectionError({ cause: error, operation, model });
|
|
250
253
|
}
|
|
@@ -255,7 +258,8 @@ export const mapFindError = (error: unknown, operation: string, model: string):
|
|
|
255
258
|
// DeleteMany
|
|
256
259
|
export const mapDeleteManyError = (error: unknown, operation: string, model: string): PrismaDeleteManyError => {
|
|
257
260
|
if (error instanceof PrismaNamespace.PrismaClientKnownRequestError) {
|
|
258
|
-
|
|
261
|
+
const prismaError = error as PrismaNamespace.PrismaClientKnownRequestError;
|
|
262
|
+
switch (prismaError.code) {
|
|
259
263
|
case "P2003":
|
|
260
264
|
return new PrismaForeignKeyConstraintError({ cause: error, operation, model });
|
|
261
265
|
case "P2014":
|
|
@@ -272,7 +276,8 @@ export const mapDeleteManyError = (error: unknown, operation: string, model: str
|
|
|
272
276
|
// UpdateMany
|
|
273
277
|
export const mapUpdateManyError = (error: unknown, operation: string, model: string): PrismaUpdateManyError => {
|
|
274
278
|
if (error instanceof PrismaNamespace.PrismaClientKnownRequestError) {
|
|
275
|
-
|
|
279
|
+
const prismaError = error as PrismaNamespace.PrismaClientKnownRequestError;
|
|
280
|
+
switch (prismaError.code) {
|
|
276
281
|
case "P2000":
|
|
277
282
|
return new PrismaValueTooLongError({ cause: error, operation, model });
|
|
278
283
|
case "P2002":
|
|
@@ -357,6 +362,26 @@ export type AnyNoContext = Schema.Schema.AnyNoContext & {
|
|
|
357
362
|
readonly jsonUpdate: Schema.Schema.AnyNoContext
|
|
358
363
|
}
|
|
359
364
|
|
|
365
|
+
/**
|
|
366
|
+
* Extract TypeScript types from model variants for compile-time validation
|
|
367
|
+
* @since 1.0.0
|
|
368
|
+
* @category types
|
|
369
|
+
*/
|
|
370
|
+
export type ModelTypes<S extends Any> = {
|
|
371
|
+
/** Type for create operations */
|
|
372
|
+
readonly Create: Schema.Schema.Type<S['create']>
|
|
373
|
+
/** Type for update operations */
|
|
374
|
+
readonly Update: Schema.Schema.Type<S['update']>
|
|
375
|
+
/** Type for base model */
|
|
376
|
+
readonly Model: Schema.Schema.Type<S>
|
|
377
|
+
/** Type for JSON API */
|
|
378
|
+
readonly Json: Schema.Schema.Type<S['json']>
|
|
379
|
+
/** Type for JSON create operations */
|
|
380
|
+
readonly JsonCreate: Schema.Schema.Type<S['jsonCreate']>
|
|
381
|
+
/** Type for JSON update operations */
|
|
382
|
+
readonly JsonUpdate: Schema.Schema.Type<S['jsonUpdate']>
|
|
383
|
+
}
|
|
384
|
+
|
|
360
385
|
/**
|
|
361
386
|
* @since 1.0.0
|
|
362
387
|
* @category models
|
|
@@ -501,23 +526,23 @@ export const make = <S extends Any, M extends keyof BasePrismaClient>(
|
|
|
501
526
|
) => Effect.Effect<Array<S['Type']>, PrismaFindError, S['Context'] | S['findMany']['Context']>
|
|
502
527
|
|
|
503
528
|
readonly create: <A extends PrismaNamespace.Args<BasePrismaClient[M], 'create'>>(
|
|
504
|
-
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'create'
|
|
529
|
+
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'create'>> & { data: Insertable<S['Type']> },
|
|
505
530
|
) => Effect.Effect<S['Type'], PrismaCreateError, S['Context'] | S['create']['Context']>
|
|
506
531
|
|
|
507
532
|
readonly createMany: <A extends PrismaNamespace.Args<BasePrismaClient[M], 'createMany'>>(
|
|
508
|
-
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'createMany'
|
|
533
|
+
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'createMany'>> & { data: ReadonlyArray<Insertable<S['Type']>> | Insertable<S['Type']> },
|
|
509
534
|
) => Effect.Effect<PrismaNamespace.BatchPayload, PrismaCreateError, S['Context'] | S['createMany']['Context']>
|
|
510
535
|
|
|
511
536
|
readonly createManyAndReturn: <A extends PrismaNamespace.Args<BasePrismaClient[M], 'createManyAndReturn'>>(
|
|
512
|
-
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'createManyAndReturn'
|
|
537
|
+
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'createManyAndReturn'>> & { data: ReadonlyArray<Insertable<S['Type']>> | Insertable<S['Type']> },
|
|
513
538
|
) => Effect.Effect<Array<S['Type']>, PrismaCreateError, S['Context'] | S['createManyAndReturn']['Context']>
|
|
514
539
|
|
|
515
540
|
readonly update: <A extends PrismaNamespace.Args<BasePrismaClient[M], 'update'>>(
|
|
516
|
-
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'update'>>
|
|
541
|
+
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'update'>> & { data: Updateable<S['Type']> }
|
|
517
542
|
) => Effect.Effect<S['Type'], PrismaUpdateError, S['Context'] | S['update']['Context']>
|
|
518
543
|
|
|
519
544
|
readonly updateMany: <A extends PrismaNamespace.Args<BasePrismaClient[M], 'updateMany'>>(
|
|
520
|
-
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'updateMany'>>
|
|
545
|
+
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'updateMany'>> & { data: Updateable<S['Type']> }
|
|
521
546
|
) => Effect.Effect<PrismaNamespace.BatchPayload, PrismaUpdateManyError, S['Context'] | S['update']['Context']>
|
|
522
547
|
|
|
523
548
|
readonly delete: <A extends PrismaNamespace.Args<BasePrismaClient[M], 'delete'>>(
|
|
@@ -529,7 +554,7 @@ export const make = <S extends Any, M extends keyof BasePrismaClient>(
|
|
|
529
554
|
) => Effect.Effect<PrismaNamespace.BatchPayload, PrismaDeleteManyError, S['Context']>
|
|
530
555
|
|
|
531
556
|
readonly upsert: <A extends PrismaNamespace.Args<BasePrismaClient[M], 'upsert'>>(
|
|
532
|
-
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'upsert'>>
|
|
557
|
+
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'upsert'>> & { create: Insertable<S['Type']>; update: Updateable<S['Type']> }
|
|
533
558
|
) => Effect.Effect<S['Type'], PrismaCreateError, S['Context']>
|
|
534
559
|
|
|
535
560
|
readonly count: <A extends PrismaNamespace.Args<BasePrismaClient[M], 'count'>>(
|
|
@@ -696,12 +721,12 @@ export const make = <S extends Any, M extends keyof BasePrismaClient>(
|
|
|
696
721
|
})
|
|
697
722
|
|
|
698
723
|
const create = <A extends PrismaNamespace.Args<BasePrismaClient[M], 'create'>>(
|
|
699
|
-
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'create'
|
|
724
|
+
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'create'>> & { data: Insertable<S['Type']> },
|
|
700
725
|
): Effect.Effect<S['Type'], never, S['Context'] | S['create']['Context']> =>
|
|
701
726
|
createSchema((args as any).data).pipe(
|
|
702
727
|
Effect.catchTag('ParseError', Effect.die),
|
|
703
728
|
Effect.catchTag('NoSuchElementException', Effect.die),
|
|
704
|
-
Effect.withSpan(
|
|
729
|
+
Effect.withSpan(`${options.spanPrefix}.create`, {
|
|
705
730
|
captureStackTrace: false,
|
|
706
731
|
attributes: { ...(args as any).data },
|
|
707
732
|
}),
|
|
@@ -719,13 +744,13 @@ export const make = <S extends Any, M extends keyof BasePrismaClient>(
|
|
|
719
744
|
})
|
|
720
745
|
|
|
721
746
|
const createMany = <A extends PrismaNamespace.Args<BasePrismaClient[M], 'createMany'>>(
|
|
722
|
-
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'createMany'
|
|
747
|
+
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'createMany'>> & { data: ReadonlyArray<Insertable<S['Type']>> | Insertable<S['Type']> },
|
|
723
748
|
): Effect.Effect<PrismaNamespace.BatchPayload, never, S['Context'] | S['createMany']['Context']> =>
|
|
724
749
|
createManySchema((args as any).data).pipe(
|
|
725
750
|
Effect.map((res) => res as unknown as PrismaNamespace.BatchPayload),
|
|
726
751
|
Effect.catchTag('ParseError', Effect.die),
|
|
727
752
|
Effect.catchTag('NoSuchElementException', Effect.die),
|
|
728
|
-
Effect.withSpan(
|
|
753
|
+
Effect.withSpan(`${options.spanPrefix}.createMany`, {
|
|
729
754
|
captureStackTrace: false,
|
|
730
755
|
attributes: { ...(args as any).data },
|
|
731
756
|
}),
|
|
@@ -745,11 +770,11 @@ export const make = <S extends Any, M extends keyof BasePrismaClient>(
|
|
|
745
770
|
})
|
|
746
771
|
|
|
747
772
|
const createManyAndReturn = <A extends PrismaNamespace.Args<BasePrismaClient[M], 'createManyAndReturn'>>(
|
|
748
|
-
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'createManyAndReturn'
|
|
773
|
+
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'createManyAndReturn'>> & { data: ReadonlyArray<Insertable<S['Type']>> | Insertable<S['Type']> },
|
|
749
774
|
): Effect.Effect<Array<S['Type']>, never, S['Context'] | S['createManyAndReturn']['Context']> =>
|
|
750
775
|
createManyAndReturnSchema((args as any).data).pipe(
|
|
751
776
|
Effect.catchTag('ParseError', Effect.die),
|
|
752
|
-
Effect.withSpan(
|
|
777
|
+
Effect.withSpan(`${options.spanPrefix}.createManyAndReturn`, {
|
|
753
778
|
captureStackTrace: false,
|
|
754
779
|
attributes: { ...(args as any).data },
|
|
755
780
|
}),
|
|
@@ -788,12 +813,12 @@ export const make = <S extends Any, M extends keyof BasePrismaClient>(
|
|
|
788
813
|
})
|
|
789
814
|
|
|
790
815
|
const update = <A extends PrismaNamespace.Args<BasePrismaClient[M], 'update'>>(
|
|
791
|
-
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'update'>>
|
|
816
|
+
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'update'>> & { data: Updateable<S['Type']> }
|
|
792
817
|
): Effect.Effect<S['Type'], never, S['Context'] | S['update']['Context']> =>
|
|
793
818
|
updateSchema(args).pipe(
|
|
794
819
|
Effect.catchTag('ParseError', Effect.die),
|
|
795
820
|
Effect.catchTag('NoSuchElementException', Effect.die),
|
|
796
|
-
Effect.withSpan(
|
|
821
|
+
Effect.withSpan(`${options.spanPrefix}.update`, {
|
|
797
822
|
captureStackTrace: false,
|
|
798
823
|
attributes: { ...(args as any) },
|
|
799
824
|
}),
|
|
@@ -815,7 +840,7 @@ export const make = <S extends Any, M extends keyof BasePrismaClient>(
|
|
|
815
840
|
deleteSchema(args).pipe(
|
|
816
841
|
Effect.catchTag('ParseError', Effect.die),
|
|
817
842
|
Effect.catchTag('NoSuchElementException', Effect.die),
|
|
818
|
-
Effect.withSpan(
|
|
843
|
+
Effect.withSpan(`${options.spanPrefix}.delete`, {
|
|
819
844
|
captureStackTrace: false,
|
|
820
845
|
attributes: { ...(args as any) },
|
|
821
846
|
}),
|
|
@@ -832,12 +857,12 @@ export const make = <S extends Any, M extends keyof BasePrismaClient>(
|
|
|
832
857
|
})
|
|
833
858
|
|
|
834
859
|
const upsert = <A extends PrismaNamespace.Args<BasePrismaClient[M], 'upsert'>>(
|
|
835
|
-
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'upsert'>>
|
|
860
|
+
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'upsert'>> & { create: Insertable<S['Type']>; update: Updateable<S['Type']> }
|
|
836
861
|
): Effect.Effect<S['Type'], never, S['Context']> =>
|
|
837
862
|
upsertSchema(args).pipe(
|
|
838
863
|
Effect.catchTag('ParseError', Effect.die),
|
|
839
864
|
Effect.catchTag('NoSuchElementException', Effect.die),
|
|
840
|
-
Effect.withSpan(
|
|
865
|
+
Effect.withSpan(`${options.spanPrefix}.upsert`, {
|
|
841
866
|
captureStackTrace: false,
|
|
842
867
|
attributes: { ...(args as any) },
|
|
843
868
|
}),
|
|
@@ -859,7 +884,7 @@ export const make = <S extends Any, M extends keyof BasePrismaClient>(
|
|
|
859
884
|
aggregateSchema(args).pipe(
|
|
860
885
|
Effect.catchTag('ParseError', Effect.die),
|
|
861
886
|
Effect.catchTag('NoSuchElementException', Effect.die),
|
|
862
|
-
Effect.withSpan(
|
|
887
|
+
Effect.withSpan(`${options.spanPrefix}.aggregate`, {
|
|
863
888
|
captureStackTrace: false,
|
|
864
889
|
attributes: { ...(args as any) },
|
|
865
890
|
}),
|
|
@@ -880,7 +905,7 @@ export const make = <S extends Any, M extends keyof BasePrismaClient>(
|
|
|
880
905
|
): Effect.Effect<unknown, never, S['Context']> =>
|
|
881
906
|
groupBySchema(args).pipe(
|
|
882
907
|
Effect.catchTag('ParseError', Effect.die),
|
|
883
|
-
Effect.withSpan(
|
|
908
|
+
Effect.withSpan(`${options.spanPrefix}.groupBy`, {
|
|
884
909
|
captureStackTrace: false,
|
|
885
910
|
attributes: { ...(args as any) },
|
|
886
911
|
}),
|
|
@@ -897,13 +922,13 @@ export const make = <S extends Any, M extends keyof BasePrismaClient>(
|
|
|
897
922
|
})
|
|
898
923
|
|
|
899
924
|
const updateMany = <A extends PrismaNamespace.Args<BasePrismaClient[M], 'updateMany'>>(
|
|
900
|
-
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'updateMany'>>
|
|
925
|
+
args: PrismaNamespace.Exact<A, PrismaNamespace.Args<BasePrismaClient[M], 'updateMany'>> & { data: Updateable<S['Type']> }
|
|
901
926
|
): Effect.Effect<PrismaNamespace.BatchPayload, never, S['Context'] | S['update']['Context']> =>
|
|
902
927
|
updateManySchema(args).pipe(
|
|
903
928
|
Effect.map((res) => res as unknown as PrismaNamespace.BatchPayload),
|
|
904
929
|
Effect.catchTag('ParseError', Effect.die),
|
|
905
930
|
Effect.catchTag('NoSuchElementException', Effect.die),
|
|
906
|
-
Effect.withSpan(
|
|
931
|
+
Effect.withSpan(`${options.spanPrefix}.updateMany`, {
|
|
907
932
|
captureStackTrace: false,
|
|
908
933
|
attributes: { ...(args as any) },
|
|
909
934
|
}),
|
|
@@ -926,7 +951,7 @@ export const make = <S extends Any, M extends keyof BasePrismaClient>(
|
|
|
926
951
|
Effect.map((res) => res as unknown as PrismaNamespace.BatchPayload),
|
|
927
952
|
Effect.catchTag('ParseError', Effect.die),
|
|
928
953
|
Effect.catchTag('NoSuchElementException', Effect.die),
|
|
929
|
-
Effect.withSpan(
|
|
954
|
+
Effect.withSpan(`${options.spanPrefix}.deleteMany`, {
|
|
930
955
|
captureStackTrace: false,
|
|
931
956
|
attributes: { ...(args as any) },
|
|
932
957
|
}),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effectify/prisma",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/src/cli.js",
|
|
6
6
|
"type": "module",
|
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
"effect-prisma": "./dist/src/cli.js"
|
|
10
10
|
},
|
|
11
11
|
"exports": {
|
|
12
|
-
".": "./dist/src/
|
|
13
|
-
"./prisma": "./dist/prisma/index.js"
|
|
12
|
+
".": "./dist/src/runtime/index.js",
|
|
13
|
+
"./prisma": "./dist/prisma/index.js",
|
|
14
|
+
"./cli": "./dist/src/cli.js"
|
|
14
15
|
},
|
|
15
16
|
"files": [
|
|
16
17
|
"dist"
|
|
@@ -21,6 +22,8 @@
|
|
|
21
22
|
"keywords": [],
|
|
22
23
|
"author": "",
|
|
23
24
|
"dependencies": {
|
|
25
|
+
"@dprint/formatter": "^0.5.1",
|
|
26
|
+
"@dprint/typescript": "^0.95.15",
|
|
24
27
|
"@effect/cli": "0.73.0",
|
|
25
28
|
"@prisma/adapter-better-sqlite3": "7.3.0",
|
|
26
29
|
"@prisma/generator": "7.3.0",
|
|
@@ -32,11 +35,10 @@
|
|
|
32
35
|
"peerDependencies": {
|
|
33
36
|
"@effect/platform": "0.94.0",
|
|
34
37
|
"@effect/platform-node": "0.104.0",
|
|
35
|
-
"
|
|
36
|
-
"
|
|
38
|
+
"@prisma/client": "7.3.0",
|
|
39
|
+
"effect": "3.19.15"
|
|
37
40
|
},
|
|
38
41
|
"devDependencies": {
|
|
39
|
-
"prisma-effect-kysely": "5.2.0",
|
|
40
42
|
"@effect/build-utils": "0.8.9",
|
|
41
43
|
"@effect/experimental": "0.58.0",
|
|
42
44
|
"@effect/language-service": "0.56.0",
|
|
@@ -45,6 +47,8 @@
|
|
|
45
47
|
"@types/better-sqlite3": "7.6.13",
|
|
46
48
|
"@types/node": "20.19.25",
|
|
47
49
|
"bun": "1.3.0",
|
|
50
|
+
"dprint": "0.51.1",
|
|
51
|
+
"oxlint": "0.15.15",
|
|
48
52
|
"prisma": "7.3.0",
|
|
49
53
|
"tsx": "4.20.6",
|
|
50
54
|
"typescript": "5.9.3",
|
|
@@ -53,6 +57,7 @@
|
|
|
53
57
|
},
|
|
54
58
|
"scripts": {
|
|
55
59
|
"prisma:generate": "pnpm dlx prisma generate",
|
|
60
|
+
"build": "effect-build",
|
|
56
61
|
"test": "vitest",
|
|
57
62
|
"dev": "tsx src/messaround.ts",
|
|
58
63
|
"cli": "pnpm dlx tsx src/cli.ts"
|