@nubitio/hydra 0.9.0 → 0.9.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/dist/index.cjs CHANGED
@@ -635,15 +635,26 @@ function resolveEntityValueField(relatedSchema) {
635
635
  function isStringLikeField(field) {
636
636
  return field.range === void 0 || field.range === "xmls:string" || field.range === "xsd:string";
637
637
  }
638
- function resolveEntityTextField(relatedSchema, valueField) {
639
- if (!relatedSchema) return "name";
638
+ function resolveEntityTextField(relatedSchema, valueField, relationTextFieldHint) {
639
+ if (!relatedSchema) return relationTextFieldHint ?? "name";
640
+ if (relationTextFieldHint) {
641
+ const hinted = relatedSchema.fields.find((field) => field.name === relationTextFieldHint);
642
+ if (hinted) return hinted.name;
643
+ }
644
+ const declared = relatedSchema.fields.find((field) => field.crudHints?.displayField === true);
645
+ if (declared) return declared.name;
640
646
  for (const fieldName of [
641
647
  "name",
648
+ "nombre",
642
649
  "businessName",
650
+ "razonSocial",
643
651
  "description",
652
+ "descripcion",
644
653
  "fullNumber",
645
654
  "title",
646
- "series"
655
+ "titulo",
656
+ "series",
657
+ "label"
647
658
  ]) {
648
659
  const match = relatedSchema.fields.find((field) => field.name === fieldName && isStringLikeField(field));
649
660
  if (match) return match.name;
@@ -796,7 +807,7 @@ function mapHydraSchemaToFields(schema, urlLookup, schemaLookup) {
796
807
  const url = resourceClass ? urlLookup?.(resourceClass) ?? `/api/${pluralize(toDashCase(resourceClass))}` : "";
797
808
  const valueField = resolveEntityValueField(relatedSchema);
798
809
  const field = {
799
- ...(0, _nubitio_crud.entityField)(url, valueField, resolveEntityTextField(relatedSchema, valueField)).name(name).label(label).required(required).build(),
810
+ ...(0, _nubitio_crud.entityField)(url, valueField, resolveEntityTextField(relatedSchema, valueField, fieldSchema.crudHints?.textField)).name(name).label(label).required(required).build(),
800
811
  filterable
801
812
  };
802
813
  stampMappingReason(field, `rule-8 entity → ${url || "unknown-url"}`, applyCrudHints(field, fieldSchema.crudHints));
package/dist/index.d.cts CHANGED
@@ -90,6 +90,33 @@ interface CrudHints {
90
90
  summable?: boolean;
91
91
  /** Aggregate function for summable columns. @default 'sum' */
92
92
  summaryType?: 'sum' | 'count' | 'avg' | 'min' | 'max';
93
+ /**
94
+ * Set on an entity-relation property (e.g. `Cotizacion::$proveedor`).
95
+ * Names the property of the *related* resource to display in pickers,
96
+ * columns and form labels for this relation specifically — takes priority
97
+ * over `displayField` and the built-in name-heuristic. Use this when the
98
+ * same related entity should show a different field depending on which
99
+ * relation is pointing at it; for the common case (one natural label per
100
+ * entity), prefer `displayField` on the related entity itself so every
101
+ * relation to it picks it up automatically.
102
+ *
103
+ * #[ApiProperty(openapiContext: ['x-crud' => ['textField' => 'razonSocial']])]
104
+ * private ?Actor $proveedor = null;
105
+ */
106
+ textField?: string;
107
+ /**
108
+ * Set on a property of the entity being *referenced* (e.g.
109
+ * `CentroCosto::$nombre`), not on the relation that points to it. Declares
110
+ * "this is the natural human-readable label for this entity" once, so
111
+ * every relation to it — anywhere in the app, present or future — resolves
112
+ * to the right field without per-relation configuration. Falls back to the
113
+ * built-in name-heuristic (`name`, `nombre`, `businessName`, `description`,
114
+ * `descripcion`, …) when no field on the related entity sets this.
115
+ *
116
+ * #[ApiProperty(openapiContext: ['x-crud' => ['displayField' => true]])]
117
+ * private string $nombre = '';
118
+ */
119
+ displayField?: boolean;
93
120
  }
94
121
  interface HydraSupportedProperty {
95
122
  '@type': 'SupportedProperty';
package/dist/index.d.mts CHANGED
@@ -90,6 +90,33 @@ interface CrudHints {
90
90
  summable?: boolean;
91
91
  /** Aggregate function for summable columns. @default 'sum' */
92
92
  summaryType?: 'sum' | 'count' | 'avg' | 'min' | 'max';
93
+ /**
94
+ * Set on an entity-relation property (e.g. `Cotizacion::$proveedor`).
95
+ * Names the property of the *related* resource to display in pickers,
96
+ * columns and form labels for this relation specifically — takes priority
97
+ * over `displayField` and the built-in name-heuristic. Use this when the
98
+ * same related entity should show a different field depending on which
99
+ * relation is pointing at it; for the common case (one natural label per
100
+ * entity), prefer `displayField` on the related entity itself so every
101
+ * relation to it picks it up automatically.
102
+ *
103
+ * #[ApiProperty(openapiContext: ['x-crud' => ['textField' => 'razonSocial']])]
104
+ * private ?Actor $proveedor = null;
105
+ */
106
+ textField?: string;
107
+ /**
108
+ * Set on a property of the entity being *referenced* (e.g.
109
+ * `CentroCosto::$nombre`), not on the relation that points to it. Declares
110
+ * "this is the natural human-readable label for this entity" once, so
111
+ * every relation to it — anywhere in the app, present or future — resolves
112
+ * to the right field without per-relation configuration. Falls back to the
113
+ * built-in name-heuristic (`name`, `nombre`, `businessName`, `description`,
114
+ * `descripcion`, …) when no field on the related entity sets this.
115
+ *
116
+ * #[ApiProperty(openapiContext: ['x-crud' => ['displayField' => true]])]
117
+ * private string $nombre = '';
118
+ */
119
+ displayField?: boolean;
93
120
  }
94
121
  interface HydraSupportedProperty {
95
122
  '@type': 'SupportedProperty';
package/dist/index.mjs CHANGED
@@ -611,15 +611,26 @@ function resolveEntityValueField(relatedSchema) {
611
611
  function isStringLikeField(field) {
612
612
  return field.range === void 0 || field.range === "xmls:string" || field.range === "xsd:string";
613
613
  }
614
- function resolveEntityTextField(relatedSchema, valueField) {
615
- if (!relatedSchema) return "name";
614
+ function resolveEntityTextField(relatedSchema, valueField, relationTextFieldHint) {
615
+ if (!relatedSchema) return relationTextFieldHint ?? "name";
616
+ if (relationTextFieldHint) {
617
+ const hinted = relatedSchema.fields.find((field) => field.name === relationTextFieldHint);
618
+ if (hinted) return hinted.name;
619
+ }
620
+ const declared = relatedSchema.fields.find((field) => field.crudHints?.displayField === true);
621
+ if (declared) return declared.name;
616
622
  for (const fieldName of [
617
623
  "name",
624
+ "nombre",
618
625
  "businessName",
626
+ "razonSocial",
619
627
  "description",
628
+ "descripcion",
620
629
  "fullNumber",
621
630
  "title",
622
- "series"
631
+ "titulo",
632
+ "series",
633
+ "label"
623
634
  ]) {
624
635
  const match = relatedSchema.fields.find((field) => field.name === fieldName && isStringLikeField(field));
625
636
  if (match) return match.name;
@@ -772,7 +783,7 @@ function mapHydraSchemaToFields(schema, urlLookup, schemaLookup) {
772
783
  const url = resourceClass ? urlLookup?.(resourceClass) ?? `/api/${pluralize(toDashCase(resourceClass))}` : "";
773
784
  const valueField = resolveEntityValueField(relatedSchema);
774
785
  const field = {
775
- ...entityField(url, valueField, resolveEntityTextField(relatedSchema, valueField)).name(name).label(label).required(required).build(),
786
+ ...entityField(url, valueField, resolveEntityTextField(relatedSchema, valueField, fieldSchema.crudHints?.textField)).name(name).label(label).required(required).build(),
776
787
  filterable
777
788
  };
778
789
  stampMappingReason(field, `rule-8 entity → ${url || "unknown-url"}`, applyCrudHints(field, fieldSchema.crudHints));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nubitio/hydra",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "type": "module",
5
5
  "description": "Hydra / OpenAPI adapter for @nubitio/crud — automatic schema discovery and data source from API Platform docs.",
6
6
  "license": "MIT",
@@ -50,7 +50,7 @@
50
50
  "react": "^18.2.0 || ^19.0.0",
51
51
  "react-dom": "^18.2.0 || ^19.0.0",
52
52
  "react-i18next": "^14.0.0",
53
- "@nubitio/core": "^0.9.0",
54
- "@nubitio/crud": "^0.9.0"
53
+ "@nubitio/core": "^0.9.2",
54
+ "@nubitio/crud": "^0.9.2"
55
55
  }
56
56
  }