@omnifyjp/omnify 2.1.3 → 2.1.4

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": "2.1.3",
3
+ "version": "2.1.4",
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": "2.1.3",
40
- "@omnifyjp/omnify-darwin-x64": "2.1.3",
41
- "@omnifyjp/omnify-linux-x64": "2.1.3",
42
- "@omnifyjp/omnify-linux-arm64": "2.1.3",
43
- "@omnifyjp/omnify-win32-x64": "2.1.3"
39
+ "@omnifyjp/omnify-darwin-arm64": "2.1.4",
40
+ "@omnifyjp/omnify-darwin-x64": "2.1.4",
41
+ "@omnifyjp/omnify-linux-x64": "2.1.4",
42
+ "@omnifyjp/omnify-linux-arm64": "2.1.4",
43
+ "@omnifyjp/omnify-win32-x64": "2.1.4"
44
44
  }
45
45
  }
@@ -30,6 +30,12 @@ export function buildRelation(propName, property, modelNamespace, context) {
30
30
  case 'MorphMany':
31
31
  method = morphMany(propName, property, target, modelNamespace);
32
32
  break;
33
+ case 'MorphToMany':
34
+ method = morphToMany(propName, property, target, modelNamespace, context);
35
+ break;
36
+ case 'MorphedByMany':
37
+ method = morphedByMany(propName, property, target, modelNamespace);
38
+ break;
33
39
  }
34
40
  if (method === null)
35
41
  return null;
@@ -50,6 +56,8 @@ export function getReturnType(relation) {
50
56
  case 'MorphTo': return 'MorphTo';
51
57
  case 'MorphOne': return 'MorphOne';
52
58
  case 'MorphMany': return 'MorphMany';
59
+ case 'MorphToMany': return 'MorphToMany';
60
+ case 'MorphedByMany': return 'MorphedByMany';
53
61
  default: return 'BelongsTo';
54
62
  }
55
63
  }
@@ -153,3 +161,30 @@ function morphMany(propName, property, target, ns) {
153
161
  return $this->morphMany(${fqcn}::class, '${morphName}');
154
162
  }`;
155
163
  }
164
+ function morphToMany(propName, property, target, ns, context) {
165
+ const morphName = property['morphName'] ?? toSnakeCase(propName);
166
+ const joinTable = property['joinTable'] ?? (morphName + 's');
167
+ const methodName = toCamelCase(propName);
168
+ const fqcn = `\\${ns}\\${target}`;
169
+ return ` /**
170
+ * The ${propName} that belong to this model.
171
+ */
172
+ public function ${methodName}(): MorphToMany
173
+ {
174
+ return $this->morphToMany(${fqcn}::class, '${morphName}', '${joinTable}')
175
+ ->withTimestamps();
176
+ }`;
177
+ }
178
+ function morphedByMany(propName, property, target, ns) {
179
+ const morphName = property['morphName'] ?? toSnakeCase(propName);
180
+ const methodName = toCamelCase(propName);
181
+ const fqcn = `\\${ns}\\${target}`;
182
+ return ` /**
183
+ * The ${propName} that belong to this model.
184
+ */
185
+ public function ${methodName}(): MorphedByMany
186
+ {
187
+ return $this->morphedByMany(${fqcn}::class, '${morphName}')
188
+ ->withTimestamps();
189
+ }`;
190
+ }