@nubitio/hydra 0.9.1 → 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 +9 -3
- package/dist/index.d.cts +27 -0
- package/dist/index.d.mts +27 -0
- package/dist/index.mjs +9 -3
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -635,8 +635,14 @@ 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",
|
|
642
648
|
"nombre",
|
|
@@ -801,7 +807,7 @@ function mapHydraSchemaToFields(schema, urlLookup, schemaLookup) {
|
|
|
801
807
|
const url = resourceClass ? urlLookup?.(resourceClass) ?? `/api/${pluralize(toDashCase(resourceClass))}` : "";
|
|
802
808
|
const valueField = resolveEntityValueField(relatedSchema);
|
|
803
809
|
const field = {
|
|
804
|
-
...(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(),
|
|
805
811
|
filterable
|
|
806
812
|
};
|
|
807
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,8 +611,14 @@ 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",
|
|
618
624
|
"nombre",
|
|
@@ -777,7 +783,7 @@ function mapHydraSchemaToFields(schema, urlLookup, schemaLookup) {
|
|
|
777
783
|
const url = resourceClass ? urlLookup?.(resourceClass) ?? `/api/${pluralize(toDashCase(resourceClass))}` : "";
|
|
778
784
|
const valueField = resolveEntityValueField(relatedSchema);
|
|
779
785
|
const field = {
|
|
780
|
-
...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(),
|
|
781
787
|
filterable
|
|
782
788
|
};
|
|
783
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.
|
|
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.
|
|
54
|
-
"@nubitio/crud": "^0.9.
|
|
53
|
+
"@nubitio/core": "^0.9.2",
|
|
54
|
+
"@nubitio/crud": "^0.9.2"
|
|
55
55
|
}
|
|
56
56
|
}
|