mutano 3.7.3 → 3.7.5

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 (2) hide show
  1. package/dist/main.js +32 -3
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -1152,12 +1152,33 @@ function parseViewColumns(sqlContent, startPos, tableDefinitions) {
1152
1152
  "user_relationship_": ["rise_entities", "user_rel"],
1153
1153
  "user_entity_": ["rise_entities", "user_entity"]
1154
1154
  };
1155
- for (const expr of columnExprs) {
1155
+ for (let i = 0; i < columnExprs.length; i++) {
1156
+ let expr = columnExprs[i];
1156
1157
  if (!expr) continue;
1157
- const aliasMatch = expr.match(/\s+AS\s+[`"]?([^`"\s,]+)[`"]?\s*$/i);
1158
+ let inlineComment = "";
1159
+ const endCommentMatch = expr.match(/--\s*(.+)$/);
1160
+ if (endCommentMatch) {
1161
+ inlineComment = endCommentMatch[1].trim();
1162
+ expr = expr.replace(/--\s*.+$/, "").trim();
1163
+ }
1164
+ const startCommentMatch = expr.match(/^--\s*(.+?)\n/);
1165
+ if (startCommentMatch && !inlineComment) {
1166
+ inlineComment = startCommentMatch[1].trim();
1167
+ expr = expr.replace(/^--\s*.+?\n/, "").trim();
1168
+ }
1169
+ const nextExpr = columnExprs[i + 1];
1170
+ if (nextExpr && !inlineComment) {
1171
+ const nextStartCommentMatch = nextExpr.match(/^--\s*(.+?)(?:\n|$)/);
1172
+ if (nextStartCommentMatch) {
1173
+ inlineComment = nextStartCommentMatch[1].trim();
1174
+ columnExprs[i + 1] = nextExpr.replace(/^--\s*.+?(?:\n|$)/, "").trim();
1175
+ }
1176
+ }
1177
+ const aliasMatch = expr.match(/\s+AS\s+[`"]?([^`"\s,]+)[`"]?\s*(?:--.*)?$/i);
1158
1178
  if (aliasMatch) {
1159
1179
  const name = aliasMatch[1];
1160
- const sourceRefMatch = expr.match(/^(?:[`"]?([\w_]+)[`"]?\.)?[`"]?([\w_]+)[`"]?\s+AS/i);
1180
+ const exprWithoutComment = expr.replace(/--.*$/, "");
1181
+ const sourceRefMatch = exprWithoutComment.match(/^(?:[`"]?([\w_]+)[`"]?\.)?[`"]?([\w_]+)[`"]?\s+AS/i);
1161
1182
  const sourceTable = sourceRefMatch?.[1];
1162
1183
  const sourceCol = sourceRefMatch?.[2];
1163
1184
  let type = "varchar(191)";
@@ -1224,6 +1245,9 @@ function parseViewColumns(sqlContent, startPos, tableDefinitions) {
1224
1245
  }
1225
1246
  }
1226
1247
  let comment = sourceColumnComment;
1248
+ if (inlineComment) {
1249
+ comment = inlineComment;
1250
+ }
1227
1251
  columns.push({
1228
1252
  name,
1229
1253
  type,
@@ -1327,6 +1351,11 @@ function parseColumns(columnSection) {
1327
1351
  if (commentMatch) {
1328
1352
  comment = commentMatch[1].replace(/\\'/g, "'");
1329
1353
  }
1354
+ if (type.match(/^(enum|set)\s*\(/i) && comment.match(/@(kysely|ts|zod)\s*\(/)) {
1355
+ throw new Error(
1356
+ `Magic comments are not supported on enum/set columns. Column "${name}" has type "${type}" with comment "${comment}". Remove the magic comment - enum types are automatically generated by mutano.`
1357
+ );
1358
+ }
1330
1359
  columns.push({
1331
1360
  name,
1332
1361
  type,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mutano",
3
3
  "type": "module",
4
- "version": "3.7.3",
4
+ "version": "3.7.5",
5
5
  "description": "Converts Prisma/MySQL/PostgreSQL/SQLite schemas to Zod/TS/Kysely interfaces",
6
6
  "author": "Alisson Cavalcante Agiani <thelinuxlich@gmail.com>",
7
7
  "license": "MIT",