@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/plugin.cjs CHANGED
@@ -41,11 +41,8 @@ var TYPE_METHOD_MAP = {
41
41
  Json: "json",
42
42
  Email: "string",
43
43
  Password: "string",
44
- File: "string",
45
- MultiFile: "json",
46
- Enum: "enum",
47
- Select: "string",
48
- Lookup: "unsignedBigInteger"
44
+ Enum: "enum"
45
+ // Note: File type is now polymorphic - no column generated, uses files table
49
46
  };
50
47
  var PK_METHOD_MAP = {
51
48
  Int: "increments",
@@ -76,6 +73,9 @@ function propertyToColumnMethod(propertyName, property) {
76
73
  if (property.type === "Association") {
77
74
  return null;
78
75
  }
76
+ if (property.type === "File") {
77
+ return null;
78
+ }
79
79
  const columnName = toColumnName(propertyName);
80
80
  const method = TYPE_METHOD_MAP[property.type] ?? "string";
81
81
  const args = [columnName];
@@ -684,502 +684,61 @@ function getMigrationPath(migration, outputDir = "database/migrations") {
684
684
  return `${outputDir}/${migration.fileName}`;
685
685
  }
686
686
 
687
- // src/typescript/interface-generator.ts
688
- var TYPE_MAP = {
689
- String: "string",
690
- Int: "number",
691
- BigInt: "number",
692
- Float: "number",
693
- Boolean: "boolean",
694
- Text: "string",
695
- LongText: "string",
696
- Date: "string",
697
- Time: "string",
698
- Timestamp: "string",
699
- Json: "unknown",
700
- Email: "string",
701
- Password: "string",
702
- File: "string",
703
- MultiFile: "string[]",
704
- Enum: "string",
705
- Select: "string",
706
- Lookup: "number"
707
- };
708
- var PK_TYPE_MAP = {
709
- Int: "number",
710
- BigInt: "number",
711
- Uuid: "string",
712
- String: "string"
713
- };
714
- function toPropertyName(name) {
715
- return name;
716
- }
717
- function toInterfaceName(schemaName) {
718
- return schemaName;
719
- }
720
- function getPropertyType(property, _allSchemas) {
721
- if (property.type === "Association") {
722
- const assocProp = property;
723
- const targetName = assocProp.target ?? "unknown";
724
- switch (assocProp.relation) {
725
- // Standard relations
726
- case "OneToOne":
727
- case "ManyToOne":
728
- return targetName;
729
- case "OneToMany":
730
- case "ManyToMany":
731
- return `${targetName}[]`;
732
- // Polymorphic relations
733
- case "MorphTo":
734
- if (assocProp.targets && assocProp.targets.length > 0) {
735
- return assocProp.targets.join(" | ");
736
- }
737
- return "unknown";
738
- case "MorphOne":
739
- return targetName;
740
- case "MorphMany":
741
- case "MorphToMany":
742
- case "MorphedByMany":
743
- return `${targetName}[]`;
744
- default:
745
- return "unknown";
746
- }
747
- }
748
- if (property.type === "Enum") {
749
- const enumProp = property;
750
- if (typeof enumProp.enum === "string") {
751
- return enumProp.enum;
752
- }
753
- if (Array.isArray(enumProp.enum)) {
754
- return enumProp.enum.map((v) => `'${v}'`).join(" | ");
755
- }
756
- }
757
- if (property.type === "Select") {
758
- const selectProp = property;
759
- if (selectProp.options && selectProp.options.length > 0) {
760
- return selectProp.options.map((v) => `'${v}'`).join(" | ");
761
- }
762
- }
763
- return TYPE_MAP[property.type] ?? "unknown";
764
- }
765
- function propertyToTSProperties(propertyName, property, allSchemas, options = {}) {
766
- const baseProp = property;
767
- const isReadonly = options.readonly ?? true;
768
- if (property.type === "Association") {
769
- const assocProp = property;
770
- if (assocProp.relation === "MorphTo" && assocProp.targets && assocProp.targets.length > 0) {
771
- const propBaseName = toPropertyName(propertyName);
772
- const targetUnion = assocProp.targets.map((t) => `'${t}'`).join(" | ");
773
- const relationUnion = assocProp.targets.join(" | ");
774
- return [
775
- {
776
- name: `${propBaseName}Type`,
777
- type: targetUnion,
778
- optional: true,
779
- // Polymorphic columns are nullable
780
- readonly: isReadonly,
781
- comment: `Polymorphic type for ${propertyName}`
782
- },
783
- {
784
- name: `${propBaseName}Id`,
785
- type: "number",
786
- optional: true,
787
- readonly: isReadonly,
788
- comment: `Polymorphic ID for ${propertyName}`
789
- },
790
- {
791
- name: propBaseName,
792
- type: `${relationUnion} | null`,
793
- optional: true,
794
- readonly: isReadonly,
795
- comment: baseProp.displayName ?? `Polymorphic relation to ${assocProp.targets.join(", ")}`
796
- }
797
- ];
798
- }
799
- }
800
- const type = getPropertyType(property, allSchemas);
801
- return [{
802
- name: toPropertyName(propertyName),
803
- type,
804
- optional: baseProp.nullable ?? false,
805
- readonly: isReadonly,
806
- comment: baseProp.displayName
807
- }];
808
- }
809
- function schemaToInterface(schema, allSchemas, options = {}) {
810
- const properties = [];
811
- if (schema.options?.id !== false) {
812
- const pkType = schema.options?.idType ?? "BigInt";
813
- properties.push({
814
- name: "id",
815
- type: PK_TYPE_MAP[pkType] ?? "number",
816
- optional: false,
817
- readonly: options.readonly ?? true,
818
- comment: "Primary key"
819
- });
820
- }
821
- if (schema.properties) {
822
- for (const [propName, property] of Object.entries(schema.properties)) {
823
- properties.push(...propertyToTSProperties(propName, property, allSchemas, options));
824
- }
825
- }
826
- if (schema.options?.timestamps !== false) {
827
- properties.push(
828
- {
829
- name: "createdAt",
830
- type: "string",
831
- optional: true,
832
- readonly: options.readonly ?? true,
833
- comment: "Creation timestamp"
834
- },
835
- {
836
- name: "updatedAt",
837
- type: "string",
838
- optional: true,
839
- readonly: options.readonly ?? true,
840
- comment: "Last update timestamp"
841
- }
842
- );
843
- }
844
- if (schema.options?.softDelete) {
845
- properties.push({
846
- name: "deletedAt",
687
+ // src/plugin.ts
688
+ var LARAVEL_CONFIG_SCHEMA = {
689
+ fields: [
690
+ {
691
+ key: "migrationsPath",
692
+ type: "path",
693
+ label: "Migrations Path",
694
+ description: "Directory for Laravel migration files",
695
+ default: "database/migrations",
696
+ group: "output"
697
+ },
698
+ {
699
+ key: "connection",
847
700
  type: "string",
848
- optional: true,
849
- readonly: options.readonly ?? true,
850
- comment: "Soft delete timestamp"
851
- });
852
- }
853
- return {
854
- name: toInterfaceName(schema.name),
855
- properties,
856
- comment: schema.displayName ?? schema.name
857
- };
858
- }
859
- function formatProperty(property) {
860
- const readonly = property.readonly ? "readonly " : "";
861
- const optional = property.optional ? "?" : "";
862
- const comment = property.comment ? ` /** ${property.comment} */
863
- ` : "";
864
- return `${comment} ${readonly}${property.name}${optional}: ${property.type};`;
865
- }
866
- function formatInterface(iface) {
867
- const comment = iface.comment ? `/**
868
- * ${iface.comment}
869
- */
870
- ` : "";
871
- const extendsClause = iface.extends && iface.extends.length > 0 ? ` extends ${iface.extends.join(", ")}` : "";
872
- const properties = iface.properties.map(formatProperty).join("\n");
873
- return `${comment}export interface ${iface.name}${extendsClause} {
874
- ${properties}
875
- }`;
876
- }
877
- function generateInterfaces(schemas, options = {}) {
878
- const interfaces = [];
879
- for (const schema of Object.values(schemas)) {
880
- if (schema.kind === "enum") {
881
- continue;
882
- }
883
- interfaces.push(schemaToInterface(schema, schemas, options));
884
- }
885
- return interfaces;
886
- }
887
-
888
- // src/typescript/enum-generator.ts
889
- function toEnumMemberName(value) {
890
- return value.split(/[-_\s]+/).map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join("").replace(/[^a-zA-Z0-9]/g, "");
891
- }
892
- function toEnumName(schemaName) {
893
- return schemaName;
894
- }
895
- function schemaToEnum(schema) {
896
- if (schema.kind !== "enum" || !schema.values) {
897
- return null;
898
- }
899
- const values = schema.values.map((value) => ({
900
- name: toEnumMemberName(value),
901
- value
902
- }));
903
- return {
904
- name: toEnumName(schema.name),
905
- values,
906
- comment: schema.displayName ?? schema.name
907
- };
908
- }
909
- function generateEnums(schemas) {
910
- const enums = [];
911
- for (const schema of Object.values(schemas)) {
912
- if (schema.kind === "enum") {
913
- const enumDef = schemaToEnum(schema);
914
- if (enumDef) {
915
- enums.push(enumDef);
916
- }
701
+ label: "Database Connection",
702
+ description: "Laravel database connection name (optional)",
703
+ placeholder: "mysql",
704
+ group: "options"
917
705
  }
918
- }
919
- return enums;
920
- }
921
- function formatEnum(enumDef) {
922
- const comment = enumDef.comment ? `/**
923
- * ${enumDef.comment}
924
- */
925
- ` : "";
926
- const values = enumDef.values.map((v) => ` ${v.name} = '${v.value}',`).join("\n");
927
- return `${comment}export enum ${enumDef.name} {
928
- ${values}
929
- }`;
930
- }
931
- function formatTypeAlias(alias) {
932
- const comment = alias.comment ? `/**
933
- * ${alias.comment}
934
- */
935
- ` : "";
936
- return `${comment}export type ${alias.name} = ${alias.type};`;
937
- }
938
- function extractInlineEnums(schemas) {
939
- const typeAliases = [];
940
- for (const schema of Object.values(schemas)) {
941
- if (schema.kind === "enum" || !schema.properties) {
942
- continue;
943
- }
944
- for (const [propName, property] of Object.entries(schema.properties)) {
945
- if (property.type === "Enum") {
946
- const enumProp = property;
947
- if (Array.isArray(enumProp.enum) && enumProp.enum.length > 0) {
948
- const typeName = `${schema.name}${propName.charAt(0).toUpperCase() + propName.slice(1)}`;
949
- typeAliases.push({
950
- name: typeName,
951
- type: enumProp.enum.map((v) => `'${v}'`).join(" | "),
952
- comment: enumProp.displayName ?? `${schema.name} ${propName} enum`
953
- });
954
- }
955
- }
956
- if (property.type === "Select") {
957
- const selectProp = property;
958
- if (selectProp.options && selectProp.options.length > 0) {
959
- const typeName = `${schema.name}${propName.charAt(0).toUpperCase() + propName.slice(1)}`;
960
- typeAliases.push({
961
- name: typeName,
962
- type: selectProp.options.map((v) => `'${v}'`).join(" | "),
963
- comment: selectProp.displayName ?? `${schema.name} ${propName} options`
964
- });
965
- }
966
- }
967
- }
968
- }
969
- return typeAliases;
970
- }
971
-
972
- // src/typescript/generator.ts
973
- var DEFAULT_OPTIONS = {
974
- singleFile: true,
975
- fileName: "types.ts",
976
- readonly: true,
977
- strictNullChecks: true
706
+ ]
978
707
  };
979
- function generateHeader() {
980
- return `/**
981
- * Auto-generated TypeScript types from Omnify schemas.
982
- * DO NOT EDIT - This file is automatically generated.
983
- */
984
-
985
- `;
986
- }
987
- function generateTypeScriptFile(schemas, options = {}) {
988
- const opts = { ...DEFAULT_OPTIONS, ...options };
989
- const parts = [generateHeader()];
990
- const types = [];
991
- const enums = generateEnums(schemas);
992
- if (enums.length > 0) {
993
- parts.push("// Enums\n");
994
- for (const enumDef of enums) {
995
- parts.push(formatEnum(enumDef));
996
- parts.push("\n\n");
997
- types.push(enumDef.name);
998
- }
999
- }
1000
- const inlineEnums = extractInlineEnums(schemas);
1001
- if (inlineEnums.length > 0) {
1002
- parts.push("// Type Aliases\n");
1003
- for (const alias of inlineEnums) {
1004
- parts.push(formatTypeAlias(alias));
1005
- parts.push("\n\n");
1006
- types.push(alias.name);
1007
- }
1008
- }
1009
- const interfaces = generateInterfaces(schemas, opts);
1010
- if (interfaces.length > 0) {
1011
- parts.push("// Interfaces\n");
1012
- for (const iface of interfaces) {
1013
- parts.push(formatInterface(iface));
1014
- parts.push("\n\n");
1015
- types.push(iface.name);
1016
- }
1017
- }
1018
- return {
1019
- fileName: opts.fileName ?? "types.ts",
1020
- content: parts.join("").trim() + "\n",
1021
- types
1022
- };
1023
- }
1024
- function generateTypeScriptFiles(schemas, options = {}) {
1025
- const opts = { ...DEFAULT_OPTIONS, ...options };
1026
- const files = [];
1027
- const enums = generateEnums(schemas);
1028
- if (enums.length > 0) {
1029
- const content = generateHeader() + enums.map(formatEnum).join("\n\n") + "\n";
1030
- files.push({
1031
- fileName: "enums.ts",
1032
- content,
1033
- types: enums.map((e) => e.name)
1034
- });
1035
- }
1036
- const inlineEnums = extractInlineEnums(schemas);
1037
- if (inlineEnums.length > 0) {
1038
- const content = generateHeader() + inlineEnums.map(formatTypeAlias).join("\n\n") + "\n";
1039
- files.push({
1040
- fileName: "type-aliases.ts",
1041
- content,
1042
- types: inlineEnums.map((a) => a.name)
1043
- });
1044
- }
1045
- const interfaces = generateInterfaces(schemas, opts);
1046
- for (const iface of interfaces) {
1047
- const imports = collectImports(iface, enums, inlineEnums, interfaces);
1048
- const importStatement = formatImports(imports);
1049
- const content = generateHeader() + (importStatement ? importStatement + "\n\n" : "") + formatInterface(iface) + "\n";
1050
- files.push({
1051
- fileName: `${toKebabCase(iface.name)}.ts`,
1052
- content,
1053
- types: [iface.name]
1054
- });
1055
- }
1056
- const indexContent = generateIndexFile(files);
1057
- files.push({
1058
- fileName: "index.ts",
1059
- content: indexContent,
1060
- types: []
1061
- });
1062
- return files;
1063
- }
1064
- function toKebabCase(name) {
1065
- return name.replace(/([A-Z])/g, "-$1").toLowerCase().replace(/^-/, "");
1066
- }
1067
- function collectImports(iface, enums, typeAliases, allInterfaces) {
1068
- const imports = /* @__PURE__ */ new Map();
1069
- const enumNames = new Set(enums.map((e) => e.name));
1070
- const aliasNames = new Set(typeAliases.map((a) => a.name));
1071
- const interfaceNames = new Set(allInterfaces.map((i) => i.name));
1072
- for (const prop of iface.properties) {
1073
- if (enumNames.has(prop.type)) {
1074
- const existing = imports.get("./enums.js") ?? [];
1075
- if (!existing.includes(prop.type)) {
1076
- imports.set("./enums.js", [...existing, prop.type]);
1077
- }
1078
- }
1079
- if (aliasNames.has(prop.type)) {
1080
- const existing = imports.get("./type-aliases.js") ?? [];
1081
- if (!existing.includes(prop.type)) {
1082
- imports.set("./type-aliases.js", [...existing, prop.type]);
1083
- }
1084
- }
1085
- const baseType = prop.type.replace("[]", "");
1086
- if (interfaceNames.has(baseType) && baseType !== iface.name) {
1087
- const fileName = `./${toKebabCase(baseType)}.js`;
1088
- const existing = imports.get(fileName) ?? [];
1089
- if (!existing.includes(baseType)) {
1090
- imports.set(fileName, [...existing, baseType]);
1091
- }
1092
- }
1093
- }
1094
- return imports;
1095
- }
1096
- function formatImports(imports) {
1097
- if (imports.size === 0) return "";
1098
- const lines = [];
1099
- for (const [path, names] of imports) {
1100
- lines.push(`import type { ${names.join(", ")} } from '${path}';`);
1101
- }
1102
- return lines.join("\n");
1103
- }
1104
- function generateIndexFile(files) {
1105
- const exports2 = [generateHeader().trim(), ""];
1106
- for (const file of files) {
1107
- if (file.fileName === "index.ts") continue;
1108
- const moduleName = file.fileName.replace(".ts", ".js");
1109
- exports2.push(`export * from './${moduleName}';`);
1110
- }
1111
- return exports2.join("\n") + "\n";
1112
- }
1113
- function generateTypeScript(schemas, options = {}) {
1114
- const opts = { ...DEFAULT_OPTIONS, ...options };
1115
- if (opts.singleFile) {
1116
- return [generateTypeScriptFile(schemas, opts)];
1117
- }
1118
- return generateTypeScriptFiles(schemas, opts);
1119
- }
1120
-
1121
- // src/plugin.ts
1122
708
  function resolveOptions(options) {
1123
709
  return {
1124
710
  migrationsPath: options?.migrationsPath ?? "database/migrations",
1125
- typesPath: options?.typesPath ?? "types",
1126
- singleFile: options?.singleFile ?? true,
1127
711
  connection: options?.connection,
1128
- timestamp: options?.timestamp,
1129
- generateTypes: options?.generateTypes ?? true,
1130
- generateMigrations: options?.generateMigrations ?? true
712
+ timestamp: options?.timestamp
1131
713
  };
1132
714
  }
1133
715
  function laravelPlugin(options) {
1134
716
  const resolved = resolveOptions(options);
1135
717
  return {
1136
718
  name: "@famgia/omnify-laravel",
1137
- version: "0.0.7",
719
+ version: "0.0.13",
720
+ configSchema: LARAVEL_CONFIG_SCHEMA,
1138
721
  generators: [
1139
- // Laravel Migrations Generator
1140
- ...resolved.generateMigrations ? [
1141
- {
1142
- name: "laravel-migrations",
1143
- description: "Generate Laravel migration files",
1144
- generate: async (ctx) => {
1145
- const migrationOptions = {
1146
- connection: resolved.connection,
1147
- timestamp: resolved.timestamp
1148
- };
1149
- const migrations = generateMigrations(ctx.schemas, migrationOptions);
1150
- return migrations.map((migration) => ({
1151
- path: getMigrationPath(migration, resolved.migrationsPath),
1152
- content: migration.content,
1153
- type: "migration",
1154
- metadata: {
1155
- tableName: migration.tables[0],
1156
- migrationType: migration.type
1157
- }
1158
- }));
1159
- }
1160
- }
1161
- ] : [],
1162
- // TypeScript Types Generator
1163
- ...resolved.generateTypes ? [
1164
- {
1165
- name: "typescript-types",
1166
- description: "Generate TypeScript type definitions",
1167
- generate: async (ctx) => {
1168
- const tsOptions = {
1169
- singleFile: resolved.singleFile
1170
- };
1171
- const files = generateTypeScript(ctx.schemas, tsOptions);
1172
- return files.map((file) => ({
1173
- path: `${resolved.typesPath}/${file.fileName}`,
1174
- content: file.content,
1175
- type: "type",
1176
- metadata: {
1177
- types: file.types
1178
- }
1179
- }));
1180
- }
722
+ {
723
+ name: "laravel-migrations",
724
+ description: "Generate Laravel migration files",
725
+ generate: async (ctx) => {
726
+ const migrationOptions = {
727
+ connection: resolved.connection,
728
+ timestamp: resolved.timestamp
729
+ };
730
+ const migrations = generateMigrations(ctx.schemas, migrationOptions);
731
+ return migrations.map((migration) => ({
732
+ path: getMigrationPath(migration, resolved.migrationsPath),
733
+ content: migration.content,
734
+ type: "migration",
735
+ metadata: {
736
+ tableName: migration.tables[0],
737
+ migrationType: migration.type
738
+ }
739
+ }));
1181
740
  }
1182
- ] : []
741
+ }
1183
742
  ]
1184
743
  };
1185
744
  }