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