@famgia/omnify-laravel 0.0.149 → 0.0.151
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-MQGFUYP7.js → chunk-SICFS6KX.js} +144 -20
- package/dist/chunk-SICFS6KX.js.map +1 -0
- package/dist/index.cjs +143 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +1 -1
- package/dist/plugin.cjs +143 -19
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.js +1 -1
- package/package.json +11 -4
- package/dist/chunk-MQGFUYP7.js.map +0 -1
|
@@ -1134,7 +1134,10 @@ function generateMigrations(schemas, options = {}) {
|
|
|
1134
1134
|
...options,
|
|
1135
1135
|
timestamp: offsetTimestamp
|
|
1136
1136
|
});
|
|
1137
|
-
migrations.push(
|
|
1137
|
+
migrations.push({
|
|
1138
|
+
...migration,
|
|
1139
|
+
schemaName: schema.name
|
|
1140
|
+
});
|
|
1138
1141
|
}
|
|
1139
1142
|
const explicitPivotTableNames = /* @__PURE__ */ new Set();
|
|
1140
1143
|
for (const schema of sortedSchemas) {
|
|
@@ -1647,6 +1650,24 @@ function resolveOptions(options) {
|
|
|
1647
1650
|
customTypes: options?.customTypes ?? /* @__PURE__ */ new Map()
|
|
1648
1651
|
};
|
|
1649
1652
|
}
|
|
1653
|
+
function resolveSchemaOptions(schema, globalOptions) {
|
|
1654
|
+
const pkgOutput = schema.packageOutput?.laravel;
|
|
1655
|
+
if (!pkgOutput) {
|
|
1656
|
+
return globalOptions;
|
|
1657
|
+
}
|
|
1658
|
+
const base = pkgOutput.base;
|
|
1659
|
+
const modelsNs = pkgOutput.modelsNamespace;
|
|
1660
|
+
const baseNs = modelsNs.replace(/\\Models$/, "");
|
|
1661
|
+
return {
|
|
1662
|
+
modelNamespace: modelsNs,
|
|
1663
|
+
baseModelNamespace: pkgOutput.baseModelsNamespace ?? `${modelsNs}\\Generated`,
|
|
1664
|
+
baseModelClassName: "BaseModel",
|
|
1665
|
+
modelPath: `${base}/${pkgOutput.modelsPath ?? "src/Models"}`,
|
|
1666
|
+
baseModelPath: `${base}/${pkgOutput.baseModelsPath ?? "src/Models/Generated"}`,
|
|
1667
|
+
providersPath: `${base}/${pkgOutput.providersPath ?? "src/Providers"}`,
|
|
1668
|
+
customTypes: globalOptions.customTypes
|
|
1669
|
+
};
|
|
1670
|
+
}
|
|
1650
1671
|
function getCastType(propDef) {
|
|
1651
1672
|
switch (propDef.type) {
|
|
1652
1673
|
case "Boolean":
|
|
@@ -2589,6 +2610,62 @@ function generateServiceProvider(schemas, options, stubContent) {
|
|
|
2589
2610
|
schemaName: "__service_provider__"
|
|
2590
2611
|
};
|
|
2591
2612
|
}
|
|
2613
|
+
function generatePackageServiceProvider(schemas, options, packageBase, stubContent) {
|
|
2614
|
+
const baseNs = options.modelNamespace.replace(/\\Models$/, "");
|
|
2615
|
+
const nsParts = baseNs.split("\\");
|
|
2616
|
+
const packageName = nsParts[nsParts.length - 1];
|
|
2617
|
+
const providerName = `${packageName}ServiceProvider`;
|
|
2618
|
+
const providerNamespace = `${baseNs}\\Providers`;
|
|
2619
|
+
const morphMap = Object.values(schemas).filter((s) => s.kind !== "enum" && s.kind !== "partial" && s.options?.hidden !== true).map((s) => {
|
|
2620
|
+
const className = toPascalCase(s.name);
|
|
2621
|
+
return ` '${s.name}' => \\${options.modelNamespace}\\${className}::class,`;
|
|
2622
|
+
}).join("\n");
|
|
2623
|
+
const content = `<?php
|
|
2624
|
+
|
|
2625
|
+
namespace ${providerNamespace};
|
|
2626
|
+
|
|
2627
|
+
use Illuminate\\Database\\Eloquent\\Relations\\Relation;
|
|
2628
|
+
use Illuminate\\Support\\ServiceProvider;
|
|
2629
|
+
|
|
2630
|
+
/**
|
|
2631
|
+
* ${packageName} Service Provider
|
|
2632
|
+
*
|
|
2633
|
+
* This provider is auto-generated by Omnify.
|
|
2634
|
+
* Register it in composer.json extra.laravel.providers for auto-discovery.
|
|
2635
|
+
*/
|
|
2636
|
+
class ${providerName} extends ServiceProvider
|
|
2637
|
+
{
|
|
2638
|
+
/**
|
|
2639
|
+
* Register services.
|
|
2640
|
+
*/
|
|
2641
|
+
public function register(): void
|
|
2642
|
+
{
|
|
2643
|
+
//
|
|
2644
|
+
}
|
|
2645
|
+
|
|
2646
|
+
/**
|
|
2647
|
+
* Bootstrap services.
|
|
2648
|
+
*/
|
|
2649
|
+
public function boot(): void
|
|
2650
|
+
{
|
|
2651
|
+
// Load migrations from package
|
|
2652
|
+
$this->loadMigrationsFrom(__DIR__ . '/../../database/migrations');
|
|
2653
|
+
|
|
2654
|
+
// Enforce morph map for this package's models
|
|
2655
|
+
Relation::enforceMorphMap([
|
|
2656
|
+
${morphMap}
|
|
2657
|
+
]);
|
|
2658
|
+
}
|
|
2659
|
+
}
|
|
2660
|
+
`;
|
|
2661
|
+
return {
|
|
2662
|
+
path: `${options.providersPath}/${providerName}.php`,
|
|
2663
|
+
content,
|
|
2664
|
+
type: "service-provider",
|
|
2665
|
+
overwrite: true,
|
|
2666
|
+
schemaName: `__package_service_provider__${packageName}`
|
|
2667
|
+
};
|
|
2668
|
+
}
|
|
2592
2669
|
function generateLocalizedDisplayNameTrait(options, stubContent) {
|
|
2593
2670
|
const content = stubContent.replace(/\{\{BASE_MODEL_NAMESPACE\}\}/g, options.baseModelNamespace);
|
|
2594
2671
|
return {
|
|
@@ -2615,11 +2692,27 @@ function generateLocalesClass(schema, options, stubContent) {
|
|
|
2615
2692
|
};
|
|
2616
2693
|
}
|
|
2617
2694
|
function generateModels(schemas, options) {
|
|
2618
|
-
const
|
|
2695
|
+
const globalResolved = resolveOptions(options);
|
|
2619
2696
|
const models = [];
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2697
|
+
const mainSchemas = {};
|
|
2698
|
+
const packageSchemaGroups = /* @__PURE__ */ new Map();
|
|
2699
|
+
for (const [name, schema] of Object.entries(schemas)) {
|
|
2700
|
+
if (schema.packageOutput?.laravel) {
|
|
2701
|
+
const base = schema.packageOutput.laravel.base;
|
|
2702
|
+
if (!packageSchemaGroups.has(base)) {
|
|
2703
|
+
packageSchemaGroups.set(base, {
|
|
2704
|
+
schemas: {},
|
|
2705
|
+
resolved: resolveSchemaOptions(schema, globalResolved)
|
|
2706
|
+
});
|
|
2707
|
+
}
|
|
2708
|
+
packageSchemaGroups.get(base).schemas[name] = schema;
|
|
2709
|
+
} else {
|
|
2710
|
+
mainSchemas[name] = schema;
|
|
2711
|
+
}
|
|
2712
|
+
}
|
|
2713
|
+
models.push(generateBaseModel(schemas, globalResolved, getStubContent("base-model")));
|
|
2714
|
+
models.push(generateLocalizedDisplayNameTrait(globalResolved, getStubContent("has-localized-display-name")));
|
|
2715
|
+
models.push(generateServiceProvider(schemas, globalResolved, getStubContent("service-provider")));
|
|
2623
2716
|
for (const schema of Object.values(schemas)) {
|
|
2624
2717
|
if (schema.kind === "enum" || schema.kind === "partial") {
|
|
2625
2718
|
continue;
|
|
@@ -2627,16 +2720,20 @@ function generateModels(schemas, options) {
|
|
|
2627
2720
|
if (schema.options?.hidden === true) {
|
|
2628
2721
|
continue;
|
|
2629
2722
|
}
|
|
2630
|
-
|
|
2723
|
+
const schemaResolved = resolveSchemaOptions(schema, globalResolved);
|
|
2724
|
+
models.push(generateLocalesClass(schema, schemaResolved, getStubContent("locales")));
|
|
2631
2725
|
models.push(generateEntityBaseModel(
|
|
2632
2726
|
schema,
|
|
2633
2727
|
schemas,
|
|
2634
|
-
|
|
2728
|
+
schemaResolved,
|
|
2635
2729
|
getStubContent("entity-base"),
|
|
2636
2730
|
getStubContent("entity-base-auth"),
|
|
2637
2731
|
getStubContent("entity-base-pivot")
|
|
2638
2732
|
));
|
|
2639
|
-
models.push(generateEntityModel(schema,
|
|
2733
|
+
models.push(generateEntityModel(schema, schemaResolved, getStubContent("entity")));
|
|
2734
|
+
}
|
|
2735
|
+
for (const [base, { schemas: pkgSchemas, resolved: pkgResolved }] of packageSchemaGroups) {
|
|
2736
|
+
models.push(generatePackageServiceProvider(pkgSchemas, pkgResolved, base, getStubContent("service-provider")));
|
|
2640
2737
|
}
|
|
2641
2738
|
return models;
|
|
2642
2739
|
}
|
|
@@ -2743,6 +2840,18 @@ function resolveOptions2(options) {
|
|
|
2743
2840
|
pluginEnums: options?.pluginEnums ?? /* @__PURE__ */ new Map()
|
|
2744
2841
|
};
|
|
2745
2842
|
}
|
|
2843
|
+
function resolveSchemaOptions2(schema, globalOptions) {
|
|
2844
|
+
const pkgOutput = schema.packageOutput?.laravel;
|
|
2845
|
+
if (!pkgOutput) {
|
|
2846
|
+
return globalOptions;
|
|
2847
|
+
}
|
|
2848
|
+
const base = pkgOutput.base;
|
|
2849
|
+
return {
|
|
2850
|
+
...globalOptions,
|
|
2851
|
+
modelNamespace: pkgOutput.modelsNamespace,
|
|
2852
|
+
factoryPath: `${base}/${pkgOutput.factoriesPath ?? "database/factories"}`
|
|
2853
|
+
};
|
|
2854
|
+
}
|
|
2746
2855
|
function getStubContent2() {
|
|
2747
2856
|
return `<?php
|
|
2748
2857
|
|
|
@@ -2940,22 +3049,25 @@ function generateStringFake(propertyName, property) {
|
|
|
2940
3049
|
return `'${propertyName}' => fake()->sentence(),`;
|
|
2941
3050
|
}
|
|
2942
3051
|
function generateIntFake(propertyName, property) {
|
|
3052
|
+
const isUnique = "unique" in property && property.unique === true;
|
|
3053
|
+
const uniquePrefix = isUnique ? "unique()->" : "";
|
|
2943
3054
|
if (propertyName.includes("count") || propertyName.includes("quantity")) {
|
|
2944
|
-
return `'${propertyName}' => fake()
|
|
3055
|
+
return `'${propertyName}' => fake()->${uniquePrefix}numberBetween(0, 100),`;
|
|
2945
3056
|
}
|
|
2946
3057
|
if (propertyName.includes("price") || propertyName.includes("amount") || propertyName.includes("cost")) {
|
|
2947
|
-
return `'${propertyName}' => fake()
|
|
3058
|
+
return `'${propertyName}' => fake()->${uniquePrefix}numberBetween(100, 10000),`;
|
|
2948
3059
|
}
|
|
2949
3060
|
if (propertyName.includes("order") || propertyName.includes("sort") || propertyName.includes("position")) {
|
|
2950
|
-
return `'${propertyName}' => fake()
|
|
3061
|
+
return `'${propertyName}' => fake()->${uniquePrefix}numberBetween(1, 100),`;
|
|
2951
3062
|
}
|
|
2952
3063
|
if (propertyName.includes("age")) {
|
|
2953
|
-
return `'${propertyName}' => fake()
|
|
3064
|
+
return `'${propertyName}' => fake()->${uniquePrefix}numberBetween(18, 80),`;
|
|
2954
3065
|
}
|
|
2955
3066
|
if (propertyName.includes("year")) {
|
|
2956
|
-
return `'${propertyName}' => fake()
|
|
3067
|
+
return `'${propertyName}' => fake()->${uniquePrefix}year(),`;
|
|
2957
3068
|
}
|
|
2958
|
-
|
|
3069
|
+
const range = isUnique ? "1, 1000000" : "1, 1000";
|
|
3070
|
+
return `'${propertyName}' => fake()->${uniquePrefix}numberBetween(${range}),`;
|
|
2959
3071
|
}
|
|
2960
3072
|
function generateEnumFake(propertyName, property) {
|
|
2961
3073
|
const enumValues = property.enum;
|
|
@@ -3057,11 +3169,12 @@ function generateFactory(schema, schemas, options, stubContent) {
|
|
|
3057
3169
|
};
|
|
3058
3170
|
}
|
|
3059
3171
|
function generateFactories(schemas, options) {
|
|
3060
|
-
const
|
|
3172
|
+
const globalResolved = resolveOptions2(options);
|
|
3061
3173
|
const stubContent = getStubContent2();
|
|
3062
3174
|
const factories = [];
|
|
3063
3175
|
for (const schema of Object.values(schemas)) {
|
|
3064
|
-
const
|
|
3176
|
+
const schemaResolved = resolveSchemaOptions2(schema, globalResolved);
|
|
3177
|
+
const factory = generateFactory(schema, schemas, schemaResolved, stubContent);
|
|
3065
3178
|
if (factory) {
|
|
3066
3179
|
factories.push(factory);
|
|
3067
3180
|
}
|
|
@@ -4494,6 +4607,17 @@ function shouldGenerateAIGuides(rootDir) {
|
|
|
4494
4607
|
}
|
|
4495
4608
|
|
|
4496
4609
|
// src/plugin.ts
|
|
4610
|
+
function getMigrationPathForSchema(migration, schemas, defaultPath) {
|
|
4611
|
+
if (migration.schemaName) {
|
|
4612
|
+
const schema = schemas[migration.schemaName];
|
|
4613
|
+
if (schema?.packageOutput?.laravel) {
|
|
4614
|
+
const pkg = schema.packageOutput.laravel;
|
|
4615
|
+
const migrationsPath = `${pkg.base}/${pkg.migrationsPath ?? "database/migrations"}`;
|
|
4616
|
+
return `${migrationsPath}/${migration.fileName}`;
|
|
4617
|
+
}
|
|
4618
|
+
}
|
|
4619
|
+
return getMigrationPath(migration, defaultPath);
|
|
4620
|
+
}
|
|
4497
4621
|
function inferLaravelRoot(providersPath) {
|
|
4498
4622
|
const normalized = providersPath.replace(/\\/g, "/");
|
|
4499
4623
|
const match = normalized.match(/^(.*)\/app\/Providers\/?$/i);
|
|
@@ -4714,7 +4838,7 @@ function laravelPlugin(options) {
|
|
|
4714
4838
|
continue;
|
|
4715
4839
|
}
|
|
4716
4840
|
outputs.push({
|
|
4717
|
-
path:
|
|
4841
|
+
path: getMigrationPathForSchema(migration, ctx.schemas, resolved.migrationsPath),
|
|
4718
4842
|
content: migration.content,
|
|
4719
4843
|
type: "migration",
|
|
4720
4844
|
metadata: {
|
|
@@ -4734,7 +4858,7 @@ function laravelPlugin(options) {
|
|
|
4734
4858
|
);
|
|
4735
4859
|
for (const migration of alterMigrations) {
|
|
4736
4860
|
outputs.push({
|
|
4737
|
-
path:
|
|
4861
|
+
path: getMigrationPathForSchema(migration, ctx.schemas, resolved.migrationsPath),
|
|
4738
4862
|
content: migration.content,
|
|
4739
4863
|
type: "migration",
|
|
4740
4864
|
metadata: {
|
|
@@ -4753,7 +4877,7 @@ function laravelPlugin(options) {
|
|
|
4753
4877
|
continue;
|
|
4754
4878
|
}
|
|
4755
4879
|
outputs.push({
|
|
4756
|
-
path:
|
|
4880
|
+
path: getMigrationPathForSchema(migration, ctx.schemas, resolved.migrationsPath),
|
|
4757
4881
|
content: migration.content,
|
|
4758
4882
|
type: "migration",
|
|
4759
4883
|
metadata: {
|
|
@@ -4996,4 +5120,4 @@ export {
|
|
|
4996
5120
|
shouldGenerateAIGuides,
|
|
4997
5121
|
laravelPlugin
|
|
4998
5122
|
};
|
|
4999
|
-
//# sourceMappingURL=chunk-
|
|
5123
|
+
//# sourceMappingURL=chunk-SICFS6KX.js.map
|