@famgia/omnify-laravel 0.0.79 → 0.0.80
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-6QYGCK3D.js → chunk-FR6LGETT.js} +410 -11
- package/dist/chunk-FR6LGETT.js.map +1 -0
- package/dist/index.cjs +409 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/plugin.cjs +409 -10
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.d.cts +25 -0
- package/dist/plugin.d.ts +25 -0
- package/dist/plugin.js +1 -1
- package/package.json +4 -4
- package/dist/chunk-6QYGCK3D.js.map +0 -1
|
@@ -2649,6 +2649,33 @@ function generateStoreRules(propName, propDef, schema, schemas, options) {
|
|
|
2649
2649
|
}
|
|
2650
2650
|
}
|
|
2651
2651
|
break;
|
|
2652
|
+
default:
|
|
2653
|
+
const customType = options.customTypes.get(propDef.type);
|
|
2654
|
+
if (customType && !customType.compound) {
|
|
2655
|
+
if (propDef.type === "JapanesePhone") {
|
|
2656
|
+
rules.push("'string'");
|
|
2657
|
+
rules.push("'max:15'");
|
|
2658
|
+
rules.push("'regex:/^\\d{2,4}-\\d{2,4}-\\d{4}$/'");
|
|
2659
|
+
} else if (propDef.type === "JapanesePostalCode") {
|
|
2660
|
+
rules.push("'string'");
|
|
2661
|
+
rules.push("'max:8'");
|
|
2662
|
+
rules.push("'regex:/^\\d{3}-\\d{4}$/'");
|
|
2663
|
+
} else {
|
|
2664
|
+
const sqlType = customType.sql?.sqlType ?? "VARCHAR";
|
|
2665
|
+
const sqlLength = customType.sql?.length ?? 255;
|
|
2666
|
+
if (sqlType === "VARCHAR" || sqlType === "TEXT") {
|
|
2667
|
+
rules.push("'string'");
|
|
2668
|
+
if (sqlType === "VARCHAR") {
|
|
2669
|
+
rules.push(`'max:${sqlLength}'`);
|
|
2670
|
+
}
|
|
2671
|
+
} else if (sqlType === "INT" || sqlType === "TINYINT" || sqlType === "BIGINT") {
|
|
2672
|
+
rules.push("'integer'");
|
|
2673
|
+
} else if (sqlType === "DECIMAL" || sqlType === "FLOAT") {
|
|
2674
|
+
rules.push("'numeric'");
|
|
2675
|
+
}
|
|
2676
|
+
}
|
|
2677
|
+
}
|
|
2678
|
+
break;
|
|
2652
2679
|
}
|
|
2653
2680
|
if (prop.unique === true) {
|
|
2654
2681
|
rules.push(`'unique:${tableName}'`);
|
|
@@ -2731,12 +2758,100 @@ function generateUpdateRules(propName, propDef, schema, schemas, options) {
|
|
|
2731
2758
|
}
|
|
2732
2759
|
}
|
|
2733
2760
|
break;
|
|
2761
|
+
default:
|
|
2762
|
+
const customType = options.customTypes.get(propDef.type);
|
|
2763
|
+
if (customType && !customType.compound) {
|
|
2764
|
+
if (propDef.type === "JapanesePhone") {
|
|
2765
|
+
rules.push("'string'");
|
|
2766
|
+
rules.push("'max:15'");
|
|
2767
|
+
rules.push("'regex:/^\\d{2,4}-\\d{2,4}-\\d{4}$/'");
|
|
2768
|
+
} else if (propDef.type === "JapanesePostalCode") {
|
|
2769
|
+
rules.push("'string'");
|
|
2770
|
+
rules.push("'max:8'");
|
|
2771
|
+
rules.push("'regex:/^\\d{3}-\\d{4}$/'");
|
|
2772
|
+
} else {
|
|
2773
|
+
const sqlType = customType.sql?.sqlType ?? "VARCHAR";
|
|
2774
|
+
const sqlLength = customType.sql?.length ?? 255;
|
|
2775
|
+
if (sqlType === "VARCHAR" || sqlType === "TEXT") {
|
|
2776
|
+
rules.push("'string'");
|
|
2777
|
+
if (sqlType === "VARCHAR") {
|
|
2778
|
+
rules.push(`'max:${sqlLength}'`);
|
|
2779
|
+
}
|
|
2780
|
+
} else if (sqlType === "INT" || sqlType === "TINYINT" || sqlType === "BIGINT") {
|
|
2781
|
+
rules.push("'integer'");
|
|
2782
|
+
} else if (sqlType === "DECIMAL" || sqlType === "FLOAT") {
|
|
2783
|
+
rules.push("'numeric'");
|
|
2784
|
+
}
|
|
2785
|
+
}
|
|
2786
|
+
}
|
|
2787
|
+
break;
|
|
2734
2788
|
}
|
|
2735
2789
|
if (prop.unique === true) {
|
|
2736
2790
|
rules.push(`Rule::unique('${tableName}')->ignore($this->route('${modelVar}'))`);
|
|
2737
2791
|
}
|
|
2738
2792
|
return rules;
|
|
2739
2793
|
}
|
|
2794
|
+
function getCompoundFieldRules(typeName, suffix, field, fieldOverride) {
|
|
2795
|
+
const rules = [];
|
|
2796
|
+
const sql = field.sql;
|
|
2797
|
+
const length = fieldOverride?.length ?? sql?.length ?? 255;
|
|
2798
|
+
switch (typeName) {
|
|
2799
|
+
case "JapaneseName":
|
|
2800
|
+
rules.push("'string'");
|
|
2801
|
+
rules.push(`'max:${length}'`);
|
|
2802
|
+
if (suffix === "KanaLastname" || suffix === "KanaFirstname") {
|
|
2803
|
+
rules.push("'regex:/^[\\x{30A0}-\\x{30FF}\\x{3000}-\\x{303F}\\x{FF00}-\\x{FF9F}\\s]+$/u'");
|
|
2804
|
+
}
|
|
2805
|
+
break;
|
|
2806
|
+
case "JapaneseAddress":
|
|
2807
|
+
if (suffix === "PostalCode") {
|
|
2808
|
+
rules.push("'string'");
|
|
2809
|
+
rules.push("'max:8'");
|
|
2810
|
+
rules.push("'regex:/^\\d{3}-\\d{4}$/'");
|
|
2811
|
+
} else if (suffix === "PrefectureId") {
|
|
2812
|
+
rules.push("'integer'");
|
|
2813
|
+
rules.push("'between:1,47'");
|
|
2814
|
+
} else {
|
|
2815
|
+
rules.push("'string'");
|
|
2816
|
+
rules.push(`'max:${length}'`);
|
|
2817
|
+
}
|
|
2818
|
+
break;
|
|
2819
|
+
case "JapaneseBankAccount":
|
|
2820
|
+
if (suffix === "BankCode") {
|
|
2821
|
+
rules.push("'string'");
|
|
2822
|
+
rules.push("'size:4'");
|
|
2823
|
+
rules.push("'regex:/^\\d{4}$/'");
|
|
2824
|
+
} else if (suffix === "BranchCode") {
|
|
2825
|
+
rules.push("'string'");
|
|
2826
|
+
rules.push("'size:3'");
|
|
2827
|
+
rules.push("'regex:/^\\d{3}$/'");
|
|
2828
|
+
} else if (suffix === "AccountType") {
|
|
2829
|
+
rules.push("'string'");
|
|
2830
|
+
rules.push("Rule::in(['1', '2', '4'])");
|
|
2831
|
+
} else if (suffix === "AccountNumber") {
|
|
2832
|
+
rules.push("'string'");
|
|
2833
|
+
rules.push("'max:7'");
|
|
2834
|
+
rules.push("'regex:/^\\d{1,7}$/'");
|
|
2835
|
+
} else if (suffix === "AccountHolder") {
|
|
2836
|
+
rules.push("'string'");
|
|
2837
|
+
rules.push(`'max:${length}'`);
|
|
2838
|
+
rules.push("'regex:/^[\\x{30A0}-\\x{30FF}\\x{3000}-\\x{303F}\\x{FF00}-\\x{FF9F}\\s]+$/u'");
|
|
2839
|
+
}
|
|
2840
|
+
break;
|
|
2841
|
+
default:
|
|
2842
|
+
if (sql?.sqlType === "TINYINT" || sql?.sqlType === "INT" || sql?.sqlType === "BIGINT") {
|
|
2843
|
+
rules.push("'integer'");
|
|
2844
|
+
if (sql?.unsigned) {
|
|
2845
|
+
rules.push("'min:0'");
|
|
2846
|
+
}
|
|
2847
|
+
} else {
|
|
2848
|
+
rules.push("'string'");
|
|
2849
|
+
rules.push(`'max:${length}'`);
|
|
2850
|
+
}
|
|
2851
|
+
break;
|
|
2852
|
+
}
|
|
2853
|
+
return rules;
|
|
2854
|
+
}
|
|
2740
2855
|
function expandCompoundTypeFields(propName, propDef, options) {
|
|
2741
2856
|
const typeDef = options.customTypes.get(propDef.type);
|
|
2742
2857
|
if (!typeDef || !typeDef.compound || !typeDef.expand) {
|
|
@@ -2750,18 +2865,18 @@ function expandCompoundTypeFields(propName, propDef, options) {
|
|
|
2750
2865
|
const suffixSnake = toSnakeCase(field.suffix);
|
|
2751
2866
|
const fieldName = `${snakeName}_${suffixSnake}`;
|
|
2752
2867
|
const fieldOverride = prop.fields?.[field.suffix];
|
|
2753
|
-
const
|
|
2868
|
+
const fieldDefNullable = field.sql?.nullable ?? false;
|
|
2869
|
+
const fieldNullable = fieldOverride?.nullable ?? fieldDefNullable ?? isNullable2;
|
|
2754
2870
|
const rules = [];
|
|
2755
2871
|
if (!fieldNullable) {
|
|
2756
2872
|
rules.push("'required'");
|
|
2757
2873
|
} else {
|
|
2758
2874
|
rules.push("'nullable'");
|
|
2759
2875
|
}
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
const
|
|
2763
|
-
|
|
2764
|
-
fields.push({ fieldName, rules });
|
|
2876
|
+
const typeRules = getCompoundFieldRules(propDef.type, field.suffix, field, fieldOverride);
|
|
2877
|
+
rules.push(...typeRules);
|
|
2878
|
+
const needsRuleImport = rules.some((r) => r.includes("Rule::"));
|
|
2879
|
+
fields.push({ fieldName, rules, needsRuleImport });
|
|
2765
2880
|
}
|
|
2766
2881
|
return fields;
|
|
2767
2882
|
}
|
|
@@ -2795,6 +2910,7 @@ function generateStoreRequestBase(schema, schemas, options) {
|
|
|
2795
2910
|
const expandedFields = expandCompoundTypeFields(propName, propDef, options);
|
|
2796
2911
|
if (expandedFields.length > 0) {
|
|
2797
2912
|
for (const field of expandedFields) {
|
|
2913
|
+
if (field.needsRuleImport) needsRuleImport = true;
|
|
2798
2914
|
rulesLines.push(` '${field.fieldName}' => [${field.rules.join(", ")}],`);
|
|
2799
2915
|
fieldList.push(field.fieldName);
|
|
2800
2916
|
attributeLines.push(` '${field.fieldName}' => '${escapePhpString2(field.fieldName)}',`);
|
|
@@ -2891,6 +3007,7 @@ function generateUpdateRequestBase(schema, schemas, options) {
|
|
|
2891
3007
|
const expandedFields = expandCompoundTypeFields(propName, propDef, options);
|
|
2892
3008
|
if (expandedFields.length > 0) {
|
|
2893
3009
|
for (const field of expandedFields) {
|
|
3010
|
+
if (field.needsRuleImport) needsRuleImport = true;
|
|
2894
3011
|
const updateRules = field.rules.map((r) => r === "'required'" ? "'sometimes'" : r);
|
|
2895
3012
|
rulesLines.push(` '${field.fieldName}' => [${updateRules.join(", ")}],`);
|
|
2896
3013
|
attributeLines.push(` '${field.fieldName}' => '${escapePhpString2(field.fieldName)}',`);
|
|
@@ -2898,7 +3015,7 @@ function generateUpdateRequestBase(schema, schemas, options) {
|
|
|
2898
3015
|
continue;
|
|
2899
3016
|
}
|
|
2900
3017
|
const rules = generateUpdateRules(propName, propDef, schema, schemas, options);
|
|
2901
|
-
if (rules.some((r) => r.includes("Rule::")
|
|
3018
|
+
if (rules.some((r) => r.includes("Rule::"))) needsRuleImport = true;
|
|
2902
3019
|
rulesLines.push(` '${snakeName}' => [${rules.join(", ")}],`);
|
|
2903
3020
|
const displayName = getDisplayName(propDef.displayName, options.locale, propName);
|
|
2904
3021
|
attributeLines.push(` '${snakeName}' => '${escapePhpString2(displayName)}',`);
|
|
@@ -3124,6 +3241,230 @@ function getRequestPath(request) {
|
|
|
3124
3241
|
return request.path;
|
|
3125
3242
|
}
|
|
3126
3243
|
|
|
3244
|
+
// src/resource/generator.ts
|
|
3245
|
+
import "@famgia/omnify-types";
|
|
3246
|
+
var DEFAULT_OPTIONS3 = {
|
|
3247
|
+
baseResourceNamespace: "App\\Http\\Resources\\OmnifyBase",
|
|
3248
|
+
resourceNamespace: "App\\Http\\Resources",
|
|
3249
|
+
baseResourcePath: "app/Http/Resources/OmnifyBase",
|
|
3250
|
+
resourcePath: "app/Http/Resources",
|
|
3251
|
+
customTypes: /* @__PURE__ */ new Map(),
|
|
3252
|
+
locale: "en"
|
|
3253
|
+
};
|
|
3254
|
+
var SKIP_FIELDS2 = /* @__PURE__ */ new Set([
|
|
3255
|
+
"password",
|
|
3256
|
+
"remember_token"
|
|
3257
|
+
]);
|
|
3258
|
+
function resolveOptions4(options) {
|
|
3259
|
+
return {
|
|
3260
|
+
baseResourceNamespace: options?.baseResourceNamespace ?? DEFAULT_OPTIONS3.baseResourceNamespace,
|
|
3261
|
+
resourceNamespace: options?.resourceNamespace ?? DEFAULT_OPTIONS3.resourceNamespace,
|
|
3262
|
+
baseResourcePath: options?.baseResourcePath ?? DEFAULT_OPTIONS3.baseResourcePath,
|
|
3263
|
+
resourcePath: options?.resourcePath ?? DEFAULT_OPTIONS3.resourcePath,
|
|
3264
|
+
customTypes: options?.customTypes ?? /* @__PURE__ */ new Map(),
|
|
3265
|
+
locale: options?.locale ?? DEFAULT_OPTIONS3.locale
|
|
3266
|
+
};
|
|
3267
|
+
}
|
|
3268
|
+
function getModuleName2(schema) {
|
|
3269
|
+
if (schema.module) {
|
|
3270
|
+
return schema.module;
|
|
3271
|
+
}
|
|
3272
|
+
return "";
|
|
3273
|
+
}
|
|
3274
|
+
function getPropertyOutput(propName, propDef, schemas, options) {
|
|
3275
|
+
const snakeName = toSnakeCase(propName);
|
|
3276
|
+
const lines = [];
|
|
3277
|
+
if (SKIP_FIELDS2.has(snakeName)) {
|
|
3278
|
+
return lines;
|
|
3279
|
+
}
|
|
3280
|
+
if (propDef.type === "Association") {
|
|
3281
|
+
const assoc = propDef;
|
|
3282
|
+
const targetClass = assoc.target ? toPascalCase(assoc.target) : "";
|
|
3283
|
+
switch (assoc.relation) {
|
|
3284
|
+
case "ManyToOne":
|
|
3285
|
+
case "OneToOne":
|
|
3286
|
+
lines.push(` '${snakeName}_id' => $this->${snakeName}_id,`);
|
|
3287
|
+
lines.push(` '${snakeName}' => $this->whenLoaded('${toCamelCase(propName)}', fn() => new ${targetClass}Resource($this->${toCamelCase(propName)})),`);
|
|
3288
|
+
break;
|
|
3289
|
+
case "OneToMany":
|
|
3290
|
+
case "ManyToMany":
|
|
3291
|
+
lines.push(` '${snakeName}' => $this->whenLoaded('${toCamelCase(propName)}', fn() => ${targetClass}Resource::collection($this->${toCamelCase(propName)})),`);
|
|
3292
|
+
break;
|
|
3293
|
+
case "MorphTo":
|
|
3294
|
+
lines.push(` '${snakeName}_type' => $this->${snakeName}_type,`);
|
|
3295
|
+
lines.push(` '${snakeName}_id' => $this->${snakeName}_id,`);
|
|
3296
|
+
lines.push(` '${snakeName}' => $this->whenLoaded('${toCamelCase(propName)}'),`);
|
|
3297
|
+
break;
|
|
3298
|
+
case "MorphOne":
|
|
3299
|
+
case "MorphMany":
|
|
3300
|
+
lines.push(` '${snakeName}' => $this->whenLoaded('${toCamelCase(propName)}', fn() => ${targetClass}Resource::collection($this->${toCamelCase(propName)})),`);
|
|
3301
|
+
break;
|
|
3302
|
+
}
|
|
3303
|
+
return lines;
|
|
3304
|
+
}
|
|
3305
|
+
const typeDef = options.customTypes.get(propDef.type);
|
|
3306
|
+
if (typeDef?.compound && typeDef.expand) {
|
|
3307
|
+
for (const field of typeDef.expand) {
|
|
3308
|
+
const suffixSnake = toSnakeCase(field.suffix);
|
|
3309
|
+
const fieldName = `${snakeName}_${suffixSnake}`;
|
|
3310
|
+
lines.push(` '${fieldName}' => $this->${fieldName},`);
|
|
3311
|
+
}
|
|
3312
|
+
if (typeDef.accessors) {
|
|
3313
|
+
for (const accessor of typeDef.accessors) {
|
|
3314
|
+
const accessorName = `${snakeName}_${toSnakeCase(accessor.name)}`;
|
|
3315
|
+
lines.push(` '${accessorName}' => $this->${accessorName},`);
|
|
3316
|
+
}
|
|
3317
|
+
}
|
|
3318
|
+
return lines;
|
|
3319
|
+
}
|
|
3320
|
+
lines.push(` '${snakeName}' => $this->${snakeName},`);
|
|
3321
|
+
return lines;
|
|
3322
|
+
}
|
|
3323
|
+
function generateResourceBase(schema, schemas, options) {
|
|
3324
|
+
const className = toPascalCase(schema.name);
|
|
3325
|
+
const module = getModuleName2(schema);
|
|
3326
|
+
const namespaceModule = module ? `\\${module}` : "";
|
|
3327
|
+
const namespace = `${options.baseResourceNamespace}${namespaceModule}`;
|
|
3328
|
+
const properties = schema.properties ?? {};
|
|
3329
|
+
const outputLines = [];
|
|
3330
|
+
const imports = /* @__PURE__ */ new Set();
|
|
3331
|
+
if (schema.options?.id !== false) {
|
|
3332
|
+
outputLines.push(` 'id' => $this->id,`);
|
|
3333
|
+
}
|
|
3334
|
+
for (const [propName, propDef] of Object.entries(properties)) {
|
|
3335
|
+
const lines = getPropertyOutput(propName, propDef, schemas, options);
|
|
3336
|
+
outputLines.push(...lines);
|
|
3337
|
+
if (propDef.type === "Association") {
|
|
3338
|
+
const assoc = propDef;
|
|
3339
|
+
if (assoc.target) {
|
|
3340
|
+
const targetModule = getModuleName2(schemas[assoc.target] ?? schema);
|
|
3341
|
+
const targetModuleNs = targetModule ? `\\${targetModule}` : "";
|
|
3342
|
+
imports.add(`use ${options.resourceNamespace}${targetModuleNs}\\${toPascalCase(assoc.target)}Resource;`);
|
|
3343
|
+
}
|
|
3344
|
+
}
|
|
3345
|
+
}
|
|
3346
|
+
if (schema.options?.timestamps !== false) {
|
|
3347
|
+
outputLines.push(` 'created_at' => $this->created_at?->toISOString(),`);
|
|
3348
|
+
outputLines.push(` 'updated_at' => $this->updated_at?->toISOString(),`);
|
|
3349
|
+
}
|
|
3350
|
+
if (schema.options?.softDelete) {
|
|
3351
|
+
outputLines.push(` 'deleted_at' => $this->deleted_at?->toISOString(),`);
|
|
3352
|
+
}
|
|
3353
|
+
const importLines = Array.from(imports).sort().join("\n");
|
|
3354
|
+
const importBlock = importLines ? `
|
|
3355
|
+
${importLines}` : "";
|
|
3356
|
+
const content = `<?php
|
|
3357
|
+
|
|
3358
|
+
/**
|
|
3359
|
+
* AUTO-GENERATED BY OMNIFY - DO NOT EDIT!
|
|
3360
|
+
*
|
|
3361
|
+
* This file is generated from Omnify schema: ${schema.name}
|
|
3362
|
+
* Re-run \`npx omnify generate\` to update.
|
|
3363
|
+
*
|
|
3364
|
+
* @generated
|
|
3365
|
+
*/
|
|
3366
|
+
|
|
3367
|
+
namespace ${namespace};
|
|
3368
|
+
|
|
3369
|
+
use Illuminate\\Http\\Request;
|
|
3370
|
+
use Illuminate\\Http\\Resources\\Json\\JsonResource;${importBlock}
|
|
3371
|
+
|
|
3372
|
+
class ${className}ResourceBase extends JsonResource
|
|
3373
|
+
{
|
|
3374
|
+
/**
|
|
3375
|
+
* Transform the resource into an array.
|
|
3376
|
+
*
|
|
3377
|
+
* @return array<string, mixed>
|
|
3378
|
+
*/
|
|
3379
|
+
protected function schemaArray(Request $request): array
|
|
3380
|
+
{
|
|
3381
|
+
return [
|
|
3382
|
+
${outputLines.join("\n")}
|
|
3383
|
+
];
|
|
3384
|
+
}
|
|
3385
|
+
}
|
|
3386
|
+
`;
|
|
3387
|
+
const modulePath = module ? `/${module}` : "";
|
|
3388
|
+
return {
|
|
3389
|
+
path: `${options.baseResourcePath}${modulePath}/${className}ResourceBase.php`,
|
|
3390
|
+
content,
|
|
3391
|
+
type: "base",
|
|
3392
|
+
overwrite: true,
|
|
3393
|
+
schemaName: schema.name,
|
|
3394
|
+
module
|
|
3395
|
+
};
|
|
3396
|
+
}
|
|
3397
|
+
function generateResource(schema, options) {
|
|
3398
|
+
const className = toPascalCase(schema.name);
|
|
3399
|
+
const module = getModuleName2(schema);
|
|
3400
|
+
const namespaceModule = module ? `\\${module}` : "";
|
|
3401
|
+
const namespace = `${options.resourceNamespace}${namespaceModule}`;
|
|
3402
|
+
const baseNamespace = `${options.baseResourceNamespace}${namespaceModule}`;
|
|
3403
|
+
const content = `<?php
|
|
3404
|
+
|
|
3405
|
+
/**
|
|
3406
|
+
* ${className} Resource
|
|
3407
|
+
*
|
|
3408
|
+
* SAFE TO EDIT - This file is never overwritten by Omnify.
|
|
3409
|
+
*/
|
|
3410
|
+
|
|
3411
|
+
namespace ${namespace};
|
|
3412
|
+
|
|
3413
|
+
use Illuminate\\Http\\Request;
|
|
3414
|
+
use ${baseNamespace}\\${className}ResourceBase;
|
|
3415
|
+
|
|
3416
|
+
class ${className}Resource extends ${className}ResourceBase
|
|
3417
|
+
{
|
|
3418
|
+
/**
|
|
3419
|
+
* Transform the resource into an array.
|
|
3420
|
+
*
|
|
3421
|
+
* @return array<string, mixed>
|
|
3422
|
+
*/
|
|
3423
|
+
public function toArray(Request $request): array
|
|
3424
|
+
{
|
|
3425
|
+
return array_merge($this->schemaArray($request), [
|
|
3426
|
+
// Custom fields here
|
|
3427
|
+
]);
|
|
3428
|
+
}
|
|
3429
|
+
|
|
3430
|
+
/**
|
|
3431
|
+
* Get additional data that should be returned with the resource array.
|
|
3432
|
+
*
|
|
3433
|
+
* @return array<string, mixed>
|
|
3434
|
+
*/
|
|
3435
|
+
public function with(Request $request): array
|
|
3436
|
+
{
|
|
3437
|
+
return [
|
|
3438
|
+
// Additional metadata here
|
|
3439
|
+
];
|
|
3440
|
+
}
|
|
3441
|
+
}
|
|
3442
|
+
`;
|
|
3443
|
+
const modulePath = module ? `/${module}` : "";
|
|
3444
|
+
return {
|
|
3445
|
+
path: `${options.resourcePath}${modulePath}/${className}Resource.php`,
|
|
3446
|
+
content,
|
|
3447
|
+
type: "user",
|
|
3448
|
+
overwrite: false,
|
|
3449
|
+
schemaName: schema.name,
|
|
3450
|
+
module
|
|
3451
|
+
};
|
|
3452
|
+
}
|
|
3453
|
+
function generateResources(schemas, options) {
|
|
3454
|
+
const resolved = resolveOptions4(options);
|
|
3455
|
+
const resources = [];
|
|
3456
|
+
for (const schema of Object.values(schemas)) {
|
|
3457
|
+
if (schema.kind === "enum") continue;
|
|
3458
|
+
if (schema.options?.hidden === true) continue;
|
|
3459
|
+
resources.push(generateResourceBase(schema, schemas, resolved));
|
|
3460
|
+
resources.push(generateResource(schema, resolved));
|
|
3461
|
+
}
|
|
3462
|
+
return resources;
|
|
3463
|
+
}
|
|
3464
|
+
function getResourcePath(resource) {
|
|
3465
|
+
return resource.path;
|
|
3466
|
+
}
|
|
3467
|
+
|
|
3127
3468
|
// src/plugin.ts
|
|
3128
3469
|
function getExistingMigrationTables(migrationsDir) {
|
|
3129
3470
|
const existingTables = /* @__PURE__ */ new Set();
|
|
@@ -3232,10 +3573,34 @@ var LARAVEL_CONFIG_SCHEMA = {
|
|
|
3232
3573
|
description: "Generate Laravel FormRequest classes for validation",
|
|
3233
3574
|
default: false,
|
|
3234
3575
|
group: "options"
|
|
3576
|
+
},
|
|
3577
|
+
{
|
|
3578
|
+
key: "resourcesPath",
|
|
3579
|
+
type: "path",
|
|
3580
|
+
label: "Resources Path",
|
|
3581
|
+
description: "Directory for user-editable API Resource files",
|
|
3582
|
+
default: "app/Http/Resources",
|
|
3583
|
+
group: "output"
|
|
3584
|
+
},
|
|
3585
|
+
{
|
|
3586
|
+
key: "baseResourcesPath",
|
|
3587
|
+
type: "path",
|
|
3588
|
+
label: "Base Resources Path",
|
|
3589
|
+
description: "Directory for auto-generated base API Resource files",
|
|
3590
|
+
default: "app/Http/Resources/OmnifyBase",
|
|
3591
|
+
group: "output"
|
|
3592
|
+
},
|
|
3593
|
+
{
|
|
3594
|
+
key: "generateResources",
|
|
3595
|
+
type: "boolean",
|
|
3596
|
+
label: "Generate Resources",
|
|
3597
|
+
description: "Generate Laravel API Resource classes",
|
|
3598
|
+
default: false,
|
|
3599
|
+
group: "options"
|
|
3235
3600
|
}
|
|
3236
3601
|
]
|
|
3237
3602
|
};
|
|
3238
|
-
function
|
|
3603
|
+
function resolveOptions5(options) {
|
|
3239
3604
|
return {
|
|
3240
3605
|
migrationsPath: options?.migrationsPath ?? "database/migrations/omnify",
|
|
3241
3606
|
modelsPath: options?.modelsPath ?? "app/Models",
|
|
@@ -3253,11 +3618,16 @@ function resolveOptions4(options) {
|
|
|
3253
3618
|
baseRequestsPath: options?.baseRequestsPath ?? "app/Http/Requests/OmnifyBase",
|
|
3254
3619
|
requestNamespace: options?.requestNamespace ?? "App\\Http\\Requests",
|
|
3255
3620
|
baseRequestNamespace: options?.baseRequestNamespace ?? "App\\Http\\Requests\\OmnifyBase",
|
|
3256
|
-
generateRequests: options?.generateRequests ?? false
|
|
3621
|
+
generateRequests: options?.generateRequests ?? false,
|
|
3622
|
+
resourcesPath: options?.resourcesPath ?? "app/Http/Resources",
|
|
3623
|
+
baseResourcesPath: options?.baseResourcesPath ?? "app/Http/Resources/OmnifyBase",
|
|
3624
|
+
resourceNamespace: options?.resourceNamespace ?? "App\\Http\\Resources",
|
|
3625
|
+
baseResourceNamespace: options?.baseResourceNamespace ?? "App\\Http\\Resources\\OmnifyBase",
|
|
3626
|
+
generateResources: options?.generateResources ?? false
|
|
3257
3627
|
};
|
|
3258
3628
|
}
|
|
3259
3629
|
function laravelPlugin(options) {
|
|
3260
|
-
const resolved =
|
|
3630
|
+
const resolved = resolveOptions5(options);
|
|
3261
3631
|
const migrationGenerator = {
|
|
3262
3632
|
name: "laravel-migrations",
|
|
3263
3633
|
description: "Generate Laravel migration files",
|
|
@@ -3456,6 +3826,32 @@ function laravelPlugin(options) {
|
|
|
3456
3826
|
}));
|
|
3457
3827
|
}
|
|
3458
3828
|
};
|
|
3829
|
+
const resourceGenerator = {
|
|
3830
|
+
name: "laravel-resources",
|
|
3831
|
+
description: "Generate Laravel API Resource classes",
|
|
3832
|
+
generate: async (ctx) => {
|
|
3833
|
+
const resourceOptions = {
|
|
3834
|
+
resourceNamespace: resolved.resourceNamespace,
|
|
3835
|
+
baseResourceNamespace: resolved.baseResourceNamespace,
|
|
3836
|
+
resourcePath: resolved.resourcesPath,
|
|
3837
|
+
baseResourcePath: resolved.baseResourcesPath,
|
|
3838
|
+
customTypes: ctx.customTypes
|
|
3839
|
+
};
|
|
3840
|
+
const resources = generateResources(ctx.schemas, resourceOptions);
|
|
3841
|
+
return resources.map((resource) => ({
|
|
3842
|
+
path: getResourcePath(resource),
|
|
3843
|
+
content: resource.content,
|
|
3844
|
+
type: "other",
|
|
3845
|
+
// Skip writing user resources if they already exist
|
|
3846
|
+
skipIfExists: !resource.overwrite,
|
|
3847
|
+
metadata: {
|
|
3848
|
+
resourceType: resource.type,
|
|
3849
|
+
schemaName: resource.schemaName,
|
|
3850
|
+
module: resource.module
|
|
3851
|
+
}
|
|
3852
|
+
}));
|
|
3853
|
+
}
|
|
3854
|
+
};
|
|
3459
3855
|
const generators = [migrationGenerator];
|
|
3460
3856
|
if (resolved.generateModels) {
|
|
3461
3857
|
generators.push(modelGenerator);
|
|
@@ -3466,6 +3862,9 @@ function laravelPlugin(options) {
|
|
|
3466
3862
|
if (resolved.generateRequests) {
|
|
3467
3863
|
generators.push(requestGenerator);
|
|
3468
3864
|
}
|
|
3865
|
+
if (resolved.generateResources) {
|
|
3866
|
+
generators.push(resourceGenerator);
|
|
3867
|
+
}
|
|
3469
3868
|
return {
|
|
3470
3869
|
name: "@famgia/omnify-laravel",
|
|
3471
3870
|
version: "0.0.14",
|
|
@@ -3501,4 +3900,4 @@ export {
|
|
|
3501
3900
|
getFactoryPath,
|
|
3502
3901
|
laravelPlugin
|
|
3503
3902
|
};
|
|
3504
|
-
//# sourceMappingURL=chunk-
|
|
3903
|
+
//# sourceMappingURL=chunk-FR6LGETT.js.map
|