pecunia-cli 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/api.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { a as generateKyselySchema, n as generateSchema, o as generateDrizzleSchema, r as generatePrismaSchema, t as adapters } from "./generators-DVhIY0TJ.mjs";
1
+ import { a as generateKyselySchema, n as generateSchema, o as generateDrizzleSchema, r as generatePrismaSchema, t as adapters } from "./generators-BSLjSGA9.mjs";
2
2
 
3
3
  export { adapters, generateDrizzleSchema, generateKyselySchema, generatePrismaSchema, generateSchema };
@@ -30,6 +30,8 @@ const generateDrizzleSchema = async ({ options, file, adapter }) => {
30
30
  schema: tables,
31
31
  usePlural: adapter.options?.adapterConfig?.usePlural
32
32
  });
33
+ const tableNameMap = /* @__PURE__ */ new Map();
34
+ for (const tableKey in tables) tableNameMap.set(tableKey, getModelName(tableKey));
33
35
  for (const tableKey in tables) {
34
36
  const table = tables[tableKey];
35
37
  const modelName = getModelName(tableKey);
@@ -131,7 +133,7 @@ const generateDrizzleSchema = async ({ options, file, adapter }) => {
131
133
  if (attr.onUpdate && attr.type === "date") {
132
134
  if (typeof attr.onUpdate === "function") type += `.$onUpdate(${attr.onUpdate})`;
133
135
  }
134
- return `${fieldName}: ${type}${attr.required ? ".notNull()" : ""}${attr.unique ? ".unique()" : ""}${attr.references ? `.references(()=> ${getModelName(attr.references.model)}.${getFieldName({
136
+ return `${fieldName}: ${type}${attr.required ? ".notNull()" : ""}${attr.unique ? ".unique()" : ""}${attr.references ? `.references(()=> ${tableNameMap.get(attr.references.model) || getModelName(attr.references.model)}.${getFieldName({
135
137
  model: attr.references.model,
136
138
  field: attr.references.field
137
139
  })}, { onDelete: '${attr.references.onDelete || "cascade"}' })` : ""}`;
@@ -209,7 +211,7 @@ const generateDrizzleSchema = async ({ options, file, adapter }) => {
209
211
  for (const relation of duplicateRelations) {
210
212
  if (!relation.reference) continue;
211
213
  const fieldName = relation.reference.fieldName;
212
- const tableRelation = `export const ${`${modelName}${fieldName.charAt(0).toUpperCase() + fieldName.slice(1)}Relations`} = relations(${getModelName(table.modelName)}, ({ one }) => ({
214
+ const tableRelation = `export const ${`${modelName}${fieldName.charAt(0).toUpperCase() + fieldName.slice(1)}Relations`} = relations(${modelName}, ({ one }) => ({
213
215
  ${relation.key}: one(${relation.model}, {
214
216
  fields: [${relation.reference.field}],
215
217
  references: [${relation.reference.references}],
@@ -220,7 +222,7 @@ const generateDrizzleSchema = async ({ options, file, adapter }) => {
220
222
  const hasOne = singleRelations.length > 0;
221
223
  const hasMany = manyRelations.length > 0;
222
224
  if (hasOne && hasMany) {
223
- const tableRelation = `export const ${modelName}Relations = relations(${getModelName(table.modelName)}, ({ one, many }) => ({
225
+ const tableRelation = `export const ${modelName}Relations = relations(${modelName}, ({ one, many }) => ({
224
226
  ${singleRelations.map((relation) => relation.reference ? ` ${relation.key}: one(${relation.model}, {
225
227
  fields: [${relation.reference.field}],
226
228
  references: [${relation.reference.references}],
@@ -229,7 +231,7 @@ const generateDrizzleSchema = async ({ options, file, adapter }) => {
229
231
  }))`;
230
232
  relationsString += `\n${tableRelation}\n`;
231
233
  } else if (hasOne) {
232
- const tableRelation = `export const ${modelName}Relations = relations(${getModelName(table.modelName)}, ({ one }) => ({
234
+ const tableRelation = `export const ${modelName}Relations = relations(${modelName}, ({ one }) => ({
233
235
  ${singleRelations.map((relation) => relation.reference ? ` ${relation.key}: one(${relation.model}, {
234
236
  fields: [${relation.reference.field}],
235
237
  references: [${relation.reference.references}],
@@ -237,7 +239,7 @@ const generateDrizzleSchema = async ({ options, file, adapter }) => {
237
239
  }))`;
238
240
  relationsString += `\n${tableRelation}\n`;
239
241
  } else if (hasMany) {
240
- const tableRelation = `export const ${modelName}Relations = relations(${getModelName(table.modelName)}, ({ many }) => ({
242
+ const tableRelation = `export const ${modelName}Relations = relations(${modelName}, ({ many }) => ({
241
243
  ${manyRelations.map(({ key, model }) => ` ${key}: many(${model})`).join(",\n ")}
242
244
  }))`;
243
245
  relationsString += `\n${tableRelation}\n`;
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { i as getPackageInfo, n as generateSchema } from "./generators-DVhIY0TJ.mjs";
2
+ import { i as getPackageInfo, n as generateSchema } from "./generators-BSLjSGA9.mjs";
3
3
  import { Command } from "commander";
4
4
  import fs, { existsSync, readFileSync } from "node:fs";
5
5
  import fs$1 from "node:fs/promises";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pecunia-cli",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "type": "module",
5
5
  "module": "dist/index.mjs",
6
6
  "main": "./dist/index.mjs",
@@ -64,8 +64,8 @@
64
64
  "dotenv": "^17.2.2",
65
65
  "drizzle-orm": "^0.33.0",
66
66
  "open": "^10.2.0",
67
- "pecunia-core": "^0.0.8",
68
- "pecunia-root": "^0.1.6",
67
+ "pecunia-core": "^0.0.9",
68
+ "pecunia-root": "^0.1.7",
69
69
  "pg": "^8.16.3",
70
70
  "prettier": "^3.6.2",
71
71
  "prompts": "^2.4.2",