@nubitio/hydra 0.9.6 → 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 +23 -3
- package/dist/index.mjs +23 -3
- 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,
|
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,
|
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
|
}
|