@omnifyjp/ts 5.8.11 → 5.8.13

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.
@@ -46,13 +46,19 @@ function generateForSchema(name, schema, reader, config) {
46
46
  function generateBasePolicyClass(name, schema, reader, config) {
47
47
  const modelName = toPascalCase(name);
48
48
  const baseNamespace = resolveModularBaseNamespace(config, name, 'Policies', config.policies.baseNamespace);
49
- // Issue #98 v5.8.4: legacy structure groups Models by folder. The
50
- // policy's `use ${modelNamespace}\\${modelName}` import must include
51
- // the schema's group too, otherwise the policy fails to autoload at
52
- // runtime when Laravel resolves it from the gate registration.
49
+ // Issue #98 v5.8.13: policy method signatures (`view(User $user,
50
+ // <Model> $record): bool`) must type-hint the USER-EDITABLE Model
51
+ // class. Same root cause + fix as the v5.8.11 service / controller
52
+ // signature fix — when the user-editable policy child overrides a
53
+ // base method with the editable Model type, PHP signature
54
+ // contravariance fires with a Fatal compile error if the parent
55
+ // typed against the BASE Model. Modular structure: per-Schema
56
+ // isolation already aligns base + editable on one namespace.
53
57
  const modelNamespace = config.structure === 'modular'
54
58
  ? config.models.namespace
55
- : nestByGroup({ path: '', namespace: config.models.namespace }, schema.group).namespace;
59
+ : (config.models.userEditableGroupByFolder
60
+ ? nestByGroup({ path: '', namespace: config.models.userEditableNamespace }, schema.group).namespace
61
+ : config.models.userEditableNamespace);
56
62
  const policies = schema.policies;
57
63
  const hasSoftDelete = schema.options?.softDelete ?? false;
58
64
  const needsCidrHelper = policiesUseCidr(policies);
@@ -198,7 +198,24 @@ function addAssociationFields(propName, prop, fields, resourceNamespace, modelNa
198
198
  const target = prop['target'] ?? '';
199
199
  const methodName = toCamelCase(propName);
200
200
  // Resolve resource namespace for the target (null if package without resource ns)
201
- const targetResNs = target ? reader.resolveResourceNamespace(target, resourceNamespace) : resourceNamespace;
201
+ // Issue #98 v5.8.12: nest the resource FQCN by the TARGET schema's
202
+ // group folder so the inline `new \<ns>\<Name>Resource(...)` ref
203
+ // matches where the target Resource file actually lives. Pre-fix
204
+ // every cross-resource ref emitted FLAT (`use App\Omnify\Resources\PaymentProviderResource`)
205
+ // while the file lived at `App\Omnify\Resources\Payments\PaymentProviderResource` —
206
+ // PHP autoload failed at runtime on every base resource that
207
+ // referenced a sibling resource (whenLoaded relation).
208
+ const rawTargetResNs = target ? reader.resolveResourceNamespace(target, resourceNamespace) : resourceNamespace;
209
+ let targetResNs = rawTargetResNs;
210
+ if (rawTargetResNs && rawTargetResNs === resourceNamespace) {
211
+ // Project-owned target: nest by the target's group so the FQCN
212
+ // matches the grouped base resource. Package targets keep their
213
+ // own namespace.
214
+ const targetSchema = target ? reader.getSchema(target) : undefined;
215
+ if (targetSchema?.group) {
216
+ targetResNs = `${rawTargetResNs}\\${toPascalCase(targetSchema.group)}`;
217
+ }
218
+ }
202
219
  // If target is a package schema without a resource namespace, use simple whenLoaded
203
220
  if (!targetResNs && relation !== 'MorphTo') {
204
221
  if (relation === 'ManyToOne') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnifyjp/ts",
3
- "version": "5.8.11",
3
+ "version": "5.8.13",
4
4
  "description": "TypeScript model type generator from Omnify schemas.json",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",