@nubitio/hydra 1.1.1 → 1.1.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
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
18
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
20
20
  value: mod,
21
21
  enumerable: true
22
22
  }) : target, mod));
@@ -341,7 +341,7 @@ function pluralize(word) {
341
341
  return word + "s";
342
342
  }
343
343
  /** Entrypoint property names that are already in plural form (dash-case). */
344
- const ALREADY_PLURAL = new Set([
344
+ const ALREADY_PLURAL = /* @__PURE__ */ new Set([
345
345
  "purchases",
346
346
  "sales",
347
347
  "invoices",
@@ -461,6 +461,26 @@ function extractSearchMappings(cls) {
461
461
  * Accepts both `hydra:method` and `method` field names inside each operation entry
462
462
  * to be safe across different API Platform serialisation variants.
463
463
  */
464
+ /**
465
+ * The class an Entrypoint property points at (`#Category` for `/api/categories`).
466
+ *
467
+ * Older API Platform emits it as the property `range` (plain or wrapped in
468
+ * `owl:equivalentClass`). Newer releases emit `range: "hydra:Collection"` for
469
+ * every collection and name the member class under `memberAssertion.object`;
470
+ * reading `range` alone there would key every resource as `hydra:Collection`
471
+ * and drop their collection operations (notably POST).
472
+ */
473
+ function entrypointTargetClass(property) {
474
+ const memberAssertion = property?.memberAssertion;
475
+ if (memberAssertion && typeof memberAssertion === "object") {
476
+ const object = memberAssertion["object"];
477
+ if (object && typeof object === "object") {
478
+ const id = object["@id"];
479
+ if (typeof id === "string") return id;
480
+ }
481
+ }
482
+ return normalizeRange(property?.range);
483
+ }
464
484
  function extractSupportedOperations(cls) {
465
485
  const operations = cls["supportedOperation"];
466
486
  if (!operations || operations.length === 0) return [];
@@ -471,8 +491,7 @@ function extractEntrypointCollectionOperations(doc) {
471
491
  if (!entrypoint) return {};
472
492
  const collectionOperations = {};
473
493
  for (const sp of entrypoint.supportedProperty ?? []) {
474
- const rawRange = sp.property?.range;
475
- const range = normalizeRange(rawRange);
494
+ const range = entrypointTargetClass(sp.property);
476
495
  if (!range) continue;
477
496
  const className = range.replace("#", "");
478
497
  collectionOperations[className] = (sp.property?.supportedOperation ?? []).map((op) => (op["hydra:method"] ?? op["method"] ?? "").toUpperCase()).filter(Boolean);
@@ -499,8 +518,7 @@ function parseHydraDoc(doc, entrypointHrefs) {
499
518
  const urlMap = {};
500
519
  const entrypoint = doc["supportedClass"].find((c) => c["@id"] === "#Entrypoint");
501
520
  if (entrypoint) for (const sp of entrypoint.supportedProperty ?? []) {
502
- const rawRange = sp.property?.range;
503
- const range = normalizeRange(rawRange);
521
+ const range = entrypointTargetClass(sp.property);
504
522
  const propId = sp.property?.["@id"];
505
523
  if (range && propId) {
506
524
  const className = range.replace("#", "");
@@ -542,7 +560,7 @@ function parseHydraDoc(doc, entrypointHrefs) {
542
560
  importable: cls["x-importable"],
543
561
  gridScale: cls["x-grid-scale"],
544
562
  searchMappings: extractSearchMappings(cls),
545
- supportedOperations: Array.from(new Set([...collectionOperationsMap[className] ?? [], ...extractSupportedOperations(cls)]))
563
+ supportedOperations: Array.from(/* @__PURE__ */ new Set([...collectionOperationsMap[className] ?? [], ...extractSupportedOperations(cls)]))
546
564
  };
547
565
  }
548
566
  return result;
@@ -1207,7 +1225,7 @@ function useHydraMetadata() {
1207
1225
  const { data, error, isPending } = (0, _tanstack_react_query.useQuery)({
1208
1226
  queryKey: [...API_DOC_QUERY_KEY, locale],
1209
1227
  queryFn: () => fetchApiDoc(httpClient),
1210
- staleTime: isDev ? 0 : 5 * 6e4,
1228
+ staleTime: isDev ? 0 : 3e5,
1211
1229
  refetchOnWindowFocus: isDev,
1212
1230
  refetchOnReconnect: isDev
1213
1231
  });
@@ -1315,8 +1333,9 @@ function useHydraResourceSchema({ apiUrl, enabled }) {
1315
1333
  return useResourceSchema(apiUrl, { enabled });
1316
1334
  }
1317
1335
  function HydraResourceSchemaProvider({ children }) {
1336
+ const resolver = (0, react.useMemo)(() => ({ useResourceSchema: useHydraResourceSchema }), []);
1318
1337
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_nubitio_crud.ResourceSchemaProvider, {
1319
- resolver: (0, react.useMemo)(() => ({ useResourceSchema: useHydraResourceSchema }), []),
1338
+ resolver,
1320
1339
  children
1321
1340
  });
1322
1341
  }
package/dist/index.d.cts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { DataRecord, GridData } from "@nubitio/core";
2
2
  import { DataRecord as DataRecord$1, EmbeddedLinesSchema, EmbeddedLinesSchema as EmbeddedLinesSchema$1, Field, FormLayout, ResourceExportResult, ResourceFilterDescriptor, ResourceFilterRule, ResourceFormDetail, ResourceLoadOptions, ResourceSchemaResolution, ResourceSortDescriptor, ResourceStore, ResourceStoreFactory, ResourceStoreOptions, SummaryItem, WorkflowSchema, WorkflowSchema as WorkflowSchema$1, WorkflowTransitionSchema } from "@nubitio/crud";
3
3
  import React, { ReactNode } from "react";
4
-
5
4
  //#region packages/hydra/HydraRemoteDataSource.d.ts
6
5
  type RemoteFilterDescriptor = ResourceFilterDescriptor;
7
6
  type RemoteSortDescriptor = ResourceSortDescriptor;
@@ -25,17 +24,13 @@ declare const createHydraResourceStore: ResourceStoreFactory;
25
24
  interface HydraResourceStoreProviderProps {
26
25
  children: React.ReactNode;
27
26
  }
28
- declare function HydraResourceStoreProvider({
29
- children
30
- }: HydraResourceStoreProviderProps): React.JSX.Element;
27
+ declare function HydraResourceStoreProvider({ children }: HydraResourceStoreProviderProps): React.JSX.Element;
31
28
  //#endregion
32
29
  //#region packages/hydra/HydraResourceSchemaProvider.d.ts
33
30
  interface HydraResourceSchemaProviderProps {
34
31
  children: React.ReactNode;
35
32
  }
36
- declare function HydraResourceSchemaProvider({
37
- children
38
- }: HydraResourceSchemaProviderProps): React.JSX.Element;
33
+ declare function HydraResourceSchemaProvider({ children }: HydraResourceSchemaProviderProps): React.JSX.Element;
39
34
  //#endregion
40
35
  //#region packages/hydra/types.d.ts
41
36
  interface HydraProperty {
@@ -51,6 +46,13 @@ interface HydraProperty {
51
46
  * Use normalizeRange() in openApiParser.ts to safely extract a string.
52
47
  */
53
48
  range?: unknown;
49
+ /**
50
+ * Newer API Platform releases (Hydra 2021 `memberAssertion`) type a collection
51
+ * link with `range: "hydra:Collection"` and name the member class here:
52
+ * `{ property: { '@id': 'rdf:type' }, object: { '@id': '#Category' } }`.
53
+ * Use entrypointTargetClass() in openApiParser.ts to read it.
54
+ */
55
+ memberAssertion?: unknown;
54
56
  }
55
57
  /**
56
58
  * UI display hints injected by the backend via `#[ApiProperty(openapiContext: ['x-crud' => [...]])]`.
@@ -504,12 +506,7 @@ interface BuildEmbeddedFormDetailOptions {
504
506
  * Builds a {@link ResourceFormDetail} from `x-embedded-lines` metadata and the
505
507
  * line entity schema in the API doc.
506
508
  */
507
- declare function buildEmbeddedFormDetail({
508
- binding,
509
- lineSchema,
510
- resourceMap,
511
- overrides
512
- }: BuildEmbeddedFormDetailOptions): ResourceFormDetail;
509
+ declare function buildEmbeddedFormDetail({ binding, lineSchema, resourceMap, overrides }: BuildEmbeddedFormDetailOptions): ResourceFormDetail;
513
510
  declare function resolveEmbeddedBinding(schema: HydraResourceSchema, propertyName?: string): EmbeddedLinesSchema | undefined;
514
511
  //#endregion
515
512
  //#region packages/hydra/HydraSchemaResolver.d.ts
@@ -595,9 +592,7 @@ interface SchemaProviderProps {
595
592
  * Wrap your app (or a subtree) with `SchemaProvider` to share a single
596
593
  * `/api/docs.jsonld` fetch across all `SchemaCrudPage` instances.
597
594
  */
598
- declare function SchemaProvider({
599
- children
600
- }: SchemaProviderProps): React.JSX.Element;
595
+ declare function SchemaProvider({ children }: SchemaProviderProps): React.JSX.Element;
601
596
  interface UseSchemaContextResult {
602
597
  data: UseHydraMetadataResult['data'];
603
598
  isLoading: boolean;
package/dist/index.d.mts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { DataRecord, GridData } from "@nubitio/core";
2
2
  import React, { ReactNode } from "react";
3
3
  import { DataRecord as DataRecord$1, EmbeddedLinesSchema, EmbeddedLinesSchema as EmbeddedLinesSchema$1, Field, FormLayout, ResourceExportResult, ResourceFilterDescriptor, ResourceFilterRule, ResourceFormDetail, ResourceLoadOptions, ResourceSchemaResolution, ResourceSortDescriptor, ResourceStore, ResourceStoreFactory, ResourceStoreOptions, SummaryItem, WorkflowSchema, WorkflowSchema as WorkflowSchema$1, WorkflowTransitionSchema } from "@nubitio/crud";
4
-
5
4
  //#region packages/hydra/HydraRemoteDataSource.d.ts
6
5
  type RemoteFilterDescriptor = ResourceFilterDescriptor;
7
6
  type RemoteSortDescriptor = ResourceSortDescriptor;
@@ -25,17 +24,13 @@ declare const createHydraResourceStore: ResourceStoreFactory;
25
24
  interface HydraResourceStoreProviderProps {
26
25
  children: React.ReactNode;
27
26
  }
28
- declare function HydraResourceStoreProvider({
29
- children
30
- }: HydraResourceStoreProviderProps): React.JSX.Element;
27
+ declare function HydraResourceStoreProvider({ children }: HydraResourceStoreProviderProps): React.JSX.Element;
31
28
  //#endregion
32
29
  //#region packages/hydra/HydraResourceSchemaProvider.d.ts
33
30
  interface HydraResourceSchemaProviderProps {
34
31
  children: React.ReactNode;
35
32
  }
36
- declare function HydraResourceSchemaProvider({
37
- children
38
- }: HydraResourceSchemaProviderProps): React.JSX.Element;
33
+ declare function HydraResourceSchemaProvider({ children }: HydraResourceSchemaProviderProps): React.JSX.Element;
39
34
  //#endregion
40
35
  //#region packages/hydra/types.d.ts
41
36
  interface HydraProperty {
@@ -51,6 +46,13 @@ interface HydraProperty {
51
46
  * Use normalizeRange() in openApiParser.ts to safely extract a string.
52
47
  */
53
48
  range?: unknown;
49
+ /**
50
+ * Newer API Platform releases (Hydra 2021 `memberAssertion`) type a collection
51
+ * link with `range: "hydra:Collection"` and name the member class here:
52
+ * `{ property: { '@id': 'rdf:type' }, object: { '@id': '#Category' } }`.
53
+ * Use entrypointTargetClass() in openApiParser.ts to read it.
54
+ */
55
+ memberAssertion?: unknown;
54
56
  }
55
57
  /**
56
58
  * UI display hints injected by the backend via `#[ApiProperty(openapiContext: ['x-crud' => [...]])]`.
@@ -504,12 +506,7 @@ interface BuildEmbeddedFormDetailOptions {
504
506
  * Builds a {@link ResourceFormDetail} from `x-embedded-lines` metadata and the
505
507
  * line entity schema in the API doc.
506
508
  */
507
- declare function buildEmbeddedFormDetail({
508
- binding,
509
- lineSchema,
510
- resourceMap,
511
- overrides
512
- }: BuildEmbeddedFormDetailOptions): ResourceFormDetail;
509
+ declare function buildEmbeddedFormDetail({ binding, lineSchema, resourceMap, overrides }: BuildEmbeddedFormDetailOptions): ResourceFormDetail;
513
510
  declare function resolveEmbeddedBinding(schema: HydraResourceSchema, propertyName?: string): EmbeddedLinesSchema | undefined;
514
511
  //#endregion
515
512
  //#region packages/hydra/HydraSchemaResolver.d.ts
@@ -595,9 +592,7 @@ interface SchemaProviderProps {
595
592
  * Wrap your app (or a subtree) with `SchemaProvider` to share a single
596
593
  * `/api/docs.jsonld` fetch across all `SchemaCrudPage` instances.
597
594
  */
598
- declare function SchemaProvider({
599
- children
600
- }: SchemaProviderProps): React.JSX.Element;
595
+ declare function SchemaProvider({ children }: SchemaProviderProps): React.JSX.Element;
601
596
  interface UseSchemaContextResult {
602
597
  data: UseHydraMetadataResult['data'];
603
598
  isLoading: boolean;
package/dist/index.mjs CHANGED
@@ -317,7 +317,7 @@ function pluralize(word) {
317
317
  return word + "s";
318
318
  }
319
319
  /** Entrypoint property names that are already in plural form (dash-case). */
320
- const ALREADY_PLURAL = new Set([
320
+ const ALREADY_PLURAL = /* @__PURE__ */ new Set([
321
321
  "purchases",
322
322
  "sales",
323
323
  "invoices",
@@ -437,6 +437,26 @@ function extractSearchMappings(cls) {
437
437
  * Accepts both `hydra:method` and `method` field names inside each operation entry
438
438
  * to be safe across different API Platform serialisation variants.
439
439
  */
440
+ /**
441
+ * The class an Entrypoint property points at (`#Category` for `/api/categories`).
442
+ *
443
+ * Older API Platform emits it as the property `range` (plain or wrapped in
444
+ * `owl:equivalentClass`). Newer releases emit `range: "hydra:Collection"` for
445
+ * every collection and name the member class under `memberAssertion.object`;
446
+ * reading `range` alone there would key every resource as `hydra:Collection`
447
+ * and drop their collection operations (notably POST).
448
+ */
449
+ function entrypointTargetClass(property) {
450
+ const memberAssertion = property?.memberAssertion;
451
+ if (memberAssertion && typeof memberAssertion === "object") {
452
+ const object = memberAssertion["object"];
453
+ if (object && typeof object === "object") {
454
+ const id = object["@id"];
455
+ if (typeof id === "string") return id;
456
+ }
457
+ }
458
+ return normalizeRange(property?.range);
459
+ }
440
460
  function extractSupportedOperations(cls) {
441
461
  const operations = cls["supportedOperation"];
442
462
  if (!operations || operations.length === 0) return [];
@@ -447,8 +467,7 @@ function extractEntrypointCollectionOperations(doc) {
447
467
  if (!entrypoint) return {};
448
468
  const collectionOperations = {};
449
469
  for (const sp of entrypoint.supportedProperty ?? []) {
450
- const rawRange = sp.property?.range;
451
- const range = normalizeRange(rawRange);
470
+ const range = entrypointTargetClass(sp.property);
452
471
  if (!range) continue;
453
472
  const className = range.replace("#", "");
454
473
  collectionOperations[className] = (sp.property?.supportedOperation ?? []).map((op) => (op["hydra:method"] ?? op["method"] ?? "").toUpperCase()).filter(Boolean);
@@ -475,8 +494,7 @@ function parseHydraDoc(doc, entrypointHrefs) {
475
494
  const urlMap = {};
476
495
  const entrypoint = doc["supportedClass"].find((c) => c["@id"] === "#Entrypoint");
477
496
  if (entrypoint) for (const sp of entrypoint.supportedProperty ?? []) {
478
- const rawRange = sp.property?.range;
479
- const range = normalizeRange(rawRange);
497
+ const range = entrypointTargetClass(sp.property);
480
498
  const propId = sp.property?.["@id"];
481
499
  if (range && propId) {
482
500
  const className = range.replace("#", "");
@@ -518,7 +536,7 @@ function parseHydraDoc(doc, entrypointHrefs) {
518
536
  importable: cls["x-importable"],
519
537
  gridScale: cls["x-grid-scale"],
520
538
  searchMappings: extractSearchMappings(cls),
521
- supportedOperations: Array.from(new Set([...collectionOperationsMap[className] ?? [], ...extractSupportedOperations(cls)]))
539
+ supportedOperations: Array.from(/* @__PURE__ */ new Set([...collectionOperationsMap[className] ?? [], ...extractSupportedOperations(cls)]))
522
540
  };
523
541
  }
524
542
  return result;
@@ -1183,7 +1201,7 @@ function useHydraMetadata() {
1183
1201
  const { data, error, isPending } = useQuery({
1184
1202
  queryKey: [...API_DOC_QUERY_KEY, locale],
1185
1203
  queryFn: () => fetchApiDoc(httpClient),
1186
- staleTime: isDev ? 0 : 5 * 6e4,
1204
+ staleTime: isDev ? 0 : 3e5,
1187
1205
  refetchOnWindowFocus: isDev,
1188
1206
  refetchOnReconnect: isDev
1189
1207
  });
@@ -1291,8 +1309,9 @@ function useHydraResourceSchema({ apiUrl, enabled }) {
1291
1309
  return useResourceSchema(apiUrl, { enabled });
1292
1310
  }
1293
1311
  function HydraResourceSchemaProvider({ children }) {
1312
+ const resolver = useMemo(() => ({ useResourceSchema: useHydraResourceSchema }), []);
1294
1313
  return /* @__PURE__ */ jsx(ResourceSchemaProvider, {
1295
- resolver: useMemo(() => ({ useResourceSchema: useHydraResourceSchema }), []),
1314
+ resolver,
1296
1315
  children
1297
1316
  });
1298
1317
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nubitio/hydra",
3
- "version": "1.1.1",
3
+ "version": "1.1.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",
@@ -51,7 +51,7 @@
51
51
  "react": "^18.2.0 || ^19.0.0",
52
52
  "react-dom": "^18.2.0 || ^19.0.0",
53
53
  "react-i18next": "^14.0.0",
54
- "@nubitio/core": "^1.1.1",
55
- "@nubitio/crud": "^1.1.1"
54
+ "@nubitio/crud": "^1.1.2",
55
+ "@nubitio/core": "^1.1.2"
56
56
  }
57
57
  }