@omnifyjp/omnify 0.2.3 → 0.3.0
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/README.md +53 -20
- package/package.json +6 -6
- package/ts-dist/cli.js +108 -61
- package/ts-dist/php/base-model-generator.d.ts +7 -0
- package/ts-dist/php/base-model-generator.js +70 -0
- package/ts-dist/php/factory-generator.d.ts +7 -0
- package/ts-dist/php/factory-generator.js +95 -0
- package/ts-dist/php/faker-mapper.d.ts +12 -0
- package/ts-dist/php/faker-mapper.js +206 -0
- package/ts-dist/php/index.d.ts +18 -0
- package/ts-dist/php/index.js +40 -0
- package/ts-dist/php/locales-generator.d.ts +7 -0
- package/ts-dist/php/locales-generator.js +135 -0
- package/ts-dist/php/model-generator.d.ts +7 -0
- package/ts-dist/php/model-generator.js +396 -0
- package/ts-dist/php/naming-helper.d.ts +22 -0
- package/ts-dist/php/naming-helper.js +61 -0
- package/ts-dist/php/relation-builder.d.ts +12 -0
- package/ts-dist/php/relation-builder.js +147 -0
- package/ts-dist/php/request-generator.d.ts +7 -0
- package/ts-dist/php/request-generator.js +221 -0
- package/ts-dist/php/resource-generator.d.ts +7 -0
- package/ts-dist/php/resource-generator.js +178 -0
- package/ts-dist/php/schema-reader.d.ts +28 -0
- package/ts-dist/php/schema-reader.js +79 -0
- package/ts-dist/php/service-provider-generator.d.ts +7 -0
- package/ts-dist/php/service-provider-generator.js +64 -0
- package/ts-dist/php/trait-generator.d.ts +6 -0
- package/ts-dist/php/trait-generator.js +104 -0
- package/ts-dist/php/type-mapper.d.ts +25 -0
- package/ts-dist/php/type-mapper.js +217 -0
- package/ts-dist/php/types.d.ts +61 -0
- package/ts-dist/php/types.js +68 -0
- package/types/config.d.ts +50 -24
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Port of TraitGenerator.php — generates HasLocalizedDisplayName trait.
|
|
3
|
+
*/
|
|
4
|
+
import { baseFile } from './types.js';
|
|
5
|
+
/** Generate the HasLocalizedDisplayName trait. */
|
|
6
|
+
export function generateTrait(config) {
|
|
7
|
+
const baseNamespace = config.models.baseNamespace;
|
|
8
|
+
const content = `<?php
|
|
9
|
+
|
|
10
|
+
namespace ${baseNamespace}\\Traits;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Trait for localized display names.
|
|
14
|
+
* Uses Laravel's app()->getLocale() for locale resolution.
|
|
15
|
+
*
|
|
16
|
+
* DO NOT EDIT - This file is auto-generated by Omnify.
|
|
17
|
+
* Any changes will be overwritten on next generation.
|
|
18
|
+
*
|
|
19
|
+
* @generated by omnify
|
|
20
|
+
*/
|
|
21
|
+
trait HasLocalizedDisplayName
|
|
22
|
+
{
|
|
23
|
+
/**
|
|
24
|
+
* Get the localized display name for this model.
|
|
25
|
+
*
|
|
26
|
+
* @param string|null $locale Locale code (defaults to app locale)
|
|
27
|
+
* @return string
|
|
28
|
+
*/
|
|
29
|
+
public static function displayName(?string $locale = null): string
|
|
30
|
+
{
|
|
31
|
+
$locale = $locale ?? app()->getLocale();
|
|
32
|
+
$displayNames = static::$localizedDisplayNames ?? [];
|
|
33
|
+
|
|
34
|
+
return $displayNames[$locale]
|
|
35
|
+
?? $displayNames[config('app.fallback_locale', 'en')]
|
|
36
|
+
?? $displayNames[array_key_first($displayNames) ?? 'en']
|
|
37
|
+
?? class_basename(static::class);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Get all localized display names for this model.
|
|
42
|
+
*
|
|
43
|
+
* @return array<string, string>
|
|
44
|
+
*/
|
|
45
|
+
public static function allDisplayNames(): array
|
|
46
|
+
{
|
|
47
|
+
return static::$localizedDisplayNames ?? [];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Get the localized display name for a property.
|
|
52
|
+
*
|
|
53
|
+
* @param string $property Property name
|
|
54
|
+
* @param string|null $locale Locale code (defaults to app locale)
|
|
55
|
+
* @return string
|
|
56
|
+
*/
|
|
57
|
+
public static function propertyDisplayName(string $property, ?string $locale = null): string
|
|
58
|
+
{
|
|
59
|
+
$locale = $locale ?? app()->getLocale();
|
|
60
|
+
$displayNames = static::$localizedPropertyDisplayNames[$property] ?? [];
|
|
61
|
+
|
|
62
|
+
return $displayNames[$locale]
|
|
63
|
+
?? $displayNames[config('app.fallback_locale', 'en')]
|
|
64
|
+
?? $displayNames[array_key_first($displayNames) ?? 'en']
|
|
65
|
+
?? $property;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Get all localized display names for a property.
|
|
70
|
+
*
|
|
71
|
+
* @param string $property Property name
|
|
72
|
+
* @return array<string, string>
|
|
73
|
+
*/
|
|
74
|
+
public static function allPropertyDisplayNames(string $property): array
|
|
75
|
+
{
|
|
76
|
+
return static::$localizedPropertyDisplayNames[$property] ?? [];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Get all property display names for a given locale.
|
|
81
|
+
*
|
|
82
|
+
* @param string|null $locale Locale code (defaults to app locale)
|
|
83
|
+
* @return array<string, string>
|
|
84
|
+
*/
|
|
85
|
+
public static function allPropertyDisplayNamesForLocale(?string $locale = null): array
|
|
86
|
+
{
|
|
87
|
+
$locale = $locale ?? app()->getLocale();
|
|
88
|
+
$result = [];
|
|
89
|
+
|
|
90
|
+
foreach (static::$localizedPropertyDisplayNames ?? [] as $property => $displayNames) {
|
|
91
|
+
$result[$property] = $displayNames[$locale]
|
|
92
|
+
?? $displayNames[config('app.fallback_locale', 'en')]
|
|
93
|
+
?? $displayNames[array_key_first($displayNames) ?? 'en']
|
|
94
|
+
?? $property;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return $result;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
`;
|
|
101
|
+
return [
|
|
102
|
+
baseFile(`${config.models.basePath}/Traits/HasLocalizedDisplayName.php`, content),
|
|
103
|
+
];
|
|
104
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Port of TypeMapper.php — type mappings for PHP casts, rules, resources.
|
|
3
|
+
*/
|
|
4
|
+
type Rule = string | ['rule_in', string[]] | ['rule_unique_ignore', string, string];
|
|
5
|
+
/** Map Omnify property type to PHP cast. */
|
|
6
|
+
export declare function toCast(type: string, property?: Record<string, unknown>): string | null;
|
|
7
|
+
/** Map Omnify property type to PHP doc type. */
|
|
8
|
+
export declare function toPhpDocType(type: string, nullable?: boolean): string;
|
|
9
|
+
/** Generate validation rules for a property (Store request). */
|
|
10
|
+
export declare function toStoreRules(property: Record<string, unknown>, tableName: string): Rule[];
|
|
11
|
+
/** Generate validation rules for a property (Update request). */
|
|
12
|
+
export declare function toUpdateRules(property: Record<string, unknown>, tableName: string, modelRouteParam: string): Rule[];
|
|
13
|
+
/** Format validation rules as PHP code string. */
|
|
14
|
+
export declare function formatRules(rules: Rule[]): string;
|
|
15
|
+
/** Resolve enum values from property definition. */
|
|
16
|
+
export declare function resolveEnumValues(property: Record<string, unknown>): string[] | null;
|
|
17
|
+
/** Check if a property type should be hidden by default. */
|
|
18
|
+
export declare function isHiddenByDefault(type: string): boolean;
|
|
19
|
+
/** Check if a property needs a cast. */
|
|
20
|
+
export declare function needsCast(type: string): boolean;
|
|
21
|
+
/** Get the resource output expression for a property. */
|
|
22
|
+
export declare function toResourceExpression(fieldName: string, type: string): string;
|
|
23
|
+
/** Check if a rules array contains a Rule:: object. */
|
|
24
|
+
export declare function hasRuleObject(rules: Rule[]): boolean;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Port of TypeMapper.php — type mappings for PHP casts, rules, resources.
|
|
3
|
+
*/
|
|
4
|
+
import { toTableName } from './naming-helper.js';
|
|
5
|
+
/** Map Omnify property type to PHP cast. */
|
|
6
|
+
export function toCast(type, property = {}) {
|
|
7
|
+
switch (type) {
|
|
8
|
+
case 'Boolean': return 'boolean';
|
|
9
|
+
case 'Int':
|
|
10
|
+
case 'BigInt':
|
|
11
|
+
case 'TinyInt': return 'integer';
|
|
12
|
+
case 'Float': return 'float';
|
|
13
|
+
case 'Decimal': return `decimal:${property['scale'] ?? 2}`;
|
|
14
|
+
case 'Json': return 'array';
|
|
15
|
+
case 'Date': return 'date';
|
|
16
|
+
case 'DateTime':
|
|
17
|
+
case 'Timestamp': return 'datetime';
|
|
18
|
+
case 'Password': return 'hashed';
|
|
19
|
+
default: return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** Map Omnify property type to PHP doc type. */
|
|
23
|
+
export function toPhpDocType(type, nullable = false) {
|
|
24
|
+
let phpType;
|
|
25
|
+
switch (type) {
|
|
26
|
+
case 'String':
|
|
27
|
+
case 'Email':
|
|
28
|
+
case 'Password':
|
|
29
|
+
case 'Text':
|
|
30
|
+
case 'MediumText':
|
|
31
|
+
case 'LongText':
|
|
32
|
+
case 'Enum':
|
|
33
|
+
case 'EnumRef':
|
|
34
|
+
case 'Uuid':
|
|
35
|
+
case 'Slug':
|
|
36
|
+
case 'Url':
|
|
37
|
+
case 'Phone':
|
|
38
|
+
phpType = 'string';
|
|
39
|
+
break;
|
|
40
|
+
case 'Int':
|
|
41
|
+
case 'BigInt':
|
|
42
|
+
case 'TinyInt':
|
|
43
|
+
phpType = 'int';
|
|
44
|
+
break;
|
|
45
|
+
case 'Float':
|
|
46
|
+
case 'Decimal':
|
|
47
|
+
phpType = 'float';
|
|
48
|
+
break;
|
|
49
|
+
case 'Boolean':
|
|
50
|
+
phpType = 'bool';
|
|
51
|
+
break;
|
|
52
|
+
case 'Date':
|
|
53
|
+
case 'DateTime':
|
|
54
|
+
case 'Timestamp':
|
|
55
|
+
case 'Time':
|
|
56
|
+
phpType = 'mixed';
|
|
57
|
+
break;
|
|
58
|
+
case 'Json':
|
|
59
|
+
phpType = 'array';
|
|
60
|
+
break;
|
|
61
|
+
default:
|
|
62
|
+
phpType = 'mixed';
|
|
63
|
+
}
|
|
64
|
+
return nullable ? `${phpType}|null` : phpType;
|
|
65
|
+
}
|
|
66
|
+
/** Generate validation rules for a property (Store request). */
|
|
67
|
+
export function toStoreRules(property, tableName) {
|
|
68
|
+
const type = property['type'] ?? 'String';
|
|
69
|
+
const nullable = property['nullable'] ?? false;
|
|
70
|
+
const unique = property['unique'] ?? false;
|
|
71
|
+
const rules = [];
|
|
72
|
+
rules.push(nullable ? 'nullable' : 'required');
|
|
73
|
+
switch (type) {
|
|
74
|
+
case 'String':
|
|
75
|
+
case 'Slug':
|
|
76
|
+
case 'Url':
|
|
77
|
+
case 'Phone': {
|
|
78
|
+
rules.push('string');
|
|
79
|
+
const length = property['length'] ?? 255;
|
|
80
|
+
rules.push(`max:${length}`);
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
case 'Email':
|
|
84
|
+
rules.push('string', 'max:255', 'email');
|
|
85
|
+
if (unique)
|
|
86
|
+
rules.push(`unique:${tableName}`);
|
|
87
|
+
break;
|
|
88
|
+
case 'Password':
|
|
89
|
+
rules.push('string', 'max:255');
|
|
90
|
+
break;
|
|
91
|
+
case 'Text':
|
|
92
|
+
case 'MediumText':
|
|
93
|
+
case 'LongText':
|
|
94
|
+
rules.push('string');
|
|
95
|
+
break;
|
|
96
|
+
case 'Int':
|
|
97
|
+
case 'BigInt':
|
|
98
|
+
case 'TinyInt':
|
|
99
|
+
rules.push('integer');
|
|
100
|
+
break;
|
|
101
|
+
case 'Float':
|
|
102
|
+
case 'Decimal':
|
|
103
|
+
rules.push('numeric');
|
|
104
|
+
break;
|
|
105
|
+
case 'Boolean':
|
|
106
|
+
rules.push('boolean');
|
|
107
|
+
break;
|
|
108
|
+
case 'Date':
|
|
109
|
+
case 'DateTime':
|
|
110
|
+
case 'Timestamp':
|
|
111
|
+
case 'Time':
|
|
112
|
+
rules.push('date');
|
|
113
|
+
break;
|
|
114
|
+
case 'Json':
|
|
115
|
+
rules.push('array');
|
|
116
|
+
break;
|
|
117
|
+
case 'Uuid':
|
|
118
|
+
rules.push('string', 'uuid');
|
|
119
|
+
break;
|
|
120
|
+
case 'Enum': {
|
|
121
|
+
rules.push('string');
|
|
122
|
+
const enumValues = resolveEnumValues(property);
|
|
123
|
+
if (enumValues)
|
|
124
|
+
rules.push(['rule_in', enumValues]);
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
case 'EnumRef':
|
|
128
|
+
rules.push('string');
|
|
129
|
+
break;
|
|
130
|
+
case 'Association': {
|
|
131
|
+
const relation = property['relation'] ?? '';
|
|
132
|
+
if (relation === 'ManyToOne') {
|
|
133
|
+
rules.push('integer');
|
|
134
|
+
const target = property['target'] ?? '';
|
|
135
|
+
if (target)
|
|
136
|
+
rules.push(`exists:${toTableName(target)},id`);
|
|
137
|
+
}
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
default:
|
|
141
|
+
rules.push('string', 'max:255');
|
|
142
|
+
}
|
|
143
|
+
if (unique && type !== 'Email') {
|
|
144
|
+
rules.push(`unique:${tableName}`);
|
|
145
|
+
}
|
|
146
|
+
return rules;
|
|
147
|
+
}
|
|
148
|
+
/** Generate validation rules for a property (Update request). */
|
|
149
|
+
export function toUpdateRules(property, tableName, modelRouteParam) {
|
|
150
|
+
let rules = toStoreRules(property, tableName);
|
|
151
|
+
const unique = property['unique'] ?? false;
|
|
152
|
+
// Replace 'required' with 'sometimes'
|
|
153
|
+
rules = rules.map(r => r === 'required' ? 'sometimes' : r);
|
|
154
|
+
// Replace simple unique with Rule::unique()->ignore()
|
|
155
|
+
if (unique) {
|
|
156
|
+
rules = rules.filter(r => !(typeof r === 'string' && r === `unique:${tableName}`));
|
|
157
|
+
rules.push(['rule_unique_ignore', tableName, modelRouteParam]);
|
|
158
|
+
}
|
|
159
|
+
return rules;
|
|
160
|
+
}
|
|
161
|
+
/** Format validation rules as PHP code string. */
|
|
162
|
+
export function formatRules(rules) {
|
|
163
|
+
const parts = [];
|
|
164
|
+
for (const rule of rules) {
|
|
165
|
+
if (typeof rule === 'string') {
|
|
166
|
+
parts.push(`'${rule}'`);
|
|
167
|
+
}
|
|
168
|
+
else if (Array.isArray(rule)) {
|
|
169
|
+
if (rule[0] === 'rule_in') {
|
|
170
|
+
const values = rule[1].map(v => `'${v}'`).join(', ');
|
|
171
|
+
parts.push(`Rule::in([${values}])`);
|
|
172
|
+
}
|
|
173
|
+
else if (rule[0] === 'rule_unique_ignore') {
|
|
174
|
+
parts.push(`Rule::unique('${rule[1]}')->ignore($this->route('${rule[2]}'))`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return `[${parts.join(', ')}]`;
|
|
179
|
+
}
|
|
180
|
+
/** Resolve enum values from property definition. */
|
|
181
|
+
export function resolveEnumValues(property) {
|
|
182
|
+
const enumDef = property['enum'];
|
|
183
|
+
if (enumDef == null)
|
|
184
|
+
return null;
|
|
185
|
+
if (Array.isArray(enumDef)) {
|
|
186
|
+
const values = [];
|
|
187
|
+
for (const v of enumDef) {
|
|
188
|
+
if (typeof v === 'string')
|
|
189
|
+
values.push(v);
|
|
190
|
+
else if (typeof v === 'object' && v !== null && 'value' in v)
|
|
191
|
+
values.push(v.value);
|
|
192
|
+
}
|
|
193
|
+
return values.length > 0 ? values : null;
|
|
194
|
+
}
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
/** Check if a property type should be hidden by default. */
|
|
198
|
+
export function isHiddenByDefault(type) {
|
|
199
|
+
return type === 'Password';
|
|
200
|
+
}
|
|
201
|
+
/** Check if a property needs a cast. */
|
|
202
|
+
export function needsCast(type) {
|
|
203
|
+
return toCast(type) !== null;
|
|
204
|
+
}
|
|
205
|
+
/** Get the resource output expression for a property. */
|
|
206
|
+
export function toResourceExpression(fieldName, type) {
|
|
207
|
+
switch (type) {
|
|
208
|
+
case 'Date': return `$this->${fieldName}?->toDateString()`;
|
|
209
|
+
case 'DateTime':
|
|
210
|
+
case 'Timestamp': return `$this->${fieldName}?->toISOString()`;
|
|
211
|
+
default: return `$this->${fieldName}`;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/** Check if a rules array contains a Rule:: object. */
|
|
215
|
+
export function hasRuleObject(rules) {
|
|
216
|
+
return rules.some(r => Array.isArray(r) && ['rule_in', 'rule_unique_ignore'].includes(r[0]));
|
|
217
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for PHP code generation output.
|
|
3
|
+
*/
|
|
4
|
+
/** A generated PHP file. */
|
|
5
|
+
export interface GeneratedFile {
|
|
6
|
+
readonly path: string;
|
|
7
|
+
readonly content: string;
|
|
8
|
+
readonly overwrite: boolean;
|
|
9
|
+
readonly type: 'base' | 'user';
|
|
10
|
+
}
|
|
11
|
+
/** Create a base file (always overwritten). */
|
|
12
|
+
export declare function baseFile(path: string, content: string): GeneratedFile;
|
|
13
|
+
/** Create a user file (created once, skip if exists). */
|
|
14
|
+
export declare function userFile(path: string, content: string): GeneratedFile;
|
|
15
|
+
/** Per-target path and namespace override from codegen.laravel config. */
|
|
16
|
+
export interface LaravelPathOverride {
|
|
17
|
+
path?: string;
|
|
18
|
+
namespace?: string;
|
|
19
|
+
}
|
|
20
|
+
/** Overrides from codegen.laravel YAML config (all optional). */
|
|
21
|
+
export interface LaravelCodegenOverrides {
|
|
22
|
+
model?: LaravelPathOverride;
|
|
23
|
+
request?: LaravelPathOverride;
|
|
24
|
+
resource?: LaravelPathOverride;
|
|
25
|
+
factory?: LaravelPathOverride;
|
|
26
|
+
provider?: LaravelPathOverride;
|
|
27
|
+
}
|
|
28
|
+
/** PHP codegen configuration (resolved with defaults). */
|
|
29
|
+
export interface PhpConfig {
|
|
30
|
+
models: {
|
|
31
|
+
namespace: string;
|
|
32
|
+
baseNamespace: string;
|
|
33
|
+
path: string;
|
|
34
|
+
basePath: string;
|
|
35
|
+
};
|
|
36
|
+
requests: {
|
|
37
|
+
namespace: string;
|
|
38
|
+
baseNamespace: string;
|
|
39
|
+
path: string;
|
|
40
|
+
basePath: string;
|
|
41
|
+
};
|
|
42
|
+
resources: {
|
|
43
|
+
namespace: string;
|
|
44
|
+
baseNamespace: string;
|
|
45
|
+
path: string;
|
|
46
|
+
basePath: string;
|
|
47
|
+
};
|
|
48
|
+
factories: {
|
|
49
|
+
namespace: string;
|
|
50
|
+
path: string;
|
|
51
|
+
};
|
|
52
|
+
providers: {
|
|
53
|
+
namespace: string;
|
|
54
|
+
path: string;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Derive full PHP config from optional overrides.
|
|
59
|
+
* All paths and namespaces fall back to sensible defaults.
|
|
60
|
+
*/
|
|
61
|
+
export declare function derivePhpConfig(overrides?: LaravelCodegenOverrides): PhpConfig;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for PHP code generation output.
|
|
3
|
+
*/
|
|
4
|
+
/** Create a base file (always overwritten). */
|
|
5
|
+
export function baseFile(path, content) {
|
|
6
|
+
return { path, content, overwrite: true, type: 'base' };
|
|
7
|
+
}
|
|
8
|
+
/** Create a user file (created once, skip if exists). */
|
|
9
|
+
export function userFile(path, content) {
|
|
10
|
+
return { path, content, overwrite: false, type: 'user' };
|
|
11
|
+
}
|
|
12
|
+
/** Convert a file path to a PHP namespace (e.g., app/Models/Omnify → App\Models\Omnify). */
|
|
13
|
+
function pathToNamespace(p) {
|
|
14
|
+
return p
|
|
15
|
+
.split('/')
|
|
16
|
+
.map(s => s.charAt(0).toUpperCase() + s.slice(1))
|
|
17
|
+
.join('\\');
|
|
18
|
+
}
|
|
19
|
+
// Default paths
|
|
20
|
+
const DEFAULT_MODEL_PATH = 'app/Models/Omnify';
|
|
21
|
+
const DEFAULT_REQUEST_PATH = 'app/Http/Requests';
|
|
22
|
+
const DEFAULT_RESOURCE_PATH = 'app/Http/Resources';
|
|
23
|
+
const DEFAULT_FACTORY_PATH = 'database/factories';
|
|
24
|
+
const DEFAULT_PROVIDER_PATH = 'app/Providers';
|
|
25
|
+
/**
|
|
26
|
+
* Derive full PHP config from optional overrides.
|
|
27
|
+
* All paths and namespaces fall back to sensible defaults.
|
|
28
|
+
*/
|
|
29
|
+
export function derivePhpConfig(overrides) {
|
|
30
|
+
const modelPath = overrides?.model?.path ?? DEFAULT_MODEL_PATH;
|
|
31
|
+
const modelNs = overrides?.model?.namespace ?? pathToNamespace(modelPath);
|
|
32
|
+
const requestPath = overrides?.request?.path ?? DEFAULT_REQUEST_PATH;
|
|
33
|
+
const requestNs = overrides?.request?.namespace ?? pathToNamespace(requestPath);
|
|
34
|
+
const resourcePath = overrides?.resource?.path ?? DEFAULT_RESOURCE_PATH;
|
|
35
|
+
const resourceNs = overrides?.resource?.namespace ?? pathToNamespace(resourcePath);
|
|
36
|
+
const factoryPath = overrides?.factory?.path ?? DEFAULT_FACTORY_PATH;
|
|
37
|
+
const factoryNs = overrides?.factory?.namespace ?? pathToNamespace(factoryPath);
|
|
38
|
+
const providerPath = overrides?.provider?.path ?? DEFAULT_PROVIDER_PATH;
|
|
39
|
+
const providerNs = overrides?.provider?.namespace ?? pathToNamespace(providerPath);
|
|
40
|
+
return {
|
|
41
|
+
models: {
|
|
42
|
+
namespace: modelNs,
|
|
43
|
+
baseNamespace: `${modelNs}\\Base`,
|
|
44
|
+
path: modelPath,
|
|
45
|
+
basePath: `${modelPath}/Base`,
|
|
46
|
+
},
|
|
47
|
+
requests: {
|
|
48
|
+
namespace: requestNs,
|
|
49
|
+
baseNamespace: `${requestNs}\\OmnifyBase`,
|
|
50
|
+
path: requestPath,
|
|
51
|
+
basePath: `${requestPath}/OmnifyBase`,
|
|
52
|
+
},
|
|
53
|
+
resources: {
|
|
54
|
+
namespace: resourceNs,
|
|
55
|
+
baseNamespace: `${resourceNs}\\OmnifyBase`,
|
|
56
|
+
path: resourcePath,
|
|
57
|
+
basePath: `${resourcePath}/OmnifyBase`,
|
|
58
|
+
},
|
|
59
|
+
factories: {
|
|
60
|
+
namespace: factoryNs,
|
|
61
|
+
path: factoryPath,
|
|
62
|
+
},
|
|
63
|
+
providers: {
|
|
64
|
+
namespace: providerNs,
|
|
65
|
+
path: providerPath,
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
package/types/config.d.ts
CHANGED
|
@@ -6,39 +6,63 @@ export type DatabaseDriver = "mysql" | "pgsql" | "postgres" | "sqlite";
|
|
|
6
6
|
/** SQL dialect for generated migrations. */
|
|
7
7
|
export type SQLDialect = "mysql" | "postgresql" | "sqlite";
|
|
8
8
|
|
|
9
|
-
/**
|
|
10
|
-
export
|
|
11
|
-
/** Directory for Laravel migration files. */
|
|
12
|
-
migrationsPath: string;
|
|
13
|
-
/** Path for exported schemas JSON (used by omnify-php-laravel). */
|
|
14
|
-
schemasPath?: string;
|
|
15
|
-
}
|
|
9
|
+
/** Migration type identifier. */
|
|
10
|
+
export type MigrationType = "laravel" | "sql";
|
|
16
11
|
|
|
17
|
-
/**
|
|
18
|
-
export interface
|
|
19
|
-
/**
|
|
12
|
+
/** Per-migration output configuration. */
|
|
13
|
+
export interface MigrationConfig {
|
|
14
|
+
/** Migration output type. */
|
|
15
|
+
type: MigrationType;
|
|
16
|
+
/** Output directory for migration files. */
|
|
20
17
|
path: string;
|
|
21
|
-
/**
|
|
18
|
+
/** Path for exported schemas JSON (laravel only). */
|
|
19
|
+
schemasPath?: string;
|
|
20
|
+
/** SQL dialect for generated migrations (sql only). */
|
|
22
21
|
dialect?: SQLDialect;
|
|
23
22
|
}
|
|
24
23
|
|
|
25
|
-
/**
|
|
26
|
-
export interface
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
/** Per-connection database and migration configuration. */
|
|
25
|
+
export interface ConnectionConfig {
|
|
26
|
+
driver: DatabaseDriver;
|
|
27
|
+
migrations?: MigrationConfig[];
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
/**
|
|
32
|
-
export interface
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
/** TypeScript codegen configuration. */
|
|
31
|
+
export interface CodegenTypeScriptConfig {
|
|
32
|
+
/** Enable TypeScript codegen. Defaults to false. */
|
|
33
|
+
enable: boolean;
|
|
34
|
+
/** Output directory for generated TypeScript model files. */
|
|
35
|
+
modelsPath: string;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
/**
|
|
39
|
-
export interface
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
/** Laravel codegen path configuration for a target (model, request, etc.). */
|
|
39
|
+
export interface CodegenLaravelPathConfig {
|
|
40
|
+
/** Output directory path. */
|
|
41
|
+
path?: string;
|
|
42
|
+
/** PHP namespace. Defaults to namespace derived from path. */
|
|
43
|
+
namespace?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Laravel PHP codegen configuration. */
|
|
47
|
+
export interface CodegenLaravelConfig {
|
|
48
|
+
/** Enable Laravel codegen. Defaults to false. */
|
|
49
|
+
enable: boolean;
|
|
50
|
+
/** Model output configuration. */
|
|
51
|
+
model?: CodegenLaravelPathConfig;
|
|
52
|
+
/** Request output configuration. */
|
|
53
|
+
request?: CodegenLaravelPathConfig;
|
|
54
|
+
/** Resource output configuration. */
|
|
55
|
+
resource?: CodegenLaravelPathConfig;
|
|
56
|
+
/** Factory output configuration. */
|
|
57
|
+
factory?: CodegenLaravelPathConfig;
|
|
58
|
+
/** Provider output configuration. */
|
|
59
|
+
provider?: CodegenLaravelPathConfig;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Code generation configuration (connection-independent). */
|
|
63
|
+
export interface CodegenConfig {
|
|
64
|
+
typescript?: CodegenTypeScriptConfig;
|
|
65
|
+
laravel?: CodegenLaravelConfig;
|
|
42
66
|
}
|
|
43
67
|
|
|
44
68
|
/** Additional schema directory to load. */
|
|
@@ -65,6 +89,8 @@ export interface OmnifyConfig {
|
|
|
65
89
|
locale?: LocaleConfig;
|
|
66
90
|
/** Built-in compound type packs to enable (e.g. "japan"). */
|
|
67
91
|
compoundTypes?: string[];
|
|
92
|
+
/** Code generation configuration (connection-independent). */
|
|
93
|
+
codegen?: CodegenConfig;
|
|
68
94
|
/** Enable verbose output during generation. */
|
|
69
95
|
verbose?: boolean;
|
|
70
96
|
}
|