@omnifyjp/omnify 5.0.1 → 5.0.2

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.0.1",
3
+ "version": "5.0.2",
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.0.1",
40
- "@omnifyjp/omnify-darwin-x64": "5.0.1",
41
- "@omnifyjp/omnify-linux-x64": "5.0.1",
42
- "@omnifyjp/omnify-linux-arm64": "5.0.1",
43
- "@omnifyjp/omnify-win32-x64": "5.0.1"
39
+ "@omnifyjp/omnify-darwin-arm64": "5.0.2",
40
+ "@omnifyjp/omnify-darwin-x64": "5.0.2",
41
+ "@omnifyjp/omnify-linux-x64": "5.0.2",
42
+ "@omnifyjp/omnify-linux-arm64": "5.0.2",
43
+ "@omnifyjp/omnify-win32-x64": "5.0.2"
44
44
  }
45
45
  }
@@ -504,7 +504,21 @@ function buildRelations(schemaName, properties, propertyOrder, modelNamespace, r
504
504
  const target = prop['target'] ?? '';
505
505
  const ns = target ? reader.resolveModelNamespace(target, modelNamespace) : modelNamespace;
506
506
  const targetTableName = target ? reader.getTableName(target) : '';
507
- const result = buildRelation(propName, prop, ns, { sourceTableName, targetTableName });
507
+ // For ManyToMany, look up the explicit `kind: pivot` schema (the
508
+ // sorted PascalCase concat of source + target — auto-created on
509
+ // first generate) and pass its property names so belongsToMany
510
+ // emits `->withPivot('col1', 'col2')`. Without this, custom pivot
511
+ // columns the user added are unreachable through the relation.
512
+ const relation = prop['relation'] ?? '';
513
+ let pivotProperties;
514
+ if (relation === 'ManyToMany' && target) {
515
+ const pivotName = [schemaName, target].sort().join('');
516
+ const pivotSchema = reader.getSchema(pivotName);
517
+ if (pivotSchema?.properties) {
518
+ pivotProperties = Object.keys(pivotSchema.properties).map(toSnakeCase);
519
+ }
520
+ }
521
+ const result = buildRelation(propName, prop, ns, { sourceTableName, targetTableName, pivotProperties });
508
522
  if (result) {
509
523
  methods.push('\n' + result.method);
510
524
  declaredMethods.add(toCamelCase(propName));
@@ -8,6 +8,12 @@ interface RelationResult {
8
8
  interface RelationContext {
9
9
  sourceTableName: string;
10
10
  targetTableName: string;
11
+ /** Property names declared on the explicit `kind: pivot` schema for
12
+ * this M2M (e.g. `["position", "notes"]`). Surfaced in the generated
13
+ * `belongsToMany()` chain via `->withPivot(...)` so consumers can
14
+ * read those columns through the relation. Empty / undefined when
15
+ * the user has not added custom columns to the pivot schema. */
16
+ pivotProperties?: string[];
11
17
  }
12
18
  /** Build Eloquent relation method PHP code. */
13
19
  export declare function buildRelation(propName: string, property: Record<string, unknown>, modelNamespace: string, context?: RelationContext): RelationResult | null;
@@ -128,12 +128,15 @@ function belongsToMany(propName, property, target, ns, context) {
128
128
  joinTable = generatePivotTableName(context.sourceTableName, context.targetTableName);
129
129
  }
130
130
  const methodName = toCamelCase(propName);
131
- const pivotFields = property['pivotFields'] ?? {};
132
131
  const fqcn = `\\${ns}\\${target}`;
133
132
  let chain = `$this->belongsToMany(${fqcn}::class, '${joinTable}')`;
134
- const fieldKeys = Object.keys(pivotFields);
135
- if (fieldKeys.length > 0) {
136
- const fields = fieldKeys.map(k => `'${toSnakeCase(k)}'`).join(', ');
133
+ // withPivot for every column declared on the explicit `kind: pivot`
134
+ // schema (resolved upstream and passed via context.pivotProperties).
135
+ // The legacy `pivotFields:` block on the M2M property was removed in
136
+ // v5.0.0; pivot columns now live on the pivot schema itself.
137
+ const pivotCols = context?.pivotProperties ?? [];
138
+ if (pivotCols.length > 0) {
139
+ const fields = pivotCols.map(k => `'${toSnakeCase(k)}'`).join(', ');
137
140
  chain += `\n ->withPivot(${fields})`;
138
141
  }
139
142
  chain += `\n ->withTimestamps()`;
package/types/schema.d.ts CHANGED
@@ -85,7 +85,16 @@ export interface CompoundFieldOverride {
85
85
  placeholder?: LocalizedString;
86
86
  }
87
87
 
88
- /** Field definition on a pivot table. */
88
+ /**
89
+ * Field definition on a pivot table.
90
+ *
91
+ * @deprecated Removed in v5.0.0 — `pivotFields:` on a M2M association
92
+ * is rejected by validation. Use an explicit `kind: pivot` schema
93
+ * (auto-created by `omnify generate`) and put extra columns under its
94
+ * `properties:` block. The interface is retained for IDE auto-complete
95
+ * compatibility on legacy YAML so users see the deprecation in their
96
+ * editor, then get the actionable hard error from the CLI.
97
+ */
89
98
  export interface PivotFieldDefinition {
90
99
  type: BuiltInPropertyType;
91
100
  nullable?: boolean;
@@ -239,7 +248,14 @@ export interface PropertyDefinition {
239
248
  onUpdate?: ReferentialAction;
240
249
  owning?: boolean;
241
250
  joinTable?: string;
251
+ /** @deprecated Removed in v5.0.0 — declare extra pivot columns on the
252
+ * explicit `kind: pivot` schema (auto-created by `omnify generate`)
253
+ * instead. Validation rejects YAML that still uses this field. */
242
254
  pivotFields?: Record<string, PivotFieldDefinition>;
255
+ /** @deprecated Removed in v5.0.0 — set `options.id` on the explicit
256
+ * `kind: pivot` schema instead. Validation rejects YAML that still
257
+ * uses this field. */
258
+ pivotId?: IdType;
243
259
  targetNamespace?: string;
244
260
  idType?: IdType;
245
261
  }