@nubitio/hydra 0.9.3 → 0.9.5
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 +14 -2
- package/dist/index.d.cts +9 -0
- package/dist/index.d.mts +9 -0
- package/dist/index.mjs +15 -3
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -297,6 +297,16 @@ function deriveApiUrl(entrypointPropertyId) {
|
|
|
297
297
|
* - a Hydra collection range array where the resource class lives under
|
|
298
298
|
* `owl:equivalentClass.owl:allValuesFrom.@id`
|
|
299
299
|
*/
|
|
300
|
+
/**
|
|
301
|
+
* True when `raw` is the Hydra collection-range wrapper — an array whose
|
|
302
|
+
* entries carry the target class under `owl:equivalentClass.owl:allValuesFrom`.
|
|
303
|
+
* This is exactly the shape API Platform emits for `ManyToMany`/`OneToMany`
|
|
304
|
+
* properties (see {@link normalizeRange}); a to-one relation's `range` is
|
|
305
|
+
* always a plain string or a single IRI object, never an array.
|
|
306
|
+
*/
|
|
307
|
+
function isCollectionRange(raw) {
|
|
308
|
+
return Array.isArray(raw);
|
|
309
|
+
}
|
|
300
310
|
function normalizeRange(raw) {
|
|
301
311
|
if (typeof raw === "string") return raw;
|
|
302
312
|
if (Array.isArray(raw)) for (const item of raw) {
|
|
@@ -436,6 +446,7 @@ function parseHydraDoc(doc, entrypointHrefs) {
|
|
|
436
446
|
required: sp.required ?? false,
|
|
437
447
|
readable,
|
|
438
448
|
writeable,
|
|
449
|
+
isCollection: isCollectionRange(sp.property?.range),
|
|
439
450
|
"hydra:title": sp["title"] ?? sp["hydra:title"] ?? void 0,
|
|
440
451
|
crudHints: sp["x-crud"],
|
|
441
452
|
enumOptions: Array.isArray(sp["enum"]) ? sp["enum"] : void 0
|
|
@@ -823,11 +834,12 @@ function mapHydraSchemaToFields(schema, urlLookup, schemaLookup) {
|
|
|
823
834
|
const relatedSchema = resourceClass ? schemaLookup?.(resourceClass) : void 0;
|
|
824
835
|
const url = resourceClass ? urlLookup?.(resourceClass) ?? `/api/${pluralize(toDashCase(resourceClass))}` : "";
|
|
825
836
|
const valueField = resolveEntityValueField(relatedSchema);
|
|
837
|
+
const textField = resolveEntityTextField(relatedSchema, valueField, fieldSchema.crudHints?.textField);
|
|
826
838
|
const field = {
|
|
827
|
-
...(0, _nubitio_crud.
|
|
839
|
+
...(fieldSchema.isCollection ? (0, _nubitio_crud.tagsField)(url, valueField, textField) : (0, _nubitio_crud.entityField)(url, valueField, textField)).name(name).label(label).required(required).build(),
|
|
828
840
|
filterable
|
|
829
841
|
};
|
|
830
|
-
stampMappingReason(field, `rule-8 entity → ${url || "unknown-url"}`, applyCrudHints(field, fieldSchema.crudHints));
|
|
842
|
+
stampMappingReason(field, `rule-8 ${fieldSchema.isCollection ? "tags (collection)" : "entity"} → ${url || "unknown-url"}`, applyCrudHints(field, fieldSchema.crudHints));
|
|
831
843
|
fields.push(field);
|
|
832
844
|
continue;
|
|
833
845
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -263,6 +263,15 @@ interface HydraFieldSchema {
|
|
|
263
263
|
crudHints?: CrudHints;
|
|
264
264
|
/** Allowed values (renders as a select). From `enum` on the supported property. */
|
|
265
265
|
enumOptions?: Array<string | number>;
|
|
266
|
+
/**
|
|
267
|
+
* True when the property is a to-many relation (Doctrine ManyToMany /
|
|
268
|
+
* OneToMany) rather than a single reference. Derived from the Hydra
|
|
269
|
+
* collection-range wrapper shape — see {@link normalizeRange} — which
|
|
270
|
+
* signals cardinality but is otherwise discarded once the target class
|
|
271
|
+
* name has been extracted. Rule 8 in {@link mapHydraSchemaToFields} uses
|
|
272
|
+
* this to render a multi-select control instead of a single picker.
|
|
273
|
+
*/
|
|
274
|
+
isCollection?: boolean;
|
|
266
275
|
}
|
|
267
276
|
/**
|
|
268
277
|
* A single entry from a Hydra `hydra:search` / `hydra:mapping` block.
|
package/dist/index.d.mts
CHANGED
|
@@ -263,6 +263,15 @@ interface HydraFieldSchema {
|
|
|
263
263
|
crudHints?: CrudHints;
|
|
264
264
|
/** Allowed values (renders as a select). From `enum` on the supported property. */
|
|
265
265
|
enumOptions?: Array<string | number>;
|
|
266
|
+
/**
|
|
267
|
+
* True when the property is a to-many relation (Doctrine ManyToMany /
|
|
268
|
+
* OneToMany) rather than a single reference. Derived from the Hydra
|
|
269
|
+
* collection-range wrapper shape — see {@link normalizeRange} — which
|
|
270
|
+
* signals cardinality but is otherwise discarded once the target class
|
|
271
|
+
* name has been extracted. Rule 8 in {@link mapHydraSchemaToFields} uses
|
|
272
|
+
* this to render a multi-select control instead of a single picker.
|
|
273
|
+
*/
|
|
274
|
+
isCollection?: boolean;
|
|
266
275
|
}
|
|
267
276
|
/**
|
|
268
277
|
* A single entry from a Hydra `hydra:search` / `hydra:mapping` block.
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createCoreHttpClient, useCoreConfig, useCoreHttpClient } from "@nubitio/core";
|
|
2
2
|
import { createContext, useContext, useMemo } from "react";
|
|
3
|
-
import { ResourceSchemaProvider, ResourceStoreProvider, currencyField, datetimeField, embeddedLinesUrl, entityField, enumField, fileField, imageField, noneField, numberField, switchField, textField } from "@nubitio/crud";
|
|
3
|
+
import { ResourceSchemaProvider, ResourceStoreProvider, currencyField, datetimeField, embeddedLinesUrl, entityField, enumField, fileField, imageField, noneField, numberField, switchField, tagsField, textField } from "@nubitio/crud";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
import { useQuery } from "@tanstack/react-query";
|
|
6
6
|
//#region packages/hydra/HydraRemoteDataSource.ts
|
|
@@ -273,6 +273,16 @@ function deriveApiUrl(entrypointPropertyId) {
|
|
|
273
273
|
* - a Hydra collection range array where the resource class lives under
|
|
274
274
|
* `owl:equivalentClass.owl:allValuesFrom.@id`
|
|
275
275
|
*/
|
|
276
|
+
/**
|
|
277
|
+
* True when `raw` is the Hydra collection-range wrapper — an array whose
|
|
278
|
+
* entries carry the target class under `owl:equivalentClass.owl:allValuesFrom`.
|
|
279
|
+
* This is exactly the shape API Platform emits for `ManyToMany`/`OneToMany`
|
|
280
|
+
* properties (see {@link normalizeRange}); a to-one relation's `range` is
|
|
281
|
+
* always a plain string or a single IRI object, never an array.
|
|
282
|
+
*/
|
|
283
|
+
function isCollectionRange(raw) {
|
|
284
|
+
return Array.isArray(raw);
|
|
285
|
+
}
|
|
276
286
|
function normalizeRange(raw) {
|
|
277
287
|
if (typeof raw === "string") return raw;
|
|
278
288
|
if (Array.isArray(raw)) for (const item of raw) {
|
|
@@ -412,6 +422,7 @@ function parseHydraDoc(doc, entrypointHrefs) {
|
|
|
412
422
|
required: sp.required ?? false,
|
|
413
423
|
readable,
|
|
414
424
|
writeable,
|
|
425
|
+
isCollection: isCollectionRange(sp.property?.range),
|
|
415
426
|
"hydra:title": sp["title"] ?? sp["hydra:title"] ?? void 0,
|
|
416
427
|
crudHints: sp["x-crud"],
|
|
417
428
|
enumOptions: Array.isArray(sp["enum"]) ? sp["enum"] : void 0
|
|
@@ -799,11 +810,12 @@ function mapHydraSchemaToFields(schema, urlLookup, schemaLookup) {
|
|
|
799
810
|
const relatedSchema = resourceClass ? schemaLookup?.(resourceClass) : void 0;
|
|
800
811
|
const url = resourceClass ? urlLookup?.(resourceClass) ?? `/api/${pluralize(toDashCase(resourceClass))}` : "";
|
|
801
812
|
const valueField = resolveEntityValueField(relatedSchema);
|
|
813
|
+
const textField = resolveEntityTextField(relatedSchema, valueField, fieldSchema.crudHints?.textField);
|
|
802
814
|
const field = {
|
|
803
|
-
...
|
|
815
|
+
...(fieldSchema.isCollection ? tagsField(url, valueField, textField) : entityField(url, valueField, textField)).name(name).label(label).required(required).build(),
|
|
804
816
|
filterable
|
|
805
817
|
};
|
|
806
|
-
stampMappingReason(field, `rule-8 entity → ${url || "unknown-url"}`, applyCrudHints(field, fieldSchema.crudHints));
|
|
818
|
+
stampMappingReason(field, `rule-8 ${fieldSchema.isCollection ? "tags (collection)" : "entity"} → ${url || "unknown-url"}`, applyCrudHints(field, fieldSchema.crudHints));
|
|
807
819
|
fields.push(field);
|
|
808
820
|
continue;
|
|
809
821
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nubitio/hydra",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.5",
|
|
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/
|
|
54
|
-
"@nubitio/
|
|
53
|
+
"@nubitio/core": "^0.9.5",
|
|
54
|
+
"@nubitio/crud": "^0.9.5"
|
|
55
55
|
}
|
|
56
56
|
}
|