prisma-flare 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.
@@ -23,9 +23,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
23
23
  mod
24
24
  ));
25
25
 
26
- // src/cli/db-create.ts
27
- var dotenv = __toESM(require("dotenv"), 1);
28
-
29
26
  // src/core/adapters/postgres.ts
30
27
  var PostgresAdapter = {
31
28
  name: "postgres",
@@ -33,26 +30,26 @@ var PostgresAdapter = {
33
30
  return url.startsWith("postgresql://") || url.startsWith("postgres://");
34
31
  },
35
32
  async create(url) {
36
- const config3 = parseDatabaseUrl(url);
33
+ const config = parseDatabaseUrl(url);
37
34
  const { Client } = await import("pg");
38
35
  const client = new Client({
39
- user: config3.user,
40
- password: config3.password,
41
- host: config3.host,
42
- port: config3.port,
36
+ user: config.user,
37
+ password: config.password,
38
+ host: config.host,
39
+ port: config.port,
43
40
  database: "postgres"
44
41
  });
45
42
  try {
46
43
  await client.connect();
47
44
  const checkRes = await client.query(
48
45
  `SELECT 1 FROM pg_database WHERE datname = $1`,
49
- [config3.database]
46
+ [config.database]
50
47
  );
51
48
  if (checkRes.rowCount === 0) {
52
- await client.query(`CREATE DATABASE "${config3.database}"`);
53
- console.log(`\u2705 Database "${config3.database}" created successfully.`);
49
+ await client.query(`CREATE DATABASE "${config.database}"`);
50
+ console.log(`\u2705 Database "${config.database}" created successfully.`);
54
51
  } else {
55
- console.log(`\u26A0\uFE0F Database "${config3.database}" already exists.`);
52
+ console.log(`\u26A0\uFE0F Database "${config.database}" already exists.`);
56
53
  }
57
54
  } catch (error) {
58
55
  console.error("\u274C Error creating database:", error);
@@ -62,13 +59,13 @@ var PostgresAdapter = {
62
59
  }
63
60
  },
64
61
  async drop(url) {
65
- const config3 = parseDatabaseUrl(url);
62
+ const config = parseDatabaseUrl(url);
66
63
  const { Client } = await import("pg");
67
64
  const client = new Client({
68
- user: config3.user,
69
- password: config3.password,
70
- host: config3.host,
71
- port: config3.port,
65
+ user: config.user,
66
+ password: config.password,
67
+ host: config.host,
68
+ port: config.port,
72
69
  database: "postgres"
73
70
  });
74
71
  try {
@@ -78,10 +75,10 @@ var PostgresAdapter = {
78
75
  FROM pg_stat_activity
79
76
  WHERE pg_stat_activity.datname = $1
80
77
  AND pid <> pg_backend_pid()`,
81
- [config3.database]
78
+ [config.database]
82
79
  );
83
- await client.query(`DROP DATABASE IF EXISTS "${config3.database}"`);
84
- console.log(`\u2705 Database "${config3.database}" dropped successfully.`);
80
+ await client.query(`DROP DATABASE IF EXISTS "${config.database}"`);
81
+ console.log(`\u2705 Database "${config.database}" dropped successfully.`);
85
82
  } catch (error) {
86
83
  console.error("\u274C Error dropping database:", error);
87
84
  throw error;
@@ -183,44 +180,7 @@ var registry = new AdapterRegistry();
183
180
  registry.register(PostgresAdapter);
184
181
  registry.register(SqliteAdapter);
185
182
 
186
- // src/cli/config.ts
187
- var fs2 = __toESM(require("fs"), 1);
188
- var path2 = __toESM(require("path"), 1);
189
- function findProjectRoot(currentDir) {
190
- if (fs2.existsSync(path2.join(currentDir, "package.json"))) {
191
- return currentDir;
192
- }
193
- const parentDir = path2.dirname(currentDir);
194
- if (parentDir === currentDir) {
195
- throw new Error("Could not find package.json");
196
- }
197
- return findProjectRoot(parentDir);
198
- }
199
- function loadConfig(rootDir) {
200
- const projectRoot = rootDir || findProjectRoot(process.cwd());
201
- const configPath = path2.join(projectRoot, "prisma-flare.config.json");
202
- let config3 = {
203
- modelsPath: "prisma/models",
204
- dbPath: "prisma/db",
205
- callbacksPath: "prisma/callbacks"
206
- };
207
- if (fs2.existsSync(configPath)) {
208
- try {
209
- const configFile = fs2.readFileSync(configPath, "utf-8");
210
- const userConfig = JSON.parse(configFile);
211
- config3 = { ...config3, ...userConfig };
212
- } catch {
213
- console.warn("\u26A0\uFE0F Could not read prisma-flare.config.json, using defaults.");
214
- }
215
- }
216
- return {
217
- ...config3
218
- };
219
- }
220
-
221
183
  // src/cli/db-create.ts
222
- var config2 = loadConfig();
223
- dotenv.config({ path: config2.envPath });
224
184
  async function createDatabase() {
225
185
  const databaseUrl = process.env.DATABASE_URL;
226
186
  if (!databaseUrl) {
@@ -1,8 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- // src/cli/db-create.ts
4
- import * as dotenv from "dotenv";
5
-
6
3
  // src/core/adapters/postgres.ts
7
4
  var PostgresAdapter = {
8
5
  name: "postgres",
@@ -10,26 +7,26 @@ var PostgresAdapter = {
10
7
  return url.startsWith("postgresql://") || url.startsWith("postgres://");
11
8
  },
12
9
  async create(url) {
13
- const config3 = parseDatabaseUrl(url);
10
+ const config = parseDatabaseUrl(url);
14
11
  const { Client } = await import("pg");
15
12
  const client = new Client({
16
- user: config3.user,
17
- password: config3.password,
18
- host: config3.host,
19
- port: config3.port,
13
+ user: config.user,
14
+ password: config.password,
15
+ host: config.host,
16
+ port: config.port,
20
17
  database: "postgres"
21
18
  });
22
19
  try {
23
20
  await client.connect();
24
21
  const checkRes = await client.query(
25
22
  `SELECT 1 FROM pg_database WHERE datname = $1`,
26
- [config3.database]
23
+ [config.database]
27
24
  );
28
25
  if (checkRes.rowCount === 0) {
29
- await client.query(`CREATE DATABASE "${config3.database}"`);
30
- console.log(`\u2705 Database "${config3.database}" created successfully.`);
26
+ await client.query(`CREATE DATABASE "${config.database}"`);
27
+ console.log(`\u2705 Database "${config.database}" created successfully.`);
31
28
  } else {
32
- console.log(`\u26A0\uFE0F Database "${config3.database}" already exists.`);
29
+ console.log(`\u26A0\uFE0F Database "${config.database}" already exists.`);
33
30
  }
34
31
  } catch (error) {
35
32
  console.error("\u274C Error creating database:", error);
@@ -39,13 +36,13 @@ var PostgresAdapter = {
39
36
  }
40
37
  },
41
38
  async drop(url) {
42
- const config3 = parseDatabaseUrl(url);
39
+ const config = parseDatabaseUrl(url);
43
40
  const { Client } = await import("pg");
44
41
  const client = new Client({
45
- user: config3.user,
46
- password: config3.password,
47
- host: config3.host,
48
- port: config3.port,
42
+ user: config.user,
43
+ password: config.password,
44
+ host: config.host,
45
+ port: config.port,
49
46
  database: "postgres"
50
47
  });
51
48
  try {
@@ -55,10 +52,10 @@ var PostgresAdapter = {
55
52
  FROM pg_stat_activity
56
53
  WHERE pg_stat_activity.datname = $1
57
54
  AND pid <> pg_backend_pid()`,
58
- [config3.database]
55
+ [config.database]
59
56
  );
60
- await client.query(`DROP DATABASE IF EXISTS "${config3.database}"`);
61
- console.log(`\u2705 Database "${config3.database}" dropped successfully.`);
57
+ await client.query(`DROP DATABASE IF EXISTS "${config.database}"`);
58
+ console.log(`\u2705 Database "${config.database}" dropped successfully.`);
62
59
  } catch (error) {
63
60
  console.error("\u274C Error dropping database:", error);
64
61
  throw error;
@@ -160,44 +157,7 @@ var registry = new AdapterRegistry();
160
157
  registry.register(PostgresAdapter);
161
158
  registry.register(SqliteAdapter);
162
159
 
163
- // src/cli/config.ts
164
- import * as fs2 from "fs";
165
- import * as path2 from "path";
166
- function findProjectRoot(currentDir) {
167
- if (fs2.existsSync(path2.join(currentDir, "package.json"))) {
168
- return currentDir;
169
- }
170
- const parentDir = path2.dirname(currentDir);
171
- if (parentDir === currentDir) {
172
- throw new Error("Could not find package.json");
173
- }
174
- return findProjectRoot(parentDir);
175
- }
176
- function loadConfig(rootDir) {
177
- const projectRoot = rootDir || findProjectRoot(process.cwd());
178
- const configPath = path2.join(projectRoot, "prisma-flare.config.json");
179
- let config3 = {
180
- modelsPath: "prisma/models",
181
- dbPath: "prisma/db",
182
- callbacksPath: "prisma/callbacks"
183
- };
184
- if (fs2.existsSync(configPath)) {
185
- try {
186
- const configFile = fs2.readFileSync(configPath, "utf-8");
187
- const userConfig = JSON.parse(configFile);
188
- config3 = { ...config3, ...userConfig };
189
- } catch {
190
- console.warn("\u26A0\uFE0F Could not read prisma-flare.config.json, using defaults.");
191
- }
192
- }
193
- return {
194
- ...config3
195
- };
196
- }
197
-
198
160
  // src/cli/db-create.ts
199
- var config2 = loadConfig();
200
- dotenv.config({ path: config2.envPath });
201
161
  async function createDatabase() {
202
162
  const databaseUrl = process.env.DATABASE_URL;
203
163
  if (!databaseUrl) {
@@ -24,7 +24,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  ));
25
25
 
26
26
  // src/cli/db-drop.ts
27
- var dotenv = __toESM(require("dotenv"), 1);
28
27
  var readline = __toESM(require("readline"), 1);
29
28
 
30
29
  // src/core/adapters/postgres.ts
@@ -34,26 +33,26 @@ var PostgresAdapter = {
34
33
  return url.startsWith("postgresql://") || url.startsWith("postgres://");
35
34
  },
36
35
  async create(url) {
37
- const config3 = parseDatabaseUrl(url);
36
+ const config = parseDatabaseUrl(url);
38
37
  const { Client } = await import("pg");
39
38
  const client = new Client({
40
- user: config3.user,
41
- password: config3.password,
42
- host: config3.host,
43
- port: config3.port,
39
+ user: config.user,
40
+ password: config.password,
41
+ host: config.host,
42
+ port: config.port,
44
43
  database: "postgres"
45
44
  });
46
45
  try {
47
46
  await client.connect();
48
47
  const checkRes = await client.query(
49
48
  `SELECT 1 FROM pg_database WHERE datname = $1`,
50
- [config3.database]
49
+ [config.database]
51
50
  );
52
51
  if (checkRes.rowCount === 0) {
53
- await client.query(`CREATE DATABASE "${config3.database}"`);
54
- console.log(`\u2705 Database "${config3.database}" created successfully.`);
52
+ await client.query(`CREATE DATABASE "${config.database}"`);
53
+ console.log(`\u2705 Database "${config.database}" created successfully.`);
55
54
  } else {
56
- console.log(`\u26A0\uFE0F Database "${config3.database}" already exists.`);
55
+ console.log(`\u26A0\uFE0F Database "${config.database}" already exists.`);
57
56
  }
58
57
  } catch (error) {
59
58
  console.error("\u274C Error creating database:", error);
@@ -63,13 +62,13 @@ var PostgresAdapter = {
63
62
  }
64
63
  },
65
64
  async drop(url) {
66
- const config3 = parseDatabaseUrl(url);
65
+ const config = parseDatabaseUrl(url);
67
66
  const { Client } = await import("pg");
68
67
  const client = new Client({
69
- user: config3.user,
70
- password: config3.password,
71
- host: config3.host,
72
- port: config3.port,
68
+ user: config.user,
69
+ password: config.password,
70
+ host: config.host,
71
+ port: config.port,
73
72
  database: "postgres"
74
73
  });
75
74
  try {
@@ -79,10 +78,10 @@ var PostgresAdapter = {
79
78
  FROM pg_stat_activity
80
79
  WHERE pg_stat_activity.datname = $1
81
80
  AND pid <> pg_backend_pid()`,
82
- [config3.database]
81
+ [config.database]
83
82
  );
84
- await client.query(`DROP DATABASE IF EXISTS "${config3.database}"`);
85
- console.log(`\u2705 Database "${config3.database}" dropped successfully.`);
83
+ await client.query(`DROP DATABASE IF EXISTS "${config.database}"`);
84
+ console.log(`\u2705 Database "${config.database}" dropped successfully.`);
86
85
  } catch (error) {
87
86
  console.error("\u274C Error dropping database:", error);
88
87
  throw error;
@@ -184,44 +183,7 @@ var registry = new AdapterRegistry();
184
183
  registry.register(PostgresAdapter);
185
184
  registry.register(SqliteAdapter);
186
185
 
187
- // src/cli/config.ts
188
- var fs2 = __toESM(require("fs"), 1);
189
- var path2 = __toESM(require("path"), 1);
190
- function findProjectRoot(currentDir) {
191
- if (fs2.existsSync(path2.join(currentDir, "package.json"))) {
192
- return currentDir;
193
- }
194
- const parentDir = path2.dirname(currentDir);
195
- if (parentDir === currentDir) {
196
- throw new Error("Could not find package.json");
197
- }
198
- return findProjectRoot(parentDir);
199
- }
200
- function loadConfig(rootDir) {
201
- const projectRoot = rootDir || findProjectRoot(process.cwd());
202
- const configPath = path2.join(projectRoot, "prisma-flare.config.json");
203
- let config3 = {
204
- modelsPath: "prisma/models",
205
- dbPath: "prisma/db",
206
- callbacksPath: "prisma/callbacks"
207
- };
208
- if (fs2.existsSync(configPath)) {
209
- try {
210
- const configFile = fs2.readFileSync(configPath, "utf-8");
211
- const userConfig = JSON.parse(configFile);
212
- config3 = { ...config3, ...userConfig };
213
- } catch {
214
- console.warn("\u26A0\uFE0F Could not read prisma-flare.config.json, using defaults.");
215
- }
216
- }
217
- return {
218
- ...config3
219
- };
220
- }
221
-
222
186
  // src/cli/db-drop.ts
223
- var config2 = loadConfig();
224
- dotenv.config({ path: config2.envPath });
225
187
  function confirm(question) {
226
188
  const rl = readline.createInterface({
227
189
  input: process.stdin,
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/cli/db-drop.ts
4
- import * as dotenv from "dotenv";
5
4
  import * as readline from "readline";
6
5
 
7
6
  // src/core/adapters/postgres.ts
@@ -11,26 +10,26 @@ var PostgresAdapter = {
11
10
  return url.startsWith("postgresql://") || url.startsWith("postgres://");
12
11
  },
13
12
  async create(url) {
14
- const config3 = parseDatabaseUrl(url);
13
+ const config = parseDatabaseUrl(url);
15
14
  const { Client } = await import("pg");
16
15
  const client = new Client({
17
- user: config3.user,
18
- password: config3.password,
19
- host: config3.host,
20
- port: config3.port,
16
+ user: config.user,
17
+ password: config.password,
18
+ host: config.host,
19
+ port: config.port,
21
20
  database: "postgres"
22
21
  });
23
22
  try {
24
23
  await client.connect();
25
24
  const checkRes = await client.query(
26
25
  `SELECT 1 FROM pg_database WHERE datname = $1`,
27
- [config3.database]
26
+ [config.database]
28
27
  );
29
28
  if (checkRes.rowCount === 0) {
30
- await client.query(`CREATE DATABASE "${config3.database}"`);
31
- console.log(`\u2705 Database "${config3.database}" created successfully.`);
29
+ await client.query(`CREATE DATABASE "${config.database}"`);
30
+ console.log(`\u2705 Database "${config.database}" created successfully.`);
32
31
  } else {
33
- console.log(`\u26A0\uFE0F Database "${config3.database}" already exists.`);
32
+ console.log(`\u26A0\uFE0F Database "${config.database}" already exists.`);
34
33
  }
35
34
  } catch (error) {
36
35
  console.error("\u274C Error creating database:", error);
@@ -40,13 +39,13 @@ var PostgresAdapter = {
40
39
  }
41
40
  },
42
41
  async drop(url) {
43
- const config3 = parseDatabaseUrl(url);
42
+ const config = parseDatabaseUrl(url);
44
43
  const { Client } = await import("pg");
45
44
  const client = new Client({
46
- user: config3.user,
47
- password: config3.password,
48
- host: config3.host,
49
- port: config3.port,
45
+ user: config.user,
46
+ password: config.password,
47
+ host: config.host,
48
+ port: config.port,
50
49
  database: "postgres"
51
50
  });
52
51
  try {
@@ -56,10 +55,10 @@ var PostgresAdapter = {
56
55
  FROM pg_stat_activity
57
56
  WHERE pg_stat_activity.datname = $1
58
57
  AND pid <> pg_backend_pid()`,
59
- [config3.database]
58
+ [config.database]
60
59
  );
61
- await client.query(`DROP DATABASE IF EXISTS "${config3.database}"`);
62
- console.log(`\u2705 Database "${config3.database}" dropped successfully.`);
60
+ await client.query(`DROP DATABASE IF EXISTS "${config.database}"`);
61
+ console.log(`\u2705 Database "${config.database}" dropped successfully.`);
63
62
  } catch (error) {
64
63
  console.error("\u274C Error dropping database:", error);
65
64
  throw error;
@@ -161,44 +160,7 @@ var registry = new AdapterRegistry();
161
160
  registry.register(PostgresAdapter);
162
161
  registry.register(SqliteAdapter);
163
162
 
164
- // src/cli/config.ts
165
- import * as fs2 from "fs";
166
- import * as path2 from "path";
167
- function findProjectRoot(currentDir) {
168
- if (fs2.existsSync(path2.join(currentDir, "package.json"))) {
169
- return currentDir;
170
- }
171
- const parentDir = path2.dirname(currentDir);
172
- if (parentDir === currentDir) {
173
- throw new Error("Could not find package.json");
174
- }
175
- return findProjectRoot(parentDir);
176
- }
177
- function loadConfig(rootDir) {
178
- const projectRoot = rootDir || findProjectRoot(process.cwd());
179
- const configPath = path2.join(projectRoot, "prisma-flare.config.json");
180
- let config3 = {
181
- modelsPath: "prisma/models",
182
- dbPath: "prisma/db",
183
- callbacksPath: "prisma/callbacks"
184
- };
185
- if (fs2.existsSync(configPath)) {
186
- try {
187
- const configFile = fs2.readFileSync(configPath, "utf-8");
188
- const userConfig = JSON.parse(configFile);
189
- config3 = { ...config3, ...userConfig };
190
- } catch {
191
- console.warn("\u26A0\uFE0F Could not read prisma-flare.config.json, using defaults.");
192
- }
193
- }
194
- return {
195
- ...config3
196
- };
197
- }
198
-
199
163
  // src/cli/db-drop.ts
200
- var config2 = loadConfig();
201
- dotenv.config({ path: config2.envPath });
202
164
  function confirm(question) {
203
165
  const rl = readline.createInterface({
204
166
  input: process.stdin,
@@ -25,7 +25,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
25
25
 
26
26
  // src/cli/db-migrate.ts
27
27
  var import_child_process = require("child_process");
28
- var dotenv = __toESM(require("dotenv"), 1);
29
28
 
30
29
  // src/cli/generate-queries.ts
31
30
  var fs2 = __toESM(require("fs"), 1);
@@ -48,7 +47,7 @@ function findProjectRoot(currentDir) {
48
47
  function loadConfig(rootDir) {
49
48
  const projectRoot = rootDir || findProjectRoot(process.cwd());
50
49
  const configPath = path.join(projectRoot, "prisma-flare.config.json");
51
- let config3 = {
50
+ let config = {
52
51
  modelsPath: "prisma/models",
53
52
  dbPath: "prisma/db",
54
53
  callbacksPath: "prisma/callbacks"
@@ -57,13 +56,13 @@ function loadConfig(rootDir) {
57
56
  try {
58
57
  const configFile = fs.readFileSync(configPath, "utf-8");
59
58
  const userConfig = JSON.parse(configFile);
60
- config3 = { ...config3, ...userConfig };
59
+ config = { ...config, ...userConfig };
61
60
  } catch {
62
61
  console.warn("\u26A0\uFE0F Could not read prisma-flare.config.json, using defaults.");
63
62
  }
64
63
  }
65
64
  return {
66
- ...config3
65
+ ...config
67
66
  };
68
67
  }
69
68
 
@@ -100,7 +99,7 @@ function parseRelations(schemaContent, models) {
100
99
  }
101
100
  function generateQueries() {
102
101
  const rootDir = findProjectRoot(process.cwd());
103
- const config3 = loadConfig(rootDir);
102
+ const config = loadConfig(rootDir);
104
103
  const schemaPath = path2.join(rootDir, "prisma", "schema.prisma");
105
104
  if (!fs2.existsSync(schemaPath)) {
106
105
  console.error(`\u274C Schema not found at ${schemaPath}`);
@@ -113,11 +112,11 @@ function generateQueries() {
113
112
  while ((match = modelRegex.exec(schemaContent)) !== null) {
114
113
  models.push(match[1]);
115
114
  }
116
- const queriesDir = path2.join(rootDir, config3.modelsPath);
115
+ const queriesDir = path2.join(rootDir, config.modelsPath);
117
116
  if (!fs2.existsSync(queriesDir)) {
118
117
  fs2.mkdirSync(queriesDir, { recursive: true });
119
118
  }
120
- const absDbPath = path2.join(rootDir, config3.dbPath);
119
+ const absDbPath = path2.join(rootDir, config.dbPath);
121
120
  let relativePathToDb = path2.relative(queriesDir, absDbPath);
122
121
  if (!relativePathToDb.startsWith(".")) relativePathToDb = "./" + relativePathToDb;
123
122
  relativePathToDb = relativePathToDb.replace(/\\/g, "/");
@@ -175,7 +174,7 @@ export default class ${model} extends FlareBuilder<'${modelCamel}'> {
175
174
  const relations = parseRelations(schemaContent, models);
176
175
  const getters = models.map((model) => {
177
176
  const modelCamel = toCamelCase(model);
178
- const customPlural = config3.plurals?.[model];
177
+ const customPlural = config.plurals?.[model];
179
178
  const modelPlural = customPlural || (0, import_pluralize.default)(modelCamel);
180
179
  return ` static get ${modelPlural}() {
181
180
  return new ${model}();
@@ -184,7 +183,7 @@ export default class ${model} extends FlareBuilder<'${modelCamel}'> {
184
183
  const registrationLines = [];
185
184
  models.forEach((model) => {
186
185
  const modelCamel = toCamelCase(model);
187
- const customPlural = config3.plurals?.[model];
186
+ const customPlural = config.plurals?.[model];
188
187
  const modelPlural = customPlural || (0, import_pluralize.default)(modelCamel);
189
188
  registrationLines.push(`modelRegistry.register('${modelCamel}', ${model});`);
190
189
  registrationLines.push(`modelRegistry.register('${modelPlural}', ${model});`);
@@ -244,14 +243,14 @@ exports.DB = DB;
244
243
  }).join("\n");
245
244
  const gettersTypes = models.map((model) => {
246
245
  const modelCamel = toCamelCase(model);
247
- const customPlural = config3.plurals?.[model];
246
+ const customPlural = config.plurals?.[model];
248
247
  const modelPlural = customPlural || (0, import_pluralize.default)(modelCamel);
249
248
  return ` static get ${modelPlural}(): ${model};`;
250
249
  }).join("\n");
251
250
  const relationMapEntries = [];
252
251
  models.forEach((model) => {
253
252
  const modelCamel = toCamelCase(model);
254
- const customPlural = config3.plurals?.[model];
253
+ const customPlural = config.plurals?.[model];
255
254
  const modelPlural = customPlural || (0, import_pluralize.default)(modelCamel);
256
255
  relationMapEntries.push(` ${modelCamel}: ${model};`);
257
256
  relationMapEntries.push(` ${modelPlural}: ${model};`);
@@ -288,8 +287,6 @@ ${gettersTypes}
288
287
  }
289
288
 
290
289
  // src/cli/db-migrate.ts
291
- var config2 = loadConfig();
292
- dotenv.config({ path: config2.envPath });
293
290
  function runMigrations() {
294
291
  const databaseUrl = process.env.DATABASE_URL;
295
292
  if (!databaseUrl) {
@@ -2,7 +2,6 @@
2
2
 
3
3
  // src/cli/db-migrate.ts
4
4
  import { execSync } from "child_process";
5
- import * as dotenv from "dotenv";
6
5
 
7
6
  // src/cli/generate-queries.ts
8
7
  import * as fs2 from "fs";
@@ -25,7 +24,7 @@ function findProjectRoot(currentDir) {
25
24
  function loadConfig(rootDir) {
26
25
  const projectRoot = rootDir || findProjectRoot(process.cwd());
27
26
  const configPath = path.join(projectRoot, "prisma-flare.config.json");
28
- let config3 = {
27
+ let config = {
29
28
  modelsPath: "prisma/models",
30
29
  dbPath: "prisma/db",
31
30
  callbacksPath: "prisma/callbacks"
@@ -34,13 +33,13 @@ function loadConfig(rootDir) {
34
33
  try {
35
34
  const configFile = fs.readFileSync(configPath, "utf-8");
36
35
  const userConfig = JSON.parse(configFile);
37
- config3 = { ...config3, ...userConfig };
36
+ config = { ...config, ...userConfig };
38
37
  } catch {
39
38
  console.warn("\u26A0\uFE0F Could not read prisma-flare.config.json, using defaults.");
40
39
  }
41
40
  }
42
41
  return {
43
- ...config3
42
+ ...config
44
43
  };
45
44
  }
46
45
 
@@ -77,7 +76,7 @@ function parseRelations(schemaContent, models) {
77
76
  }
78
77
  function generateQueries() {
79
78
  const rootDir = findProjectRoot(process.cwd());
80
- const config3 = loadConfig(rootDir);
79
+ const config = loadConfig(rootDir);
81
80
  const schemaPath = path2.join(rootDir, "prisma", "schema.prisma");
82
81
  if (!fs2.existsSync(schemaPath)) {
83
82
  console.error(`\u274C Schema not found at ${schemaPath}`);
@@ -90,11 +89,11 @@ function generateQueries() {
90
89
  while ((match = modelRegex.exec(schemaContent)) !== null) {
91
90
  models.push(match[1]);
92
91
  }
93
- const queriesDir = path2.join(rootDir, config3.modelsPath);
92
+ const queriesDir = path2.join(rootDir, config.modelsPath);
94
93
  if (!fs2.existsSync(queriesDir)) {
95
94
  fs2.mkdirSync(queriesDir, { recursive: true });
96
95
  }
97
- const absDbPath = path2.join(rootDir, config3.dbPath);
96
+ const absDbPath = path2.join(rootDir, config.dbPath);
98
97
  let relativePathToDb = path2.relative(queriesDir, absDbPath);
99
98
  if (!relativePathToDb.startsWith(".")) relativePathToDb = "./" + relativePathToDb;
100
99
  relativePathToDb = relativePathToDb.replace(/\\/g, "/");
@@ -152,7 +151,7 @@ export default class ${model} extends FlareBuilder<'${modelCamel}'> {
152
151
  const relations = parseRelations(schemaContent, models);
153
152
  const getters = models.map((model) => {
154
153
  const modelCamel = toCamelCase(model);
155
- const customPlural = config3.plurals?.[model];
154
+ const customPlural = config.plurals?.[model];
156
155
  const modelPlural = customPlural || pluralize(modelCamel);
157
156
  return ` static get ${modelPlural}() {
158
157
  return new ${model}();
@@ -161,7 +160,7 @@ export default class ${model} extends FlareBuilder<'${modelCamel}'> {
161
160
  const registrationLines = [];
162
161
  models.forEach((model) => {
163
162
  const modelCamel = toCamelCase(model);
164
- const customPlural = config3.plurals?.[model];
163
+ const customPlural = config.plurals?.[model];
165
164
  const modelPlural = customPlural || pluralize(modelCamel);
166
165
  registrationLines.push(`modelRegistry.register('${modelCamel}', ${model});`);
167
166
  registrationLines.push(`modelRegistry.register('${modelPlural}', ${model});`);
@@ -221,14 +220,14 @@ exports.DB = DB;
221
220
  }).join("\n");
222
221
  const gettersTypes = models.map((model) => {
223
222
  const modelCamel = toCamelCase(model);
224
- const customPlural = config3.plurals?.[model];
223
+ const customPlural = config.plurals?.[model];
225
224
  const modelPlural = customPlural || pluralize(modelCamel);
226
225
  return ` static get ${modelPlural}(): ${model};`;
227
226
  }).join("\n");
228
227
  const relationMapEntries = [];
229
228
  models.forEach((model) => {
230
229
  const modelCamel = toCamelCase(model);
231
- const customPlural = config3.plurals?.[model];
230
+ const customPlural = config.plurals?.[model];
232
231
  const modelPlural = customPlural || pluralize(modelCamel);
233
232
  relationMapEntries.push(` ${modelCamel}: ${model};`);
234
233
  relationMapEntries.push(` ${modelPlural}: ${model};`);
@@ -265,8 +264,6 @@ ${gettersTypes}
265
264
  }
266
265
 
267
266
  // src/cli/db-migrate.ts
268
- var config2 = loadConfig();
269
- dotenv.config({ path: config2.envPath });
270
267
  function runMigrations() {
271
268
  const databaseUrl = process.env.DATABASE_URL;
272
269
  if (!databaseUrl) {
@@ -25,47 +25,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
25
25
 
26
26
  // src/cli/db-reset.ts
27
27
  var import_child_process = require("child_process");
28
- var dotenv = __toESM(require("dotenv"), 1);
29
28
  var readline = __toESM(require("readline"), 1);
30
-
31
- // src/cli/config.ts
32
- var fs = __toESM(require("fs"), 1);
33
- var path = __toESM(require("path"), 1);
34
- function findProjectRoot(currentDir) {
35
- if (fs.existsSync(path.join(currentDir, "package.json"))) {
36
- return currentDir;
37
- }
38
- const parentDir = path.dirname(currentDir);
39
- if (parentDir === currentDir) {
40
- throw new Error("Could not find package.json");
41
- }
42
- return findProjectRoot(parentDir);
43
- }
44
- function loadConfig(rootDir) {
45
- const projectRoot = rootDir || findProjectRoot(process.cwd());
46
- const configPath = path.join(projectRoot, "prisma-flare.config.json");
47
- let config3 = {
48
- modelsPath: "prisma/models",
49
- dbPath: "prisma/db",
50
- callbacksPath: "prisma/callbacks"
51
- };
52
- if (fs.existsSync(configPath)) {
53
- try {
54
- const configFile = fs.readFileSync(configPath, "utf-8");
55
- const userConfig = JSON.parse(configFile);
56
- config3 = { ...config3, ...userConfig };
57
- } catch {
58
- console.warn("\u26A0\uFE0F Could not read prisma-flare.config.json, using defaults.");
59
- }
60
- }
61
- return {
62
- ...config3
63
- };
64
- }
65
-
66
- // src/cli/db-reset.ts
67
- var config2 = loadConfig();
68
- dotenv.config({ path: config2.envPath });
69
29
  function confirm(question) {
70
30
  const rl = readline.createInterface({
71
31
  input: process.stdin,
@@ -2,47 +2,7 @@
2
2
 
3
3
  // src/cli/db-reset.ts
4
4
  import { execSync } from "child_process";
5
- import * as dotenv from "dotenv";
6
5
  import * as readline from "readline";
7
-
8
- // src/cli/config.ts
9
- import * as fs from "fs";
10
- import * as path from "path";
11
- function findProjectRoot(currentDir) {
12
- if (fs.existsSync(path.join(currentDir, "package.json"))) {
13
- return currentDir;
14
- }
15
- const parentDir = path.dirname(currentDir);
16
- if (parentDir === currentDir) {
17
- throw new Error("Could not find package.json");
18
- }
19
- return findProjectRoot(parentDir);
20
- }
21
- function loadConfig(rootDir) {
22
- const projectRoot = rootDir || findProjectRoot(process.cwd());
23
- const configPath = path.join(projectRoot, "prisma-flare.config.json");
24
- let config3 = {
25
- modelsPath: "prisma/models",
26
- dbPath: "prisma/db",
27
- callbacksPath: "prisma/callbacks"
28
- };
29
- if (fs.existsSync(configPath)) {
30
- try {
31
- const configFile = fs.readFileSync(configPath, "utf-8");
32
- const userConfig = JSON.parse(configFile);
33
- config3 = { ...config3, ...userConfig };
34
- } catch {
35
- console.warn("\u26A0\uFE0F Could not read prisma-flare.config.json, using defaults.");
36
- }
37
- }
38
- return {
39
- ...config3
40
- };
41
- }
42
-
43
- // src/cli/db-reset.ts
44
- var config2 = loadConfig();
45
- dotenv.config({ path: config2.envPath });
46
6
  function confirm(question) {
47
7
  const rl = readline.createInterface({
48
8
  input: process.stdin,
@@ -1,70 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
18
- // If the importer is in node compatibility mode or this is not an ESM
19
- // file that has been converted to a CommonJS file using a Babel-
20
- // compatible transform (i.e. "__esModule" has not been set), then set
21
- // "default" to the CommonJS "module.exports" for node compatibility.
22
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
- mod
24
- ));
25
3
 
26
4
  // src/cli/db-seed.ts
27
5
  var import_child_process = require("child_process");
28
- var dotenv = __toESM(require("dotenv"), 1);
29
-
30
- // src/cli/config.ts
31
- var fs = __toESM(require("fs"), 1);
32
- var path = __toESM(require("path"), 1);
33
- function findProjectRoot(currentDir) {
34
- if (fs.existsSync(path.join(currentDir, "package.json"))) {
35
- return currentDir;
36
- }
37
- const parentDir = path.dirname(currentDir);
38
- if (parentDir === currentDir) {
39
- throw new Error("Could not find package.json");
40
- }
41
- return findProjectRoot(parentDir);
42
- }
43
- function loadConfig(rootDir) {
44
- const projectRoot = rootDir || findProjectRoot(process.cwd());
45
- const configPath = path.join(projectRoot, "prisma-flare.config.json");
46
- let config3 = {
47
- modelsPath: "prisma/models",
48
- dbPath: "prisma/db",
49
- callbacksPath: "prisma/callbacks"
50
- };
51
- if (fs.existsSync(configPath)) {
52
- try {
53
- const configFile = fs.readFileSync(configPath, "utf-8");
54
- const userConfig = JSON.parse(configFile);
55
- config3 = { ...config3, ...userConfig };
56
- } catch {
57
- console.warn("\u26A0\uFE0F Could not read prisma-flare.config.json, using defaults.");
58
- }
59
- }
60
- return {
61
- ...config3
62
- };
63
- }
64
-
65
- // src/cli/db-seed.ts
66
- var config2 = loadConfig();
67
- dotenv.config({ path: config2.envPath });
68
6
  function seedDatabase() {
69
7
  const databaseUrl = process.env.DATABASE_URL;
70
8
  if (!databaseUrl) {
@@ -2,46 +2,6 @@
2
2
 
3
3
  // src/cli/db-seed.ts
4
4
  import { execSync } from "child_process";
5
- import * as dotenv from "dotenv";
6
-
7
- // src/cli/config.ts
8
- import * as fs from "fs";
9
- import * as path from "path";
10
- function findProjectRoot(currentDir) {
11
- if (fs.existsSync(path.join(currentDir, "package.json"))) {
12
- return currentDir;
13
- }
14
- const parentDir = path.dirname(currentDir);
15
- if (parentDir === currentDir) {
16
- throw new Error("Could not find package.json");
17
- }
18
- return findProjectRoot(parentDir);
19
- }
20
- function loadConfig(rootDir) {
21
- const projectRoot = rootDir || findProjectRoot(process.cwd());
22
- const configPath = path.join(projectRoot, "prisma-flare.config.json");
23
- let config3 = {
24
- modelsPath: "prisma/models",
25
- dbPath: "prisma/db",
26
- callbacksPath: "prisma/callbacks"
27
- };
28
- if (fs.existsSync(configPath)) {
29
- try {
30
- const configFile = fs.readFileSync(configPath, "utf-8");
31
- const userConfig = JSON.parse(configFile);
32
- config3 = { ...config3, ...userConfig };
33
- } catch {
34
- console.warn("\u26A0\uFE0F Could not read prisma-flare.config.json, using defaults.");
35
- }
36
- }
37
- return {
38
- ...config3
39
- };
40
- }
41
-
42
- // src/cli/db-seed.ts
43
- var config2 = loadConfig();
44
- dotenv.config({ path: config2.envPath });
45
5
  function seedDatabase() {
46
6
  const databaseUrl = process.env.DATABASE_URL;
47
7
  if (!databaseUrl) {
package/dist/index.cjs CHANGED
@@ -1066,7 +1066,7 @@ async function executeHookLogic(prisma, model, action, args, next) {
1066
1066
  const isUpdateAction = action === "update" || action === "updateMany";
1067
1067
  if (hasColumnHooks && isUpdateAction) {
1068
1068
  fields = hookRegistry_default.getRelevantFields(modelName);
1069
- prevData = await fetchAffectedRecords(prisma, modelName, args.where, fields);
1069
+ prevData = await fetchAffectedRecords(prisma, model, args.where, fields);
1070
1070
  shouldRunColumnHooks = hookRegistry_default.shouldRunColumnHooks(modelName, prevData.length, { __flare: flareOptions });
1071
1071
  }
1072
1072
  await hookRegistry_default.runHooks("before", modelName, action, [args], prisma);
@@ -1074,7 +1074,7 @@ async function executeHookLogic(prisma, model, action, args, next) {
1074
1074
  if (shouldRunColumnHooks && prevData.length > 0) {
1075
1075
  let newData = [];
1076
1076
  const ids = prevData.map((r) => r.id);
1077
- newData = await fetchAffectedRecords(prisma, modelName, { id: { in: ids } }, fields);
1077
+ newData = await fetchAffectedRecords(prisma, model, { id: { in: ids } }, fields);
1078
1078
  for (let i = 0; i < prevData.length; i++) {
1079
1079
  const prevRecord = prevData[i];
1080
1080
  const newRecord = newData.find((record) => record.id === prevRecord.id);
package/dist/index.js CHANGED
@@ -1013,7 +1013,7 @@ async function executeHookLogic(prisma, model, action, args, next) {
1013
1013
  const isUpdateAction = action === "update" || action === "updateMany";
1014
1014
  if (hasColumnHooks && isUpdateAction) {
1015
1015
  fields = hookRegistry_default.getRelevantFields(modelName);
1016
- prevData = await fetchAffectedRecords(prisma, modelName, args.where, fields);
1016
+ prevData = await fetchAffectedRecords(prisma, model, args.where, fields);
1017
1017
  shouldRunColumnHooks = hookRegistry_default.shouldRunColumnHooks(modelName, prevData.length, { __flare: flareOptions });
1018
1018
  }
1019
1019
  await hookRegistry_default.runHooks("before", modelName, action, [args], prisma);
@@ -1021,7 +1021,7 @@ async function executeHookLogic(prisma, model, action, args, next) {
1021
1021
  if (shouldRunColumnHooks && prevData.length > 0) {
1022
1022
  let newData = [];
1023
1023
  const ids = prevData.map((r) => r.id);
1024
- newData = await fetchAffectedRecords(prisma, modelName, { id: { in: ids } }, fields);
1024
+ newData = await fetchAffectedRecords(prisma, model, { id: { in: ids } }, fields);
1025
1025
  for (let i = 0; i < prevData.length; i++) {
1026
1026
  const prevRecord = prevData[i];
1027
1027
  const newRecord = newData.find((record) => record.id === prevRecord.id);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prisma-flare",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Prisma utilities package with callback system and query builder for chained operations",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -52,8 +52,7 @@
52
52
  },
53
53
  "dependencies": {
54
54
  "pg": "^8.16.3",
55
- "pluralize": "^8.0.0",
56
- "dotenv": "^17.2.3"
55
+ "pluralize": "^8.0.0"
57
56
  },
58
57
  "devDependencies": {
59
58
  "@prisma/client": "^5.18.0",