@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.
Files changed (81) hide show
  1. package/dist/src/cli.d.ts +1 -1
  2. package/dist/src/cli.js +9 -9
  3. package/dist/src/commands/init.d.ts +1 -1
  4. package/dist/src/commands/init.js +0 -2
  5. package/dist/src/commands/prisma.d.ts +5 -0
  6. package/dist/src/commands/prisma.js +35 -0
  7. package/dist/src/generators/sql-schema-generator.d.ts +9 -0
  8. package/dist/src/generators/sql-schema-generator.js +50 -58
  9. package/dist/src/services/generator-context.d.ts +6 -0
  10. package/dist/src/services/generator-context.js +3 -0
  11. package/dist/src/services/generator-service.d.ts +14 -0
  12. package/dist/src/services/generator-service.js +121 -0
  13. package/dist/src/services/render-service.d.ts +10 -0
  14. package/dist/src/services/render-service.js +23 -0
  15. package/{src → dist/src}/templates/index-default.eta +1 -1
  16. package/dist/src/templates/model.eta +8 -0
  17. package/{src → dist/src}/templates/prisma-repository.eta +7 -7
  18. package/package.json +15 -11
  19. package/dist/src/commands/generate-effect.d.ts +0 -2
  20. package/dist/src/commands/generate-effect.js +0 -73
  21. package/dist/src/commands/generate-sql-schema.d.ts +0 -2
  22. package/dist/src/commands/generate-sql-schema.js +0 -72
  23. package/dist/src/effect-prisma.d.ts +0 -2
  24. package/dist/src/effect-prisma.js +0 -1771
  25. package/dist/src/generators/prisma-effect-generator.d.ts +0 -1
  26. package/dist/src/generators/prisma-effect-generator.js +0 -446
  27. package/prisma/dev.db +0 -0
  28. package/prisma/generated/client.d.ts +0 -1
  29. package/prisma/generated/client.js +0 -5
  30. package/prisma/generated/default.d.ts +0 -1
  31. package/prisma/generated/default.js +0 -5
  32. package/prisma/generated/edge.d.ts +0 -1
  33. package/prisma/generated/edge.js +0 -141
  34. package/prisma/generated/effect/index.ts +0 -392
  35. package/prisma/generated/effect/models/Todo.ts +0 -6
  36. package/prisma/generated/effect/prisma-repository.ts +0 -954
  37. package/prisma/generated/effect/prisma-schema.ts +0 -94
  38. package/prisma/generated/effect/schemas/enums.ts +0 -6
  39. package/prisma/generated/effect/schemas/index.ts +0 -2
  40. package/prisma/generated/effect/schemas/types.ts +0 -40
  41. package/prisma/generated/index-browser.js +0 -172
  42. package/prisma/generated/index.d.ts +0 -2376
  43. package/prisma/generated/index.js +0 -141
  44. package/prisma/generated/package.json +0 -144
  45. package/prisma/generated/query_compiler_bg.js +0 -2
  46. package/prisma/generated/query_compiler_bg.wasm +0 -0
  47. package/prisma/generated/query_compiler_bg.wasm-base64.js +0 -2
  48. package/prisma/generated/runtime/client.d.ts +0 -3180
  49. package/prisma/generated/runtime/client.js +0 -86
  50. package/prisma/generated/runtime/index-browser.d.ts +0 -87
  51. package/prisma/generated/runtime/index-browser.js +0 -6
  52. package/prisma/generated/runtime/wasm-compiler-edge.js +0 -76
  53. package/prisma/generated/schema.prisma +0 -31
  54. package/prisma/generated/wasm-edge-light-loader.mjs +0 -5
  55. package/prisma/generated/wasm-worker-loader.mjs +0 -5
  56. package/prisma/migrations/20250721164420_init/migration.sql +0 -9
  57. package/prisma/migrations/20250721191716_dumb/migration.sql +0 -49
  58. package/prisma/migrations/migration_lock.toml +0 -3
  59. package/prisma/schema.prisma +0 -31
  60. package/prisma.config.ts +0 -8
  61. package/project.json +0 -48
  62. package/scripts/cleanup-tests.ts +0 -26
  63. package/scripts/generate-test-files.ts +0 -93
  64. package/setup-tests.ts +0 -10
  65. package/src/cli.ts +0 -22
  66. package/src/commands/init.ts +0 -153
  67. package/src/commands/prisma.ts +0 -50
  68. package/src/generators/sql-schema-generator.ts +0 -66
  69. package/src/services/generator-context.ts +0 -4
  70. package/src/services/generator-service.ts +0 -178
  71. package/src/services/render-service.ts +0 -32
  72. package/src/templates/model.eta +0 -6
  73. package/test/prisma-model.test.ts +0 -340
  74. package/test/utils.ts +0 -10
  75. package/tsconfig.json +0 -20
  76. package/tsconfig.lib.json +0 -24
  77. package/tsconfig.spec.json +0 -15
  78. package/vitest.config.ts +0 -24
  79. /package/{src → dist/src}/templates/index-custom-error.eta +0 -0
  80. /package/{src → dist/src}/templates/prisma-raw-sql.eta +0 -0
  81. /package/{src → dist/src}/templates/prisma-schema.eta +0 -0
