@nubitio/hydra 0.9.4 → 0.9.6
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 +18 -3
- package/dist/index.d.cts +13 -0
- package/dist/index.d.mts +13 -0
- package/dist/index.mjs +19 -4
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -297,6 +297,18 @@ 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
|
+
* Some API Platform configurations emit this shape for `ManyToMany`/`OneToMany`
|
|
304
|
+
* properties instead of the plain string `range` + `@type: "Link"` combination
|
|
305
|
+
* (see the `isCollection` field on `HydraFieldSchema` for the other signal) —
|
|
306
|
+
* this function only recognises the array-wrapper variant. A to-one relation's
|
|
307
|
+
* `range` is always a plain string or a single IRI object, never an array.
|
|
308
|
+
*/
|
|
309
|
+
function isCollectionRange(raw) {
|
|
310
|
+
return Array.isArray(raw);
|
|
311
|
+
}
|
|
300
312
|
function normalizeRange(raw) {
|
|
301
313
|
if (typeof raw === "string") return raw;
|
|
302
314
|
if (Array.isArray(raw)) for (const item of raw) {
|
|
@@ -429,13 +441,15 @@ function parseHydraDoc(doc, entrypointHrefs) {
|
|
|
429
441
|
const readable = sp.readable !== false;
|
|
430
442
|
const writeable = sp.writeable !== false;
|
|
431
443
|
if (!readable) continue;
|
|
444
|
+
const propertyType = sp.property?.["@type"] ?? "rdf:Property";
|
|
432
445
|
fields.push({
|
|
433
446
|
name: technicalName(sp),
|
|
434
447
|
range: normalizeRange(sp.property?.range),
|
|
435
|
-
propertyType
|
|
448
|
+
propertyType,
|
|
436
449
|
required: sp.required ?? false,
|
|
437
450
|
readable,
|
|
438
451
|
writeable,
|
|
452
|
+
isCollection: isCollectionRange(sp.property?.range) || propertyType === "Link",
|
|
439
453
|
"hydra:title": sp["title"] ?? sp["hydra:title"] ?? void 0,
|
|
440
454
|
crudHints: sp["x-crud"],
|
|
441
455
|
enumOptions: Array.isArray(sp["enum"]) ? sp["enum"] : void 0
|
|
@@ -823,11 +837,12 @@ function mapHydraSchemaToFields(schema, urlLookup, schemaLookup) {
|
|
|
823
837
|
const relatedSchema = resourceClass ? schemaLookup?.(resourceClass) : void 0;
|
|
824
838
|
const url = resourceClass ? urlLookup?.(resourceClass) ?? `/api/${pluralize(toDashCase(resourceClass))}` : "";
|
|
825
839
|
const valueField = resolveEntityValueField(relatedSchema);
|
|
840
|
+
const textField = resolveEntityTextField(relatedSchema, valueField, fieldSchema.crudHints?.textField);
|
|
826
841
|
const field = {
|
|
827
|
-
...(0, _nubitio_crud.
|
|
842
|
+
...(fieldSchema.isCollection ? (0, _nubitio_crud.tagsField)(url, valueField, textField) : (0, _nubitio_crud.entityField)(url, valueField, textField)).name(name).label(label).required(required).build(),
|
|
828
843
|
filterable
|
|
829
844
|
};
|
|
830
|
-
stampMappingReason(field, `rule-8 entity → ${url || "unknown-url"}`, applyCrudHints(field, fieldSchema.crudHints));
|
|
845
|
+
stampMappingReason(field, `rule-8 ${fieldSchema.isCollection ? "tags (collection)" : "entity"} → ${url || "unknown-url"}`, applyCrudHints(field, fieldSchema.crudHints));
|
|
831
846
|
fields.push(field);
|
|
832
847
|
continue;
|
|
833
848
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -263,6 +263,19 @@ 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. Two independent Hydra signals
|
|
269
|
+
* feed this, checked with OR since different API Platform configurations
|
|
270
|
+
* emit different ones: the collection-range array wrapper (see
|
|
271
|
+
* {@link isCollectionRange}), or `propertyType === 'Link'` — confirmed
|
|
272
|
+
* empirically to be exactly the to-many properties in at least one real
|
|
273
|
+
* deployment, where `range` alone is an unchanged plain string identical to
|
|
274
|
+
* a to-one relation's and carries no cardinality information at all. Rule 8
|
|
275
|
+
* in {@link mapHydraSchemaToFields} uses this to render a multi-select
|
|
276
|
+
* control instead of a single picker.
|
|
277
|
+
*/
|
|
278
|
+
isCollection?: boolean;
|
|
266
279
|
}
|
|
267
280
|
/**
|
|
268
281
|
* A single entry from a Hydra `hydra:search` / `hydra:mapping` block.
|
package/dist/index.d.mts
CHANGED
|
@@ -263,6 +263,19 @@ 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. Two independent Hydra signals
|
|
269
|
+
* feed this, checked with OR since different API Platform configurations
|
|
270
|
+
* emit different ones: the collection-range array wrapper (see
|
|
271
|
+
* {@link isCollectionRange}), or `propertyType === 'Link'` — confirmed
|
|
272
|
+
* empirically to be exactly the to-many properties in at least one real
|
|
273
|
+
* deployment, where `range` alone is an unchanged plain string identical to
|
|
274
|
+
* a to-one relation's and carries no cardinality information at all. Rule 8
|
|
275
|
+
* in {@link mapHydraSchemaToFields} uses this to render a multi-select
|
|
276
|
+
* control instead of a single picker.
|
|
277
|
+
*/
|
|
278
|
+
isCollection?: boolean;
|
|
266
279
|
}
|
|
267
280
|
/**
|
|
268
281
|
* 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,18 @@ 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
|
+
* Some API Platform configurations emit this shape for `ManyToMany`/`OneToMany`
|
|
280
|
+
* properties instead of the plain string `range` + `@type: "Link"` combination
|
|
281
|
+
* (see the `isCollection` field on `HydraFieldSchema` for the other signal) —
|
|
282
|
+
* this function only recognises the array-wrapper variant. A to-one relation's
|
|
283
|
+
* `range` is always a plain string or a single IRI object, never an array.
|
|
284
|
+
*/
|
|
285
|
+
function isCollectionRange(raw) {
|
|
286
|
+
return Array.isArray(raw);
|
|
287
|
+
}
|
|
276
288
|
function normalizeRange(raw) {
|
|
277
289
|
if (typeof raw === "string") return raw;
|
|
278
290
|
if (Array.isArray(raw)) for (const item of raw) {
|
|
@@ -405,13 +417,15 @@ function parseHydraDoc(doc, entrypointHrefs) {
|
|
|
405
417
|
const readable = sp.readable !== false;
|
|
406
418
|
const writeable = sp.writeable !== false;
|
|
407
419
|
if (!readable) continue;
|
|
420
|
+
const propertyType = sp.property?.["@type"] ?? "rdf:Property";
|
|
408
421
|
fields.push({
|
|
409
422
|
name: technicalName(sp),
|
|
410
423
|
range: normalizeRange(sp.property?.range),
|
|
411
|
-
propertyType
|
|
424
|
+
propertyType,
|
|
412
425
|
required: sp.required ?? false,
|
|
413
426
|
readable,
|
|
414
427
|
writeable,
|
|
428
|
+
isCollection: isCollectionRange(sp.property?.range) || propertyType === "Link",
|
|
415
429
|
"hydra:title": sp["title"] ?? sp["hydra:title"] ?? void 0,
|
|
416
430
|
crudHints: sp["x-crud"],
|
|
417
431
|
enumOptions: Array.isArray(sp["enum"]) ? sp["enum"] : void 0
|
|
@@ -799,11 +813,12 @@ function mapHydraSchemaToFields(schema, urlLookup, schemaLookup) {
|
|
|
799
813
|
const relatedSchema = resourceClass ? schemaLookup?.(resourceClass) : void 0;
|
|
800
814
|
const url = resourceClass ? urlLookup?.(resourceClass) ?? `/api/${pluralize(toDashCase(resourceClass))}` : "";
|
|
801
815
|
const valueField = resolveEntityValueField(relatedSchema);
|
|
816
|
+
const textField = resolveEntityTextField(relatedSchema, valueField, fieldSchema.crudHints?.textField);
|
|
802
817
|
const field = {
|
|
803
|
-
...
|
|
818
|
+
...(fieldSchema.isCollection ? tagsField(url, valueField, textField) : entityField(url, valueField, textField)).name(name).label(label).required(required).build(),
|
|
804
819
|
filterable
|
|
805
820
|
};
|
|
806
|
-
stampMappingReason(field, `rule-8 entity → ${url || "unknown-url"}`, applyCrudHints(field, fieldSchema.crudHints));
|
|
821
|
+
stampMappingReason(field, `rule-8 ${fieldSchema.isCollection ? "tags (collection)" : "entity"} → ${url || "unknown-url"}`, applyCrudHints(field, fieldSchema.crudHints));
|
|
807
822
|
fields.push(field);
|
|
808
823
|
continue;
|
|
809
824
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nubitio/hydra",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.6",
|
|
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.6",
|
|
54
|
+
"@nubitio/crud": "^0.9.6"
|
|
55
55
|
}
|
|
56
56
|
}
|