@nubitio/hydra 0.9.5 → 0.9.7
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 +31 -8
- package/dist/index.d.cts +9 -5
- package/dist/index.d.mts +9 -5
- package/dist/index.mjs +31 -8
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -97,6 +97,21 @@ function stripAdapterOnlyParams(loadOptions) {
|
|
|
97
97
|
if (nextOptions.searchExpr === void 0) delete nextOptions.searchValue;
|
|
98
98
|
return nextOptions;
|
|
99
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* prependData/appendData are client-side merge instructions consumed in
|
|
102
|
+
* `fetchAll` after the response comes back — they were never meant to leave
|
|
103
|
+
* the browser. `preparedOptions` (which still carries them, for `fetchAll`
|
|
104
|
+
* to read) doubles as the HTTP request's query params, so left in place
|
|
105
|
+
* they'd serialize into the URL as a wall of prependData[0][...] params:
|
|
106
|
+
* harmless to the server, which ignores unrecognized filters, but noisy and
|
|
107
|
+
* wasteful.
|
|
108
|
+
*/
|
|
109
|
+
function stripMergeOnlyParams(loadOptions) {
|
|
110
|
+
const nextOptions = { ...loadOptions };
|
|
111
|
+
delete nextOptions.prependData;
|
|
112
|
+
delete nextOptions.appendData;
|
|
113
|
+
return nextOptions;
|
|
114
|
+
}
|
|
100
115
|
function convertPaginationParams(loadOptions) {
|
|
101
116
|
const nextOptions = { ...loadOptions };
|
|
102
117
|
const take = typeof nextOptions.take === "number" ? nextOptions.take : void 0;
|
|
@@ -201,11 +216,16 @@ var HydraRemoteDataSource = class {
|
|
|
201
216
|
return this.config.iriMode && item ? addIriField(this.config.url, item) : item;
|
|
202
217
|
}
|
|
203
218
|
async fetchAll(loadOptions) {
|
|
204
|
-
const response = await this.httpClient.get(this.config.url, { params: loadOptions });
|
|
219
|
+
const response = await this.httpClient.get(this.config.url, { params: stripMergeOnlyParams(loadOptions) });
|
|
205
220
|
const parsed = parseCollectionResponse(response.data, response.headers);
|
|
206
221
|
let data = parsed.data;
|
|
207
|
-
|
|
208
|
-
|
|
222
|
+
const itemKey = (item) => item["id"] ?? item["code"] ?? item["uuid"] ?? item["slug"] ?? item["@id"] ?? item[this.config.idField];
|
|
223
|
+
const dedupeAgainst = (extra, existing) => {
|
|
224
|
+
const existingKeys = new Set(existing.map(itemKey));
|
|
225
|
+
return extra.filter((item) => !existingKeys.has(itemKey(item)));
|
|
226
|
+
};
|
|
227
|
+
if (loadOptions.appendData) data = [...data, ...dedupeAgainst(loadOptions.appendData, data)];
|
|
228
|
+
if (loadOptions.prependData) data = [...dedupeAgainst(loadOptions.prependData, data), ...data];
|
|
209
229
|
const totalCount = parsed.totalCount === parsed.data.length ? data.length : parsed.totalCount;
|
|
210
230
|
return {
|
|
211
231
|
data,
|
|
@@ -300,9 +320,11 @@ function deriveApiUrl(entrypointPropertyId) {
|
|
|
300
320
|
/**
|
|
301
321
|
* True when `raw` is the Hydra collection-range wrapper — an array whose
|
|
302
322
|
* entries carry the target class under `owl:equivalentClass.owl:allValuesFrom`.
|
|
303
|
-
*
|
|
304
|
-
* properties
|
|
305
|
-
*
|
|
323
|
+
* Some API Platform configurations emit this shape for `ManyToMany`/`OneToMany`
|
|
324
|
+
* properties instead of the plain string `range` + `@type: "Link"` combination
|
|
325
|
+
* (see the `isCollection` field on `HydraFieldSchema` for the other signal) —
|
|
326
|
+
* this function only recognises the array-wrapper variant. A to-one relation's
|
|
327
|
+
* `range` is always a plain string or a single IRI object, never an array.
|
|
306
328
|
*/
|
|
307
329
|
function isCollectionRange(raw) {
|
|
308
330
|
return Array.isArray(raw);
|
|
@@ -439,14 +461,15 @@ function parseHydraDoc(doc, entrypointHrefs) {
|
|
|
439
461
|
const readable = sp.readable !== false;
|
|
440
462
|
const writeable = sp.writeable !== false;
|
|
441
463
|
if (!readable) continue;
|
|
464
|
+
const propertyType = sp.property?.["@type"] ?? "rdf:Property";
|
|
442
465
|
fields.push({
|
|
443
466
|
name: technicalName(sp),
|
|
444
467
|
range: normalizeRange(sp.property?.range),
|
|
445
|
-
propertyType
|
|
468
|
+
propertyType,
|
|
446
469
|
required: sp.required ?? false,
|
|
447
470
|
readable,
|
|
448
471
|
writeable,
|
|
449
|
-
isCollection: isCollectionRange(sp.property?.range),
|
|
472
|
+
isCollection: isCollectionRange(sp.property?.range) || propertyType === "Link",
|
|
450
473
|
"hydra:title": sp["title"] ?? sp["hydra:title"] ?? void 0,
|
|
451
474
|
crudHints: sp["x-crud"],
|
|
452
475
|
enumOptions: Array.isArray(sp["enum"]) ? sp["enum"] : void 0
|
package/dist/index.d.cts
CHANGED
|
@@ -265,11 +265,15 @@ interface HydraFieldSchema {
|
|
|
265
265
|
enumOptions?: Array<string | number>;
|
|
266
266
|
/**
|
|
267
267
|
* True when the property is a to-many relation (Doctrine ManyToMany /
|
|
268
|
-
* OneToMany) rather than a single reference.
|
|
269
|
-
*
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
*
|
|
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.
|
|
273
277
|
*/
|
|
274
278
|
isCollection?: boolean;
|
|
275
279
|
}
|
package/dist/index.d.mts
CHANGED
|
@@ -265,11 +265,15 @@ interface HydraFieldSchema {
|
|
|
265
265
|
enumOptions?: Array<string | number>;
|
|
266
266
|
/**
|
|
267
267
|
* True when the property is a to-many relation (Doctrine ManyToMany /
|
|
268
|
-
* OneToMany) rather than a single reference.
|
|
269
|
-
*
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
*
|
|
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.
|
|
273
277
|
*/
|
|
274
278
|
isCollection?: boolean;
|
|
275
279
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -73,6 +73,21 @@ function stripAdapterOnlyParams(loadOptions) {
|
|
|
73
73
|
if (nextOptions.searchExpr === void 0) delete nextOptions.searchValue;
|
|
74
74
|
return nextOptions;
|
|
75
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* prependData/appendData are client-side merge instructions consumed in
|
|
78
|
+
* `fetchAll` after the response comes back — they were never meant to leave
|
|
79
|
+
* the browser. `preparedOptions` (which still carries them, for `fetchAll`
|
|
80
|
+
* to read) doubles as the HTTP request's query params, so left in place
|
|
81
|
+
* they'd serialize into the URL as a wall of prependData[0][...] params:
|
|
82
|
+
* harmless to the server, which ignores unrecognized filters, but noisy and
|
|
83
|
+
* wasteful.
|
|
84
|
+
*/
|
|
85
|
+
function stripMergeOnlyParams(loadOptions) {
|
|
86
|
+
const nextOptions = { ...loadOptions };
|
|
87
|
+
delete nextOptions.prependData;
|
|
88
|
+
delete nextOptions.appendData;
|
|
89
|
+
return nextOptions;
|
|
90
|
+
}
|
|
76
91
|
function convertPaginationParams(loadOptions) {
|
|
77
92
|
const nextOptions = { ...loadOptions };
|
|
78
93
|
const take = typeof nextOptions.take === "number" ? nextOptions.take : void 0;
|
|
@@ -177,11 +192,16 @@ var HydraRemoteDataSource = class {
|
|
|
177
192
|
return this.config.iriMode && item ? addIriField(this.config.url, item) : item;
|
|
178
193
|
}
|
|
179
194
|
async fetchAll(loadOptions) {
|
|
180
|
-
const response = await this.httpClient.get(this.config.url, { params: loadOptions });
|
|
195
|
+
const response = await this.httpClient.get(this.config.url, { params: stripMergeOnlyParams(loadOptions) });
|
|
181
196
|
const parsed = parseCollectionResponse(response.data, response.headers);
|
|
182
197
|
let data = parsed.data;
|
|
183
|
-
|
|
184
|
-
|
|
198
|
+
const itemKey = (item) => item["id"] ?? item["code"] ?? item["uuid"] ?? item["slug"] ?? item["@id"] ?? item[this.config.idField];
|
|
199
|
+
const dedupeAgainst = (extra, existing) => {
|
|
200
|
+
const existingKeys = new Set(existing.map(itemKey));
|
|
201
|
+
return extra.filter((item) => !existingKeys.has(itemKey(item)));
|
|
202
|
+
};
|
|
203
|
+
if (loadOptions.appendData) data = [...data, ...dedupeAgainst(loadOptions.appendData, data)];
|
|
204
|
+
if (loadOptions.prependData) data = [...dedupeAgainst(loadOptions.prependData, data), ...data];
|
|
185
205
|
const totalCount = parsed.totalCount === parsed.data.length ? data.length : parsed.totalCount;
|
|
186
206
|
return {
|
|
187
207
|
data,
|
|
@@ -276,9 +296,11 @@ function deriveApiUrl(entrypointPropertyId) {
|
|
|
276
296
|
/**
|
|
277
297
|
* True when `raw` is the Hydra collection-range wrapper — an array whose
|
|
278
298
|
* entries carry the target class under `owl:equivalentClass.owl:allValuesFrom`.
|
|
279
|
-
*
|
|
280
|
-
* properties
|
|
281
|
-
*
|
|
299
|
+
* Some API Platform configurations emit this shape for `ManyToMany`/`OneToMany`
|
|
300
|
+
* properties instead of the plain string `range` + `@type: "Link"` combination
|
|
301
|
+
* (see the `isCollection` field on `HydraFieldSchema` for the other signal) —
|
|
302
|
+
* this function only recognises the array-wrapper variant. A to-one relation's
|
|
303
|
+
* `range` is always a plain string or a single IRI object, never an array.
|
|
282
304
|
*/
|
|
283
305
|
function isCollectionRange(raw) {
|
|
284
306
|
return Array.isArray(raw);
|
|
@@ -415,14 +437,15 @@ function parseHydraDoc(doc, entrypointHrefs) {
|
|
|
415
437
|
const readable = sp.readable !== false;
|
|
416
438
|
const writeable = sp.writeable !== false;
|
|
417
439
|
if (!readable) continue;
|
|
440
|
+
const propertyType = sp.property?.["@type"] ?? "rdf:Property";
|
|
418
441
|
fields.push({
|
|
419
442
|
name: technicalName(sp),
|
|
420
443
|
range: normalizeRange(sp.property?.range),
|
|
421
|
-
propertyType
|
|
444
|
+
propertyType,
|
|
422
445
|
required: sp.required ?? false,
|
|
423
446
|
readable,
|
|
424
447
|
writeable,
|
|
425
|
-
isCollection: isCollectionRange(sp.property?.range),
|
|
448
|
+
isCollection: isCollectionRange(sp.property?.range) || propertyType === "Link",
|
|
426
449
|
"hydra:title": sp["title"] ?? sp["hydra:title"] ?? void 0,
|
|
427
450
|
crudHints: sp["x-crud"],
|
|
428
451
|
enumOptions: Array.isArray(sp["enum"]) ? sp["enum"] : void 0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nubitio/hydra",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.7",
|
|
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/crud": "^0.9.7",
|
|
54
|
+
"@nubitio/core": "^0.9.7"
|
|
55
55
|
}
|
|
56
56
|
}
|