@omnifyjp/ts 5.8.14 → 5.8.16
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.
|
@@ -65,7 +65,16 @@ function generateForSchema(name, schema, reader, config) {
|
|
|
65
65
|
}
|
|
66
66
|
function generateBasePolicyClass(name, schema, reader, config) {
|
|
67
67
|
const modelName = toPascalCase(name);
|
|
68
|
-
|
|
68
|
+
// Issue #98 v5.8.15: legacy structure must nest the policy base's
|
|
69
|
+
// `namespace ...;` declaration by group folder so it matches the
|
|
70
|
+
// grouped path on disk. Pre-fix every base emitted
|
|
71
|
+
// `namespace App\\Omnify\\Policies;` (FLAT) while the file lived at
|
|
72
|
+
// `app/Omnify/Policies/<Group>/<Name>Policy.php` — PSR-4 autoload
|
|
73
|
+
// failed at runtime for every grouped policy. Same template fix
|
|
74
|
+
// that v5.8.2 applied to Requests / Resources / Services.
|
|
75
|
+
const baseNamespace = config.structure === 'modular'
|
|
76
|
+
? resolveModularBaseNamespace(config, name, 'Policies', config.policies.baseNamespace)
|
|
77
|
+
: nestByGroup({ path: '', namespace: config.policies.baseNamespace }, schema.group).namespace;
|
|
69
78
|
// Issue #98 v5.8.13: policy method signatures (`view(User $user,
|
|
70
79
|
// <Model> $record): bool`) must type-hint the USER-EDITABLE Model
|
|
71
80
|
// class. Same root cause + fix as the v5.8.11 service / controller
|
|
@@ -5,24 +5,42 @@ import { toPascalCase } from './naming-helper.js';
|
|
|
5
5
|
import { baseFile, nestByGroup } from './types.js';
|
|
6
6
|
/** Generate the OmnifyServiceProvider for the application. */
|
|
7
7
|
export function generateServiceProvider(reader, config) {
|
|
8
|
+
// Issue #98 v5.8.16: morph map entries point at the USER-EDITABLE
|
|
9
|
+
// class FQN, NOT the BASE. Same fix as v5.8.9 factory \$model,
|
|
10
|
+
// v5.8.10 model relations, v5.8.11 service / controller signatures —
|
|
11
|
+
// every layer that produces / type-hints model instances now uses
|
|
12
|
+
// the editable. Without this, Eloquent's `getMorphClass()` lookup
|
|
13
|
+
// misses (factory + relation output is `App\Models\<Name>`, but
|
|
14
|
+
// morph map keys point at `App\Omnify\Models\<Group>\<Name>`)
|
|
15
|
+
// and the runtime throws ClassMorphViolationException on every
|
|
16
|
+
// polymorphic relation in the project.
|
|
8
17
|
const modelNamespace = config.models.namespace;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
// morph map
|
|
12
|
-
// `App\Omnify\Models\<Name>::class` and Laravel's morphMap resolved to
|
|
13
|
-
// a non-existent class for every grouped schema, breaking polymorphic
|
|
14
|
-
// relationships project-wide.
|
|
18
|
+
const editableNamespace = config.models.userEditableNamespace;
|
|
19
|
+
const editableGrouped = config.models.userEditableGroupByFolder;
|
|
20
|
+
// Build morph map entries (project-owned schemas only).
|
|
15
21
|
const morphEntries = [];
|
|
16
22
|
for (const [name, schema] of Object.entries(reader.getProjectVisibleObjectSchemas())) {
|
|
17
23
|
const modelName = toPascalCase(name);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
24
|
+
let ns;
|
|
25
|
+
if (config.structure === 'modular') {
|
|
26
|
+
ns = modelNamespace;
|
|
27
|
+
}
|
|
28
|
+
else if (schema.kind === 'pivot') {
|
|
29
|
+
// Pivot models always live under `<editableNs>\Pivot` (issue #98 v5.8.5).
|
|
30
|
+
ns = `${editableNamespace}\\Pivot`;
|
|
31
|
+
}
|
|
32
|
+
else if (editableGrouped) {
|
|
33
|
+
ns = nestByGroup({ path: '', namespace: editableNamespace }, schema.group).namespace;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
ns = editableNamespace;
|
|
37
|
+
}
|
|
21
38
|
morphEntries.push(` '${modelName}' => \\${ns}\\${modelName}::class,`);
|
|
22
39
|
}
|
|
23
|
-
// Add File to morph map when any schema uses File type
|
|
40
|
+
// Add File to morph map when any schema uses File type. File is a
|
|
41
|
+
// shared / global model — uses the editable namespace too.
|
|
24
42
|
if (reader.hasFileProperties()) {
|
|
25
|
-
morphEntries.push(` 'File' => \\${
|
|
43
|
+
morphEntries.push(` 'File' => \\${editableNamespace}\\File::class,`);
|
|
26
44
|
}
|
|
27
45
|
morphEntries.sort();
|
|
28
46
|
const morphMapContent = morphEntries.join('\n');
|