go-duck-cli 1.1.22 → 1.1.24

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.
@@ -3,6 +3,14 @@ import path from 'path';
3
3
  import chalk from 'chalk';
4
4
  import { toLiquibaseType } from '../parser/gdl.js';
5
5
 
6
+ const toSnakeCase = (str) => {
7
+ if (!str) return '';
8
+ return str
9
+ .replace(/([a-z0-9])([A-Z])/g, '$1_$2')
10
+ .replace(/([A-Z])([A-Z][a-z])/g, '$1_$2')
11
+ .toLowerCase();
12
+ };
13
+
6
14
  export const generateLiquibaseChangelogs = async (entities, relationships, projectRootDir, delta = null, enums = []) => {
7
15
  const migrationsDir = path.join(projectRootDir, 'migrations');
8
16
  const sqlDir = path.join(migrationsDir, 'sql');
@@ -87,11 +95,11 @@ DROP TABLE IF EXISTS api_usage CASCADE;
87
95
  if (field.required) constraints.push('NOT NULL');
88
96
  if (field.unique) constraints.push('UNIQUE');
89
97
 
90
- columns += `,\n ${field.name.toLowerCase()} ${sqlType} ${constraints.join(' ')}`;
98
+ columns += `,\n ${toSnakeCase(field.name)} ${sqlType} ${constraints.join(' ')}`;
91
99
  }
92
100
 
93
101
  // Auditing / Timestamp columns
94
- if (entity.annotation === '@Audited') {
102
+ if (entity.isAudited) {
95
103
  columns += `,\n created_by VARCHAR(255),\n created_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,\n last_modified_by VARCHAR(255),\n last_modified_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,\n last_modified_user_id VARCHAR(255)`;
96
104
  } else {
97
105
  columns += `,\n created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,\n updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP`;
@@ -111,8 +119,8 @@ DROP TABLE IF EXISTS api_usage CASCADE;
111
119
  if (field.required) constraints.push('NOT NULL');
112
120
  if (field.unique) constraints.push('UNIQUE');
113
121
 
114
- sqlUp += `ALTER TABLE ${entityName.toLowerCase()} ADD COLUMN IF NOT EXISTS ${field.name.toLowerCase()} ${sqlType} ${constraints.join(' ')};\n`;
115
- sqlDown += `ALTER TABLE ${entityName.toLowerCase()} DROP COLUMN IF EXISTS ${field.name.toLowerCase()};\n`;
122
+ sqlUp += `ALTER TABLE ${entityName.toLowerCase()} ADD COLUMN IF NOT EXISTS ${toSnakeCase(field.name)} ${sqlType} ${constraints.join(' ')};\n`;
123
+ sqlDown += `ALTER TABLE ${entityName.toLowerCase()} DROP COLUMN IF EXISTS ${toSnakeCase(field.name)};\n`;
116
124
  }
117
125
  }
118
126
  }
@@ -342,6 +342,7 @@ func CORSMiddleware(cfg *config.Config) gin.HandlerFunc {
342
342
  }
343
343
 
344
344
  c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
345
+ c.Writer.Header().Set("Access-Control-Expose-Headers", "X-Total-Count")
345
346
 
346
347
  headerString := ""
347
348
  for i, h := range headers {
package/index.js CHANGED
@@ -288,10 +288,13 @@ Handlebars.registerPartial('renderFields', `
288
288
  {{/each}}
289
289
  `);
290
290
 
291
+ const pkgPath = path.resolve(path.dirname(import.meta.url.replace('file://', '')), 'package.json');
292
+ const pkg = fs.readJsonSync(pkgPath);
293
+
291
294
  program
292
295
  .name('go-duck-cli')
293
296
  .description('A powerful Go code generator for microservices')
294
- .version('1.0.0');
297
+ .version(pkg.version || '1.0.0');
295
298
 
296
299
  // Helper to load configuration
297
300
  const loadConfig = async (configPath) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "go-duck-cli",
3
- "version": "1.1.22",
3
+ "version": "1.1.24",
4
4
  "description": "The Ultimate Evolutionary Go Microservice Scaffolder.",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -181,8 +181,6 @@ func (ctrl *{{capitalize name}}Controller) GetAll(c *gin.Context) {
181
181
 
182
182
  db, _ := c.Get("tenantMongoDB")
183
183
  tenantDB := db.(*mongo.Database)
184
- var entities []models.{{capitalize name}}
185
- opts := options.Find().SetSkip(int64(page * size)).SetLimit(int64(size))
186
184
 
187
185
  // PostgREST-lite Filter Translation (Simple eq check for now)
188
186
  filter := bson.M{}
@@ -192,6 +190,11 @@ func (ctrl *{{capitalize name}}Controller) GetAll(c *gin.Context) {
192
190
  }
193
191
  }
194
192
 
193
+ totalCount, _ := tenantDB.Collection("{{toLowerCase name}}s").CountDocuments(ctx, filter)
194
+ c.Header("X-Total-Count", strconv.FormatInt(totalCount, 10))
195
+
196
+ var entities []models.{{capitalize name}}
197
+ opts := options.Find().SetSkip(int64(page * size)).SetLimit(int64(size))
195
198
  cursor, err := tenantDB.Collection("{{toLowerCase name}}s").Find(ctx, filter, opts)
196
199
  if err != nil {
197
200
  c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
@@ -232,6 +235,13 @@ func (ctrl *{{capitalize name}}Controller) GetAll(c *gin.Context) {
232
235
  }
233
236
  {{/if}}
234
237
 
238
+ var totalCount int64
239
+ if err := tenantDB.WithContext(ctx).Model(&models.{{capitalize name}}{}).Count(&totalCount).Error; err != nil {
240
+ c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
241
+ return
242
+ }
243
+ c.Header("X-Total-Count", strconv.FormatInt(totalCount, 10))
244
+
235
245
  var entities []models.{{capitalize name}}
236
246
  if err := tenantDB.WithContext(ctx).Offset(page * size).Limit(size).Find(&entities).Error; err != nil {
237
247
  c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})