@nubitio/hydra 0.11.1 → 0.11.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 CHANGED
@@ -159,33 +159,49 @@ function parseGridSummaryHeader(headers) {
159
159
  return null;
160
160
  }
161
161
  }
162
+ /** The `next` link a cursor-paginated collection publishes in `hydra:view`. */
163
+ function parseNextPageUrl(body) {
164
+ const view = body["hydra:view"] ?? body["view"];
165
+ if (!view || typeof view !== "object") return null;
166
+ const next = view["hydra:next"] ?? view["next"];
167
+ return typeof next === "string" ? next : null;
168
+ }
162
169
  function parseCollectionResponse(responseData, responseHeaders) {
163
170
  const gridSummary = parseGridSummaryHeader(responseHeaders);
171
+ const estimated = Number(responseHeaders.get("x-estimated-count"));
172
+ const hasEstimate = Number.isFinite(estimated) && responseHeaders.get("x-estimated-count") !== null;
164
173
  if (Array.isArray(responseData)) {
165
174
  const headerCount = Number(responseHeaders.get("x-total-count"));
166
175
  return {
167
176
  data: responseData,
168
177
  totalCount: Number.isFinite(headerCount) ? headerCount : responseData.length,
169
- gridSummary
178
+ gridSummary,
179
+ totalIsEstimate: false,
180
+ nextPageUrl: null
170
181
  };
171
182
  }
172
183
  if (responseData && typeof responseData === "object") {
173
184
  const body = responseData;
174
185
  const member = body["hydra:member"] ?? body["member"];
175
186
  if (Array.isArray(member)) {
176
- const rawTotal = body["hydra:totalItems"] ?? body["totalItems"] ?? member.length;
177
- const totalCount = Number(rawTotal);
187
+ const rawTotal = body["hydra:totalItems"] ?? body["totalItems"];
188
+ const exact = Number(rawTotal);
189
+ const hasExact = rawTotal !== void 0 && Number.isFinite(exact);
178
190
  return {
179
191
  data: member,
180
- totalCount: Number.isFinite(totalCount) ? totalCount : member.length,
181
- gridSummary
192
+ totalCount: hasExact ? exact : hasEstimate ? estimated : member.length,
193
+ gridSummary,
194
+ totalIsEstimate: !hasExact,
195
+ nextPageUrl: parseNextPageUrl(body)
182
196
  };
183
197
  }
184
198
  }
185
199
  return {
186
200
  data: [],
187
201
  totalCount: 0,
188
- gridSummary
202
+ gridSummary,
203
+ totalIsEstimate: false,
204
+ nextPageUrl: null
189
205
  };
190
206
  }
191
207
  var HydraRemoteDataSource = class {
@@ -268,7 +284,9 @@ var HydraRemoteDataSource = class {
268
284
  data,
269
285
  totalCount,
270
286
  summary: null,
271
- gridSummary: parsed.gridSummary
287
+ gridSummary: parsed.gridSummary,
288
+ totalIsEstimate: parsed.totalIsEstimate,
289
+ nextPageUrl: parsed.nextPageUrl
272
290
  };
273
291
  }
274
292
  async fetchById(url, id, loadOptions) {
@@ -520,6 +538,9 @@ function parseHydraDoc(doc, entrypointHrefs) {
520
538
  workflow: cls["x-workflow"],
521
539
  sequence: cls["x-sequence"],
522
540
  embeddedLines: cls["x-embedded-lines"],
541
+ printable: cls["x-printable"],
542
+ importable: cls["x-importable"],
543
+ gridScale: cls["x-grid-scale"],
523
544
  searchMappings: extractSearchMappings(cls),
524
545
  supportedOperations: Array.from(new Set([...collectionOperationsMap[className] ?? [], ...extractSupportedOperations(cls)]))
525
546
  };
@@ -678,6 +699,14 @@ function applyCrudHints(field, hints, fieldName) {
678
699
  field.width = hints.width;
679
700
  applied.push(`width=${hints.width}`);
680
701
  }
702
+ if (hints.presentation !== void 0) {
703
+ field.presentation = hints.presentation;
704
+ applied.push(`presentation=${hints.presentation}`);
705
+ }
706
+ if (hints.toneByValue !== void 0) {
707
+ field.toneByValue = hints.toneByValue;
708
+ applied.push("toneByValue");
709
+ }
681
710
  return applied;
682
711
  }
