@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
package/dist/index.js
CHANGED
package/dist/plugin.cjs
CHANGED
|
@@ -2624,6 +2624,33 @@ function generateStoreRules(propName, propDef, schema, schemas, options) {
|
|
|
2624
2624
|
}
|
|
2625
2625
|
}
|
|
2626
2626
|
break;
|
|
2627
|
+
default:
|
|
2628
|
+
const customType = options.customTypes.get(propDef.type);
|
|
2629
|
+
if (customType && !customType.compound) {
|
|
2630
|
+
if (propDef.type === "JapanesePhone") {
|
|
2631
|
+
rules.push("'string'");
|
|
2632
|
+
rules.push("'max:15'");
|
|
2633
|
+
rules.push("'regex:/^\\d{2,4}-\\d{2,4}-\\d{4}$/'");
|
|
2634
|
+
} else if (propDef.type === "JapanesePostalCode") {
|
|
2635
|
+
rules.push("'string'");
|
|
2636
|
+
rules.push("'max:8'");
|
|
2637
|
+
rules.push("'regex:/^\\d{3}-\\d{4}$/'");
|
|
2638
|
+
} else {
|
|
2639
|
+
const sqlType = customType.sql?.sqlType ?? "VARCHAR";
|
|
2640
|
+
const sqlLength = customType.sql?.length ?? 255;
|
|
2641
|
+
if (sqlType === "VARCHAR" || sqlType === "TEXT") {
|
|
2642
|
+
rules.push("'string'");
|
|
2643
|
+
if (sqlType === "VARCHAR") {
|
|
2644
|
+
rules.push(`'max:${sqlLength}'`);
|
|
2645
|
+
}
|
|
2646
|
+
} else if (sqlType === "INT" || sqlType === "TINYINT" || sqlType === "BIGINT") {
|
|
2647
|
+
rules.push("'integer'");
|
|
2648
|
+
} else if (sqlType === "DECIMAL" || sqlType === "FLOAT") {
|
|
2649
|
+
rules.push("'numeric'");
|
|
2650
|
+
}
|
|
2651
|
+
}
|
|
2652
|
+
}
|
|
2653
|
+
break;
|
|
2627
2654
|
}
|
|
2628
2655
|
if (prop.unique === true) {
|
|
2629
2656
|
rules.push(`'unique:${tableName}'`);
|
|
@@ -2706,12 +2733,100 @@ function generateUpdateRules(propName, propDef, schema, schemas, options) {
|
|
|
2706
2733
|
}
|
|
2707
2734
|
}
|
|
2708
2735
|
break;
|
|
2736
|
+
default:
|
|
2737
|
+
const customType = options.customTypes.get(propDef.type);
|
|
2738
|
+
if (customType && !customType.compound) {
|
|
2739
|
+
if (propDef.type === "JapanesePhone") {
|
|
2740
|
+
rules.push("'string'");
|
|
2741
|
+
rules.push("'max:15'");
|
|
2742
|
+
rules.push("'regex:/^\\d{2,4}-\\d{2,4}-\\d{4}$/'");
|
|
2743
|
+
} else if (propDef.type === "JapanesePostalCode") {
|
|
2744
|
+
rules.push("'string'");
|
|
2745
|
+
rules.push("'max:8'");
|
|
2746
|
+
rules.push("'regex:/^\\d{3}-\\d{4}$/'");
|
|
2747
|
+
} else {
|
|
2748
|
+
const sqlType = customType.sql?.sqlType ?? "VARCHAR";
|
|
2749
|
+
const sqlLength = customType.sql?.length ?? 255;
|
|
2750
|
+
if (sqlType === "VARCHAR" || sqlType === "TEXT") {
|
|
2751
|
+
rules.push("'string'");
|
|
2752
|
+
if (sqlType === "VARCHAR") {
|
|
2753
|
+
rules.push(`'max:${sqlLength}'`);
|
|
2754
|
+
}
|
|
2755
|
+
} else if (sqlType === "INT" || sqlType === "TINYINT" || sqlType === "BIGINT") {
|
|
2756
|
+
rules.push("'integer'");
|
|
2757
|
+
} else if (sqlType === "DECIMAL" || sqlType === "FLOAT") {
|
|
2758
|
+
rules.push("'numeric'");
|
|
2759
|
+
}
|
|
2760
|
+
}
|
|
2761
|
+
}
|
|
2762
|
+
break;
|
|
2709
2763
|
}
|
|
2710
2764
|
if (prop.unique === true) {
|
|
2711
2765
|
rules.push(`Rule::unique('${tableName}')->ignore($this->route('${modelVar}'))`);
|
|
2712
2766
|
}
|
|
2713
2767
|
return rules;
|
|
2714
2768
|
}
|
|
2769
|
+
function getCompoundFieldRules(typeName, suffix, field, fieldOverride) {
|
|
2770
|
+
const rules = [];
|
|
2771
|
+
const sql = field.sql;
|
|
2772
|
+
const length = fieldOverride?.length ?? sql?.length ?? 255;
|
|
2773
|
+
switch (typeName) {
|
|
2774
|
+
case "JapaneseName":
|
|
2775
|
+
rules.push("'string'");
|
|
2776
|
+
rules.push(`'max:${length}'`);
|
|
2777
|
+
if (suffix === "KanaLastname" || suffix === "KanaFirstname") {
|
|
2778
|
+
rules.push("'regex:/^[\\x{30A0}-\\x{30FF}\\x{3000}-\\x{303F}\\x{FF00}-\\x{FF9F}\\s]+$/u'");
|
|
2779
|
+
}
|
|
2780
|
+
break;
|
|
2781
|
+
case "JapaneseAddress":
|
|
2782
|
+
if (suffix === "PostalCode") {
|
|
2783
|
+
rules.push("'string'");
|
|
2784
|
+
rules.push("'max:8'");
|
|
2785
|
+
rules.push("'regex:/^\\d{3}-\\d{4}$/'");
|
|
2786
|
+
} else if (suffix === "PrefectureId") {
|
|
2787
|
+
rules.push("'integer'");
|
|
2788
|
+
rules.push("'between:1,47'");
|
|
2789
|
+
} else {
|
|
2790
|
+
rules.push("'string'");
|
|
2791
|
+
rules.push(`'max:${length}'`);
|
|
2792
|
+
}
|
|
2793
|
+
break;
|
|
2794
|
+
case "JapaneseBankAccount":
|
|
2795
|
+
if (suffix === "BankCode") {
|
|
2796
|
+
rules.push("'string'");
|
|
2797
|
+
rules.push("'size:4'");
|
|
2798
|
+
rules.push("'regex:/^\\d{4}$/'");
|
|
2799
|
+
} else if (suffix === "BranchCode") {
|
|
2800
|
+
rules.push("'string'");
|
|
2801
|
+
rules.push("'size:3'");
|
|
2802
|
+
rules.push("'regex:/^\\d{3}$/'");
|
|
2803
|
+
} else if (suffix === "AccountType") {
|
|
2804
|
+
rules.push("'string'");
|
|
2805
|
+
rules.push("Rule::in(['1', '2', '4'])");
|
|
2806
|
+
} else if (suffix === "AccountNumber") {
|
|
2807
|
+
rules.push("'string'");
|
|
2808
|
+
rules.push("'max:7'");
|
|
2809
|
+
rules.push("'regex:/^\\d{1,7}$/'");
|
|
2810
|
+
} else if (suffix === "AccountHolder") {
|
|
2811
|
+
rules.push("'string'");
|
|
2812
|
+
rules.push(`'max:${length}'`);
|
|
2813
|
+
rules.push("'regex:/^[\\x{30A0}-\\x{30FF}\\x{3000}-\\x{303F}\\x{FF00}-\\x{FF9F}\\s]+$/u'");
|
|
2814
|
+
}
|
|
2815
|
+
break;
|
|
2816
|
+
default:
|
|
2817
|
+
if (sql?.sqlType === "TINYINT" || sql?.sqlType === "INT" || sql?.sqlType === "BIGINT") {
|
|
2818
|
+
rules.push("'integer'");
|
|
2819
|
+
if (sql?.unsigned) {
|
|
2820
|
+
rules.push("'min:0'");
|
|
2821
|
+
}
|
|
2822
|
+
} else {
|
|
2823
|
+
rules.push("'string'");
|
|
2824
|
+
rules.push(`'max:${length}'`);
|
|
2825
|
+
}
|
|
2826
|
+
break;
|
|
2827
|
+
}
|
|
2828
|
+
return rules;
|
|
2829
|
+
}
|
|
2715
2830
|
function expandCompoundTypeFields(propName, propDef, options) {
|
|
2716
2831
|
const typeDef = options.customTypes.get(propDef.type);
|
|
2717
2832
|
if (!typeDef || !typeDef.compound || !typeDef.expand) {
|
|
@@ -2725,18 +2840,18 @@ function expandCompoundTypeFields(propName, propDef, options) {
|
|
|
2725
2840
|
const suffixSnake = toSnakeCase(field.suffix);
|
|
2726
2841
|
const fieldName = `${snakeName}_${suffixSnake}`;
|
|
2727
2842
|
const fieldOverride = prop.fields?.[field.suffix];
|
|
2728
|
-
const
|
|
2843
|
+
const fieldDefNullable = field.sql?.nullable ?? false;
|
|
2844
|
+
const fieldNullable = fieldOverride?.nullable ?? fieldDefNullable ?? isNullable2;
|
|
2729
2845
|
const rules = [];
|
|
2730
2846
|
if (!fieldNullable) {
|
|
2731
2847
|
rules.push("'required'");
|
|
2732
2848
|
} else {
|
|
2733
2849
|
rules.push("'nullable'");
|
|
2734
2850
|
}
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
const
|
|
2738
|
-
|
|
2739
|
-
fields.push({ fieldName, rules });
|
|
2851
|
+
const typeRules = getCompoundFieldRules(propDef.type, field.suffix, field, fieldOverride);
|
|
2852
|
+
rules.push(...typeRules);
|
|
2853
|
+
const needsRuleImport = rules.some((r) => r.includes("Rule::"));
|
|
2854
|
+
fields.push({ fieldName, rules, needsRuleImport });
|
|
2740
2855
|
}
|
|
2741
2856
|
return fields;
|
|
2742
2857
|
}
|
|
@@ -2770,6 +2885,7 @@ function generateStoreRequestBase(schema, schemas, options) {
|
|
|
2770
2885
|
const expandedFields = expandCompoundTypeFields(propName, propDef, options);
|
|
2771
2886
|
if (expandedFields.length > 0) {
|
|
2772
2887
|
for (const field of expandedFields) {
|
|
2888
|
+
if (field.needsRuleImport) needsRuleImport = true;
|
|
2773
2889
|
rulesLines.push(` '${field.fieldName}' => [${field.rules.join(", ")}],`);
|
|
2774
2890
|
fieldList.push(field.fieldName);
|
|
2775
2891
|
attributeLines.push(` '${field.fieldName}' => '${escapePhpString2(field.fieldName)}',`);
|
|
@@ -2866,6 +2982,7 @@ function generateUpdateRequestBase(schema, schemas, options) {
|
|
|
2866
2982
|
const expandedFields = expandCompoundTypeFields(propName, propDef, options);
|
|
2867
2983
|
if (expandedFields.length > 0) {
|
|
2868
2984
|
for (const field of expandedFields) {
|
|
2985
|
+
if (field.needsRuleImport) needsRuleImport = true;
|
|
2869
2986
|
const updateRules = field.rules.map((r) => r === "'required'" ? "'sometimes'" : r);
|
|
2870
2987
|
rulesLines.push(` '${field.fieldName}' => [${updateRules.join(", ")}],`);
|
|
2871
2988
|
attributeLines.push(` '${field.fieldName}' => '${escapePhpString2(field.fieldName)}',`);
|
|
@@ -2873,7 +2990,7 @@ function generateUpdateRequestBase(schema, schemas, options) {
|
|
|
2873
2990
|
continue;
|
|
2874
2991
|
}
|
|
2875
2992
|
const rules = generateUpdateRules(propName, propDef, schema, schemas, options);
|
|
2876
|
-
if (rules.some((r) => r.includes("Rule::")
|
|
2993
|
+
if (rules.some((r) => r.includes("Rule::"))) needsRuleImport = true;
|
|
2877
2994
|
rulesLines.push(` '${snakeName}' => [${rules.join(", ")}],`);
|
|
2878
2995
|
const displayName = getDisplayName(propDef.displayName, options.locale, propName);
|
|
2879
2996
|
attributeLines.push(` '${snakeName}' => '${escapePhpString2(displayName)}',`);
|
|
@@ -3099,6 +3216,230 @@ function getRequestPath(request) {
|
|
|
3099
3216
|
return request.path;
|
|
3100
3217
|
}
|
|
3101
3218
|
|
|
3219
|
+
// src/resource/generator.ts
|
|
3220
|
+
var import_omnify_types4 = require("@famgia/omnify-types");
|
|
3221
|
+
var DEFAULT_OPTIONS3 = {
|
|
3222
|
+
baseResourceNamespace: "App\\Http\\Resources\\OmnifyBase",
|
|
3223
|
+
resourceNamespace: "App\\Http\\Resources",
|
|
3224
|
+
baseResourcePath: "app/Http/Resources/OmnifyBase",
|
|
3225
|
+
resourcePath: "app/Http/Resources",
|
|
3226
|
+
customTypes: /* @__PURE__ */ new Map(),
|
|
3227
|
+
locale: "en"
|
|
3228
|
+
};
|
|
3229
|
+
var SKIP_FIELDS2 = /* @__PURE__ */ new Set([
|
|
3230
|
+
"password",
|
|
3231
|
+
"remember_token"
|
|
3232
|
+
]);
|
|
3233
|
+
function resolveOptions4(options) {
|
|
3234
|
+
return {
|
|
3235
|
+
baseResourceNamespace: options?.baseResourceNamespace ?? DEFAULT_OPTIONS3.baseResourceNamespace,
|
|
3236
|
+
resourceNamespace: options?.resourceNamespace ?? DEFAULT_OPTIONS3.resourceNamespace,
|
|
3237
|
+
baseResourcePath: options?.baseResourcePath ?? DEFAULT_OPTIONS3.baseResourcePath,
|
|
3238
|
+
resourcePath: options?.resourcePath ?? DEFAULT_OPTIONS3.resourcePath,
|
|
3239
|
+
customTypes: options?.customTypes ?? /* @__PURE__ */ new Map(),
|
|
3240
|
+
locale: options?.locale ?? DEFAULT_OPTIONS3.locale
|
|
3241
|
+
};
|
|
3242
|
+
}
|
|
3243
|
+
function getModuleName2(schema) {
|
|
3244
|
+
if (schema.module) {
|
|
3245
|
+
return schema.module;
|
|
3246
|
+
}
|
|
3247
|
+
return "";
|
|
3248
|
+
}
|
|
3249
|
+
function getPropertyOutput(propName, propDef, schemas, options) {
|
|
3250
|
+
const snakeName = toSnakeCase(propName);
|
|
3251
|
+
const lines = [];
|
|
3252
|
+
if (SKIP_FIELDS2.has(snakeName)) {
|
|
3253
|
+
return lines;
|
|
3254
|
+
}
|
|
3255
|
+
if (propDef.type === "Association") {
|
|
3256
|
+
const assoc = propDef;
|
|
3257
|
+
const targetClass = assoc.target ? toPascalCase(assoc.target) : "";
|
|
3258
|
+
switch (assoc.relation) {
|
|
3259
|
+
case "ManyToOne":
|
|
3260
|
+
case "OneToOne":
|
|
3261
|
+
lines.push(` '${snakeName}_id' => $this->${snakeName}_id,`);
|
|
3262
|
+
lines.push(` '${snakeName}' => $this->whenLoaded('${toCamelCase(propName)}', fn() => new ${targetClass}Resource($this->${toCamelCase(propName)})),`);
|
|
3263
|
+
break;
|
|
3264
|
+
case "OneToMany":
|
|
3265
|
+
case "ManyToMany":
|
|
3266
|
+
lines.push(` '${snakeName}' => $this->whenLoaded('${toCamelCase(propName)}', fn() => ${targetClass}Resource::collection($this->${toCamelCase(propName)})),`);
|
|
3267
|
+
break;
|
|
3268
|
+
case "MorphTo":
|
|
3269
|
+
lines.push(` '${snakeName}_type' => $this->${snakeName}_type,`);
|
|
3270
|
+
lines.push(` '${snakeName}_id' => $this->${snakeName}_id,`);
|
|
3271
|
+
lines.push(` '${snakeName}' => $this->whenLoaded('${toCamelCase(propName)}'),`);
|
|
3272
|
+
break;
|
|
3273
|
+
case "MorphOne":
|
|
3274
|
+
case "MorphMany":
|
|
3275
|
+
lines.push(` '${snakeName}' => $this->whenLoaded('${toCamelCase(propName)}', fn() => ${targetClass}Resource::collection($this->${toCamelCase(propName)})),`);
|
|
3276
|
+
break;
|
|
3277
|
+
}
|
|
3278
|
+
return lines;
|
|
3279
|
+
}
|
|
3280
|
+
const typeDef = options.customTypes.get(propDef.type);
|
|
3281
|
+
if (typeDef?.compound && typeDef.expand) {
|
|
3282
|
+
for (const field of typeDef.expand) {
|
|
3283
|
+
const suffixSnake = toSnakeCase(field.suffix);
|
|
3284
|
+
const fieldName = `${snakeName}_${suffixSnake}`;
|
|
3285
|
+
lines.push(` '${fieldName}' => $this->${fieldName},`);
|
|
3286
|
+
}
|
|
3287
|
+
if (typeDef.accessors) {
|
|
3288
|
+
for (const accessor of typeDef.accessors) {
|
|
3289
|
+
const accessorName = `${snakeName}_${toSnakeCase(accessor.name)}`;
|
|
3290
|
+
lines.push(` '${accessorName}' => $this->${accessorName},`);
|
|
3291
|
+
}
|
|
3292
|
+
}
|
|
3293
|
+
return lines;
|
|
3294
|
+
}
|
|
3295
|
+
lines.push(` '${snakeName}' => $this->${snakeName},`);
|
|
3296
|
+
return lines;
|
|
3297
|
+
}
|
|
3298
|
+
function generateResourceBase(schema, schemas, options) {
|
|
3299
|
+
const className = toPascalCase(schema.name);
|
|
3300
|
+
const module2 = getModuleName2(schema);
|
|
3301
|
+
const namespaceModule = module2 ? `\\${module2}` : "";
|
|
3302
|
+
const namespace = `${options.baseResourceNamespace}${namespaceModule}`;
|
|
3303
|
+
const properties = schema.properties ?? {};
|
|
3304
|
+
const outputLines = [];
|
|
3305
|
+
const imports = /* @__PURE__ */ new Set();
|
|
3306
|
+
if (schema.options?.id !== false) {
|
|
3307
|
+
outputLines.push(` 'id' => $this->id,`);
|
|
3308
|
+
}
|
|
3309
|
+
for (const [propName, propDef] of Object.entries(properties)) {
|
|
3310
|
+
const lines = getPropertyOutput(propName, propDef, schemas, options);
|
|
3311
|
+
outputLines.push(...lines);
|
|
3312
|
+
if (propDef.type === "Association") {
|
|
3313
|
+
const assoc = propDef;
|
|
3314
|
+
if (assoc.target) {
|
|
3315
|
+
const targetModule = getModuleName2(schemas[assoc.target] ?? schema);
|
|
3316
|
+
const targetModuleNs = targetModule ? `\\${targetModule}` : "";
|
|
3317
|
+
imports.add(`use ${options.resourceNamespace}${targetModuleNs}\\${toPascalCase(assoc.target)}Resource;`);
|
|
3318
|
+
}
|
|
3319
|
+
}
|
|
3320
|
+
}
|
|
3321
|
+
if (schema.options?.timestamps !== false) {
|
|
3322
|
+
outputLines.push(` 'created_at' => $this->created_at?->toISOString(),`);
|
|
3323
|
+
outputLines.push(` 'updated_at' => $this->updated_at?->toISOString(),`);
|
|
3324
|
+
}
|
|
3325
|
+
if (schema.options?.softDelete) {
|
|
3326
|
+
outputLines.push(` 'deleted_at' => $this->deleted_at?->toISOString(),`);
|
|
3327
|
+
}
|
|
3328
|
+
const importLines = Array.from(imports).sort().join("\n");
|
|
3329
|
+
const importBlock = importLines ? `
|
|
3330
|
+
${importLines}` : "";
|
|
3331
|
+
const content = `<?php
|
|
3332
|
+
|
|
3333
|
+
/**
|
|
3334
|
+
* AUTO-GENERATED BY OMNIFY - DO NOT EDIT!
|
|
3335
|
+
*
|
|
3336
|
+
* This file is generated from Omnify schema: ${schema.name}
|
|
3337
|
+
* Re-run \`npx omnify generate\` to update.
|
|
3338
|
+
*
|
|
3339
|
+
* @generated
|
|
3340
|
+
*/
|
|
3341
|
+
|
|
3342
|
+
namespace ${namespace};
|
|
3343
|
+
|
|
3344
|
+
use Illuminate\\Http\\Request;
|
|
3345
|
+
use Illuminate\\Http\\Resources\\Json\\JsonResource;${importBlock}
|
|
3346
|
+
|
|
3347
|
+
class ${className}ResourceBase extends JsonResource
|
|
3348
|
+
{
|
|
3349
|
+
/**
|
|
3350
|
+
* Transform the resource into an array.
|
|
3351
|
+
*
|
|
3352
|
+
* @return array<string, mixed>
|
|
3353
|
+
*/
|
|
3354
|
+
protected function schemaArray(Request $request): array
|
|
3355
|
+
{
|
|
3356
|
+
return [
|
|
3357
|
+
${outputLines.join("\n")}
|
|
3358
|
+
];
|
|
3359
|
+
}
|
|
3360
|
+
}
|
|
3361
|
+
`;
|
|
3362
|
+
const modulePath = module2 ? `/${module2}` : "";
|
|
3363
|
+
return {
|
|
3364
|
+
path: `${options.baseResourcePath}${modulePath}/${className}ResourceBase.php`,
|
|
3365
|
+
content,
|
|
3366
|
+
type: "base",
|
|
3367
|
+
overwrite: true,
|
|
3368
|
+
schemaName: schema.name,
|
|
3369
|
+
module: module2
|
|
3370
|
+
};
|
|
3371
|
+
}
|
|
3372
|
+
function generateResource(schema, options) {
|
|
3373
|
+
const className = toPascalCase(schema.name);
|
|
3374
|
+
const module2 = getModuleName2(schema);
|
|
3375
|
+
const namespaceModule = module2 ? `\\${module2}` : "";
|
|
3376
|
+
const namespace = `${options.resourceNamespace}${namespaceModule}`;
|
|
3377
|
+
const baseNamespace = `${options.baseResourceNamespace}${namespaceModule}`;
|
|
3378
|
+
const content = `<?php
|
|
3379
|
+
|
|
3380
|
+
/**
|
|
3381
|
+
* ${className} Resource
|
|
3382
|
+
*
|
|
3383
|
+
* SAFE TO EDIT - This file is never overwritten by Omnify.
|
|
3384
|
+
*/
|
|
3385
|
+
|
|
3386
|
+
namespace ${namespace};
|
|
3387
|
+
|
|
3388
|
+
use Illuminate\\Http\\Request;
|
|
3389
|
+
use ${baseNamespace}\\${className}ResourceBase;
|
|
3390
|
+
|
|
3391
|
+
class ${className}Resource extends ${className}ResourceBase
|
|
3392
|
+
{
|
|
3393
|
+
/**
|
|
3394
|
+
* Transform the resource into an array.
|
|
3395
|
+
*
|
|
3396
|
+
* @return array<string, mixed>
|
|
3397
|
+
*/
|
|
3398
|
+
public function toArray(Request $request): array
|
|
3399
|
+
{
|
|
3400
|
+
return array_merge($this->schemaArray($request), [
|
|
3401
|
+
// Custom fields here
|
|
3402
|
+
]);
|
|
3403
|
+
}
|
|
3404
|
+
|
|
3405
|
+
/**
|
|
3406
|
+
* Get additional data that should be returned with the resource array.
|
|
3407
|
+
*
|
|
3408
|
+
* @return array<string, mixed>
|
|
3409
|
+
*/
|
|
3410
|
+
public function with(Request $request): array
|
|
3411
|
+
{
|
|
3412
|
+
return [
|
|
3413
|
+
// Additional metadata here
|
|
3414
|
+
];
|
|
3415
|
+
}
|
|
3416
|
+
}
|
|
3417
|
+
`;
|
|
3418
|
+
const modulePath = module2 ? `/${module2}` : "";
|
|
3419
|
+
return {
|
|
3420
|
+
path: `${options.resourcePath}${modulePath}/${className}Resource.php`,
|
|
3421
|
+
content,
|
|
3422
|
+
type: "user",
|
|
3423
|
+
overwrite: false,
|
|
3424
|
+
schemaName: schema.name,
|
|
3425
|
+
module: module2
|
|
3426
|
+
};
|
|
3427
|
+
}
|
|
3428
|
+
function generateResources(schemas, options) {
|
|
3429
|
+
const resolved = resolveOptions4(options);
|
|
3430
|
+
const resources = [];
|
|
3431
|
+
for (const schema of Object.values(schemas)) {
|
|
3432
|
+
if (schema.kind === "enum") continue;
|
|
3433
|
+
if (schema.options?.hidden === true) continue;
|
|
3434
|
+
resources.push(generateResourceBase(schema, schemas, resolved));
|
|
3435
|
+
resources.push(generateResource(schema, resolved));
|
|
3436
|
+
}
|
|
3437
|
+
return resources;
|
|
3438
|
+
}
|
|
3439
|
+
function getResourcePath(resource) {
|
|
3440
|
+
return resource.path;
|
|
3441
|
+
}
|
|
3442
|
+
|
|
3102
3443
|
// src/plugin.ts
|
|
3103
3444
|
function getExistingMigrationTables(migrationsDir) {
|
|
3104
3445
|
const existingTables = /* @__PURE__ */ new Set();
|
|
@@ -3207,10 +3548,34 @@ var LARAVEL_CONFIG_SCHEMA = {
|
|
|
3207
3548
|
description: "Generate Laravel FormRequest classes for validation",
|
|
3208
3549
|
default: false,
|
|
3209
3550
|
group: "options"
|
|
3551
|
+
},
|
|
3552
|
+
{
|
|
3553
|
+
key: "resourcesPath",
|
|
3554
|
+
type: "path",
|
|
3555
|
+
label: "Resources Path",
|
|
3556
|
+
description: "Directory for user-editable API Resource files",
|
|
3557
|
+
default: "app/Http/Resources",
|
|
3558
|
+
group: "output"
|
|
3559
|
+
},
|
|
3560
|
+
{
|
|
3561
|
+
key: "baseResourcesPath",
|
|
3562
|
+
type: "path",
|
|
3563
|
+
label: "Base Resources Path",
|
|
3564
|
+
description: "Directory for auto-generated base API Resource files",
|
|
3565
|
+
default: "app/Http/Resources/OmnifyBase",
|
|
3566
|
+
group: "output"
|
|
3567
|
+
},
|
|
3568
|
+
{
|
|
3569
|
+
key: "generateResources",
|
|
3570
|
+
type: "boolean",
|
|
3571
|
+
label: "Generate Resources",
|
|
3572
|
+
description: "Generate Laravel API Resource classes",
|
|
3573
|
+
default: false,
|
|
3574
|
+
group: "options"
|
|
3210
3575
|
}
|
|
3211
3576
|
]
|
|
3212
3577
|
};
|
|
3213
|
-
function
|
|
3578
|
+
function resolveOptions5(options) {
|
|
3214
3579
|
return {
|
|
3215
3580
|
migrationsPath: options?.migrationsPath ?? "database/migrations/omnify",
|
|
3216
3581
|
modelsPath: options?.modelsPath ?? "app/Models",
|
|
@@ -3228,11 +3593,16 @@ function resolveOptions4(options) {
|
|
|
3228
3593
|
baseRequestsPath: options?.baseRequestsPath ?? "app/Http/Requests/OmnifyBase",
|
|
3229
3594
|
requestNamespace: options?.requestNamespace ?? "App\\Http\\Requests",
|
|
3230
3595
|
baseRequestNamespace: options?.baseRequestNamespace ?? "App\\Http\\Requests\\OmnifyBase",
|
|
3231
|
-
generateRequests: options?.generateRequests ?? false
|
|
3596
|
+
generateRequests: options?.generateRequests ?? false,
|
|
3597
|
+
resourcesPath: options?.resourcesPath ?? "app/Http/Resources",
|
|
3598
|
+
baseResourcesPath: options?.baseResourcesPath ?? "app/Http/Resources/OmnifyBase",
|
|
3599
|
+
resourceNamespace: options?.resourceNamespace ?? "App\\Http\\Resources",
|
|
3600
|
+
baseResourceNamespace: options?.baseResourceNamespace ?? "App\\Http\\Resources\\OmnifyBase",
|
|
3601
|
+
generateResources: options?.generateResources ?? false
|
|
3232
3602
|
};
|
|
3233
3603
|
}
|
|
3234
3604
|
function laravelPlugin(options) {
|
|
3235
|
-
const resolved =
|
|
3605
|
+
const resolved = resolveOptions5(options);
|
|
3236
3606
|
const migrationGenerator = {
|
|
3237
3607
|
name: "laravel-migrations",
|
|
3238
3608
|
description: "Generate Laravel migration files",
|
|
@@ -3431,6 +3801,32 @@ function laravelPlugin(options) {
|
|
|
3431
3801
|
}));
|
|
3432
3802
|
}
|
|
3433
3803
|
};
|
|
3804
|
+
const resourceGenerator = {
|
|
3805
|
+
name: "laravel-resources",
|
|
3806
|
+
description: "Generate Laravel API Resource classes",
|
|
3807
|
+
generate: async (ctx) => {
|
|
3808
|
+
const resourceOptions = {
|
|
3809
|
+
resourceNamespace: resolved.resourceNamespace,
|
|
3810
|
+
baseResourceNamespace: resolved.baseResourceNamespace,
|
|
3811
|
+
resourcePath: resolved.resourcesPath,
|
|
3812
|
+
baseResourcePath: resolved.baseResourcesPath,
|
|
3813
|
+
customTypes: ctx.customTypes
|
|
3814
|
+
};
|
|
3815
|
+
const resources = generateResources(ctx.schemas, resourceOptions);
|
|
3816
|
+
return resources.map((resource) => ({
|
|
3817
|
+
path: getResourcePath(resource),
|
|
3818
|
+
content: resource.content,
|
|
3819
|
+
type: "other",
|
|
3820
|
+
// Skip writing user resources if they already exist
|
|
3821
|
+
skipIfExists: !resource.overwrite,
|
|
3822
|
+
metadata: {
|
|
3823
|
+
resourceType: resource.type,
|
|
3824
|
+
schemaName: resource.schemaName,
|
|
3825
|
+
module: resource.module
|
|
3826
|
+
}
|
|
3827
|
+
}));
|
|
3828
|
+
}
|
|
3829
|
+
};
|
|
3434
3830
|
const generators = [migrationGenerator];
|
|
3435
3831
|
if (resolved.generateModels) {
|
|
3436
3832
|
generators.push(modelGenerator);
|
|
@@ -3441,6 +3837,9 @@ function laravelPlugin(options) {
|
|
|
3441
3837
|
if (resolved.generateRequests) {
|
|
3442
3838
|
generators.push(requestGenerator);
|
|
3443
3839
|
}
|
|
3840
|
+
if (resolved.generateResources) {
|
|
3841
|
+
generators.push(resourceGenerator);
|
|
3842
|
+
}
|
|
3444
3843
|
return {
|
|
3445
3844
|
name: "@famgia/omnify-laravel",
|
|
3446
3845
|
version: "0.0.14",
|