@omnifyjp/omnify 6.0.6 → 6.0.7
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": "6.0.
|
|
3
|
+
"version": "6.0.7",
|
|
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": "6.0.
|
|
40
|
-
"@omnifyjp/omnify-darwin-x64": "6.0.
|
|
41
|
-
"@omnifyjp/omnify-linux-x64": "6.0.
|
|
42
|
-
"@omnifyjp/omnify-linux-arm64": "6.0.
|
|
43
|
-
"@omnifyjp/omnify-win32-x64": "6.0.
|
|
39
|
+
"@omnifyjp/omnify-darwin-arm64": "6.0.7",
|
|
40
|
+
"@omnifyjp/omnify-darwin-x64": "6.0.7",
|
|
41
|
+
"@omnifyjp/omnify-linux-x64": "6.0.7",
|
|
42
|
+
"@omnifyjp/omnify-linux-arm64": "6.0.7",
|
|
43
|
+
"@omnifyjp/omnify-win32-x64": "6.0.7"
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -17,7 +17,6 @@ export declare function toSnakeCase(str: string): string;
|
|
|
17
17
|
* unconditionally produced `table_session_id_id` (issue #149).
|
|
18
18
|
*/
|
|
19
19
|
export declare function toFkColumnName(propertyName: string): string;
|
|
20
|
-
/** Gets TypeScript type for a property. */
|
|
21
20
|
export declare function getPropertyType(property: PropertyDefinition, allSchemas: Record<string, SchemaDefinition>): string;
|
|
22
21
|
/**
|
|
23
22
|
* Convert a property to TSProperty array.
|
|
@@ -63,12 +63,29 @@ function getIdType(options) {
|
|
|
63
63
|
return 'BigInt';
|
|
64
64
|
}
|
|
65
65
|
/** Gets TypeScript type for a property. */
|
|
66
|
+
/**
|
|
67
|
+
* The interface name to write for a relation target, or `unknown` when the
|
|
68
|
+
* target lives outside the generated schema set (external `targetNamespace`
|
|
69
|
+
* models). Imports are collected from the same schema set, so anything absent
|
|
70
|
+
* here would be referenced without ever being imported.
|
|
71
|
+
*/
|
|
72
|
+
function resolveTargetName(target, allSchemas) {
|
|
73
|
+
if (!target || !(target in allSchemas)) {
|
|
74
|
+
return 'unknown';
|
|
75
|
+
}
|
|
76
|
+
return target;
|
|
77
|
+
}
|
|
66
78
|
export function getPropertyType(property, allSchemas) {
|
|
67
79
|
if (property.type === 'File') {
|
|
68
80
|
return property.multiple ? 'OmnifyFile[]' : 'OmnifyFile | null';
|
|
69
81
|
}
|
|
70
82
|
if (property.type === 'Association') {
|
|
71
|
-
|
|
83
|
+
// A target outside the schema set (an external model reached through
|
|
84
|
+
// `targetNamespace`, e.g. the app's own User) has no generated interface
|
|
85
|
+
// and therefore no import. Naming it anyway emits `user?: User` against an
|
|
86
|
+
// identifier nothing declares — TS2304 in every consumer. `unknown` is the
|
|
87
|
+
// honest type for a shape this generator cannot see.
|
|
88
|
+
const targetName = resolveTargetName(property.target, allSchemas);
|
|
72
89
|
switch (property.relation) {
|
|
73
90
|
case 'OneToOne':
|
|
74
91
|
case 'ManyToOne':
|
|
@@ -78,7 +95,9 @@ export function getPropertyType(property, allSchemas) {
|
|
|
78
95
|
return `${targetName}[]`;
|
|
79
96
|
case 'MorphTo':
|
|
80
97
|
if (property.targets && property.targets.length > 0) {
|
|
81
|
-
return property.targets
|
|
98
|
+
return property.targets
|
|
99
|
+
.map(target => resolveTargetName(target, allSchemas))
|
|
100
|
+
.join(' | ');
|
|
82
101
|
}
|
|
83
102
|
return 'unknown';
|
|
84
103
|
case 'MorphOne':
|
|
@@ -162,7 +181,9 @@ export function propertyToTSProperties(propertyName, property, schema, allSchema
|
|
|
162
181
|
// Handle Association: MorphTo — creates _type, _id, and relation properties
|
|
163
182
|
if (property.type === 'Association' && property.relation === 'MorphTo' && property.targets && property.targets.length > 0) {
|
|
164
183
|
const targetUnion = property.targets.map(t => `'${t}'`).join(' | ');
|
|
165
|
-
const relationUnion = property.targets
|
|
184
|
+
const relationUnion = property.targets
|
|
185
|
+
.map(target => resolveTargetName(target, allSchemas))
|
|
186
|
+
.join(' | ');
|
|
166
187
|
return [
|
|
167
188
|
{
|
|
168
189
|
name: `${propertyName}_type`,
|
|
@@ -186,7 +207,7 @@ export function propertyToTSProperties(propertyName, property, schema, allSchema
|
|
|
186
207
|
}
|
|
187
208
|
// Handle Association: ManyToOne / OneToOne (owning side) — creates FK _id and relation
|
|
188
209
|
if (property.type === 'Association' && (property.relation === 'ManyToOne' || property.relation === 'OneToOne') && !property.mappedBy) {
|
|
189
|
-
const targetName = property.target
|
|
210
|
+
const targetName = resolveTargetName(property.target, allSchemas);
|
|
190
211
|
// Determine FK type from target schema
|
|
191
212
|
let fkType = 'number';
|
|
192
213
|
const targetSchema = property.target ? allSchemas[property.target] : undefined;
|