683
712
  function stampMappingReason(field, rule, hintSuffix) {
@@ -793,7 +822,9 @@ function mapHydraSchemaToFields(schema, urlLookup, schemaLookup) {
793
822
  const label = hydraTitle && hydraTitle.trim() !== "" && hydraTitle !== name ? hydraTitle : toLabel(name);
794
823
  const filterable = filterableProperties.size === 0 ? true : filterableProperties.has(name);
795
824
  const tag = resolveRangeTag(range, propertyType);
796
- if (!writeable) {
825
+ const enumOptions = fieldSchema.enumOptions;
826
+ const isScalarEnum = enumOptions && enumOptions.length > 0 && (tag === "text" || tag === "integer" || tag === "decimal");
827
+ if (!writeable && !isScalarEnum) {
797
828
  if (tag === "entity" || propertyType === "Link") {
798
829
  const resourceClass = range ? range.replace("#", "") : "";
799
830
  const relatedSchema = resourceClass ? schemaLookup?.(resourceClass) : void 0;
@@ -812,20 +843,19 @@ function mapHydraSchemaToFields(schema, urlLookup, schemaLookup) {
812
843
  continue;
813
844
  }
814
845
  const field = {
815
- ...(fieldSchema.crudHints?.format === "currency" ? (0, _nubitio_crud.currencyField)().readonly(true) : (0, _nubitio_crud.noneField)()).name(name).label(label).required(required).build(),
846
+ ...(fieldSchema.crudHints?.format === "money" ? (0, _nubitio_crud.moneyField)().readonly(true) : fieldSchema.crudHints?.format === "currency" ? (0, _nubitio_crud.currencyField)().readonly(true) : (0, _nubitio_crud.noneField)()).name(name).label(label).required(required).build(),
816
847
  filterable
817
848
  };
818
- stampMappingReason(field, fieldSchema.crudHints?.format === "currency" ? "rule-3 display-only+currency" : "rule-3 display-only", applyCrudHints(field, fieldSchema.crudHints));
849
+ stampMappingReason(field, fieldSchema.crudHints?.format === "money" ? "rule-3 display-only+money" : fieldSchema.crudHints?.format === "currency" ? "rule-3 display-only+currency" : "rule-3 display-only", applyCrudHints(field, fieldSchema.crudHints));
819
850
  fields.push(field);
820
851
  continue;
821
852
  }
822
- const enumOptions = fieldSchema.enumOptions;
823
- if (enumOptions && enumOptions.length > 0 && (tag === "text" || tag === "integer" || tag === "decimal")) {
853
+ if (isScalarEnum) {
824
854
  const field = {
825
855
  ...(0, _nubitio_crud.enumField)(enumOptions.map((value) => ({
826
856
  value,
827
857
  text: toLabel(String(value)).replace(/\b[a-z]/g, (c) => c.toUpperCase())
828
- }))).name(name).label(label).required(required).build(),
858
+ }))).name(name).label(label).required(required).readonly(!writeable).build(),
829
859
  filterable
830
860
  };
831
861
  stampMappingReason(field, "rule-3.5 enum", applyCrudHints(field, fieldSchema.crudHints));
@@ -844,6 +874,15 @@ function mapHydraSchemaToFields(schema, urlLookup, schemaLookup) {
844
874
  fields.push(field);
845
875
  continue;
846
876
  }
877
+ if (fieldSchema.crudHints?.format === "money") {
878
+ const field = {
879
+ ...(0, _nubitio_crud.moneyField)().name(name).label(label).required(required).build(),
880
+ filterable
881
+ };
882
+ stampMappingReason(field, "rule-3.55b money", applyCrudHints(field, fieldSchema.crudHints));
883
+ fields.push(field);
884
+ continue;
885
+ }
847
886
  if (fieldSchema.crudHints?.format === "currency" && (tag === "text" || tag === "integer" || tag === "decimal")) {
848
887
  const field = {
849
888
  ...(0, _nubitio_crud.currencyField)().name(name).label(label).required(required).build(),
package/dist/index.d.cts CHANGED
@@ -81,12 +81,21 @@ interface CrudHints {
81
81
  order?: number;
82
82
  /** Column width in pixels or as a CSS string. */
83
83
  width?: number;
84
+ /** Render the enum value using a richer presentation such as a badge. */
85
+ presentation?: 'badge';
86
+ /** Visual tone per enum value when `presentation` is `badge`. */
87
+ toneByValue?: Record<string, string>;
84
88
  /**
85
- * Render hint. 'currency' maps decimals to a money control; 'image'/'file'
86
- * map media relations (nubitio/admin-bundle Media or compatible) to instant
87
- * upload controls that submit the media IRI.
89
+ * Render hint.
90
+ *
91
+ * 'money' is the exact form: the property is published as
92
+ * `{ amount, currency, scale }` and never converted to a JavaScript number.
93
+ * 'currency' is the older decimal-as-string form, kept for resources that
94
+ * have not moved over. 'image'/'file' map media relations
95
+ * (nubitio/admin-bundle Media or compatible) to instant upload controls that
96
+ * submit the media IRI.
88
97
  */
89
- format?: 'currency' | 'image' | 'file';
98
+ format?: 'money' | 'currency' | 'image' | 'file';
90
99
  /** Include this column in the server-side grid summary footer. */
91
100
  summable?: boolean;
92
101
  /** Aggregate function for summable columns. @default 'sum' */
@@ -191,6 +200,12 @@ interface HydraClass {
191
200
  'x-crud-layout'?: FormLayout;
192
201
  /** Embedded line collections declared on parent document resources. */
193
202
  'x-embedded-lines'?: EmbeddedLinesSchema$1[];
203
+ /** Document issuing declared by `#[Printable]` (nubitio/admin-bundle). */
204
+ 'x-printable'?: PrintableSchema;
205
+ /** Spreadsheet import declared by `#[Importable]` (nubitio/admin-bundle). */
206
+ 'x-importable'?: ImportableSchema;
207
+ /** How the resource expects to be paginated once it is large. */
208
+ 'x-grid-scale'?: GridScaleSchema;
194
209
  /**
195
210
  * Hydra search template describing server-side filterable query params.
196
211
  * Present on collection operations in API Platform JSON-LD responses.
@@ -296,6 +311,67 @@ interface HydraResourceSchema {
296
311
  sequence?: SequenceSchema;
297
312
  /** Embedded line collections (nubitio/admin-bundle). */
298
313
  embeddedLines?: EmbeddedLinesSchema$1[];
314
+ /** The resource can be issued as a document. */
315
+ printable?: PrintableSchema;
316
+ /** The resource can be loaded from a spreadsheet. */
317
+ importable?: ImportableSchema;
318
+ /** How the resource expects to be paginated once it is large. */
319
+ gridScale?: GridScaleSchema;
320
+ }
321
+ /**
322
+ * How a resource expects to be read once it has grown.
323
+ *
324
+ * Every grid is small on the day it ships. The ones that stop working are the
325
+ * ones nobody decided anything about, so the backend states the decision and
326
+ * the client follows it rather than paginating the way it always has.
327
+ */
328
+ interface GridScaleSchema {
329
+ /**
330
+ * `cursor` is a promise the client has to keep: advance by following the
331
+ * server's next link, and do not re-sort. `page` is ordinary offset paging.
332
+ */
333
+ mode: 'cursor' | 'page';
334
+ cursorField: string | null;
335
+ cursorDirection: 'ASC' | 'DESC';
336
+ /** False means the total is an estimate or absent; never render it as precise. */
337
+ exactCount: boolean;
338
+ /** Rows above which the server queues an export instead of streaming it. */
339
+ inlineExportLimit: number;
340
+ /** Fields the server will accept a sort on. Null means any. */
341
+ sortableFields: string[] | null;
342
+ }
343
+ /**
344
+ * What the backend publishes for a printable resource.
345
+ *
346
+ * The URLs are absolute templates rather than a base the client assembles: a
347
+ * client that builds the path itself will eventually build it differently from
348
+ * the server.
349
+ */
350
+ interface PrintableSchema {
351
+ /** Translation key or literal for the print action. */
352
+ title: string;
353
+ paper: string;
354
+ orientation: 'portrait' | 'landscape';
355
+ /** False for documents a jurisdiction forbids reissuing. */
356
+ allowReissue: boolean;
357
+ numberProperty: string | null;
358
+ /** POST here to issue, GET for the history. `{id}` is the record's identifier. */
359
+ issueUrl: string;
360
+ historyUrl: string;
361
+ }
362
+ /** What the backend publishes for an importable resource. */
363
+ interface ImportableSchema {
364
+ fields: string[];
365
+ required: string[];
366
+ /** Fields identifying an existing row. Empty means a re-run duplicates. */
367
+ naturalKey: string[];
368
+ maxRows: number;
369
+ uploadUrl: string;
370
+ /**
371
+ * Always true today, and stated rather than implied: a client must not offer
372
+ * an "import now" button that skips the review step.
373
+ */
374
+ requiresReview: boolean;
299
375
  }
300
376
  interface OpenApiProperty {
301
377
  type?: string;
@@ -522,4 +598,4 @@ interface UseSchemaContextResult {
522
598
  */
523
599
  declare function useSchemaContext(): UseSchemaContextResult;
524
600
  //#endregion
525
- export { API_DOC_QUERY_KEY, type ApiDoc, type EmbeddedLinesSchema, type HydraApiDoc, HydraRemoteDataSource, HydraResourceSchemaProvider, type HydraResourceSchemaProviderProps, HydraResourceStoreProvider, type HydraResourceStoreProviderProps, HydraSchemaResolver, type OpenApiDoc, type RemoteDataSourceOptions, type RemoteFilterDescriptor, type RemoteLoadOptions, type RemoteSortDescriptor, type ResolvedResourceSchema, SchemaProvider, type SequenceSchema, type UseSchemaContextResult, type WorkflowSchema, type WorkflowTransitionSchema, buildEmbeddedFormDetail, createHydraResourceStore, getSchemaResolver, mapHydraSchemaToFields, parseHydraDoc, parseOpenApiDoc, resolveEmbeddedBinding, resolveInferredFormDetail, resolveRangeTag, useHydraMetadata, useResourceSchema, useSchemaContext };
601
+ export { API_DOC_QUERY_KEY, type ApiDoc, type EmbeddedLinesSchema, type GridScaleSchema, type HydraApiDoc, HydraRemoteDataSource, HydraResourceSchemaProvider, type HydraResourceSchemaProviderProps, HydraResourceStoreProvider, type HydraResourceStoreProviderProps, HydraSchemaResolver, type ImportableSchema, type OpenApiDoc, type PrintableSchema, type RemoteDataSourceOptions, type RemoteFilterDescriptor, type RemoteLoadOptions, type RemoteSortDescriptor, type ResolvedResourceSchema, SchemaProvider, type SequenceSchema, type UseSchemaContextResult, type WorkflowSchema, type WorkflowTransitionSchema, buildEmbeddedFormDetail, createHydraResourceStore, getSchemaResolver, mapHydraSchemaToFields, parseHydraDoc, parseOpenApiDoc, resolveEmbeddedBinding, resolveInferredFormDetail, resolveRangeTag, useHydraMetadata, useResourceSchema, useSchemaContext };
package/dist/index.d.mts CHANGED
@@ -81,12 +81,21 @@ interface CrudHints {
81
81
  order?: number;
82
82
  /** Column width in pixels or as a CSS string. */
83
83
  width?: number;
84
+ /** Render the enum value using a richer presentation such as a badge. */
85
+ presentation?: 'badge';
86
+ /** Visual tone per enum value when `presentation` is `badge`. */
87
+ toneByValue?: Record<string, string>;
84
88
  /**
85
- * Render hint. 'currency' maps decimals to a money control; 'image'/'file'
86
- * map media relations (nubitio/admin-bundle Media or compatible) to instant
87
- * upload controls that submit the media IRI.
89
+ * Render hint.
90
+ *
91
+ * 'money' is the exact form: the property is published as
92
+ * `{ amount, currency, scale }` and never converted to a JavaScript number.
93
+ * 'currency' is the older decimal-as-string form, kept for resources that
94
+ * have not moved over. 'image'/'file' map media relations
95
+ * (nubitio/admin-bundle Media or compatible) to instant upload controls that
96
+ * submit the media IRI.
88
97
  */
89
- format?: 'currency' | 'image' | 'file';
98
+ format?: 'money' | 'currency' | 'image' | 'file';
90
99
  /** Include this column in the server-side grid summary footer. */
91
100
  summable?: boolean;
92
101
  /** Aggregate function for summable columns. @default 'sum' */
@@ -191,6 +200,12 @@ interface HydraClass {
191
200
  'x-crud-layout'?: FormLayout;
192
201
  /** Embedded line collections declared on parent document resources. */
193
202
  'x-embedded-lines'?: EmbeddedLinesSchema$1[];
203
+ /** Document issuing declared by `#[Printable]` (nubitio/admin-bundle). */
204
+ 'x-printable'?: PrintableSchema;
205
+ /** Spreadsheet import declared by `#[Importable]` (nubitio/admin-bundle). */
206
+ 'x-importable'?: ImportableSchema;
207
+ /** How the resource expects to be paginated once it is large. */
208
+ 'x-grid-scale'?: GridScaleSchema;
194
209
  /**
195
210
  * Hydra search template describing server-side filterable query params.
196
211
  * Present on collection operations in API Platform JSON-LD responses.
@@ -296,6 +311,67 @@ interface HydraResourceSchema {
296
311
  sequence?: SequenceSchema;
297
312
  /** Embedded line collections (nubitio/admin-bundle). */
298
313
  embeddedLines?: EmbeddedLinesSchema$1[];
314
+ /** The resource can be issued as a document. */
315
+ printable?: PrintableSchema;
316
+ /** The resource can be loaded from a spreadsheet. */
317
+ importable?: ImportableSchema;
318
+ /** How the resource expects to be paginated once it is large. */
319
+ gridScale?: GridScaleSchema;
320
+ }
321
+ /**
322
+ * How a resource expects to be read once it has grown.
323
+ *
324
+ * Every grid is small on the day it ships. The ones that stop working are the
325
+ * ones nobody decided anything about, so the backend states the decision and
326
+ * the client follows it rather than paginating the way it always has.
327
+ */
328
+ interface GridScaleSchema {
329
+ /**
330
+ * `cursor` is a promise the client has to keep: advance by following the
331
+ * server's next link, and do not re-sort. `page` is ordinary offset paging.
332
+ */
333
+ mode: 'cursor' | 'page';
334
+ cursorField: string | null;
335
+ cursorDirection: 'ASC' | 'DESC';
336
+ /** False means the total is an estimate or absent; never render it as precise. */
337
+ exactCount: boolean;
338
+ /** Rows above which the server queues an export instead of streaming it. */
339
+ inlineExportLimit: number;
340
+ /** Fields the server will accept a sort on. Null means any. */
341
+ sortableFields: string[] | null;
342
+ }
343
+ /**
344
+ * What the backend publishes for a printable resource.
345
+ *
346
+ * The URLs are absolute templates rather than a base the client assembles: a
347
+ * client that builds the path itself will eventually build it differently from
348
+ * the server.
349
+ */
350
+ interface PrintableSchema {
351
+ /** Translation key or literal for the print action. */
352
+ title: string;
353
+ paper: string;
354
+ orientation: 'portrait' | 'landscape';
355
+ /** False for documents a jurisdiction forbids reissuing. */
356
+ allowReissue: boolean;
357
+ numberProperty: string | null;
358
+ /** POST here to issue, GET for the history. `{id}` is the record's identifier. */
359
+ issueUrl: string;
360
+ historyUrl: string;
361
+ }
362
+ /** What the backend publishes for an importable resource. */
363
+ interface ImportableSchema {
364
+ fields: string[];
365
+ required: string[];
366
+ /** Fields identifying an existing row. Empty means a re-run duplicates. */
367
+ naturalKey: string[];
368
+ maxRows: number;
369
+ uploadUrl: string;
370
+ /**
371
+ * Always true today, and stated rather than implied: a client must not offer
372
+ * an "import now" button that skips the review step.
373
+ */
374
+ requiresReview: boolean;
299
375
  }
300
376
  interface OpenApiProperty {
301
377
  type?: string;
@@ -522,4 +598,4 @@ interface UseSchemaContextResult {
522
598
  */
523
599
  declare function useSchemaContext(): UseSchemaContextResult;
524
600
  //#endregion
525
- export { API_DOC_QUERY_KEY, type ApiDoc, type EmbeddedLinesSchema, type HydraApiDoc, HydraRemoteDataSource, HydraResourceSchemaProvider, type HydraResourceSchemaProviderProps, HydraResourceStoreProvider, type HydraResourceStoreProviderProps, HydraSchemaResolver, type OpenApiDoc, type RemoteDataSourceOptions, type RemoteFilterDescriptor, type RemoteLoadOptions, type RemoteSortDescriptor, type ResolvedResourceSchema, SchemaProvider, type SequenceSchema, type UseSchemaContextResult, type WorkflowSchema, type WorkflowTransitionSchema, buildEmbeddedFormDetail, createHydraResourceStore, getSchemaResolver, mapHydraSchemaToFields, parseHydraDoc, parseOpenApiDoc, resolveEmbeddedBinding, resolveInferredFormDetail, resolveRangeTag, useHydraMetadata, useResourceSchema, useSchemaContext };
601
+ export { API_DOC_QUERY_KEY, type ApiDoc, type EmbeddedLinesSchema, type GridScaleSchema, type HydraApiDoc, HydraRemoteDataSource, HydraResourceSchemaProvider, type HydraResourceSchemaProviderProps, HydraResourceStoreProvider, type HydraResourceStoreProviderProps, HydraSchemaResolver, type ImportableSchema, type OpenApiDoc, type PrintableSchema, type RemoteDataSourceOptions, type RemoteFilterDescriptor, type RemoteLoadOptions, type RemoteSortDescriptor, type ResolvedResourceSchema, SchemaProvider, type SequenceSchema, type UseSchemaContextResult, type WorkflowSchema, type WorkflowTransitionSchema, buildEmbeddedFormDetail, createHydraResourceStore, getSchemaResolver, mapHydraSchemaToFields, parseHydraDoc, parseOpenApiDoc, resolveEmbeddedBinding, resolveInferredFormDetail, resolveRangeTag, useHydraMetadata, useResourceSchema, useSchemaContext };
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, tagsField, textField } from "@nubitio/crud";
3
+ import { ResourceSchemaProvider, ResourceStoreProvider, currencyField, datetimeField, embeddedLinesUrl, entityField, enumField, fileField, imageField, moneyField, 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
@@ -135,33 +135,49 @@ function parseGridSummaryHeader(headers) {
135
135
  return null;
136
136
  }
137
137
  }
138
+ /** The `next` link a cursor-paginated collection publishes in `hydra:view`. */
139
+ function parseNextPageUrl(body) {
140
+ const view = body["hydra:view"] ?? body["view"];
141
+ if (!view || typeof view !== "object") return null;
142
+ const next = view["hydra:next"] ?? view["next"];
143
+ return typeof next === "string" ? next : null;
144
+ }
138
145
  function parseCollectionResponse(responseData, responseHeaders) {
139
146
  const gridSummary = parseGridSummaryHeader(responseHeaders);
147
+ const estimated = Number(responseHeaders.get("x-estimated-count"));
148
+ const hasEstimate = Number.isFinite(estimated) && responseHeaders.get("x-estimated-count") !== null;
140
149
  if (Array.isArray(responseData)) {
141
150
  const headerCount = Number(responseHeaders.get("x-total-count"));
142
151
  return {
143
152
  data: responseData,
144
153
  totalCount: Number.isFinite(headerCount) ? headerCount : responseData.length,
145
- gridSummary
154
+ gridSummary,
155
+ totalIsEstimate: false,
156
+ nextPageUrl: null
146
157
  };
147
158
  }
148
159
  if (responseData && typeof responseData === "object") {
149
160
  const body = responseData;
150
161
  const member = body["hydra:member"] ?? body["member"];
151
162
  if (Array.isArray(member)) {
152
- const rawTotal = body["hydra:totalItems"] ?? body["totalItems"] ?? member.length;
153
- const totalCount = Number(rawTotal);
163
+ const rawTotal = body["hydra:totalItems"] ?? body["totalItems"];
164
+ const exact = Number(rawTotal);
165
+ const hasExact = rawTotal !== void 0 && Number.isFinite(exact);
154
166
  return {
155
167
  data: member,
156
- totalCount: Number.isFinite(totalCount) ? totalCount : member.length,
157
- gridSummary
168
+ totalCount: hasExact ? exact : hasEstimate ? estimated : member.length,
169
+ gridSummary,
170
+ totalIsEstimate: !hasExact,
171
+ nextPageUrl: parseNextPageUrl(body)
158
172
  };
159
173
  }
160
174
  }
161
175
  return {
162
176
  data: [],
163
177
  totalCount: 0,
164
- gridSummary
178
+ gridSummary,
179
+ totalIsEstimate: false,
180
+ nextPageUrl: null
165
181
  };
166
182
  }
167
183
  var HydraRemoteDataSource = class {
@@ -244,7 +260,9 @@ var HydraRemoteDataSource = class {
244
260
  data,
245
261
  totalCount,
246
262
  summary: null,
247
- gridSummary: parsed.gridSummary
263
+ gridSummary: parsed.gridSummary,
264
+ totalIsEstimate: parsed.totalIsEstimate,
265
+ nextPageUrl: parsed.nextPageUrl
248
266
  };
249
267
  }
250
268
  async fetchById(url, id, loadOptions) {
@@ -496,6 +514,9 @@ function parseHydraDoc(doc, entrypointHrefs) {
496
514
  workflow: cls["x-workflow"],
497
515
  sequence: cls["x-sequence"],
498
516
  embeddedLines: cls["x-embedded-lines"],
517
+ printable: cls["x-printable"],
518
+ importable: cls["x-importable"],
519
+ gridScale: cls["x-grid-scale"],
499
520
  searchMappings: extractSearchMappings(cls),
500
521
  supportedOperations: Array.from(new Set([...collectionOperationsMap[className] ?? [], ...extractSupportedOperations(cls)]))
501
522
  };
@@ -654,6 +675,14 @@ function applyCrudHints(field, hints, fieldName) {
654
675
  field.width = hints.width;
655
676
  applied.push(`width=${hints.width}`);
656
677
  }
678
+ if (hints.presentation !== void 0) {
679
+ field.presentation = hints.presentation;
680
+ applied.push(`presentation=${hints.presentation}`);
681
+ }
682
+ if (hints.toneByValue !== void 0) {
683
+ field.toneByValue = hints.toneByValue;
684
+ applied.push("toneByValue");
685
+ }
657
686
  return applied;
658
687
  }
659
688
  function stampMappingReason(field, rule, hintSuffix) {
@@ -769,7 +798,9 @@ function mapHydraSchemaToFields(schema, urlLookup, schemaLookup) {
769
798
  const label = hydraTitle && hydraTitle.trim() !== "" && hydraTitle !== name ? hydraTitle : toLabel(name);
770
799
  const filterable = filterableProperties.size === 0 ? true : filterableProperties.has(name);
771
800
  const tag = resolveRangeTag(range, propertyType);
772
- if (!writeable) {
801
+ const enumOptions = fieldSchema.enumOptions;
802
+ const isScalarEnum = enumOptions && enumOptions.length > 0 && (tag === "text" || tag === "integer" || tag === "decimal");
803
+ if (!writeable && !isScalarEnum) {
773
804
  if (tag === "entity" || propertyType === "Link") {
774
805
  const resourceClass = range ? range.replace("#", "") : "";
775
806
  const relatedSchema = resourceClass ? schemaLookup?.(resourceClass) : void 0;
@@ -788,20 +819,19 @@ function mapHydraSchemaToFields(schema, urlLookup, schemaLookup) {
788
819
  continue;
789
820
  }
790
821
  const field = {
791
- ...(fieldSchema.crudHints?.format === "currency" ? currencyField().readonly(true) : noneField()).name(name).label(label).required(required).build(),
822
+ ...(fieldSchema.crudHints?.format === "money" ? moneyField().readonly(true) : fieldSchema.crudHints?.format === "currency" ? currencyField().readonly(true) : noneField()).name(name).label(label).required(required).build(),
792
823
  filterable
793
824
  };
794
- stampMappingReason(field, fieldSchema.crudHints?.format === "currency" ? "rule-3 display-only+currency" : "rule-3 display-only", applyCrudHints(field, fieldSchema.crudHints));
825
+ stampMappingReason(field, fieldSchema.crudHints?.format === "money" ? "rule-3 display-only+money" : fieldSchema.crudHints?.format === "currency" ? "rule-3 display-only+currency" : "rule-3 display-only", applyCrudHints(field, fieldSchema.crudHints));
795
826
  fields.push(field);
796
827
  continue;
797
828
  }
798
- const enumOptions = fieldSchema.enumOptions;
799
- if (enumOptions && enumOptions.length > 0 && (tag === "text" || tag === "integer" || tag === "decimal")) {
829
+ if (isScalarEnum) {
800
830
  const field = {
801
831
  ...enumField(enumOptions.map((value) => ({
802
832
  value,
803
833
  text: toLabel(String(value)).replace(/\b[a-z]/g, (c) => c.toUpperCase())
804
- }))).name(name).label(label).required(required).build(),
834
+ }))).name(name).label(label).required(required).readonly(!writeable).build(),
805
835
  filterable
806
836
  };
807
837
  stampMappingReason(field, "rule-3.5 enum", applyCrudHints(field, fieldSchema.crudHints));
@@ -820,6 +850,15 @@ function mapHydraSchemaToFields(schema, urlLookup, schemaLookup) {
820
850
  fields.push(field);
821
851
  continue;
822
852
  }
853
+ if (fieldSchema.crudHints?.format === "money") {
854
+ const field = {
855
+ ...moneyField().name(name).label(label).required(required).build(),
856
+ filterable
857
+ };
858
+ stampMappingReason(field, "rule-3.55b money", applyCrudHints(field, fieldSchema.crudHints));
859
+ fields.push(field);
860
+ continue;
861
+ }
823
862
  if (fieldSchema.crudHints?.format === "currency" && (tag === "text" || tag === "integer" || tag === "decimal")) {
824
863
  const field = {
825
864
  ...currencyField().name(name).label(label).required(required).build(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nubitio/hydra",
3
- "version": "0.11.1",
3
+ "version": "0.11.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",
@@ -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/crud": "^0.11.1",
55
- "@nubitio/core": "^0.11.1"
54
+ "@nubitio/core": "^0.11.3",
55
+ "@nubitio/crud": "^0.11.3"
56
56
  }
57
57
  }