@famgia/omnify-laravel 0.0.11 → 0.0.13
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/{chunk-UEJWSSDU.js → chunk-G4UAJVC2.js} +46 -521
- package/dist/chunk-G4UAJVC2.js.map +1 -0
- package/dist/index.cjs +45 -540
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -197
- package/dist/index.d.ts +1 -197
- package/dist/index.js +1 -41
- package/dist/plugin.cjs +45 -486
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.d.cts +3 -24
- package/dist/plugin.d.ts +3 -24
- package/dist/plugin.js +1 -1
- package/package.json +5 -4
- package/dist/chunk-UEJWSSDU.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -20,45 +20,25 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
-
enumToUnionType: () => enumToUnionType,
|
|
24
|
-
extractInlineEnums: () => extractInlineEnums,
|
|
25
23
|
formatColumnMethod: () => formatColumnMethod,
|
|
26
|
-
formatEnum: () => formatEnum,
|
|
27
24
|
formatForeignKey: () => formatForeignKey,
|
|
28
25
|
formatIndex: () => formatIndex,
|
|
29
|
-
formatInterface: () => formatInterface,
|
|
30
26
|
formatMigrationFile: () => formatMigrationFile,
|
|
31
|
-
formatProperty: () => formatProperty,
|
|
32
|
-
formatTypeAlias: () => formatTypeAlias,
|
|
33
27
|
generateAlterMigration: () => generateAlterMigration,
|
|
34
28
|
generateDropMigrationForTable: () => generateDropMigrationForTable,
|
|
35
29
|
generateDropTableMigration: () => generateDropTableMigration,
|
|
36
|
-
generateEnums: () => generateEnums,
|
|
37
30
|
generateForeignKey: () => generateForeignKey,
|
|
38
|
-
generateInterfaces: () => generateInterfaces,
|
|
39
31
|
generateMigrationFromSchema: () => generateMigrationFromSchema,
|
|
40
32
|
generateMigrations: () => generateMigrations,
|
|
41
33
|
generateMigrationsFromChanges: () => generateMigrationsFromChanges,
|
|
42
34
|
generatePrimaryKeyColumn: () => generatePrimaryKeyColumn,
|
|
43
35
|
generateSoftDeleteColumn: () => generateSoftDeleteColumn,
|
|
44
36
|
generateTimestampColumns: () => generateTimestampColumns,
|
|
45
|
-
generateTypeScript: () => generateTypeScript,
|
|
46
|
-
generateTypeScriptFile: () => generateTypeScriptFile,
|
|
47
|
-
generateTypeScriptFiles: () => generateTypeScriptFiles,
|
|
48
37
|
getMigrationPath: () => getMigrationPath,
|
|
49
|
-
getPropertyType: () => getPropertyType,
|
|
50
|
-
getTypeScriptPath: () => getTypeScriptPath,
|
|
51
38
|
laravelPlugin: () => laravelPlugin,
|
|
52
39
|
propertyToColumnMethod: () => propertyToColumnMethod,
|
|
53
|
-
propertyToTSProperty: () => propertyToTSProperty,
|
|
54
40
|
schemaToBlueprint: () => schemaToBlueprint,
|
|
55
|
-
schemaToEnum: () => schemaToEnum,
|
|
56
|
-
schemaToInterface: () => schemaToInterface,
|
|
57
41
|
toColumnName: () => toColumnName,
|
|
58
|
-
toEnumMemberName: () => toEnumMemberName,
|
|
59
|
-
toEnumName: () => toEnumName,
|
|
60
|
-
toInterfaceName: () => toInterfaceName,
|
|
61
|
-
toPropertyName: () => toPropertyName,
|
|
62
42
|
toTableName: () => toTableName
|
|
63
43
|
});
|
|
64
44
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -79,11 +59,8 @@ var TYPE_METHOD_MAP = {
|
|
|
79
59
|
Json: "json",
|
|
80
60
|
Email: "string",
|
|
81
61
|
Password: "string",
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
Enum: "enum",
|
|
85
|
-
Select: "string",
|
|
86
|
-
Lookup: "unsignedBigInteger"
|
|
62
|
+
Enum: "enum"
|
|
63
|
+
// Note: File type is now polymorphic - no column generated, uses files table
|
|
87
64
|
};
|
|
88
65
|
var PK_METHOD_MAP = {
|
|
89
66
|
Int: "increments",
|
|
@@ -114,6 +91,9 @@ function propertyToColumnMethod(propertyName, property) {
|
|
|
114
91
|
if (property.type === "Association") {
|
|
115
92
|
return null;
|
|
116
93
|
}
|
|
94
|
+
if (property.type === "File") {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
117
97
|
const columnName = toColumnName(propertyName);
|
|
118
98
|
const method = TYPE_METHOD_MAP[property.type] ?? "string";
|
|
119
99
|
const args = [columnName];
|
|
@@ -1053,560 +1033,85 @@ function generateMigrationsFromChanges(changes, options = {}) {
|
|
|
1053
1033
|
return migrations;
|
|
1054
1034
|
}
|
|
1055
1035
|
|
|
1056
|
-
// src/
|
|
1057
|
-
var
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
Email: "string",
|
|
1070
|
-
Password: "string",
|
|
1071
|
-
File: "string",
|
|
1072
|
-
MultiFile: "string[]",
|
|
1073
|
-
Enum: "string",
|
|
1074
|
-
Select: "string",
|
|
1075
|
-
Lookup: "number"
|
|
1076
|
-
};
|
|
1077
|
-
var PK_TYPE_MAP = {
|
|
1078
|
-
Int: "number",
|
|
1079
|
-
BigInt: "number",
|
|
1080
|
-
Uuid: "string",
|
|
1081
|
-
String: "string"
|
|
1082
|
-
};
|
|
1083
|
-
function toPropertyName(name) {
|
|
1084
|
-
return name;
|
|
1085
|
-
}
|
|
1086
|
-
function toInterfaceName(schemaName) {
|
|
1087
|
-
return schemaName;
|
|
1088
|
-
}
|
|
1089
|
-
function getPropertyType(property, _allSchemas) {
|
|
1090
|
-
if (property.type === "Association") {
|
|
1091
|
-
const assocProp = property;
|
|
1092
|
-
const targetName = assocProp.target ?? "unknown";
|
|
1093
|
-
switch (assocProp.relation) {
|
|
1094
|
-
// Standard relations
|
|
1095
|
-
case "OneToOne":
|
|
1096
|
-
case "ManyToOne":
|
|
1097
|
-
return targetName;
|
|
1098
|
-
case "OneToMany":
|
|
1099
|
-
case "ManyToMany":
|
|
1100
|
-
return `${targetName}[]`;
|
|
1101
|
-
// Polymorphic relations
|
|
1102
|
-
case "MorphTo":
|
|
1103
|
-
if (assocProp.targets && assocProp.targets.length > 0) {
|
|
1104
|
-
return assocProp.targets.join(" | ");
|
|
1105
|
-
}
|
|
1106
|
-
return "unknown";
|
|
1107
|
-
case "MorphOne":
|
|
1108
|
-
return targetName;
|
|
1109
|
-
case "MorphMany":
|
|
1110
|
-
case "MorphToMany":
|
|
1111
|
-
case "MorphedByMany":
|
|
1112
|
-
return `${targetName}[]`;
|
|
1113
|
-
default:
|
|
1114
|
-
return "unknown";
|
|
1115
|
-
}
|
|
1116
|
-
}
|
|
1117
|
-
if (property.type === "Enum") {
|
|
1118
|
-
const enumProp = property;
|
|
1119
|
-
if (typeof enumProp.enum === "string") {
|
|
1120
|
-
return enumProp.enum;
|
|
1121
|
-
}
|
|
1122
|
-
if (Array.isArray(enumProp.enum)) {
|
|
1123
|
-
return enumProp.enum.map((v) => `'${v}'`).join(" | ");
|
|
1124
|
-
}
|
|
1125
|
-
}
|
|
1126
|
-
if (property.type === "Select") {
|
|
1127
|
-
const selectProp = property;
|
|
1128
|
-
if (selectProp.options && selectProp.options.length > 0) {
|
|
1129
|
-
return selectProp.options.map((v) => `'${v}'`).join(" | ");
|
|
1130
|
-
}
|
|
1131
|
-
}
|
|
1132
|
-
return TYPE_MAP[property.type] ?? "unknown";
|
|
1133
|
-
}
|
|
1134
|
-
function propertyToTSProperties(propertyName, property, allSchemas, options = {}) {
|
|
1135
|
-
const baseProp = property;
|
|
1136
|
-
const isReadonly = options.readonly ?? true;
|
|
1137
|
-
if (property.type === "Association") {
|
|
1138
|
-
const assocProp = property;
|
|
1139
|
-
if (assocProp.relation === "MorphTo" && assocProp.targets && assocProp.targets.length > 0) {
|
|
1140
|
-
const propBaseName = toPropertyName(propertyName);
|
|
1141
|
-
const targetUnion = assocProp.targets.map((t) => `'${t}'`).join(" | ");
|
|
1142
|
-
const relationUnion = assocProp.targets.join(" | ");
|
|
1143
|
-
return [
|
|
1144
|
-
{
|
|
1145
|
-
name: `${propBaseName}Type`,
|
|
1146
|
-
type: targetUnion,
|
|
1147
|
-
optional: true,
|
|
1148
|
-
// Polymorphic columns are nullable
|
|
1149
|
-
readonly: isReadonly,
|
|
1150
|
-
comment: `Polymorphic type for ${propertyName}`
|
|
1151
|
-
},
|
|
1152
|
-
{
|
|
1153
|
-
name: `${propBaseName}Id`,
|
|
1154
|
-
type: "number",
|
|
1155
|
-
optional: true,
|
|
1156
|
-
readonly: isReadonly,
|
|
1157
|
-
comment: `Polymorphic ID for ${propertyName}`
|
|
1158
|
-
},
|
|
1159
|
-
{
|
|
1160
|
-
name: propBaseName,
|
|
1161
|
-
type: `${relationUnion} | null`,
|
|
1162
|
-
optional: true,
|
|
1163
|
-
readonly: isReadonly,
|
|
1164
|
-
comment: baseProp.displayName ?? `Polymorphic relation to ${assocProp.targets.join(", ")}`
|
|
1165
|
-
}
|
|
1166
|
-
];
|
|
1167
|
-
}
|
|
1168
|
-
}
|
|
1169
|
-
const type = getPropertyType(property, allSchemas);
|
|
1170
|
-
return [{
|
|
1171
|
-
name: toPropertyName(propertyName),
|
|
1172
|
-
type,
|
|
1173
|
-
optional: baseProp.nullable ?? false,
|
|
1174
|
-
readonly: isReadonly,
|
|
1175
|
-
comment: baseProp.displayName
|
|
1176
|
-
}];
|
|
1177
|
-
}
|
|
1178
|
-
function propertyToTSProperty(propertyName, property, allSchemas, options = {}) {
|
|
1179
|
-
return propertyToTSProperties(propertyName, property, allSchemas, options)[0];
|
|
1180
|
-
}
|
|
1181
|
-
function schemaToInterface(schema, allSchemas, options = {}) {
|
|
1182
|
-
const properties = [];
|
|
1183
|
-
if (schema.options?.id !== false) {
|
|
1184
|
-
const pkType = schema.options?.idType ?? "BigInt";
|
|
1185
|
-
properties.push({
|
|
1186
|
-
name: "id",
|
|
1187
|
-
type: PK_TYPE_MAP[pkType] ?? "number",
|
|
1188
|
-
optional: false,
|
|
1189
|
-
readonly: options.readonly ?? true,
|
|
1190
|
-
comment: "Primary key"
|
|
1191
|
-
});
|
|
1192
|
-
}
|
|
1193
|
-
if (schema.properties) {
|
|
1194
|
-
for (const [propName, property] of Object.entries(schema.properties)) {
|
|
1195
|
-
properties.push(...propertyToTSProperties(propName, property, allSchemas, options));
|
|
1196
|
-
}
|
|
1197
|
-
}
|
|
1198
|
-
if (schema.options?.timestamps !== false) {
|
|
1199
|
-
properties.push(
|
|
1200
|
-
{
|
|
1201
|
-
name: "createdAt",
|
|
1202
|
-
type: "string",
|
|
1203
|
-
optional: true,
|
|
1204
|
-
readonly: options.readonly ?? true,
|
|
1205
|
-
comment: "Creation timestamp"
|
|
1206
|
-
},
|
|
1207
|
-
{
|
|
1208
|
-
name: "updatedAt",
|
|
1209
|
-
type: "string",
|
|
1210
|
-
optional: true,
|
|
1211
|
-
readonly: options.readonly ?? true,
|
|
1212
|
-
comment: "Last update timestamp"
|
|
1213
|
-
}
|
|
1214
|
-
);
|
|
1215
|
-
}
|
|
1216
|
-
if (schema.options?.softDelete) {
|
|
1217
|
-
properties.push({
|
|
1218
|
-
name: "deletedAt",
|
|
1036
|
+
// src/plugin.ts
|
|
1037
|
+
var LARAVEL_CONFIG_SCHEMA = {
|
|
1038
|
+
fields: [
|
|
1039
|
+
{
|
|
1040
|
+
key: "migrationsPath",
|
|
1041
|
+
type: "path",
|
|
1042
|
+
label: "Migrations Path",
|
|
1043
|
+
description: "Directory for Laravel migration files",
|
|
1044
|
+
default: "database/migrations",
|
|
1045
|
+
group: "output"
|
|
1046
|
+
},
|
|
1047
|
+
{
|
|
1048
|
+
key: "connection",
|
|
1219
1049
|
type: "string",
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
}
|
|
1225
|
-
return {
|
|
1226
|
-
name: toInterfaceName(schema.name),
|
|
1227
|
-
properties,
|
|
1228
|
-
comment: schema.displayName ?? schema.name
|
|
1229
|
-
};
|
|
1230
|
-
}
|
|
1231
|
-
function formatProperty(property) {
|
|
1232
|
-
const readonly = property.readonly ? "readonly " : "";
|
|
1233
|
-
const optional = property.optional ? "?" : "";
|
|
1234
|
-
const comment = property.comment ? ` /** ${property.comment} */
|
|
1235
|
-
` : "";
|
|
1236
|
-
return `${comment} ${readonly}${property.name}${optional}: ${property.type};`;
|
|
1237
|
-
}
|
|
1238
|
-
function formatInterface(iface) {
|
|
1239
|
-
const comment = iface.comment ? `/**
|
|
1240
|
-
* ${iface.comment}
|
|
1241
|
-
*/
|
|
1242
|
-
` : "";
|
|
1243
|
-
const extendsClause = iface.extends && iface.extends.length > 0 ? ` extends ${iface.extends.join(", ")}` : "";
|
|
1244
|
-
const properties = iface.properties.map(formatProperty).join("\n");
|
|
1245
|
-
return `${comment}export interface ${iface.name}${extendsClause} {
|
|
1246
|
-
${properties}
|
|
1247
|
-
}`;
|
|
1248
|
-
}
|
|
1249
|
-
function generateInterfaces(schemas, options = {}) {
|
|
1250
|
-
const interfaces = [];
|
|
1251
|
-
for (const schema of Object.values(schemas)) {
|
|
1252
|
-
if (schema.kind === "enum") {
|
|
1253
|
-
continue;
|
|
1254
|
-
}
|
|
1255
|
-
interfaces.push(schemaToInterface(schema, schemas, options));
|
|
1256
|
-
}
|
|
1257
|
-
return interfaces;
|
|
1258
|
-
}
|
|
1259
|
-
|
|
1260
|
-
// src/typescript/enum-generator.ts
|
|
1261
|
-
function toEnumMemberName(value) {
|
|
1262
|
-
return value.split(/[-_\s]+/).map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join("").replace(/[^a-zA-Z0-9]/g, "");
|
|
1263
|
-
}
|
|
1264
|
-
function toEnumName(schemaName) {
|
|
1265
|
-
return schemaName;
|
|
1266
|
-
}
|
|
1267
|
-
function schemaToEnum(schema) {
|
|
1268
|
-
if (schema.kind !== "enum" || !schema.values) {
|
|
1269
|
-
return null;
|
|
1270
|
-
}
|
|
1271
|
-
const values = schema.values.map((value) => ({
|
|
1272
|
-
name: toEnumMemberName(value),
|
|
1273
|
-
value
|
|
1274
|
-
}));
|
|
1275
|
-
return {
|
|
1276
|
-
name: toEnumName(schema.name),
|
|
1277
|
-
values,
|
|
1278
|
-
comment: schema.displayName ?? schema.name
|
|
1279
|
-
};
|
|
1280
|
-
}
|
|
1281
|
-
function generateEnums(schemas) {
|
|
1282
|
-
const enums = [];
|
|
1283
|
-
for (const schema of Object.values(schemas)) {
|
|
1284
|
-
if (schema.kind === "enum") {
|
|
1285
|
-
const enumDef = schemaToEnum(schema);
|
|
1286
|
-
if (enumDef) {
|
|
1287
|
-
enums.push(enumDef);
|
|
1288
|
-
}
|
|
1289
|
-
}
|
|
1290
|
-
}
|
|
1291
|
-
return enums;
|
|
1292
|
-
}
|
|
1293
|
-
function formatEnum(enumDef) {
|
|
1294
|
-
const comment = enumDef.comment ? `/**
|
|
1295
|
-
* ${enumDef.comment}
|
|
1296
|
-
*/
|
|
1297
|
-
` : "";
|
|
1298
|
-
const values = enumDef.values.map((v) => ` ${v.name} = '${v.value}',`).join("\n");
|
|
1299
|
-
return `${comment}export enum ${enumDef.name} {
|
|
1300
|
-
${values}
|
|
1301
|
-
}`;
|
|
1302
|
-
}
|
|
1303
|
-
function enumToUnionType(enumDef) {
|
|
1304
|
-
const type = enumDef.values.map((v) => `'${v.value}'`).join(" | ");
|
|
1305
|
-
return {
|
|
1306
|
-
name: enumDef.name,
|
|
1307
|
-
type,
|
|
1308
|
-
comment: enumDef.comment
|
|
1309
|
-
};
|
|
1310
|
-
}
|
|
1311
|
-
function formatTypeAlias(alias) {
|
|
1312
|
-
const comment = alias.comment ? `/**
|
|
1313
|
-
* ${alias.comment}
|
|
1314
|
-
*/
|
|
1315
|
-
` : "";
|
|
1316
|
-
return `${comment}export type ${alias.name} = ${alias.type};`;
|
|
1317
|
-
}
|
|
1318
|
-
function extractInlineEnums(schemas) {
|
|
1319
|
-
const typeAliases = [];
|
|
1320
|
-
for (const schema of Object.values(schemas)) {
|
|
1321
|
-
if (schema.kind === "enum" || !schema.properties) {
|
|
1322
|
-
continue;
|
|
1050
|
+
label: "Database Connection",
|
|
1051
|
+
description: "Laravel database connection name (optional)",
|
|
1052
|
+
placeholder: "mysql",
|
|
1053
|
+
group: "options"
|
|
1323
1054
|
}
|
|
1324
|
-
|
|
1325
|
-
if (property.type === "Enum") {
|
|
1326
|
-
const enumProp = property;
|
|
1327
|
-
if (Array.isArray(enumProp.enum) && enumProp.enum.length > 0) {
|
|
1328
|
-
const typeName = `${schema.name}${propName.charAt(0).toUpperCase() + propName.slice(1)}`;
|
|
1329
|
-
typeAliases.push({
|
|
1330
|
-
name: typeName,
|
|
1331
|
-
type: enumProp.enum.map((v) => `'${v}'`).join(" | "),
|
|
1332
|
-
comment: enumProp.displayName ?? `${schema.name} ${propName} enum`
|
|
1333
|
-
});
|
|
1334
|
-
}
|
|
1335
|
-
}
|
|
1336
|
-
if (property.type === "Select") {
|
|
1337
|
-
const selectProp = property;
|
|
1338
|
-
if (selectProp.options && selectProp.options.length > 0) {
|
|
1339
|
-
const typeName = `${schema.name}${propName.charAt(0).toUpperCase() + propName.slice(1)}`;
|
|
1340
|
-
typeAliases.push({
|
|
1341
|
-
name: typeName,
|
|
1342
|
-
type: selectProp.options.map((v) => `'${v}'`).join(" | "),
|
|
1343
|
-
comment: selectProp.displayName ?? `${schema.name} ${propName} options`
|
|
1344
|
-
});
|
|
1345
|
-
}
|
|
1346
|
-
}
|
|
1347
|
-
}
|
|
1348
|
-
}
|
|
1349
|
-
return typeAliases;
|
|
1350
|
-
}
|
|
1351
|
-
|
|
1352
|
-
// src/typescript/generator.ts
|
|
1353
|
-
var DEFAULT_OPTIONS = {
|
|
1354
|
-
singleFile: true,
|
|
1355
|
-
fileName: "types.ts",
|
|
1356
|
-
readonly: true,
|
|
1357
|
-
strictNullChecks: true
|
|
1055
|
+
]
|
|
1358
1056
|
};
|
|
1359
|
-
function generateHeader() {
|
|
1360
|
-
return `/**
|
|
1361
|
-
* Auto-generated TypeScript types from Omnify schemas.
|
|
1362
|
-
* DO NOT EDIT - This file is automatically generated.
|
|
1363
|
-
*/
|
|
1364
|
-
|
|
1365
|
-
`;
|
|
1366
|
-
}
|
|
1367
|
-
function generateTypeScriptFile(schemas, options = {}) {
|
|
1368
|
-
const opts = { ...DEFAULT_OPTIONS, ...options };
|
|
1369
|
-
const parts = [generateHeader()];
|
|
1370
|
-
const types = [];
|
|
1371
|
-
const enums = generateEnums(schemas);
|
|
1372
|
-
if (enums.length > 0) {
|
|
1373
|
-
parts.push("// Enums\n");
|
|
1374
|
-
for (const enumDef of enums) {
|
|
1375
|
-
parts.push(formatEnum(enumDef));
|
|
1376
|
-
parts.push("\n\n");
|
|
1377
|
-
types.push(enumDef.name);
|
|
1378
|
-
}
|
|
1379
|
-
}
|
|
1380
|
-
const inlineEnums = extractInlineEnums(schemas);
|
|
1381
|
-
if (inlineEnums.length > 0) {
|
|
1382
|
-
parts.push("// Type Aliases\n");
|
|
1383
|
-
for (const alias of inlineEnums) {
|
|
1384
|
-
parts.push(formatTypeAlias(alias));
|
|
1385
|
-
parts.push("\n\n");
|
|
1386
|
-
types.push(alias.name);
|
|
1387
|
-
}
|
|
1388
|
-
}
|
|
1389
|
-
const interfaces = generateInterfaces(schemas, opts);
|
|
1390
|
-
if (interfaces.length > 0) {
|
|
1391
|
-
parts.push("// Interfaces\n");
|
|
1392
|
-
for (const iface of interfaces) {
|
|
1393
|
-
parts.push(formatInterface(iface));
|
|
1394
|
-
parts.push("\n\n");
|
|
1395
|
-
types.push(iface.name);
|
|
1396
|
-
}
|
|
1397
|
-
}
|
|
1398
|
-
return {
|
|
1399
|
-
fileName: opts.fileName ?? "types.ts",
|
|
1400
|
-
content: parts.join("").trim() + "\n",
|
|
1401
|
-
types
|
|
1402
|
-
};
|
|
1403
|
-
}
|
|
1404
|
-
function generateTypeScriptFiles(schemas, options = {}) {
|
|
1405
|
-
const opts = { ...DEFAULT_OPTIONS, ...options };
|
|
1406
|
-
const files = [];
|
|
1407
|
-
const enums = generateEnums(schemas);
|
|
1408
|
-
if (enums.length > 0) {
|
|
1409
|
-
const content = generateHeader() + enums.map(formatEnum).join("\n\n") + "\n";
|
|
1410
|
-
files.push({
|
|
1411
|
-
fileName: "enums.ts",
|
|
1412
|
-
content,
|
|
1413
|
-
types: enums.map((e) => e.name)
|
|
1414
|
-
});
|
|
1415
|
-
}
|
|
1416
|
-
const inlineEnums = extractInlineEnums(schemas);
|
|
1417
|
-
if (inlineEnums.length > 0) {
|
|
1418
|
-
const content = generateHeader() + inlineEnums.map(formatTypeAlias).join("\n\n") + "\n";
|
|
1419
|
-
files.push({
|
|
1420
|
-
fileName: "type-aliases.ts",
|
|
1421
|
-
content,
|
|
1422
|
-
types: inlineEnums.map((a) => a.name)
|
|
1423
|
-
});
|
|
1424
|
-
}
|
|
1425
|
-
const interfaces = generateInterfaces(schemas, opts);
|
|
1426
|
-
for (const iface of interfaces) {
|
|
1427
|
-
const imports = collectImports(iface, enums, inlineEnums, interfaces);
|
|
1428
|
-
const importStatement = formatImports(imports);
|
|
1429
|
-
const content = generateHeader() + (importStatement ? importStatement + "\n\n" : "") + formatInterface(iface) + "\n";
|
|
1430
|
-
files.push({
|
|
1431
|
-
fileName: `${toKebabCase(iface.name)}.ts`,
|
|
1432
|
-
content,
|
|
1433
|
-
types: [iface.name]
|
|
1434
|
-
});
|
|
1435
|
-
}
|
|
1436
|
-
const indexContent = generateIndexFile(files);
|
|
1437
|
-
files.push({
|
|
1438
|
-
fileName: "index.ts",
|
|
1439
|
-
content: indexContent,
|
|
1440
|
-
types: []
|
|
1441
|
-
});
|
|
1442
|
-
return files;
|
|
1443
|
-
}
|
|
1444
|
-
function toKebabCase(name) {
|
|
1445
|
-
return name.replace(/([A-Z])/g, "-$1").toLowerCase().replace(/^-/, "");
|
|
1446
|
-
}
|
|
1447
|
-
function collectImports(iface, enums, typeAliases, allInterfaces) {
|
|
1448
|
-
const imports = /* @__PURE__ */ new Map();
|
|
1449
|
-
const enumNames = new Set(enums.map((e) => e.name));
|
|
1450
|
-
const aliasNames = new Set(typeAliases.map((a) => a.name));
|
|
1451
|
-
const interfaceNames = new Set(allInterfaces.map((i) => i.name));
|
|
1452
|
-
for (const prop of iface.properties) {
|
|
1453
|
-
if (enumNames.has(prop.type)) {
|
|
1454
|
-
const existing = imports.get("./enums.js") ?? [];
|
|
1455
|
-
if (!existing.includes(prop.type)) {
|
|
1456
|
-
imports.set("./enums.js", [...existing, prop.type]);
|
|
1457
|
-
}
|
|
1458
|
-
}
|
|
1459
|
-
if (aliasNames.has(prop.type)) {
|
|
1460
|
-
const existing = imports.get("./type-aliases.js") ?? [];
|
|
1461
|
-
if (!existing.includes(prop.type)) {
|
|
1462
|
-
imports.set("./type-aliases.js", [...existing, prop.type]);
|
|
1463
|
-
}
|
|
1464
|
-
}
|
|
1465
|
-
const baseType = prop.type.replace("[]", "");
|
|
1466
|
-
if (interfaceNames.has(baseType) && baseType !== iface.name) {
|
|
1467
|
-
const fileName = `./${toKebabCase(baseType)}.js`;
|
|
1468
|
-
const existing = imports.get(fileName) ?? [];
|
|
1469
|
-
if (!existing.includes(baseType)) {
|
|
1470
|
-
imports.set(fileName, [...existing, baseType]);
|
|
1471
|
-
}
|
|
1472
|
-
}
|
|
1473
|
-
}
|
|
1474
|
-
return imports;
|
|
1475
|
-
}
|
|
1476
|
-
function formatImports(imports) {
|
|
1477
|
-
if (imports.size === 0) return "";
|
|
1478
|
-
const lines = [];
|
|
1479
|
-
for (const [path, names] of imports) {
|
|
1480
|
-
lines.push(`import type { ${names.join(", ")} } from '${path}';`);
|
|
1481
|
-
}
|
|
1482
|
-
return lines.join("\n");
|
|
1483
|
-
}
|
|
1484
|
-
function generateIndexFile(files) {
|
|
1485
|
-
const exports2 = [generateHeader().trim(), ""];
|
|
1486
|
-
for (const file of files) {
|
|
1487
|
-
if (file.fileName === "index.ts") continue;
|
|
1488
|
-
const moduleName = file.fileName.replace(".ts", ".js");
|
|
1489
|
-
exports2.push(`export * from './${moduleName}';`);
|
|
1490
|
-
}
|
|
1491
|
-
return exports2.join("\n") + "\n";
|
|
1492
|
-
}
|
|
1493
|
-
function generateTypeScript(schemas, options = {}) {
|
|
1494
|
-
const opts = { ...DEFAULT_OPTIONS, ...options };
|
|
1495
|
-
if (opts.singleFile) {
|
|
1496
|
-
return [generateTypeScriptFile(schemas, opts)];
|
|
1497
|
-
}
|
|
1498
|
-
return generateTypeScriptFiles(schemas, opts);
|
|
1499
|
-
}
|
|
1500
|
-
function getTypeScriptPath(file, outputDir = "src/types") {
|
|
1501
|
-
return `${outputDir}/${file.fileName}`;
|
|
1502
|
-
}
|
|
1503
|
-
|
|
1504
|
-
// src/plugin.ts
|
|
1505
1057
|
function resolveOptions(options) {
|
|
1506
1058
|
return {
|
|
1507
1059
|
migrationsPath: options?.migrationsPath ?? "database/migrations",
|
|
1508
|
-
typesPath: options?.typesPath ?? "types",
|
|
1509
|
-
singleFile: options?.singleFile ?? true,
|
|
1510
1060
|
connection: options?.connection,
|
|
1511
|
-
timestamp: options?.timestamp
|
|
1512
|
-
generateTypes: options?.generateTypes ?? true,
|
|
1513
|
-
generateMigrations: options?.generateMigrations ?? true
|
|
1061
|
+
timestamp: options?.timestamp
|
|
1514
1062
|
};
|
|
1515
1063
|
}
|
|
1516
1064
|
function laravelPlugin(options) {
|
|
1517
1065
|
const resolved = resolveOptions(options);
|
|
1518
1066
|
return {
|
|
1519
1067
|
name: "@famgia/omnify-laravel",
|
|
1520
|
-
version: "0.0.
|
|
1068
|
+
version: "0.0.13",
|
|
1069
|
+
configSchema: LARAVEL_CONFIG_SCHEMA,
|
|
1521
1070
|
generators: [
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
}
|
|
1541
|
-
}));
|
|
1542
|
-
}
|
|
1543
|
-
}
|
|
1544
|
-
] : [],
|
|
1545
|
-
// TypeScript Types Generator
|
|
1546
|
-
...resolved.generateTypes ? [
|
|
1547
|
-
{
|
|
1548
|
-
name: "typescript-types",
|
|
1549
|
-
description: "Generate TypeScript type definitions",
|
|
1550
|
-
generate: async (ctx) => {
|
|
1551
|
-
const tsOptions = {
|
|
1552
|
-
singleFile: resolved.singleFile
|
|
1553
|
-
};
|
|
1554
|
-
const files = generateTypeScript(ctx.schemas, tsOptions);
|
|
1555
|
-
return files.map((file) => ({
|
|
1556
|
-
path: `${resolved.typesPath}/${file.fileName}`,
|
|
1557
|
-
content: file.content,
|
|
1558
|
-
type: "type",
|
|
1559
|
-
metadata: {
|
|
1560
|
-
types: file.types
|
|
1561
|
-
}
|
|
1562
|
-
}));
|
|
1563
|
-
}
|
|
1071
|
+
{
|
|
1072
|
+
name: "laravel-migrations",
|
|
1073
|
+
description: "Generate Laravel migration files",
|
|
1074
|
+
generate: async (ctx) => {
|
|
1075
|
+
const migrationOptions = {
|
|
1076
|
+
connection: resolved.connection,
|
|
1077
|
+
timestamp: resolved.timestamp
|
|
1078
|
+
};
|
|
1079
|
+
const migrations = generateMigrations(ctx.schemas, migrationOptions);
|
|
1080
|
+
return migrations.map((migration) => ({
|
|
1081
|
+
path: getMigrationPath(migration, resolved.migrationsPath),
|
|
1082
|
+
content: migration.content,
|
|
1083
|
+
type: "migration",
|
|
1084
|
+
metadata: {
|
|
1085
|
+
tableName: migration.tables[0],
|
|
1086
|
+
migrationType: migration.type
|
|
1087
|
+
}
|
|
1088
|
+
}));
|
|
1564
1089
|
}
|
|
1565
|
-
|
|
1090
|
+
}
|
|
1566
1091
|
]
|
|
1567
1092
|
};
|
|
1568
1093
|
}
|
|
1569
1094
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1570
1095
|
0 && (module.exports = {
|
|
1571
|
-
enumToUnionType,
|
|
1572
|
-
extractInlineEnums,
|
|
1573
1096
|
formatColumnMethod,
|
|
1574
|
-
formatEnum,
|
|
1575
1097
|
formatForeignKey,
|
|
1576
1098
|
formatIndex,
|
|
1577
|
-
formatInterface,
|
|
1578
1099
|
formatMigrationFile,
|
|
1579
|
-
formatProperty,
|
|
1580
|
-
formatTypeAlias,
|
|
1581
1100
|
generateAlterMigration,
|
|
1582
1101
|
generateDropMigrationForTable,
|
|
1583
1102
|
generateDropTableMigration,
|
|
1584
|
-
generateEnums,
|
|
1585
1103
|
generateForeignKey,
|
|
1586
|
-
generateInterfaces,
|
|
1587
1104
|
generateMigrationFromSchema,
|
|
1588
1105
|
generateMigrations,
|
|
1589
1106
|
generateMigrationsFromChanges,
|
|
1590
1107
|
generatePrimaryKeyColumn,
|
|
1591
1108
|
generateSoftDeleteColumn,
|
|
1592
1109
|
generateTimestampColumns,
|
|
1593
|
-
generateTypeScript,
|
|
1594
|
-
generateTypeScriptFile,
|
|
1595
|
-
generateTypeScriptFiles,
|
|
1596
1110
|
getMigrationPath,
|
|
1597
|
-
getPropertyType,
|
|
1598
|
-
getTypeScriptPath,
|
|
1599
1111
|
laravelPlugin,
|
|
1600
1112
|
propertyToColumnMethod,
|
|
1601
|
-
propertyToTSProperty,
|
|
1602
1113
|
schemaToBlueprint,
|
|
1603
|
-
schemaToEnum,
|
|
1604
|
-
schemaToInterface,
|
|
1605
1114
|
toColumnName,
|
|
1606
|
-
toEnumMemberName,
|
|
1607
|
-
toEnumName,
|
|
1608
|
-
toInterfaceName,
|
|
1609
|
-
toPropertyName,
|
|
1610
1115
|
toTableName
|
|
1611
1116
|
});
|
|
1612
1117
|
//# sourceMappingURL=index.cjs.map
|