package/dist/src/cli.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env bun
1
+ #!/usr/bin/env -S pnpm dlx tsx
2
2
  export {};
package/dist/src/cli.js CHANGED
@@ -1,17 +1,17 @@
1
- #!/usr/bin/env bun
1
+ #!/usr/bin/env -S pnpm dlx tsx
2
2
  import * as Command from '@effect/cli/Command';
3
3
  import * as NodeContext from '@effect/platform-node/NodeContext';
4
4
  import * as NodeRuntime from '@effect/platform-node/NodeRuntime';
5
- import * as Console from 'effect/Console';
6
5
  import * as Effect from 'effect/Effect';
7
- import { generateEffectCommand } from './commands/generate-effect.js';
8
- import { generateSqlSchemaCommand } from './commands/generate-sql-schema.js';
6
+ import * as Layer from 'effect/Layer';
9
7
  import { initCommand } from './commands/init.js';
10
- // Main CLI command
11
- const prisma = Command.make('prisma', {}, () => Console.log('🚀 prisma CLI - Use --help to see available commands')).pipe(Command.withSubcommands([initCommand, generateEffectCommand, generateSqlSchemaCommand]));
12
- // Run the CLI
13
- const cli = Command.run(prisma, {
8
+ import { prismaCommand } from './commands/prisma.js';
9
+ import { GeneratorService } from './services/generator-service.js';
10
+ import { RenderService } from './services/render-service.js';
11
+ const cli = Command.run(prismaCommand.pipe(Command.withSubcommands([initCommand])), {
14
12
  name: '@effectify/prisma CLI',
15
13
  version: '0.1.0',
16
14
  });
17
- cli(process.argv).pipe(Effect.provide(NodeContext.layer), NodeRuntime.runMain);
15
+ const GeneratorLayer = GeneratorService.Live.pipe(Layer.provide(RenderService.Live), Layer.provide(NodeContext.layer));
16
+ const MainLayer = Layer.mergeAll(GeneratorLayer, RenderService.Live, NodeContext.layer);
17
+ cli(process.argv).pipe(Effect.provide(MainLayer), NodeRuntime.runMain);
@@ -1,4 +1,4 @@
1
1
  import * as Command from '@effect/cli/Command';
2
- export declare const initCommand: Command.Command<"init", never, Error | import("@effect/platform/Error").PlatformError, {
2
+ export declare const initCommand: Command.Command<"init", never, import("@effect/platform/Error").PlatformError | Error, {
3
3
  readonly output: string;
4
4
  }>;
@@ -91,10 +91,8 @@ generator sqlSchema {
91
91
  yield* Console.log(' 1. Set your DATABASE_URL environment variable');
92
92
  yield* Console.log(' 2. Run: @effectify/prisma prisma generate-effect');
93
93
  yield* Console.log(' 3. Run: @effectify/prisma prisma generate-sql-schema');
94
- // Ensure the effect completes and exits
95
94
  yield* Effect.sync(() => process.exit(0));
96
95
  });
97
- // Export the init command
98
96
  export const initCommand = Command.make('init', {
99
97
  output: outputOption,
100
98
  }, ({ output }) => initializePrismaSchema({
@@ -0,0 +1,5 @@
1
+ import * as Command from '@effect/cli/Command';
2
+ import type * as NodeContext from '@effect/platform-node/NodeContext';
3
+ import { GeneratorService } from '../services/generator-service.js';
4
+ import type { RenderService } from '../services/render-service.js';
5
+ export declare const prismaCommand: Command.Command<"prisma", RenderService | GeneratorService | NodeContext.NodeContext, never, {}>;
@@ -0,0 +1,35 @@
1
+ import * as Command from '@effect/cli/Command';
2
+ import generatorHelper from '@prisma/generator-helper';
3
+ import * as Deferred from 'effect/Deferred';
4
+ import * as Effect from 'effect/Effect';
5
+ import * as Layer from 'effect/Layer';
6
+ import * as Runtime from 'effect/Runtime';
7
+ import * as Stream from 'effect/Stream';
8
+ import { GeneratorContext } from '../services/generator-context.js';
9
+ import { GeneratorService } from '../services/generator-service.js';
10
+ export const prismaCommand = Command.make('prisma', {}, () => Effect.gen(function* () {
11
+ const generator = yield* GeneratorService;
12
+ const runtime = yield* Effect.runtime();
13
+ const run = Runtime.runPromise(runtime);
14
+ const events = Stream.async((emit) => {
15
+ generatorHelper.generatorHandler({
16
+ onManifest() {
17
+ return {
18
+ defaultOutput: '../generated/effect',
19
+ prettyName: 'Prisma Effect Generator',
20
+ requiresEngines: [],
21
+ };
22
+ },
23
+ async onGenerate(options) {
24
+ await run(Effect.gen(function* () {
25
+ const deferred = yield* Deferred.make();
26
+ yield* Effect.promise(() => emit.single([options, deferred]));
27
+ yield* Deferred.await(deferred);
28
+ }));
29
+ // Cerrar el stream después de procesar la generación
30
+ emit.end();
31
+ },
32
+ });
33
+ });
34
+ yield* events.pipe(Stream.runForEach(([options, deferred]) => generator.generate.pipe(Effect.provide(Layer.succeed(GeneratorContext, options)), Effect.intoDeferred(deferred))));
35
+ }));
@@ -1 +1,10 @@
1
+ #!/usr/bin/env tsx
2
+ type SqlGeneratorOptions = {
3
+ generator: {
4
+ output?: {
5
+ value: string;
6
+ };
7
+ };
8
+ };
9
+ export declare function generateSqlSchema(options: SqlGeneratorOptions): Promise<void>;
1
10
  export {};
@@ -1,58 +1,50 @@
1
- // #!/usr/bin/env tsx
2
- export {};
3
- // import { execSync } from 'node:child_process'
4
- // import fs from 'node:fs/promises'
5
- // import path from 'node:path'
6
- // import gh from '@prisma/generator-helper'
7
- // const header = `-- This file was generated by sql-schema-generator, do not edit manually.
8
- // -- Generated at: ${new Date().toISOString()}
9
- // `
10
- // // Types for generator options
11
- // interface SqlGeneratorOptions {
12
- // generator: {
13
- // output?: {
14
- // value: string
15
- // }
16
- // }
17
- // }
18
- // // Export the generator function for use in CLI
19
- // export async function generateSqlSchema(options: SqlGeneratorOptions) {
20
- // const outputDir = options.generator.output?.value || '../generated'
21
- // const datasourceUrl = 'prisma/dev.db'
22
- // if (!datasourceUrl) {
23
- // throw new Error('No datasource URL found')
24
- // }
25
- // // Ensure output directory exists
26
- // await fs.mkdir(outputDir, { recursive: true })
27
- // try {
28
- // // Extract the database path from the URL (assuming sqlite)
29
- // let dbPath = datasourceUrl
30
- // if (dbPath.startsWith('file:')) {
31
- // dbPath = dbPath.replace('file:', '')
32
- // }
33
- // // Make path relative to current working directory if needed
34
- // if (!path.isAbsolute(dbPath)) {
35
- // dbPath = path.resolve(process.cwd(), dbPath)
36
- // }
37
- // // Use sqlite3 to dump only the schema (no data)
38
- // const schemaOutput = execSync(`sqlite3 "${dbPath}" ".schema"`, { encoding: 'utf8' })
39
- // // Write the schema to the output file
40
- // const outputPath = path.join(outputDir, 'schema.sql')
41
- // await fs.writeFile(outputPath, header + schemaOutput)
42
- // } catch (error) {
43
- // console.error('❌ Failed to generate schema dump:', error.message)
44
- // throw error
45
- // }
46
- // }
47
- // gh.generatorHandler({
48
- // onManifest() {
49
- // return {
50
- // defaultOutput: '../generated',
51
- // prettyName: 'SQL Schema Generator',
52
- // requiresEngines: [],
53
- // }
54
- // },
55
- // async onGenerate(options) {
56
- // await generateSqlSchema(options)
57
- // },
58
- // })
1
+ #!/usr/bin/env tsx
2
+ // biome-ignore-all lint: Generated code
3
+ import { execSync } from 'node:child_process';
4
+ import fs from 'node:fs/promises';
5
+ import path from 'node:path';
6
+ import gh from '@prisma/generator-helper';
7
+ const header = `-- This file was generated by sql-schema-generator, do not edit manually.
8
+ -- Generated at: ${new Date().toISOString()}
9
+
10
+ `;
11
+ export async function generateSqlSchema(options) {
12
+ const outputDir = options.generator.output?.value || '../generated';
13
+ const datasourceUrl = 'prisma/dev.db';
14
+ if (!datasourceUrl) {
15
+ throw new Error('No datasource URL found');
16
+ }
17
+ await fs.mkdir(outputDir, { recursive: true });
18
+ try {
19
+ let dbPath = datasourceUrl;
20
+ if (dbPath.startsWith('file:')) {
21
+ dbPath = dbPath.replace('file:', '');
22
+ }
23
+ if (!path.isAbsolute(dbPath)) {
24
+ dbPath = path.resolve(process.cwd(), dbPath);
25
+ }
26
+ const schemaOutput = execSync(`sqlite3 "${dbPath}" ".schema"`, { encoding: 'utf8' });
27
+ const outputPath = path.join(outputDir, 'schema.sql');
28
+ await fs.writeFile(outputPath, header + schemaOutput);
29
+ }
30
+ catch (error) {
31
+ console.error('❌ Failed to generate schema dump:', error);
32
+ throw error;
33
+ }
34
+ }
35
+ gh.generatorHandler({
36
+ onManifest() {
37
+ return {
38
+ defaultOutput: '../generated',
39
+ prettyName: 'SQL Schema Generator',
40
+ requiresEngines: [],
41
+ };
42
+ },
43
+ async onGenerate(options) {
44
+ await generateSqlSchema({
45
+ generator: {
46
+ output: options?.generator?.output ? { value: options.generator.output.value || '' } : undefined,
47
+ },
48
+ });
49
+ },
50
+ });
@@ -0,0 +1,6 @@
1
+ import type { GeneratorOptions } from '@prisma/generator-helper';
2
+ import * as Context from 'effect/Context';
3
+ declare const GeneratorContext_base: Context.TagClass<GeneratorContext, "GeneratorContext", GeneratorOptions>;
4
+ export declare class GeneratorContext extends GeneratorContext_base {
5
+ }
6
+ export {};
@@ -0,0 +1,3 @@
1
+ import * as Context from 'effect/Context';
2
+ export class GeneratorContext extends Context.Tag('GeneratorContext')() {
3
+ }
@@ -0,0 +1,14 @@
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
+ declare const GeneratorService_base: Context.TagClass<GeneratorService, "GeneratorService", {
9
+ readonly generate: Effect.Effect<void, Error, GeneratorContext>;
10
+ }>;
11
+ export declare class GeneratorService extends GeneratorService_base {
12
+ static Live: Layer.Layer<GeneratorService, never, FileSystem.FileSystem | Path.Path | RenderService>;
13
+ }
14
+ export {};
@@ -0,0 +1,121 @@
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
+ export class GeneratorService extends Context.Tag('GeneratorService')() {
9
+ static Live = Layer.effect(GeneratorService, Effect.gen(function* () {
10
+ const fs = yield* FileSystem.FileSystem;
11
+ const path = yield* Path.Path;
12
+ const { render } = yield* RenderService;
13
+ const parseErrorImportPath = (errorImportPath) => {
14
+ if (!errorImportPath) {
15
+ return null;
16
+ }
17
+ const [modulePath, className] = errorImportPath.split('#');
18
+ if (!(modulePath && className)) {
19
+ throw new Error(`Invalid errorImportPath format: "${errorImportPath}". Expected "path/to/module#ErrorClassName"`);
20
+ }
21
+ return { path: modulePath, className };
22
+ };
23
+ const addExtension = (filePath, extension) => {
24
+ if (!extension) {
25
+ return filePath;
26
+ }
27
+ const ext = path.extname(filePath);
28
+ if (ext) {
29
+ return filePath;
30
+ }
31
+ return `${filePath}.${extension}`;
32
+ };
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
+ const getClientImportPath = (config) => Array.isArray(config.clientImportPath)
49
+ ? config.clientImportPath[0]
50
+ : (config.clientImportPath ?? '@prisma/client');
51
+ 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 ?? '');
53
+ const getCustomError = (config, options, schemaDir) => {
54
+ const errorImportPathRaw = getErrorImportPath(config);
55
+ const importFileExtension = getImportFileExtension(config);
56
+ let customError = parseErrorImportPath(errorImportPathRaw);
57
+ if (customError?.path.startsWith('.')) {
58
+ const outputDir = options.generator.output?.value;
59
+ if (outputDir) {
60
+ const absoluteErrorPath = path.resolve(schemaDir, customError.path);
61
+ const relativeToOutput = path.relative(outputDir, absoluteErrorPath);
62
+ const normalizedPath = relativeToOutput.startsWith('.') ? relativeToOutput : `./${relativeToOutput}`;
63
+ const pathWithExtension = addExtension(normalizedPath, importFileExtension);
64
+ customError = { ...customError, path: pathWithExtension };
65
+ }
66
+ }
67
+ return customError;
68
+ };
69
+ const getGeneratorConfig = (options, schemaDir) => {
70
+ const { config } = options.generator;
71
+ const clientImportPath = getClientImportPath(config);
72
+ const customError = getCustomError(config, options, schemaDir);
73
+ return { clientImportPath, customError };
74
+ };
75
+ const generatePrismaSchema = (outputDir) => Effect.gen(function* () {
76
+ const content = yield* render('prisma-schema', {});
77
+ yield* fs.writeFileString(path.join(outputDir, 'prisma-schema.ts'), content);
78
+ });
79
+ const generatePrismaRepository = (outputDir, clientImportPath) => Effect.gen(function* () {
80
+ const content = yield* render('prisma-repository', { clientImportPath });
81
+ yield* fs.writeFileString(path.join(outputDir, 'prisma-repository.ts'), content);
82
+ });
83
+ const generateModels = (outputDir, models) => Effect.gen(function* () {
84
+ yield* fs.makeDirectory(path.join(outputDir, 'models'), { recursive: true });
85
+ for (const model of models) {
86
+ const content = yield* render('model', { model });
87
+ yield* fs.writeFileString(path.join(outputDir, 'models', `${model.name}.ts`), content);
88
+ }
89
+ });
90
+ const generateIndex = (outputDir, models, clientImportPath, customError) => Effect.gen(function* () {
91
+ const errorType = customError ? customError.className : 'PrismaError';
92
+ const rawSqlOperations = yield* render('prisma-raw-sql', { errorType });
93
+ const modelExports = models.map((m) => `export * from "./models/${m.name}.js"`).join('\n');
94
+ const templateName = customError ? 'index-custom-error' : 'index-default';
95
+ const content = yield* render(templateName, {
96
+ clientImportPath,
97
+ customError,
98
+ rawSqlOperations,
99
+ modelExports,
100
+ });
101
+ yield* fs.writeFileString(path.join(outputDir, 'index.ts'), content);
102
+ });
103
+ const generate = Effect.gen(function* () {
104
+ const options = yield* GeneratorContext;
105
+ const models = options.dmmf.datamodel.models;
106
+ const outputDir = options.generator.output?.value;
107
+ const schemaDir = path.dirname(options.schemaPath);
108
+ if (!outputDir) {
109
+ return yield* Effect.fail(new Error('No output directory specified'));
110
+ }
111
+ const { clientImportPath, customError } = getGeneratorConfig(options, schemaDir);
112
+ yield* fs.makeDirectory(outputDir, { recursive: true });
113
+ yield* generatePrismaSchema(outputDir);
114
+ yield* generatePrismaRepository(outputDir, clientImportPath);
115
+ yield* generateModels(outputDir, models);
116
+ yield* generateIndex(outputDir, models, clientImportPath, customError);
117
+ yield* fixSchemaImports(outputDir);
118
+ });
119
+ return { generate };
120
+ }));
121
+ }
@@ -0,0 +1,10 @@
1
+ import * as Context from 'effect/Context';
2
+ import * as Effect from 'effect/Effect';
3
+ import * as Layer from 'effect/Layer';
4
+ declare const RenderService_base: Context.TagClass<RenderService, "RenderService", {
5
+ readonly render: (templateName: string, data: Record<string, unknown>) => Effect.Effect<string, Error>;
6
+ }>;
7
+ export declare class RenderService extends RenderService_base {
8
+ static Live: Layer.Layer<RenderService, never, never>;
9
+ }
10
+ export {};
@@ -0,0 +1,23 @@
1
+ import * as path from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
3
+ import * as Context from 'effect/Context';
4
+ import * as Effect from 'effect/Effect';
5
+ import * as Layer from 'effect/Layer';
6
+ import { Eta } from 'eta';
7
+ export class RenderService extends Context.Tag('RenderService')() {
8
+ static Live = Layer.sync(RenderService, () => {
9
+ const __filename = fileURLToPath(import.meta.url);
10
+ const __dirname = path.dirname(__filename);
11
+ const templatesDir = path.resolve(__dirname, '../templates');
12
+ const eta = new Eta({
13
+ views: templatesDir,
14
+ autoEscape: false,
15
+ });
16
+ return {
17
+ render: (templateName, data) => Effect.try({
18
+ try: () => eta.render(templateName, data),
19
+ catch: (error) => new Error(`Failed to render template ${templateName}: ${error}`),
20
+ }),
21
+ };
22
+ });
23
+ }
@@ -201,7 +201,7 @@ 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
- switch (error.code) {
204
+ switch (error instanceof PrismaNamespace.PrismaClientKnownRequestError) {
205
205
  case "P2000":
206
206
  return new PrismaValueTooLongError({ cause: error, operation, model });
207
207
  case "P2002":
@@ -0,0 +1,8 @@
1
+ import * as Model from "../prisma-repository.js"
2
+ import { <%= it.model.name %>, <%= it.model.name %>Id } from "../schemas/index.js"
3
+
4
+ export class <%= it.model.name %>Model extends Model.Class<<%= it.model.name %>Model>("<%= it.model.name %>")({
5
+ ...<%= it.model.name %>.fields
6
+ }) {}
7
+
8
+ export { <%= it.model.name %>, <%= it.model.name %>Id }
@@ -142,7 +142,7 @@ export type PrismaUpdateManyError =
142
142
  // Create, Upsert
143
143
  export const mapCreateError = (error: unknown, operation: string, model: string): PrismaCreateError => {
144
144
  if (error instanceof PrismaNamespace.PrismaClientKnownRequestError) {
145
- switch (error.code) {
145
+ switch (error instanceof PrismaNamespace.PrismaClientKnownRequestError) {
146
146
  case 'P2000':
147
147
  return new PrismaValueTooLongError({ cause: error, operation, model })
148
148
  case 'P2002':
@@ -175,7 +175,7 @@ export const mapCreateError = (error: unknown, operation: string, model: string)
175
175
  // Update
176
176
  export const mapUpdateError = (error: unknown, operation: string, model: string): PrismaUpdateError => {
177
177
  if (error instanceof PrismaNamespace.PrismaClientKnownRequestError) {
178
- switch (error.code) {
178
+ switch (error instanceof PrismaNamespace.PrismaClientKnownRequestError) {
179
179
  case "P2000":
180
180
  return new PrismaValueTooLongError({ cause: error, operation, model });
181
181
  case "P2002":
@@ -212,7 +212,7 @@ 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
- switch (error.code) {
215
+ switch (error instanceof PrismaNamespace.PrismaClientKnownRequestError) {
216
216
  case "P2003":
217
217
  return new PrismaForeignKeyConstraintError({ cause: error, operation, model });
218
218
  case "P2014":
@@ -231,7 +231,7 @@ export const mapDeleteError = (error: unknown, operation: string, model: string)
231
231
  // FindOrThrow
232
232
  export const mapFindOrThrowError = (error: unknown, operation: string, model: string): PrismaFindOrThrowError => {
233
233
  if (error instanceof PrismaNamespace.PrismaClientKnownRequestError) {
234
- switch (error.code) {
234
+ switch (error instanceof PrismaNamespace.PrismaClientKnownRequestError) {
235
235
  case "P2024":
236
236
  return new PrismaConnectionError({ cause: error, operation, model });
237
237
  case "P2025":
@@ -244,7 +244,7 @@ export const mapFindOrThrowError = (error: unknown, operation: string, model: st
244
244
  // Find
245
245
  export const mapFindError = (error: unknown, operation: string, model: string): PrismaFindError => {
246
246
  if (error instanceof PrismaNamespace.PrismaClientKnownRequestError) {
247
- switch (error.code) {
247
+ switch (error instanceof PrismaNamespace.PrismaClientKnownRequestError) {
248
248
  case "P2024":
249
249
  return new PrismaConnectionError({ cause: error, operation, model });
250
250
  }
@@ -255,7 +255,7 @@ export const mapFindError = (error: unknown, operation: string, model: string):
255
255
  // DeleteMany
256
256
  export const mapDeleteManyError = (error: unknown, operation: string, model: string): PrismaDeleteManyError => {
257
257
  if (error instanceof PrismaNamespace.PrismaClientKnownRequestError) {
258
- switch (error.code) {
258
+ switch (error instanceof PrismaNamespace.PrismaClientKnownRequestError) {
259
259
  case "P2003":
260
260
  return new PrismaForeignKeyConstraintError({ cause: error, operation, model });
261
261
  case "P2014":
@@ -272,7 +272,7 @@ export const mapDeleteManyError = (error: unknown, operation: string, model: str
272
272
  // UpdateMany
273
273
  export const mapUpdateManyError = (error: unknown, operation: string, model: string): PrismaUpdateManyError => {
274
274
  if (error instanceof PrismaNamespace.PrismaClientKnownRequestError) {
275
- switch (error.code) {
275
+ switch (error instanceof PrismaNamespace.PrismaClientKnownRequestError) {
276
276
  case "P2000":
277
277
  return new PrismaValueTooLongError({ cause: error, operation, model });
278
278
  case "P2002":
package/package.json CHANGED
@@ -1,16 +1,20 @@
1
1
  {
2
2
  "name": "@effectify/prisma",
3
- "version": "0.1.2",
3
+ "version": "1.0.1",
4
4
  "description": "",
5
- "main": "index.js",
5
+ "main": "./dist/src/cli.js",
6
6
  "type": "module",
7
7
  "license": "MIT",
8
8
  "bin": {
9
- "effect-prisma": "./src/cli.ts"
9
+ "effect-prisma": "./dist/src/cli.js"
10
10
  },
11
11
  "exports": {
12
- "./prisma": "./prisma/index.ts"
12
+ ".": "./dist/src/cli.js",
13
+ "./prisma": "./dist/prisma/index.js"
13
14
  },
15
+ "files": [
16
+ "dist"
17
+ ],
14
18
  "publishConfig": {
15
19
  "access": "public"
16
20
  },
@@ -18,9 +22,9 @@
18
22
  "author": "",
19
23
  "dependencies": {
20
24
  "@effect/cli": "0.73.0",
21
- "@prisma/adapter-better-sqlite3": "7.0.0",
22
- "@prisma/generator": "^7.0.1",
23
- "@prisma/generator-helper": "7.0.0",
25
+ "@prisma/adapter-better-sqlite3": "7.3.0",
26
+ "@prisma/generator": "7.3.0",
27
+ "@prisma/generator-helper": "7.3.0",
24
28
  "better-sqlite3": "12.4.6",
25
29
  "eta": "^4.5.0",
26
30
  "kysely": "0.28.8"
@@ -29,19 +33,19 @@
29
33
  "@effect/platform": "0.94.0",
30
34
  "@effect/platform-node": "0.104.0",
31
35
  "effect": "3.19.13",
32
- "@prisma/client": "7.0.0"
36
+ "@prisma/client": "7.3.0"
33
37
  },
34
38
  "devDependencies": {
35
- "prisma-effect-kysely": "1.13.1",
39
+ "prisma-effect-kysely": "5.2.0",
36
40
  "@effect/build-utils": "0.8.9",
37
41
  "@effect/experimental": "0.58.0",
38
42
  "@effect/language-service": "0.56.0",
39
43
  "@effect/vitest": "0.27.0",
40
- "@prisma/internals": "7.0.0",
44
+ "@prisma/internals": "7.3.0",
41
45
  "@types/better-sqlite3": "7.6.13",
42
46
  "@types/node": "20.19.25",
43
47
  "bun": "1.3.0",
44
- "prisma": "7.0.0",
48
+ "prisma": "7.3.0",
45
49
  "tsx": "4.20.6",
46
50
  "typescript": "5.9.3",
47
51
  "vite-tsconfig-paths": "5.1.4",
@@ -1,2 +0,0 @@
1
- import * as Command from '@effect/cli/Command';
2
- export declare const generateEffectCommand: Command.Command<"generate-effect", never, Error | import("@effect/platform/Error").PlatformError, {}>;
@@ -1,73 +0,0 @@
1
- import * as Command from '@effect/cli/Command';
2
- import * as FileSystem from '@effect/platform/FileSystem';
3
- import * as NodeFileSystem from '@effect/platform-node/NodeFileSystem';
4
- import * as NodePath from '@effect/platform-node/NodePath';
5
- import * as Console from 'effect/Console';
6
- import * as Effect from 'effect/Effect';
7
- import * as Match from 'effect/Match';
8
- // import { generateEffectPrisma } from '../generators/prisma-effect-generator.js'
9
- // Check if file exists
10
- const fileExists = (path) => Effect.gen(function* () {
11
- const fs = yield* FileSystem.FileSystem;
12
- return yield* fs.exists(path);
13
- });
14
- // Detect package manager using pattern matching
15
- const detectPackageManager = () => Effect.gen(function* () {
16
- const pnpmExists = yield* fileExists('pnpm-lock.yaml');
17
- const bunExists = yield* fileExists('bun.lockb');
18
- const npmExists = yield* fileExists('package-lock.json');
19
- // Create a tuple to match against
20
- const lockFiles = [pnpmExists, bunExists, npmExists];
21
- return Match.value(lockFiles).pipe(Match.when([true, false, false], () => 'pnpm'), Match.when([false, true, false], () => 'bun'), Match.when([false, false, true], () => 'npm'), Match.orElse(() => 'npm'));
22
- });
23
- // Check if Prisma schema exists
24
- const checkPrismaSchema = () => Effect.gen(function* () {
25
- const schemaExists = yield* fileExists('prisma/schema.prisma');
26
- if (!schemaExists) {
27
- yield* Console.log('❌ Prisma schema not found.');
28
- yield* Console.log('');
29
- yield* Console.log('Please run the following command first:');
30
- const packageManager = yield* detectPackageManager();
31
- const initCommand = Match.value(packageManager).pipe(Match.when('pnpm', () => 'pnpm dlx prisma init'), Match.when('bun', () => 'bunx prisma init'), Match.when('npm', () => 'npx prisma init'), Match.exhaustive);
32
- yield* Console.log(` ${initCommand}`);
33
- yield* Effect.fail(new Error('Prisma schema not found'));
34
- }
35
- });
36
- // Execute the Effect generator
37
- const generateEffectServices = () => Effect.gen(function* () {
38
- // Check if we're being called by Prisma (no interactive output)
39
- const isCalledByPrisma = process.env.PRISMA_GENERATOR_INVOCATION === 'true' ||
40
- process.argv.includes('--generator') ||
41
- !process.stdout.isTTY;
42
- if (!isCalledByPrisma) {
43
- yield* Console.log('🔧 Running Effect generator...');
44
- }
45
- // Check if Prisma schema exists
46
- yield* checkPrismaSchema();
47
- // Note: We don't need to check for local generator files
48
- // since we're importing from our own package
49
- if (!isCalledByPrisma) {
50
- yield* Console.log('🚀 Executing Effect generator...');
51
- }
52
- // Execute the generator function
53
- yield* Effect.tryPromise({
54
- try: () => {
55
- // Create mock options for the generator
56
- // const mockOptions = {
57
- // dmmf: { datamodel: { models: [] } }, // Empty models for now
58
- // generator: { output: { value: 'src/generated/effect-prisma' } },
59
- // }
60
- return Promise.resolve();
61
- // return generateEffectPrisma(mockOptions)
62
- },
63
- catch: (error) => new Error(`Generator execution failed: ${error}`),
64
- });
65
- if (!isCalledByPrisma) {
66
- yield* Console.log('✅ Effect generator executed successfully!');
67
- yield* Console.log('💡 Generated files are available in the configured output directory');
68
- }
69
- // Ensure the effect completes and exits
70
- yield* Effect.sync(() => process.exit(0));
71
- });
72
- // Export the generate-effect command
73
- export const generateEffectCommand = Command.make('generate-effect', {}, () => generateEffectServices().pipe(Effect.provide(NodeFileSystem.layer), Effect.provide(NodePath.layer)));
@@ -1,2 +0,0 @@
1
- import * as Command from '@effect/cli/Command';
2
- export declare const generateSqlSchemaCommand: Command.Command<"generate-sql-schema", never, Error | import("@effect/platform/Error").PlatformError, {}>;