@omnifyjp/omnify 5.8.2 → 5.8.3

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": "5.8.2",
3
+ "version": "5.8.3",
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": "5.8.2",
40
- "@omnifyjp/omnify-darwin-x64": "5.8.2",
41
- "@omnifyjp/omnify-linux-x64": "5.8.2",
42
- "@omnifyjp/omnify-linux-arm64": "5.8.2",
43
- "@omnifyjp/omnify-win32-x64": "5.8.2"
39
+ "@omnifyjp/omnify-darwin-arm64": "5.8.3",
40
+ "@omnifyjp/omnify-darwin-x64": "5.8.3",
41
+ "@omnifyjp/omnify-linux-x64": "5.8.3",
42
+ "@omnifyjp/omnify-linux-arm64": "5.8.3",
43
+ "@omnifyjp/omnify-win32-x64": "5.8.3"
44
44
  }
45
45
  }
@@ -64,6 +64,12 @@ function generateTranslationBaseModel(name, translatableFields, enforceLanguageF
64
64
  // Astrotomic's `translation_model_namespace` once globally instead
65
65
  // of per-model `$translationModel` overrides. Modular structure
66
66
  // already isolates per-Schema so this nesting only applies to legacy.
67
+ // Issue #98 v5.8.3: when `flatBase: true`, the model layer drops
68
+ // the `Base/` subfolder + `BaseModel` suffix everywhere else; the
69
+ // translation base must follow the same convention so naming
70
+ // stays consistent across layers (a class extending `Model` named
71
+ // `CategoryTranslationBaseModel` while siblings drop the suffix is
72
+ // the bug the reporter flagged).
67
73
  const baseNamespace = config.structure === 'modular'
68
74
  ? resolveModularBaseNamespace(config, name, 'Models', config.models.baseNamespace)
69
75
  : `${config.models.baseNamespace}\\Translation`;
@@ -93,6 +99,12 @@ function generateTranslationBaseModel(name, translatableFields, enforceLanguageF
93
99
  protected $casts = [
94
100
  ${castEntries.join('\n')}
95
101
  ];`;
102
+ // Issue #98 v5.8.3: honor flatBase. With flatBase=true the base
103
+ // class drops the `BaseModel` suffix and lives at the bare name,
104
+ // matching how every other Models-layer base behaves under flatBase.
105
+ // Modular structure ignores flatBase (per-Schema isolation already).
106
+ const flatBase = config.structure !== 'modular' && config.models.flatBase === true;
107
+ const baseClassName = flatBase ? `${modelName}Translation` : `${modelName}TranslationBaseModel`;
96
108
  const content = `<?php
97
109
 
98
110
  namespace ${baseNamespace};
@@ -107,9 +119,9 @@ namespace ${baseNamespace};
107
119
  use Illuminate\\Database\\Eloquent\\Model;
108
120
 
109
121
  /**
110
- * ${modelName}TranslationBaseModel
122
+ * ${baseClassName}
111
123
  */
112
- class ${modelName}TranslationBaseModel extends Model
124
+ class ${baseClassName} extends Model
113
125
  {
114
126
  /**
115
127
  * The table associated with the model.
@@ -130,10 +142,11 @@ ${fillableLines}
130
142
  }
131
143
  `;
132
144
  // Issue #98 v5.8.2: legacy structure routes translation bases to
133
- // `<modelsBasePath>/Translation/<Name>TranslationBaseModel.php`.
145
+ // `<modelsBasePath>/Translation/<Name>TranslationBaseModel.php`
146
+ // (or `${modelName}Translation.php` when flatBase drops the suffix).
134
147
  const filePath = config.structure === 'modular'
135
- ? resolveModularBasePath(config, name, 'Models', `${modelName}TranslationBaseModel.php`, config.models.basePath)
136
- : `${config.models.basePath}/Translation/${modelName}TranslationBaseModel.php`;
148
+ ? resolveModularBasePath(config, name, 'Models', `${baseClassName}.php`, config.models.basePath)
149
+ : `${config.models.basePath}/Translation/${baseClassName}.php`;
137
150
  return baseFile(filePath, content);
138
151
  }
139
152
  function generateTranslationUserModel(name, config) {
@@ -141,32 +154,51 @@ function generateTranslationUserModel(name, config) {
141
154
  // Issue #98 v5.8.2: editable translation stub also lives under
142
155
  // `Translation/` to mirror the base layout. Astrotomic finds it via
143
156
  // the project-set `translation_model_namespace`.
157
+ // Issue #98 v5.8.3 (Bug 1): when `userEditablePath` points elsewhere
158
+ // (e.g. canonical Laravel `app/Models/`), the namespace must match
159
+ // the FILE LOCATION, not the base namespace — otherwise PSR-4 fails
160
+ // at runtime. Use `userEditableNamespace` (resolved from the config
161
+ // override) instead of the base `models.namespace`.
144
162
  const modelNamespace = config.structure === 'modular'
145
163
  ? config.models.namespace
146
- : `${config.models.namespace}\\Translation`;
164
+ : `${config.models.userEditableNamespace}\\Translation`;
147
165
  const baseNamespace = config.structure === 'modular'
148
166
  ? resolveModularBaseNamespace(config, name, 'Models', config.models.baseNamespace)
149
167
  : `${config.models.baseNamespace}\\Translation`;
168
+ // Issue #98 v5.8.3 (Bug 2): honor flatBase + alias on class-name
169
+ // collision. With flatBase the base class is also named
170
+ // `<Model>Translation` (no suffix); the editable stub then needs
171
+ // an alias to avoid a self-collision when extending. Mirrors the
172
+ // pattern used by resource / service / request user generators.
173
+ const flatBase = config.structure !== 'modular' && config.models.flatBase === true;
174
+ const baseClassName = flatBase ? `${modelName}Translation` : `${modelName}TranslationBaseModel`;
175
+ const editableClassName = `${modelName}Translation`;
176
+ const baseAlias = baseClassName === editableClassName
177
+ ? `${editableClassName}Base`
178
+ : baseClassName;
179
+ const baseImport = baseAlias === baseClassName
180
+ ? `use ${baseNamespace}\\${baseClassName};`
181
+ : `use ${baseNamespace}\\${baseClassName} as ${baseAlias};`;
150
182
  const content = `<?php
151
183
 
152
184
  namespace ${modelNamespace};
153
185
 
154
- use ${baseNamespace}\\${modelName}TranslationBaseModel;
186
+ ${baseImport}
155
187
 
156
188
  /**
157
- * ${modelName}Translation Model
189
+ * ${editableClassName} Model
158
190
  *
159
191
  * This file is generated once and can be customized.
160
192
  * Add your custom methods and logic here.
161
193
  */
162
- class ${modelName}Translation extends ${modelName}TranslationBaseModel
194
+ class ${editableClassName} extends ${baseAlias}
163
195
  {
164
196
  // Add your custom methods here
165
197
  }
166
198
  `;
167
199
  // Editable file path mirrors the namespace nesting.
168
200
  const filePath = config.structure === 'modular'
169
- ? `${config.models.path}/${modelName}Translation.php`
170
- : `${config.models.userEditablePath}/Translation/${modelName}Translation.php`;
201
+ ? `${config.models.path}/${editableClassName}.php`
202
+ : `${config.models.userEditablePath}/Translation/${editableClassName}.php`;
171
203
  return userFile(filePath, content);
172
204
  }
@@ -184,10 +184,19 @@ nsFromPath) {
184
184
  const baseNamespace = flatBase ? namespace : `${namespace}\\${baseSubfolder}`;
185
185
  // User-editable: defaults to the same dir as base (legacy behavior),
186
186
  // overridable to e.g. canonical Laravel paths (`app/Models/`).
187
+ // Issue #98 v5.8.3: when only `userEditablePath` is overridden,
188
+ // derive the namespace from the editable PATH (not the base
189
+ // namespace) so the file's `namespace ...;` declaration matches
190
+ // its physical location and PSR-4 autoload doesn't break at
191
+ // runtime. Reporter hit this with `userEditablePath: app/Models`
192
+ // and the base path defaulting to `app/Omnify/Models/`: the
193
+ // editable stub claimed the base namespace and Laravel couldn't
194
+ // load it.
187
195
  const userEditablePath = override?.userEditablePath
188
196
  ? withRoot(rootPath, override.userEditablePath)
189
197
  : path;
190
- const userEditableNamespace = override?.userEditableNamespace ?? namespace;
198
+ const userEditableNamespace = override?.userEditableNamespace
199
+ ?? (override?.userEditablePath ? nsFromPath(userEditablePath) : namespace);
191
200
  return { namespace, baseNamespace, path, basePath, userEditablePath, userEditableNamespace, flatBase };
192
201
  }
193
202
  /**