@famgia/omnify-laravel 0.0.150 → 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-M6MP6RID.js → chunk-SICFS6KX.js} +135 -14
- package/dist/chunk-SICFS6KX.js.map +1 -0
- package/dist/index.cjs +134 -13
- 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 +134 -13
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.js +1 -1
- package/package.json +4 -4
- package/dist/chunk-M6MP6RID.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
|
|
|
@@ -3060,11 +3169,12 @@ function generateFactory(schema, schemas, options, stubContent) {
|
|
|
3060
3169
|
};
|
|
3061
3170
|
}
|
|
3062
3171
|
function generateFactories(schemas, options) {
|
|
3063
|
-
const
|
|
3172
|
+
const globalResolved = resolveOptions2(options);
|
|
3064
3173
|
const stubContent = getStubContent2();
|
|
3065
3174
|
const factories = [];
|
|
3066
3175
|
for (const schema of Object.values(schemas)) {
|
|
3067
|
-
const
|
|
3176
|
+
const schemaResolved = resolveSchemaOptions2(schema, globalResolved);
|
|
3177
|
+
const factory = generateFactory(schema, schemas, schemaResolved, stubContent);
|
|
3068
3178
|
if (factory) {
|
|
3069
3179
|
factories.push(factory);
|
|
3070
3180
|
}
|
|
@@ -4497,6 +4607,17 @@ function shouldGenerateAIGuides(rootDir) {
|
|
|
4497
4607
|
}
|
|
4498
4608
|
|
|
4499
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
|
+
}
|
|
4500
4621
|
function inferLaravelRoot(providersPath) {
|
|
4501
4622
|
const normalized = providersPath.replace(/\\/g, "/");
|
|
4502
4623
|
const match = normalized.match(/^(.*)\/app\/Providers\/?$/i);
|
|
@@ -4717,7 +4838,7 @@ function laravelPlugin(options) {
|
|
|
4717
4838
|
continue;
|
|
4718
4839
|
}
|
|
4719
4840
|
outputs.push({
|
|
4720
|
-
path:
|
|
4841
|
+
path: getMigrationPathForSchema(migration, ctx.schemas, resolved.migrationsPath),
|
|
4721
4842
|
content: migration.content,
|
|
4722
4843
|
type: "migration",
|
|
4723
4844
|
metadata: {
|
|
@@ -4737,7 +4858,7 @@ function laravelPlugin(options) {
|
|
|
4737
4858
|
);
|
|
4738
4859
|
for (const migration of alterMigrations) {
|
|
4739
4860
|
outputs.push({
|
|
4740
|
-
path:
|
|
4861
|
+
path: getMigrationPathForSchema(migration, ctx.schemas, resolved.migrationsPath),
|
|
4741
4862
|
content: migration.content,
|
|
4742
4863
|
type: "migration",
|
|
4743
4864
|
metadata: {
|
|
@@ -4756,7 +4877,7 @@ function laravelPlugin(options) {
|
|
|
4756
4877
|
continue;
|
|
4757
4878
|
}
|
|
4758
4879
|
outputs.push({
|
|
4759
|
-
path:
|
|
4880
|
+
path: getMigrationPathForSchema(migration, ctx.schemas, resolved.migrationsPath),
|
|
4760
4881
|
content: migration.content,
|
|
4761
4882
|
type: "migration",
|
|
4762
4883
|
metadata: {
|
|
@@ -4999,4 +5120,4 @@ export {
|
|
|
4999
5120
|
shouldGenerateAIGuides,
|
|
5000
5121
|
laravelPlugin
|
|
5001
5122
|
};
|
|
5002
|
-
//# sourceMappingURL=chunk-
|
|
5123
|
+
//# sourceMappingURL=chunk-SICFS6KX.js.map
|