@omnifyjp/omnify 3.7.0 → 3.7.1
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omnifyjp/omnify",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.1",
|
|
4
4
|
"description": "Schema-driven code generation for Laravel, TypeScript, and SQL",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
"zod": "^3.24.0"
|
|
37
37
|
},
|
|
38
38
|
"optionalDependencies": {
|
|
39
|
-
"@omnifyjp/omnify-darwin-arm64": "3.7.
|
|
40
|
-
"@omnifyjp/omnify-darwin-x64": "3.7.
|
|
41
|
-
"@omnifyjp/omnify-linux-x64": "3.7.
|
|
42
|
-
"@omnifyjp/omnify-linux-arm64": "3.7.
|
|
43
|
-
"@omnifyjp/omnify-win32-x64": "3.7.
|
|
39
|
+
"@omnifyjp/omnify-darwin-arm64": "3.7.1",
|
|
40
|
+
"@omnifyjp/omnify-darwin-x64": "3.7.1",
|
|
41
|
+
"@omnifyjp/omnify-linux-x64": "3.7.1",
|
|
42
|
+
"@omnifyjp/omnify-linux-arm64": "3.7.1",
|
|
43
|
+
"@omnifyjp/omnify-win32-x64": "3.7.1"
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -4,6 +4,24 @@
|
|
|
4
4
|
import { toPascalCase, toSnakeCase, toCamelCase } from './naming-helper.js';
|
|
5
5
|
import { toStoreRules, toUpdateRules, formatRules, hasRuleObject } from './type-mapper.js';
|
|
6
6
|
import { baseFile, userFile, resolveModularBasePath, resolveModularBaseNamespace } from './types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Resolve the Laravel validation rule type ('integer', 'uuid', or 'string') for
|
|
9
|
+
* a foreign key column based on the target schema's primary key type.
|
|
10
|
+
*
|
|
11
|
+
* Mirrors the FK cast logic in `model-generator.ts` so validation rules and
|
|
12
|
+
* Eloquent casts agree about the wire format. Issue #36.
|
|
13
|
+
*/
|
|
14
|
+
function resolveFkRuleType(target, reader) {
|
|
15
|
+
if (!target)
|
|
16
|
+
return 'integer';
|
|
17
|
+
const targetSchema = reader.getSchema(target);
|
|
18
|
+
const id = targetSchema?.options?.id;
|
|
19
|
+
if (id === 'Uuid')
|
|
20
|
+
return 'uuid';
|
|
21
|
+
if (id === 'Ulid' || id === 'String')
|
|
22
|
+
return 'string';
|
|
23
|
+
return 'integer';
|
|
24
|
+
}
|
|
7
25
|
/** Generate Store/Update request classes for all project-owned visible object schemas. */
|
|
8
26
|
export function generateRequests(reader, config) {
|
|
9
27
|
const files = [];
|
|
@@ -78,9 +96,11 @@ function generateBaseRequest(name, schema, reader, config, action) {
|
|
|
78
96
|
const relation = prop['relation'] ?? '';
|
|
79
97
|
if (relation === 'ManyToOne') {
|
|
80
98
|
const snakeName = toSnakeCase(propName) + '_id';
|
|
99
|
+
const target = prop['target'] ?? '';
|
|
100
|
+
const targetIdType = resolveFkRuleType(target, reader);
|
|
81
101
|
const rules = isUpdate
|
|
82
|
-
? toUpdateRules(prop, tableName, modelRouteParam)
|
|
83
|
-
: toStoreRules(prop, tableName);
|
|
102
|
+
? toUpdateRules(prop, tableName, modelRouteParam, targetIdType)
|
|
103
|
+
: toStoreRules(prop, tableName, targetIdType);
|
|
84
104
|
rulesLines.push(` '${snakeName}' => ${formatRules(rules)},`);
|
|
85
105
|
attributeKeys.push(snakeName);
|
|
86
106
|
}
|
|
@@ -6,10 +6,17 @@ type Rule = string | ['rule_in', string[]] | ['rule_unique_ignore', string, stri
|
|
|
6
6
|
export declare function toCast(type: string, property?: Record<string, unknown>): string | null;
|
|
7
7
|
/** Map Omnify property type to PHP doc type. */
|
|
8
8
|
export declare function toPhpDocType(type: string, nullable?: boolean): string;
|
|
9
|
-
/**
|
|
10
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Generate validation rules for a property (Store request).
|
|
11
|
+
*
|
|
12
|
+
* @param fkRuleType - For ManyToOne associations, the validation rule type
|
|
13
|
+
* matching the target schema's primary key ('integer' for Int/BigInt PKs,
|
|
14
|
+
* 'uuid' for Uuid PKs, 'string' for Ulid/String PKs). Defaults to 'integer'
|
|
15
|
+
* for backwards compatibility. Issue #36.
|
|
16
|
+
*/
|
|
17
|
+
export declare function toStoreRules(property: Record<string, unknown>, tableName: string, fkRuleType?: 'integer' | 'uuid' | 'string'): Rule[];
|
|
11
18
|
/** Generate validation rules for a property (Update request). */
|
|
12
|
-
export declare function toUpdateRules(property: Record<string, unknown>, tableName: string, modelRouteParam: string): Rule[];
|
|
19
|
+
export declare function toUpdateRules(property: Record<string, unknown>, tableName: string, modelRouteParam: string, fkRuleType?: 'integer' | 'uuid' | 'string'): Rule[];
|
|
13
20
|
/** Format validation rules as PHP code string. */
|
|
14
21
|
export declare function formatRules(rules: Rule[]): string;
|
|
15
22
|
/** Resolve enum values from property definition. */
|
|
@@ -70,8 +70,15 @@ const STRING_TYPES = new Set([
|
|
|
70
70
|
]);
|
|
71
71
|
const NUMERIC_TYPES = new Set(['Int', 'BigInt', 'TinyInt', 'Float', 'Decimal']);
|
|
72
72
|
const ARRAY_TYPES = new Set(['Json']);
|
|
73
|
-
/**
|
|
74
|
-
|
|
73
|
+
/**
|
|
74
|
+
* Generate validation rules for a property (Store request).
|
|
75
|
+
*
|
|
76
|
+
* @param fkRuleType - For ManyToOne associations, the validation rule type
|
|
77
|
+
* matching the target schema's primary key ('integer' for Int/BigInt PKs,
|
|
78
|
+
* 'uuid' for Uuid PKs, 'string' for Ulid/String PKs). Defaults to 'integer'
|
|
79
|
+
* for backwards compatibility. Issue #36.
|
|
80
|
+
*/
|
|
81
|
+
export function toStoreRules(property, tableName, fkRuleType = 'integer') {
|
|
75
82
|
const type = property['type'] ?? 'String';
|
|
76
83
|
// File type defaults to nullable (uploads are optional, attached separately)
|
|
77
84
|
const nullable = property['nullable'] ?? (type === 'File' ? true : false);
|
|
@@ -143,7 +150,7 @@ export function toStoreRules(property, tableName) {
|
|
|
143
150
|
case 'Association': {
|
|
144
151
|
const relation = property['relation'] ?? '';
|
|
145
152
|
if (relation === 'ManyToOne') {
|
|
146
|
-
rules.push(
|
|
153
|
+
rules.push(fkRuleType);
|
|
147
154
|
const target = property['target'] ?? '';
|
|
148
155
|
if (target)
|
|
149
156
|
rules.push(`exists:${toTableName(target)},id`);
|
|
@@ -267,8 +274,8 @@ function mergeValidationRules(rules, vr, type) {
|
|
|
267
274
|
}
|
|
268
275
|
}
|
|
269
276
|
/** Generate validation rules for a property (Update request). */
|
|
270
|
-
export function toUpdateRules(property, tableName, modelRouteParam) {
|
|
271
|
-
let rules = toStoreRules(property, tableName);
|
|
277
|
+
export function toUpdateRules(property, tableName, modelRouteParam, fkRuleType = 'integer') {
|
|
278
|
+
let rules = toStoreRules(property, tableName, fkRuleType);
|
|
272
279
|
const unique = property['unique'] ?? false;
|
|
273
280
|
// Replace 'required' with 'sometimes'
|
|
274
281
|
rules = rules.map(r => r === 'required' ? 'sometimes' : r);
|