@nubitio/hydra 0.6.1 → 0.6.3
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 +10 -5
- package/dist/index.mjs +10 -5
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1088,12 +1088,15 @@ function normalizeUrl(url) {
|
|
|
1088
1088
|
const base = url.split("?")[0];
|
|
1089
1089
|
return base.startsWith("/") ? base.slice(1) : base;
|
|
1090
1090
|
}
|
|
1091
|
-
function shouldInferFormDetail(formDetail
|
|
1092
|
-
if (!embeddedLines?.length) return false;
|
|
1091
|
+
function shouldInferFormDetail(formDetail) {
|
|
1093
1092
|
if (formDetail?.inferFields === false) return false;
|
|
1094
1093
|
if (formDetail?.fields && formDetail.fields.length > 0) return false;
|
|
1095
1094
|
return true;
|
|
1096
1095
|
}
|
|
1096
|
+
function resolveParentSchema(apiUrl, schemaData) {
|
|
1097
|
+
const resourceMap = schemaData.format === "hydra" ? parseHydraDoc(schemaData.doc, schemaData.entrypointHrefs) : parseOpenApiDoc(schemaData.doc);
|
|
1098
|
+
return Object.values(resourceMap).find((schema) => normalizeUrl(schema.apiUrl) === normalizeUrl(apiUrl));
|
|
1099
|
+
}
|
|
1097
1100
|
/**
|
|
1098
1101
|
* Builds or augments `formDetail` from `x-embedded-lines` when the parent
|
|
1099
1102
|
* resource publishes embedded line metadata.
|
|
@@ -1103,14 +1106,16 @@ function shouldInferFormDetail(formDetail, embeddedLines) {
|
|
|
1103
1106
|
* - `formDetail.fields` is a non-empty manual array.
|
|
1104
1107
|
*/
|
|
1105
1108
|
function resolveInferredFormDetail(apiUrl, formDetail, schemaData, embeddedLines) {
|
|
1106
|
-
if (!shouldInferFormDetail(formDetail
|
|
1109
|
+
if (!shouldInferFormDetail(formDetail) || !schemaData) return formDetail;
|
|
1107
1110
|
const resourceMap = schemaData.format === "hydra" ? parseHydraDoc(schemaData.doc, schemaData.entrypointHrefs) : parseOpenApiDoc(schemaData.doc);
|
|
1108
|
-
const parentSchema =
|
|
1111
|
+
const parentSchema = resolveParentSchema(apiUrl, schemaData);
|
|
1112
|
+
const effectiveEmbeddedLines = parentSchema?.embeddedLines ?? embeddedLines;
|
|
1113
|
+
if (!effectiveEmbeddedLines?.length) return formDetail;
|
|
1109
1114
|
const binding = resolveEmbeddedBinding({
|
|
1110
1115
|
className: parentSchema?.className ?? "",
|
|
1111
1116
|
apiUrl,
|
|
1112
1117
|
fields: parentSchema?.fields ?? [],
|
|
1113
|
-
embeddedLines:
|
|
1118
|
+
embeddedLines: effectiveEmbeddedLines
|
|
1114
1119
|
}, formDetail?.propertyName);
|
|
1115
1120
|
if (!binding) return formDetail;
|
|
1116
1121
|
const lineSchema = resourceMap[binding.lineClass];
|
package/dist/index.mjs
CHANGED
|
@@ -1064,12 +1064,15 @@ function normalizeUrl(url) {
|
|
|
1064
1064
|
const base = url.split("?")[0];
|
|
1065
1065
|
return base.startsWith("/") ? base.slice(1) : base;
|
|
1066
1066
|
}
|
|
1067
|
-
function shouldInferFormDetail(formDetail
|
|
1068
|
-
if (!embeddedLines?.length) return false;
|
|
1067
|
+
function shouldInferFormDetail(formDetail) {
|
|
1069
1068
|
if (formDetail?.inferFields === false) return false;
|
|
1070
1069
|
if (formDetail?.fields && formDetail.fields.length > 0) return false;
|
|
1071
1070
|
return true;
|
|
1072
1071
|
}
|
|
1072
|
+
function resolveParentSchema(apiUrl, schemaData) {
|
|
1073
|
+
const resourceMap = schemaData.format === "hydra" ? parseHydraDoc(schemaData.doc, schemaData.entrypointHrefs) : parseOpenApiDoc(schemaData.doc);
|
|
1074
|
+
return Object.values(resourceMap).find((schema) => normalizeUrl(schema.apiUrl) === normalizeUrl(apiUrl));
|
|
1075
|
+
}
|
|
1073
1076
|
/**
|
|
1074
1077
|
* Builds or augments `formDetail` from `x-embedded-lines` when the parent
|
|
1075
1078
|
* resource publishes embedded line metadata.
|
|
@@ -1079,14 +1082,16 @@ function shouldInferFormDetail(formDetail, embeddedLines) {
|
|
|
1079
1082
|
* - `formDetail.fields` is a non-empty manual array.
|
|
1080
1083
|
*/
|
|
1081
1084
|
function resolveInferredFormDetail(apiUrl, formDetail, schemaData, embeddedLines) {
|
|
1082
|
-
if (!shouldInferFormDetail(formDetail
|
|
1085
|
+
if (!shouldInferFormDetail(formDetail) || !schemaData) return formDetail;
|
|
1083
1086
|
const resourceMap = schemaData.format === "hydra" ? parseHydraDoc(schemaData.doc, schemaData.entrypointHrefs) : parseOpenApiDoc(schemaData.doc);
|
|
1084
|
-
const parentSchema =
|
|
1087
|
+
const parentSchema = resolveParentSchema(apiUrl, schemaData);
|
|
1088
|
+
const effectiveEmbeddedLines = parentSchema?.embeddedLines ?? embeddedLines;
|
|
1089
|
+
if (!effectiveEmbeddedLines?.length) return formDetail;
|
|
1085
1090
|
const binding = resolveEmbeddedBinding({
|
|
1086
1091
|
className: parentSchema?.className ?? "",
|
|
1087
1092
|
apiUrl,
|
|
1088
1093
|
fields: parentSchema?.fields ?? [],
|
|
1089
|
-
embeddedLines:
|
|
1094
|
+
embeddedLines: effectiveEmbeddedLines
|
|
1090
1095
|
}, formDetail?.propertyName);
|
|
1091
1096
|
if (!binding) return formDetail;
|
|
1092
1097
|
const lineSchema = resourceMap[binding.lineClass];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nubitio/hydra",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3",
|
|
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": "^19.0.0",
|
|
51
51
|
"react-dom": "^19.0.0",
|
|
52
52
|
"react-i18next": "^14.0.0",
|
|
53
|
-
"@nubitio/core": "^0.6.
|
|
54
|
-
"@nubitio/crud": "^0.6.
|
|
53
|
+
"@nubitio/core": "^0.6.3",
|
|
54
|
+
"@nubitio/crud": "^0.6.3"
|
|
55
55
|
}
|
|
56
56
|
}
|