@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
|
@@ -14,11 +14,8 @@ var TYPE_METHOD_MAP = {
|
|
|
14
14
|
Json: "json",
|
|
15
15
|
Email: "string",
|
|
16
16
|
Password: "string",
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
Enum: "enum",
|
|
20
|
-
Select: "string",
|
|
21
|
-
Lookup: "unsignedBigInteger"
|
|
17
|
+
Enum: "enum"
|
|
18
|
+
// Note: File type is now polymorphic - no column generated, uses files table
|
|
22
19
|
};
|
|
23
20
|
var PK_METHOD_MAP = {
|
|
24
21
|
Int: "increments",
|
|
@@ -49,6 +46,9 @@ function propertyToColumnMethod(propertyName, property) {
|
|
|
49
46
|
if (property.type === "Association") {
|
|
50
47
|
return null;
|
|
51
48
|
}
|
|
49
|
+
if (property.type === "File") {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
52
|
const columnName = toColumnName(propertyName);
|
|
53
53
|
const method = TYPE_METHOD_MAP[property.type] ?? "string";
|
|
54
54
|
const args = [columnName];
|
|
@@ -988,516 +988,61 @@ function generateMigrationsFromChanges(changes, options = {}) {
|
|
|
988
988
|
return migrations;
|
|
989
989
|
}
|
|
990
990
|
|
|
991
|
-
// src/
|
|
992
|
-
var
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
Email: "string",
|
|
1005
|
-
Password: "string",
|
|
1006
|
-
File: "string",
|
|
1007
|
-
MultiFile: "string[]",
|
|
1008
|
-
Enum: "string",
|
|
1009
|
-
Select: "string",
|
|
1010
|
-
Lookup: "number"
|
|
1011
|
-
};
|
|
1012
|
-
var PK_TYPE_MAP = {
|
|
1013
|
-
Int: "number",
|
|
1014
|
-
BigInt: "number",
|
|
1015
|
-
Uuid: "string",
|
|
1016
|
-
String: "string"
|
|
1017
|
-
};
|
|
1018
|
-
function toPropertyName(name) {
|
|
1019
|
-
return name;
|
|
1020
|
-
}
|
|
1021
|
-
function toInterfaceName(schemaName) {
|
|
1022
|
-
return schemaName;
|
|
1023
|
-
}
|
|
1024
|
-
function getPropertyType(property, _allSchemas) {
|
|
1025
|
-
if (property.type === "Association") {
|
|
1026
|
-
const assocProp = property;
|
|
1027
|
-
const targetName = assocProp.target ?? "unknown";
|
|
1028
|
-
switch (assocProp.relation) {
|
|
1029
|
-
// Standard relations
|
|
1030
|
-
case "OneToOne":
|
|
1031
|
-
case "ManyToOne":
|
|
1032
|
-
return targetName;
|
|
1033
|
-
case "OneToMany":
|
|
1034
|
-
case "ManyToMany":
|
|
1035
|
-
return `${targetName}[]`;
|
|
1036
|
-
// Polymorphic relations
|
|
1037
|
-
case "MorphTo":
|
|
1038
|
-
if (assocProp.targets && assocProp.targets.length > 0) {
|
|
1039
|
-
return assocProp.targets.join(" | ");
|
|
1040
|
-
}
|
|
1041
|
-
return "unknown";
|
|
1042
|
-
case "MorphOne":
|
|
1043
|
-
return targetName;
|
|
1044
|
-
case "MorphMany":
|
|
1045
|
-
case "MorphToMany":
|
|
1046
|
-
case "MorphedByMany":
|
|
1047
|
-
return `${targetName}[]`;
|
|
1048
|
-
default:
|
|
1049
|
-
return "unknown";
|
|
1050
|
-
}
|
|
1051
|
-
}
|
|
1052
|
-
if (property.type === "Enum") {
|
|
1053
|
-
const enumProp = property;
|
|
1054
|
-
if (typeof enumProp.enum === "string") {
|
|
1055
|
-
return enumProp.enum;
|
|
1056
|
-
}
|
|
1057
|
-
if (Array.isArray(enumProp.enum)) {
|
|
1058
|
-
return enumProp.enum.map((v) => `'${v}'`).join(" | ");
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
if (property.type === "Select") {
|
|
1062
|
-
const selectProp = property;
|
|
1063
|
-
if (selectProp.options && selectProp.options.length > 0) {
|
|
1064
|
-
return selectProp.options.map((v) => `'${v}'`).join(" | ");
|
|
1065
|
-
}
|
|
1066
|
-
}
|
|
1067
|
-
return TYPE_MAP[property.type] ?? "unknown";
|
|
1068
|
-
}
|
|
1069
|
-
function propertyToTSProperties(propertyName, property, allSchemas, options = {}) {
|
|
1070
|
-
const baseProp = property;
|
|
1071
|
-
const isReadonly = options.readonly ?? true;
|
|
1072
|
-
if (property.type === "Association") {
|
|
1073
|
-
const assocProp = property;
|
|
1074
|
-
if (assocProp.relation === "MorphTo" && assocProp.targets && assocProp.targets.length > 0) {
|
|
1075
|
-
const propBaseName = toPropertyName(propertyName);
|
|
1076
|
-
const targetUnion = assocProp.targets.map((t) => `'${t}'`).join(" | ");
|
|
1077
|
-
const relationUnion = assocProp.targets.join(" | ");
|
|
1078
|
-
return [
|
|
1079
|
-
{
|
|
1080
|
-
name: `${propBaseName}Type`,
|
|
1081
|
-
type: targetUnion,
|
|
1082
|
-
optional: true,
|
|
1083
|
-
// Polymorphic columns are nullable
|
|
1084
|
-
readonly: isReadonly,
|
|
1085
|
-
comment: `Polymorphic type for ${propertyName}`
|
|
1086
|
-
},
|
|
1087
|
-
{
|
|
1088
|
-
name: `${propBaseName}Id`,
|
|
1089
|
-
type: "number",
|
|
1090
|
-
optional: true,
|
|
1091
|
-
readonly: isReadonly,
|
|
1092
|
-
comment: `Polymorphic ID for ${propertyName}`
|
|
1093
|
-
},
|
|
1094
|
-
{
|
|
1095
|
-
name: propBaseName,
|
|
1096
|
-
type: `${relationUnion} | null`,
|
|
1097
|
-
optional: true,
|
|
1098
|
-
readonly: isReadonly,
|
|
1099
|
-
comment: baseProp.displayName ?? `Polymorphic relation to ${assocProp.targets.join(", ")}`
|
|
1100
|
-
}
|
|
1101
|
-
];
|
|
1102
|
-
}
|
|
1103
|
-
}
|
|
1104
|
-
const type = getPropertyType(property, allSchemas);
|
|
1105
|
-
return [{
|
|
1106
|
-
name: toPropertyName(propertyName),
|
|
1107
|
-
type,
|
|
1108
|
-
optional: baseProp.nullable ?? false,
|
|
1109
|
-
readonly: isReadonly,
|
|
1110
|
-
comment: baseProp.displayName
|
|
1111
|
-
}];
|
|
1112
|
-
}
|
|
1113
|
-
function propertyToTSProperty(propertyName, property, allSchemas, options = {}) {
|
|
1114
|
-
return propertyToTSProperties(propertyName, property, allSchemas, options)[0];
|
|
1115
|
-
}
|
|
1116
|
-
function schemaToInterface(schema, allSchemas, options = {}) {
|
|
1117
|
-
const properties = [];
|
|
1118
|
-
if (schema.options?.id !== false) {
|
|
1119
|
-
const pkType = schema.options?.idType ?? "BigInt";
|
|
1120
|
-
properties.push({
|
|
1121
|
-
name: "id",
|
|
1122
|
-
type: PK_TYPE_MAP[pkType] ?? "number",
|
|
1123
|
-
optional: false,
|
|
1124
|
-
readonly: options.readonly ?? true,
|
|
1125
|
-
comment: "Primary key"
|
|
1126
|
-
});
|
|
1127
|
-
}
|
|
1128
|
-
if (schema.properties) {
|
|
1129
|
-
for (const [propName, property] of Object.entries(schema.properties)) {
|
|
1130
|
-
properties.push(...propertyToTSProperties(propName, property, allSchemas, options));
|
|
1131
|
-
}
|
|
1132
|
-
}
|
|
1133
|
-
if (schema.options?.timestamps !== false) {
|
|
1134
|
-
properties.push(
|
|
1135
|
-
{
|
|
1136
|
-
name: "createdAt",
|
|
1137
|
-
type: "string",
|
|
1138
|
-
optional: true,
|
|
1139
|
-
readonly: options.readonly ?? true,
|
|
1140
|
-
comment: "Creation timestamp"
|
|
1141
|
-
},
|
|
1142
|
-
{
|
|
1143
|
-
name: "updatedAt",
|
|
1144
|
-
type: "string",
|
|
1145
|
-
optional: true,
|
|
1146
|
-
readonly: options.readonly ?? true,
|
|
1147
|
-
comment: "Last update timestamp"
|
|
1148
|
-
}
|
|
1149
|
-
);
|
|
1150
|
-
}
|
|
1151
|
-
if (schema.options?.softDelete) {
|
|
1152
|
-
properties.push({
|
|
1153
|
-
name: "deletedAt",
|
|
991
|
+
// src/plugin.ts
|
|
992
|
+
var LARAVEL_CONFIG_SCHEMA = {
|
|
993
|
+
fields: [
|
|
994
|
+
{
|
|
995
|
+
key: "migrationsPath",
|
|
996
|
+
type: "path",
|
|
997
|
+
label: "Migrations Path",
|
|
998
|
+
description: "Directory for Laravel migration files",
|
|
999
|
+
default: "database/migrations",
|
|
1000
|
+
group: "output"
|
|
1001
|
+
},
|
|
1002
|
+
{
|
|
1003
|
+
key: "connection",
|
|
1154
1004
|
type: "string",
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
}
|
|
1160
|
-
return {
|
|
1161
|
-
name: toInterfaceName(schema.name),
|
|
1162
|
-
properties,
|
|
1163
|
-
comment: schema.displayName ?? schema.name
|
|
1164
|
-
};
|
|
1165
|
-
}
|
|
1166
|
-
function formatProperty(property) {
|
|
1167
|
-
const readonly = property.readonly ? "readonly " : "";
|
|
1168
|
-
const optional = property.optional ? "?" : "";
|
|
1169
|
-
const comment = property.comment ? ` /** ${property.comment} */
|
|
1170
|
-
` : "";
|
|
1171
|
-
return `${comment} ${readonly}${property.name}${optional}: ${property.type};`;
|
|
1172
|
-
}
|
|
1173
|
-
function formatInterface(iface) {
|
|
1174
|
-
const comment = iface.comment ? `/**
|
|
1175
|
-
* ${iface.comment}
|
|
1176
|
-
*/
|
|
1177
|
-
` : "";
|
|
1178
|
-
const extendsClause = iface.extends && iface.extends.length > 0 ? ` extends ${iface.extends.join(", ")}` : "";
|
|
1179
|
-
const properties = iface.properties.map(formatProperty).join("\n");
|
|
1180
|
-
return `${comment}export interface ${iface.name}${extendsClause} {
|
|
1181
|
-
${properties}
|
|
1182
|
-
}`;
|
|
1183
|
-
}
|
|
1184
|
-
function generateInterfaces(schemas, options = {}) {
|
|
1185
|
-
const interfaces = [];
|
|
1186
|
-
for (const schema of Object.values(schemas)) {
|
|
1187
|
-
if (schema.kind === "enum") {
|
|
1188
|
-
continue;
|
|
1189
|
-
}
|
|
1190
|
-
interfaces.push(schemaToInterface(schema, schemas, options));
|
|
1191
|
-
}
|
|
1192
|
-
return interfaces;
|
|
1193
|
-
}
|
|
1194
|
-
|
|
1195
|
-
// src/typescript/enum-generator.ts
|
|
1196
|
-
function toEnumMemberName(value) {
|
|
1197
|
-
return value.split(/[-_\s]+/).map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join("").replace(/[^a-zA-Z0-9]/g, "");
|
|
1198
|
-
}
|
|
1199
|
-
function toEnumName(schemaName) {
|
|
1200
|
-
return schemaName;
|
|
1201
|
-
}
|
|
1202
|
-
function schemaToEnum(schema) {
|
|
1203
|
-
if (schema.kind !== "enum" || !schema.values) {
|
|
1204
|
-
return null;
|
|
1205
|
-
}
|
|
1206
|
-
const values = schema.values.map((value) => ({
|
|
1207
|
-
name: toEnumMemberName(value),
|
|
1208
|
-
value
|
|
1209
|
-
}));
|
|
1210
|
-
return {
|
|
1211
|
-
name: toEnumName(schema.name),
|
|
1212
|
-
values,
|
|
1213
|
-
comment: schema.displayName ?? schema.name
|
|
1214
|
-
};
|
|
1215
|
-
}
|
|
1216
|
-
function generateEnums(schemas) {
|
|
1217
|
-
const enums = [];
|
|
1218
|
-
for (const schema of Object.values(schemas)) {
|
|
1219
|
-
if (schema.kind === "enum") {
|
|
1220
|
-
const enumDef = schemaToEnum(schema);
|
|
1221
|
-
if (enumDef) {
|
|
1222
|
-
enums.push(enumDef);
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
}
|
|
1226
|
-
return enums;
|
|
1227
|
-
}
|
|
1228
|
-
function formatEnum(enumDef) {
|
|
1229
|
-
const comment = enumDef.comment ? `/**
|
|
1230
|
-
* ${enumDef.comment}
|
|
1231
|
-
*/
|
|
1232
|
-
` : "";
|
|
1233
|
-
const values = enumDef.values.map((v) => ` ${v.name} = '${v.value}',`).join("\n");
|
|
1234
|
-
return `${comment}export enum ${enumDef.name} {
|
|
1235
|
-
${values}
|
|
1236
|
-
}`;
|
|
1237
|
-
}
|
|
1238
|
-
function enumToUnionType(enumDef) {
|
|
1239
|
-
const type = enumDef.values.map((v) => `'${v.value}'`).join(" | ");
|
|
1240
|
-
return {
|
|
1241
|
-
name: enumDef.name,
|
|
1242
|
-
type,
|
|
1243
|
-
comment: enumDef.comment
|
|
1244
|
-
};
|
|
1245
|
-
}
|
|
1246
|
-
function formatTypeAlias(alias) {
|
|
1247
|
-
const comment = alias.comment ? `/**
|
|
1248
|
-
* ${alias.comment}
|
|
1249
|
-
*/
|
|
1250
|
-
` : "";
|
|
1251
|
-
return `${comment}export type ${alias.name} = ${alias.type};`;
|
|
1252
|
-
}
|
|
1253
|
-
function extractInlineEnums(schemas) {
|
|
1254
|
-
const typeAliases = [];
|
|
1255
|
-
for (const schema of Object.values(schemas)) {
|
|
1256
|
-
if (schema.kind === "enum" || !schema.properties) {
|
|
1257
|
-
continue;
|
|
1005
|
+
label: "Database Connection",
|
|
1006
|
+
description: "Laravel database connection name (optional)",
|
|
1007
|
+
placeholder: "mysql",
|
|
1008
|
+
group: "options"
|
|
1258
1009
|
}
|
|
1259
|
-
|
|
1260
|
-
if (property.type === "Enum") {
|
|
1261
|
-
const enumProp = property;
|
|
1262
|
-
if (Array.isArray(enumProp.enum) && enumProp.enum.length > 0) {
|
|
1263
|
-
const typeName = `${schema.name}${propName.charAt(0).toUpperCase() + propName.slice(1)}`;
|
|
1264
|
-
typeAliases.push({
|
|
1265
|
-
name: typeName,
|
|
1266
|
-
type: enumProp.enum.map((v) => `'${v}'`).join(" | "),
|
|
1267
|
-
comment: enumProp.displayName ?? `${schema.name} ${propName} enum`
|
|
1268
|
-
});
|
|
1269
|
-
}
|
|
1270
|
-
}
|
|
1271
|
-
if (property.type === "Select") {
|
|
1272
|
-
const selectProp = property;
|
|
1273
|
-
if (selectProp.options && selectProp.options.length > 0) {
|
|
1274
|
-
const typeName = `${schema.name}${propName.charAt(0).toUpperCase() + propName.slice(1)}`;
|
|
1275
|
-
typeAliases.push({
|
|
1276
|
-
name: typeName,
|
|
1277
|
-
type: selectProp.options.map((v) => `'${v}'`).join(" | "),
|
|
1278
|
-
comment: selectProp.displayName ?? `${schema.name} ${propName} options`
|
|
1279
|
-
});
|
|
1280
|
-
}
|
|
1281
|
-
}
|
|
1282
|
-
}
|
|
1283
|
-
}
|
|
1284
|
-
return typeAliases;
|
|
1285
|
-
}
|
|
1286
|
-
|
|
1287
|
-
// src/typescript/generator.ts
|
|
1288
|
-
var DEFAULT_OPTIONS = {
|
|
1289
|
-
singleFile: true,
|
|
1290
|
-
fileName: "types.ts",
|
|
1291
|
-
readonly: true,
|
|
1292
|
-
strictNullChecks: true
|
|
1010
|
+
]
|
|
1293
1011
|
};
|
|
1294
|
-
function generateHeader() {
|
|
1295
|
-
return `/**
|
|
1296
|
-
* Auto-generated TypeScript types from Omnify schemas.
|
|
1297
|
-
* DO NOT EDIT - This file is automatically generated.
|
|
1298
|
-
*/
|
|
1299
|
-
|
|
1300
|
-
`;
|
|
1301
|
-
}
|
|
1302
|
-
function generateTypeScriptFile(schemas, options = {}) {
|
|
1303
|
-
const opts = { ...DEFAULT_OPTIONS, ...options };
|
|
1304
|
-
const parts = [generateHeader()];
|
|
1305
|
-
const types = [];
|
|
1306
|
-
const enums = generateEnums(schemas);
|
|
1307
|
-
if (enums.length > 0) {
|
|
1308
|
-
parts.push("// Enums\n");
|
|
1309
|
-
for (const enumDef of enums) {
|
|
1310
|
-
parts.push(formatEnum(enumDef));
|
|
1311
|
-
parts.push("\n\n");
|
|
1312
|
-
types.push(enumDef.name);
|
|
1313
|
-
}
|
|
1314
|
-
}
|
|
1315
|
-
const inlineEnums = extractInlineEnums(schemas);
|
|
1316
|
-
if (inlineEnums.length > 0) {
|
|
1317
|
-
parts.push("// Type Aliases\n");
|
|
1318
|
-
for (const alias of inlineEnums) {
|
|
1319
|
-
parts.push(formatTypeAlias(alias));
|
|
1320
|
-
parts.push("\n\n");
|
|
1321
|
-
types.push(alias.name);
|
|
1322
|
-
}
|
|
1323
|
-
}
|
|
1324
|
-
const interfaces = generateInterfaces(schemas, opts);
|
|
1325
|
-
if (interfaces.length > 0) {
|
|
1326
|
-
parts.push("// Interfaces\n");
|
|
1327
|
-
for (const iface of interfaces) {
|
|
1328
|
-
parts.push(formatInterface(iface));
|
|
1329
|
-
parts.push("\n\n");
|
|
1330
|
-
types.push(iface.name);
|
|
1331
|
-
}
|
|
1332
|
-
}
|
|
1333
|
-
return {
|
|
1334
|
-
fileName: opts.fileName ?? "types.ts",
|
|
1335
|
-
content: parts.join("").trim() + "\n",
|
|
1336
|
-
types
|
|
1337
|
-
};
|
|
1338
|
-
}
|
|
1339
|
-
function generateTypeScriptFiles(schemas, options = {}) {
|
|
1340
|
-
const opts = { ...DEFAULT_OPTIONS, ...options };
|
|
1341
|
-
const files = [];
|
|
1342
|
-
const enums = generateEnums(schemas);
|
|
1343
|
-
if (enums.length > 0) {
|
|
1344
|
-
const content = generateHeader() + enums.map(formatEnum).join("\n\n") + "\n";
|
|
1345
|
-
files.push({
|
|
1346
|
-
fileName: "enums.ts",
|
|
1347
|
-
content,
|
|
1348
|
-
types: enums.map((e) => e.name)
|
|
1349
|
-
});
|
|
1350
|
-
}
|
|
1351
|
-
const inlineEnums = extractInlineEnums(schemas);
|
|
1352
|
-
if (inlineEnums.length > 0) {
|
|
1353
|
-
const content = generateHeader() + inlineEnums.map(formatTypeAlias).join("\n\n") + "\n";
|
|
1354
|
-
files.push({
|
|
1355
|
-
fileName: "type-aliases.ts",
|
|
1356
|
-
content,
|
|
1357
|
-
types: inlineEnums.map((a) => a.name)
|
|
1358
|
-
});
|
|
1359
|
-
}
|
|
1360
|
-
const interfaces = generateInterfaces(schemas, opts);
|
|
1361
|
-
for (const iface of interfaces) {
|
|
1362
|
-
const imports = collectImports(iface, enums, inlineEnums, interfaces);
|
|
1363
|
-
const importStatement = formatImports(imports);
|
|
1364
|
-
const content = generateHeader() + (importStatement ? importStatement + "\n\n" : "") + formatInterface(iface) + "\n";
|
|
1365
|
-
files.push({
|
|
1366
|
-
fileName: `${toKebabCase(iface.name)}.ts`,
|
|
1367
|
-
content,
|
|
1368
|
-
types: [iface.name]
|
|
1369
|
-
});
|
|
1370
|
-
}
|
|
1371
|
-
const indexContent = generateIndexFile(files);
|
|
1372
|
-
files.push({
|
|
1373
|
-
fileName: "index.ts",
|
|
1374
|
-
content: indexContent,
|
|
1375
|
-
types: []
|
|
1376
|
-
});
|
|
1377
|
-
return files;
|
|
1378
|
-
}
|
|
1379
|
-
function toKebabCase(name) {
|
|
1380
|
-
return name.replace(/([A-Z])/g, "-$1").toLowerCase().replace(/^-/, "");
|
|
1381
|
-
}
|
|
1382
|
-
function collectImports(iface, enums, typeAliases, allInterfaces) {
|
|
1383
|
-
const imports = /* @__PURE__ */ new Map();
|
|
1384
|
-
const enumNames = new Set(enums.map((e) => e.name));
|
|
1385
|
-
const aliasNames = new Set(typeAliases.map((a) => a.name));
|
|
1386
|
-
const interfaceNames = new Set(allInterfaces.map((i) => i.name));
|
|
1387
|
-
for (const prop of iface.properties) {
|
|
1388
|
-
if (enumNames.has(prop.type)) {
|
|
1389
|
-
const existing = imports.get("./enums.js") ?? [];
|
|
1390
|
-
if (!existing.includes(prop.type)) {
|
|
1391
|
-
imports.set("./enums.js", [...existing, prop.type]);
|
|
1392
|
-
}
|
|
1393
|
-
}
|
|
1394
|
-
if (aliasNames.has(prop.type)) {
|
|
1395
|
-
const existing = imports.get("./type-aliases.js") ?? [];
|
|
1396
|
-
if (!existing.includes(prop.type)) {
|
|
1397
|
-
imports.set("./type-aliases.js", [...existing, prop.type]);
|
|
1398
|
-
}
|
|
1399
|
-
}
|
|
1400
|
-
const baseType = prop.type.replace("[]", "");
|
|
1401
|
-
if (interfaceNames.has(baseType) && baseType !== iface.name) {
|
|
1402
|
-
const fileName = `./${toKebabCase(baseType)}.js`;
|
|
1403
|
-
const existing = imports.get(fileName) ?? [];
|
|
1404
|
-
if (!existing.includes(baseType)) {
|
|
1405
|
-
imports.set(fileName, [...existing, baseType]);
|
|
1406
|
-
}
|
|
1407
|
-
}
|
|
1408
|
-
}
|
|
1409
|
-
return imports;
|
|
1410
|
-
}
|
|
1411
|
-
function formatImports(imports) {
|
|
1412
|
-
if (imports.size === 0) return "";
|
|
1413
|
-
const lines = [];
|
|
1414
|
-
for (const [path, names] of imports) {
|
|
1415
|
-
lines.push(`import type { ${names.join(", ")} } from '${path}';`);
|
|
1416
|
-
}
|
|
1417
|
-
return lines.join("\n");
|
|
1418
|
-
}
|
|
1419
|
-
function generateIndexFile(files) {
|
|
1420
|
-
const exports = [generateHeader().trim(), ""];
|
|
1421
|
-
for (const file of files) {
|
|
1422
|
-
if (file.fileName === "index.ts") continue;
|
|
1423
|
-
const moduleName = file.fileName.replace(".ts", ".js");
|
|
1424
|
-
exports.push(`export * from './${moduleName}';`);
|
|
1425
|
-
}
|
|
1426
|
-
return exports.join("\n") + "\n";
|
|
1427
|
-
}
|
|
1428
|
-
function generateTypeScript(schemas, options = {}) {
|
|
1429
|
-
const opts = { ...DEFAULT_OPTIONS, ...options };
|
|
1430
|
-
if (opts.singleFile) {
|
|
1431
|
-
return [generateTypeScriptFile(schemas, opts)];
|
|
1432
|
-
}
|
|
1433
|
-
return generateTypeScriptFiles(schemas, opts);
|
|
1434
|
-
}
|
|
1435
|
-
function getTypeScriptPath(file, outputDir = "src/types") {
|
|
1436
|
-
return `${outputDir}/${file.fileName}`;
|
|
1437
|
-
}
|
|
1438
|
-
|
|
1439
|
-
// src/plugin.ts
|
|
1440
1012
|
function resolveOptions(options) {
|
|
1441
1013
|
return {
|
|
1442
1014
|
migrationsPath: options?.migrationsPath ?? "database/migrations",
|
|
1443
|
-
typesPath: options?.typesPath ?? "types",
|
|
1444
|
-
singleFile: options?.singleFile ?? true,
|
|
1445
1015
|
connection: options?.connection,
|
|
1446
|
-
timestamp: options?.timestamp
|
|
1447
|
-
generateTypes: options?.generateTypes ?? true,
|
|
1448
|
-
generateMigrations: options?.generateMigrations ?? true
|
|
1016
|
+
timestamp: options?.timestamp
|
|
1449
1017
|
};
|
|
1450
1018
|
}
|
|
1451
1019
|
function laravelPlugin(options) {
|
|
1452
1020
|
const resolved = resolveOptions(options);
|
|
1453
1021
|
return {
|
|
1454
1022
|
name: "@famgia/omnify-laravel",
|
|
1455
|
-
version: "0.0.
|
|
1023
|
+
version: "0.0.13",
|
|
1024
|
+
configSchema: LARAVEL_CONFIG_SCHEMA,
|
|
1456
1025
|
generators: [
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
}
|
|
1476
|
-
}));
|
|
1477
|
-
}
|
|
1478
|
-
}
|
|
1479
|
-
] : [],
|
|
1480
|
-
// TypeScript Types Generator
|
|
1481
|
-
...resolved.generateTypes ? [
|
|
1482
|
-
{
|
|
1483
|
-
name: "typescript-types",
|
|
1484
|
-
description: "Generate TypeScript type definitions",
|
|
1485
|
-
generate: async (ctx) => {
|
|
1486
|
-
const tsOptions = {
|
|
1487
|
-
singleFile: resolved.singleFile
|
|
1488
|
-
};
|
|
1489
|
-
const files = generateTypeScript(ctx.schemas, tsOptions);
|
|
1490
|
-
return files.map((file) => ({
|
|
1491
|
-
path: `${resolved.typesPath}/${file.fileName}`,
|
|
1492
|
-
content: file.content,
|
|
1493
|
-
type: "type",
|
|
1494
|
-
metadata: {
|
|
1495
|
-
types: file.types
|
|
1496
|
-
}
|
|
1497
|
-
}));
|
|
1498
|
-
}
|
|
1026
|
+
{
|
|
1027
|
+
name: "laravel-migrations",
|
|
1028
|
+
description: "Generate Laravel migration files",
|
|
1029
|
+
generate: async (ctx) => {
|
|
1030
|
+
const migrationOptions = {
|
|
1031
|
+
connection: resolved.connection,
|
|
1032
|
+
timestamp: resolved.timestamp
|
|
1033
|
+
};
|
|
1034
|
+
const migrations = generateMigrations(ctx.schemas, migrationOptions);
|
|
1035
|
+
return migrations.map((migration) => ({
|
|
1036
|
+
path: getMigrationPath(migration, resolved.migrationsPath),
|
|
1037
|
+
content: migration.content,
|
|
1038
|
+
type: "migration",
|
|
1039
|
+
metadata: {
|
|
1040
|
+
tableName: migration.tables[0],
|
|
1041
|
+
migrationType: migration.type
|
|
1042
|
+
}
|
|
1043
|
+
}));
|
|
1499
1044
|
}
|
|
1500
|
-
|
|
1045
|
+
}
|
|
1501
1046
|
]
|
|
1502
1047
|
};
|
|
1503
1048
|
}
|
|
@@ -1522,26 +1067,6 @@ export {
|
|
|
1522
1067
|
generateAlterMigration,
|
|
1523
1068
|
generateDropTableMigration,
|
|
1524
1069
|
generateMigrationsFromChanges,
|
|
1525
|
-
toPropertyName,
|
|
1526
|
-
toInterfaceName,
|
|
1527
|
-
getPropertyType,
|
|
1528
|
-
propertyToTSProperty,
|
|
1529
|
-
schemaToInterface,
|
|
1530
|
-
formatProperty,
|
|
1531
|
-
formatInterface,
|
|
1532
|
-
generateInterfaces,
|
|
1533
|
-
toEnumMemberName,
|
|
1534
|
-
toEnumName,
|
|
1535
|
-
schemaToEnum,
|
|
1536
|
-
generateEnums,
|
|
1537
|
-
formatEnum,
|
|
1538
|
-
enumToUnionType,
|
|
1539
|
-
formatTypeAlias,
|
|
1540
|
-
extractInlineEnums,
|
|
1541
|
-
generateTypeScriptFile,
|
|
1542
|
-
generateTypeScriptFiles,
|
|
1543
|
-
generateTypeScript,
|
|
1544
|
-
getTypeScriptPath,
|
|
1545
1070
|
laravelPlugin
|
|
1546
1071
|
};
|
|
1547
|
-
//# sourceMappingURL=chunk-
|
|
1072
|
+
//# sourceMappingURL=chunk-G4UAJVC2.js.map
|