@nubitio/hydra 1.1.1 → 1.2.0

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));
@@ -129,6 +129,7 @@ function stripMergeOnlyParams(loadOptions) {
129
129
  const nextOptions = { ...loadOptions };
130
130
  delete nextOptions.prependData;
131
131
  delete nextOptions.appendData;
132
+ delete nextOptions.signal;
132
133
  return nextOptions;
133
134
  }
134
135
  function convertPaginationParams(loadOptions) {
@@ -269,7 +270,10 @@ var HydraRemoteDataSource = class {
269
270
  return this.config.iriMode && item ? addIriField(this.config.url, item) : item;
270
271
  }
271
272
  async fetchAll(loadOptions) {
272
- const response = await this.httpClient.get(this.config.url, { params: stripMergeOnlyParams(loadOptions) });
273
+ const response = await this.httpClient.get(this.config.url, {
274
+ params: stripMergeOnlyParams(loadOptions),
275
+ ...loadOptions.signal ? { signal: loadOptions.signal } : {}
276
+ });
273
277
  const parsed = parseCollectionResponse(response.data, response.headers);
274
278
  let data = parsed.data;
275
279
  const itemKey = (item) => item["id"] ?? item["code"] ?? item["uuid"] ?? item["slug"] ?? item["@id"] ?? item[this.config.idField];
@@ -341,7 +345,7 @@ function pluralize(word) {
341
345
  return word + "s";
342
346
  }
343
347
  /** Entrypoint property names that are already in plural form (dash-case). */
344
- const ALREADY_PLURAL = new Set([
348
+ const ALREADY_PLURAL = /* @__PURE__ */ new Set([
345
349
  "purchases",
346
350
  "sales",
347
351
  "invoices",
@@ -461,6 +465,26 @@ function extractSearchMappings(cls) {
461
465
  * Accepts both `hydra:method` and `method` field names inside each operation entry
462
466
  * to be safe across different API Platform serialisation variants.
463
467
  */
468
+ /**
469
+ * The class an Entrypoint property points at (`#Category` for `/api/categories`).
470
+ *
471
+ * Older API Platform emits it as the property `range` (plain or wrapped in
472
+ * `owl:equivalentClass`). Newer releases emit `range: "hydra:Collection"` for
473
+ * every collection and name the member class under `memberAssertion.object`;
474
+ * reading `range` alone there would key every resource as `hydra:Collection`
475
+ * and drop their collection operations (notably POST).
476
+ */
477
+ function entrypointTargetClass(property) {
478
+ const memberAssertion = property?.memberAssertion;
479
+ if (memberAssertion && typeof memberAssertion === "object") {
480
+ const object = memberAssertion["object"];
481
+ if (object && typeof object === "object") {
482
+ const id = object["@id"];
483
+ if (typeof id === "string") return id;
484
+ }
485
+ }
486
+ return normalizeRange(property?.range);
487
+ }
464
488
  function extractSupportedOperations(cls) {
465
489
  const operations = cls["supportedOperation"];
466
490
  if (!operations || operations.length === 0) return [];
@@ -471,8 +495,7 @@ function extractEntrypointCollectionOperations(doc) {
471
495
  if (!entrypoint) return {};
472
496
  const collectionOperations = {};
473
497
  for (const sp of entrypoint.supportedProperty ?? []) {
474
- const rawRange = sp.property?.range;
475
- const range = normalizeRange(rawRange);
498
+ const range = entrypointTargetClass(sp.property);
476
499
  if (!range) continue;
477
500
  const className = range.replace("#", "");
478
501
  collectionOperations[className] = (sp.property?.supportedOperation ?? []).map((op) => (op["hydra:method"] ?? op["method"] ?? "").toUpperCase()).filter(Boolean);
@@ -499,8 +522,7 @@ function parseHydraDoc(doc, entrypointHrefs) {
499
522
  const urlMap = {};
500
523
  const entrypoint = doc["supportedClass"].find((c) => c["@id"] === "#Entrypoint");
501
524
  if (entrypoint) for (const sp of entrypoint.supportedProperty ?? []) {
502
- const rawRange = sp.property?.range;
503
- const range = normalizeRange(rawRange);
525
+ const range = entrypointTargetClass(sp.property);
504
526
  const propId = sp.property?.["@id"];
505
527
  if (range && propId) {
506
528
  const className = range.replace("#", "");
@@ -542,7 +564,7 @@ function parseHydraDoc(doc, entrypointHrefs) {
542
564
  importable: cls["x-importable"],
543
565
  gridScale: cls["x-grid-scale"],
544
566
  searchMappings: extractSearchMappings(cls),
545
- supportedOperations: Array.from(new Set([...collectionOperationsMap[className] ?? [], ...extractSupportedOperations(cls)]))
567
+ supportedOperations: Array.from(/* @__PURE__ */ new Set([...collectionOperationsMap[className] ?? [], ...extractSupportedOperations(cls)]))
546
568
  };
547
569
  }
548
570
  return result;
@@ -1207,7 +1229,7 @@ function useHydraMetadata() {
1207
1229
  const { data, error, isPending } = (0, _tanstack_react_query.useQuery)({
1208
1230
  queryKey: [...API_DOC_QUERY_KEY, locale],
1209
1231
  queryFn: () => fetchApiDoc(httpClient),
1210
- staleTime: isDev ? 0 : 5 * 6e4,
1232
+ staleTime: isDev ? 0 : 3e5,
1211
1233
  refetchOnWindowFocus: isDev,
1212
1234
  refetchOnReconnect: isDev
1213
1235
  });
@@ -1315,8 +1337,9 @@ function useHydraResourceSchema({ apiUrl, enabled }) {
1315
1337
  return useResourceSchema(apiUrl, { enabled });
1316
1338
  }
1317
1339
  function HydraResourceSchemaProvider({ children }) {
1340
+ const resolver = (0, react.useMemo)(() => ({ useResourceSchema: useHydraResourceSchema }), []);
1318
1341
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_nubitio_crud.ResourceSchemaProvider, {
1319
- resolver: (0, react.useMemo)(() => ({ useResourceSchema: useHydraResourceSchema }), []),
1342
+ resolver,
1320
1343
  children
1321
1344
  });
1322
1345
  }
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
@@ -105,6 +105,7 @@ function stripMergeOnlyParams(loadOptions) {
105
105
  const nextOptions = { ...loadOptions };
106
106
  delete nextOptions.prependData;
107
107
  delete nextOptions.appendData;
108
+ delete nextOptions.signal;
108
109
  return nextOptions;
109
110
  }
110
111
  function convertPaginationParams(loadOptions) {
@@ -245,7 +246,10 @@ var HydraRemoteDataSource = class {
245
246
  return this.config.iriMode && item ? addIriField(this.config.url, item) : item;
246
247
  }
247
248
  async fetchAll(loadOptions) {
248
- const response = await this.httpClient.get(this.config.url, { params: stripMergeOnlyParams(loadOptions) });
249
+ const response = await this.httpClient.get(this.config.url, {
250
+ params: stripMergeOnlyParams(loadOptions),
251
+ ...loadOptions.signal ? { signal: loadOptions.signal } : {}
252
+ });
249
253
  const parsed = parseCollectionResponse(response.data, response.headers);
250
254
  let data = parsed.data;
251
255
  const itemKey = (item) => item["id"] ?? item["code"] ?? item["uuid"] ?? item["slug"] ?? item["@id"] ?? item[this.config.idField];
@@ -317,7 +321,7 @@ function pluralize(word) {
317
321
  return word + "s";
318
322
  }
319
323
  /** Entrypoint property names that are already in plural form (dash-case). */
320
- const ALREADY_PLURAL = new Set([
324
+ const ALREADY_PLURAL = /* @__PURE__ */ new Set([
321
325
  "purchases",
322
326
  "sales",
323
327
  "invoices",
@@ -437,6 +441,26 @@ function extractSearchMappings(cls) {
437
441
  * Accepts both `hydra:method` and `method` field names inside each operation entry
438
442
  * to be safe across different API Platform serialisation variants.
439
443
  */
444
+ /**
445
+ * The class an Entrypoint property points at (`#Category` for `/api/categories`).
446
+ *
447
+ * Older API Platform emits it as the property `range` (plain or wrapped in
448
+ * `owl:equivalentClass`). Newer releases emit `range: "hydra:Collection"` for
449
+ * every collection and name the member class under `memberAssertion.object`;
450
+ * reading `range` alone there would key every resource as `hydra:Collection`
451
+ * and drop their collection operations (notably POST).
452
+ */
453
+ function entrypointTargetClass(property) {
454
+ const memberAssertion = property?.memberAssertion;
455
+ if (memberAssertion && typeof memberAssertion === "object") {
456
+ const object = memberAssertion["object"];
457
+ if (object && typeof object === "object") {
458
+ const id = object["@id"];
459
+ if (typeof id === "string") return id;
460
+ }
461
+ }
462
+ return normalizeRange(property?.range);
463
+ }
440
464
  function extractSupportedOperations(cls) {
441
465
  const operations = cls["supportedOperation"];
442
466
  if (!operations || operations.length === 0) return [];
@@ -447,8 +471,7 @@ function extractEntrypointCollectionOperations(doc) {
447
471
  if (!entrypoint) return {};
448
472
  const collectionOperations = {};
449
473
  for (const sp of entrypoint.supportedProperty ?? []) {
450
- const rawRange = sp.property?.range;
451
- const range = normalizeRange(rawRange);
474
+ const range = entrypointTargetClass(sp.property);
452
475
  if (!range) continue;
453
476
  const className = range.replace("#", "");
454
477
  collectionOperations[className] = (sp.property?.supportedOperation ?? []).map((op) => (op["hydra:method"] ?? op["method"] ?? "").toUpperCase()).filter(Boolean);
@@ -475,8 +498,7 @@ function parseHydraDoc(doc, entrypointHrefs) {
475
498
  const urlMap = {};
476
499
  const entrypoint = doc["supportedClass"].find((c) => c["@id"] === "#Entrypoint");
477
500
  if (entrypoint) for (const sp of entrypoint.supportedProperty ?? []) {
478
- const rawRange = sp.property?.range;
479
- const range = normalizeRange(rawRange);
501
+ const range = entrypointTargetClass(sp.property);
480
502
  const propId = sp.property?.["@id"];
481
503
  if (range && propId) {
482
504
  const className = range.replace("#", "");
@@ -518,7 +540,7 @@ function parseHydraDoc(doc, entrypointHrefs) {
518
540
  importable: cls["x-importable"],
519
541
  gridScale: cls["x-grid-scale"],
520
542
  searchMappings: extractSearchMappings(cls),
521
- supportedOperations: Array.from(new Set([...collectionOperationsMap[className] ?? [], ...extractSupportedOperations(cls)]))
543
+ supportedOperations: Array.from(/* @__PURE__ */ new Set([...collectionOperationsMap[className] ?? [], ...extractSupportedOperations(cls)]))
522
544
  };
523
545
  }
524
546
  return result;
@@ -1183,7 +1205,7 @@ function useHydraMetadata() {
1183
1205
  const { data, error, isPending } = useQuery({
1184
1206
  queryKey: [...API_DOC_QUERY_KEY, locale],
1185
1207
  queryFn: () => fetchApiDoc(httpClient),
1186
- staleTime: isDev ? 0 : 5 * 6e4,
1208
+ staleTime: isDev ? 0 : 3e5,
1187
1209
  refetchOnWindowFocus: isDev,
1188
1210
  refetchOnReconnect: isDev
1189
1211
  });
@@ -1291,8 +1313,9 @@ function useHydraResourceSchema({ apiUrl, enabled }) {
1291
1313
  return useResourceSchema(apiUrl, { enabled });
1292
1314
  }
1293
1315
  function HydraResourceSchemaProvider({ children }) {
1316
+ const resolver = useMemo(() => ({ useResourceSchema: useHydraResourceSchema }), []);
1294
1317
  return /* @__PURE__ */ jsx(ResourceSchemaProvider, {
1295
- resolver: useMemo(() => ({ useResourceSchema: useHydraResourceSchema }), []),
1318
+ resolver,
1296
1319
  children
1297
1320
  });
1298
1321
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nubitio/hydra",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
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.2.0",
55
+ "@nubitio/core": "^1.2.0"
56
56
  }
57
57
  }