@nubitio/hydra 0.9.10 → 0.11.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 +41 -2
- package/dist/index.d.cts +6 -24
- package/dist/index.d.mts +6 -24
- package/dist/index.mjs +41 -2
- package/package.json +4 -3
package/dist/index.cjs
CHANGED
|
@@ -28,6 +28,25 @@ let _nubitio_crud = require("@nubitio/crud");
|
|
|
28
28
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
29
29
|
let _tanstack_react_query = require("@tanstack/react-query");
|
|
30
30
|
//#region packages/hydra/HydraRemoteDataSource.ts
|
|
31
|
+
const XLSX_MIME_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
32
|
+
const CONTENT_DISPOSITION_FILENAME_EXT = /filename\*\s*=\s*[^']*'[^']*'([^;]+)/i;
|
|
33
|
+
const CONTENT_DISPOSITION_FILENAME = /filename\s*=\s*"([^"]+)"|filename\s*=\s*([^;]+)/i;
|
|
34
|
+
function parseContentDispositionFilename(headers, fallback) {
|
|
35
|
+
const raw = headers.get("content-disposition");
|
|
36
|
+
if (!raw) return fallback;
|
|
37
|
+
const extended = CONTENT_DISPOSITION_FILENAME_EXT.exec(raw)?.[1];
|
|
38
|
+
if (extended) try {
|
|
39
|
+
return sanitizeFilename(decodeURIComponent(extended.trim())) ?? fallback;
|
|
40
|
+
} catch {}
|
|
41
|
+
const match = CONTENT_DISPOSITION_FILENAME.exec(raw);
|
|
42
|
+
const plain = match?.[1] ?? match?.[2];
|
|
43
|
+
return plain && sanitizeFilename(plain.trim()) || fallback;
|
|
44
|
+
}
|
|
45
|
+
/** The server names the file; never let that name escape the download directory. */
|
|
46
|
+
function sanitizeFilename(value) {
|
|
47
|
+
const name = value.replace(/[/\\]/g, "_").trim();
|
|
48
|
+
return name === "" || name === "." || name === ".." ? null : name;
|
|
49
|
+
}
|
|
31
50
|
const defaultHttpClient = (0, _nubitio_core.createCoreHttpClient)({ baseUrl: "" });
|
|
32
51
|
function findPreloadedItem(loadOptions, idField, id) {
|
|
33
52
|
const prependData = Array.isArray(loadOptions.prependData) ? loadOptions.prependData : [];
|
|
@@ -208,6 +227,24 @@ var HydraRemoteDataSource = class {
|
|
|
208
227
|
}
|
|
209
228
|
return this.fetchAll(preparedOptions);
|
|
210
229
|
}
|
|
230
|
+
async export(loadOptions) {
|
|
231
|
+
const preparedOptions = this.prepareLoadOptions({
|
|
232
|
+
...loadOptions,
|
|
233
|
+
skip: void 0,
|
|
234
|
+
take: void 0
|
|
235
|
+
});
|
|
236
|
+
delete preparedOptions.itemsPerPage;
|
|
237
|
+
delete preparedOptions.page;
|
|
238
|
+
const response = await this.httpClient.get(this.config.url, {
|
|
239
|
+
params: stripMergeOnlyParams(preparedOptions),
|
|
240
|
+
headers: { Accept: XLSX_MIME_TYPE },
|
|
241
|
+
responseType: "blob"
|
|
242
|
+
});
|
|
243
|
+
return {
|
|
244
|
+
blob: response.data,
|
|
245
|
+
filename: parseContentDispositionFilename(response.headers, "export.xlsx")
|
|
246
|
+
};
|
|
247
|
+
}
|
|
211
248
|
async byKey(key) {
|
|
212
249
|
const id = typeof key === "object" && key !== null ? key[this.config.idField] : key;
|
|
213
250
|
if (id === void 0) return null;
|
|
@@ -1205,11 +1242,13 @@ function useResourceSchema(apiUrl, options) {
|
|
|
1205
1242
|
error,
|
|
1206
1243
|
supportedOperations: []
|
|
1207
1244
|
};
|
|
1208
|
-
const
|
|
1245
|
+
const resolver = getSchemaResolver(data);
|
|
1246
|
+
const resolved = resolver.resolveResource(apiUrl);
|
|
1209
1247
|
return {
|
|
1210
1248
|
...resolved,
|
|
1211
1249
|
error: resolved.error,
|
|
1212
|
-
isLoading: false
|
|
1250
|
+
isLoading: false,
|
|
1251
|
+
resolveFormDetail: (formDetail) => resolver.resolveFormDetail(apiUrl, formDetail, resolved.embeddedLines)
|
|
1213
1252
|
};
|
|
1214
1253
|
}, [
|
|
1215
1254
|
data,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DataRecord, GridData } from "@nubitio/core";
|
|
2
|
-
import { DataRecord as DataRecord$1, Field, FormLayout, ResourceFilterDescriptor, ResourceFilterRule, ResourceFormDetail, ResourceLoadOptions, ResourceSchemaResolution, ResourceSortDescriptor, ResourceStore, ResourceStoreFactory, ResourceStoreOptions, SummaryItem } from "@nubitio/crud";
|
|
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
4
|
|
|
5
5
|
//#region packages/hydra/HydraRemoteDataSource.d.ts
|
|
@@ -14,6 +14,7 @@ declare class HydraRemoteDataSource implements ResourceStore {
|
|
|
14
14
|
makeFilterRules(filterRules: ResourceFilterRule[]): string;
|
|
15
15
|
prepareLoadOptions(loadOptions: ResourceLoadOptions): ResourceLoadOptions;
|
|
16
16
|
load(loadOptions: ResourceLoadOptions): Promise<GridData<DataRecord>>;
|
|
17
|
+
export(loadOptions: ResourceLoadOptions): Promise<ResourceExportResult>;
|
|
17
18
|
byKey(key: unknown): Promise<DataRecord | null>;
|
|
18
19
|
private fetchAll;
|
|
19
20
|
private fetchById;
|
|
@@ -165,17 +166,6 @@ interface HydraSupportedOperation {
|
|
|
165
166
|
'hydra:method'?: string;
|
|
166
167
|
method?: string;
|
|
167
168
|
}
|
|
168
|
-
interface WorkflowTransitionSchema {
|
|
169
|
-
name: string;
|
|
170
|
-
from: string[];
|
|
171
|
-
to: string;
|
|
172
|
-
label?: string;
|
|
173
|
-
roles?: string[];
|
|
174
|
-
}
|
|
175
|
-
interface WorkflowSchema {
|
|
176
|
-
field: string;
|
|
177
|
-
transitions: WorkflowTransitionSchema[];
|
|
178
|
-
}
|
|
179
169
|
interface SequenceSchema {
|
|
180
170
|
field: string;
|
|
181
171
|
name?: string;
|
|
@@ -184,21 +174,13 @@ interface SequenceSchema {
|
|
|
184
174
|
scope?: string[];
|
|
185
175
|
}
|
|
186
176
|
/** Master-detail line metadata from nubitio/admin-bundle EmbeddedLinesDocumentationNormalizer. */
|
|
187
|
-
interface EmbeddedLinesSchema {
|
|
188
|
-
propertyName: string;
|
|
189
|
-
lineClass: string;
|
|
190
|
-
lineEntityClass?: string;
|
|
191
|
-
routePath: string;
|
|
192
|
-
parentQueryParam: string;
|
|
193
|
-
reloadUrl: string;
|
|
194
|
-
}
|
|
195
177
|
interface HydraClass {
|
|
196
178
|
'@id': string;
|
|
197
179
|
'@type': string;
|
|
198
180
|
title: string;
|
|
199
181
|
supportedProperty: HydraSupportedProperty[];
|
|
200
182
|
/** State machine metadata from nubitio/workflow-bundle. */
|
|
201
|
-
'x-workflow'?: WorkflowSchema;
|
|
183
|
+
'x-workflow'?: WorkflowSchema$1;
|
|
202
184
|
/** Auto-numbering metadata from nubitio/sequence-bundle. */
|
|
203
185
|
'x-sequence'?: SequenceSchema;
|
|
204
186
|
/**
|
|
@@ -208,7 +190,7 @@ interface HydraClass {
|
|
|
208
190
|
*/
|
|
209
191
|
'x-crud-layout'?: FormLayout;
|
|
210
192
|
/** Embedded line collections declared on parent document resources. */
|
|
211
|
-
'x-embedded-lines'?: EmbeddedLinesSchema[];
|
|
193
|
+
'x-embedded-lines'?: EmbeddedLinesSchema$1[];
|
|
212
194
|
/**
|
|
213
195
|
* Hydra search template describing server-side filterable query params.
|
|
214
196
|
* Present on collection operations in API Platform JSON-LD responses.
|
|
@@ -309,11 +291,11 @@ interface HydraResourceSchema {
|
|
|
309
291
|
*/
|
|
310
292
|
supportedOperations?: string[];
|
|
311
293
|
/** Workflow transitions for auto row actions (nubitio/workflow-bundle). */
|
|
312
|
-
workflow?: WorkflowSchema;
|
|
294
|
+
workflow?: WorkflowSchema$1;
|
|
313
295
|
/** Server-allocated sequence field (nubitio/sequence-bundle). */
|
|
314
296
|
sequence?: SequenceSchema;
|
|
315
297
|
/** Embedded line collections (nubitio/admin-bundle). */
|
|
316
|
-
embeddedLines?: EmbeddedLinesSchema[];
|
|
298
|
+
embeddedLines?: EmbeddedLinesSchema$1[];
|
|
317
299
|
}
|
|
318
300
|
interface OpenApiProperty {
|
|
319
301
|
type?: string;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DataRecord, GridData } from "@nubitio/core";
|
|
2
2
|
import React, { ReactNode } from "react";
|
|
3
|
-
import { DataRecord as DataRecord$1, Field, FormLayout, ResourceFilterDescriptor, ResourceFilterRule, ResourceFormDetail, ResourceLoadOptions, ResourceSchemaResolution, ResourceSortDescriptor, ResourceStore, ResourceStoreFactory, ResourceStoreOptions, SummaryItem } from "@nubitio/crud";
|
|
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
4
|
|
|
5
5
|
//#region packages/hydra/HydraRemoteDataSource.d.ts
|
|
6
6
|
type RemoteFilterDescriptor = ResourceFilterDescriptor;
|
|
@@ -14,6 +14,7 @@ declare class HydraRemoteDataSource implements ResourceStore {
|
|
|
14
14
|
makeFilterRules(filterRules: ResourceFilterRule[]): string;
|
|
15
15
|
prepareLoadOptions(loadOptions: ResourceLoadOptions): ResourceLoadOptions;
|
|
16
16
|
load(loadOptions: ResourceLoadOptions): Promise<GridData<DataRecord>>;
|
|
17
|
+
export(loadOptions: ResourceLoadOptions): Promise<ResourceExportResult>;
|
|
17
18
|
byKey(key: unknown): Promise<DataRecord | null>;
|
|
18
19
|
private fetchAll;
|
|
19
20
|
private fetchById;
|
|
@@ -165,17 +166,6 @@ interface HydraSupportedOperation {
|
|
|
165
166
|
'hydra:method'?: string;
|
|
166
167
|
method?: string;
|
|
167
168
|
}
|
|
168
|
-
interface WorkflowTransitionSchema {
|
|
169
|
-
name: string;
|
|
170
|
-
from: string[];
|
|
171
|
-
to: string;
|
|
172
|
-
label?: string;
|
|
173
|
-
roles?: string[];
|
|
174
|
-
}
|
|
175
|
-
interface WorkflowSchema {
|
|
176
|
-
field: string;
|
|
177
|
-
transitions: WorkflowTransitionSchema[];
|
|
178
|
-
}
|
|
179
169
|
interface SequenceSchema {
|
|
180
170
|
field: string;
|
|
181
171
|
name?: string;
|
|
@@ -184,21 +174,13 @@ interface SequenceSchema {
|
|
|
184
174
|
scope?: string[];
|
|
185
175
|
}
|
|
186
176
|
/** Master-detail line metadata from nubitio/admin-bundle EmbeddedLinesDocumentationNormalizer. */
|
|
187
|
-
interface EmbeddedLinesSchema {
|
|
188
|
-
propertyName: string;
|
|
189
|
-
lineClass: string;
|
|
190
|
-
lineEntityClass?: string;
|
|
191
|
-
routePath: string;
|
|
192
|
-
parentQueryParam: string;
|
|
193
|
-
reloadUrl: string;
|
|
194
|
-
}
|
|
195
177
|
interface HydraClass {
|
|
196
178
|
'@id': string;
|
|
197
179
|
'@type': string;
|
|
198
180
|
title: string;
|
|
199
181
|
supportedProperty: HydraSupportedProperty[];
|
|
200
182
|
/** State machine metadata from nubitio/workflow-bundle. */
|
|
201
|
-
'x-workflow'?: WorkflowSchema;
|
|
183
|
+
'x-workflow'?: WorkflowSchema$1;
|
|
202
184
|
/** Auto-numbering metadata from nubitio/sequence-bundle. */
|
|
203
185
|
'x-sequence'?: SequenceSchema;
|
|
204
186
|
/**
|
|
@@ -208,7 +190,7 @@ interface HydraClass {
|
|
|
208
190
|
*/
|
|
209
191
|
'x-crud-layout'?: FormLayout;
|
|
210
192
|
/** Embedded line collections declared on parent document resources. */
|
|
211
|
-
'x-embedded-lines'?: EmbeddedLinesSchema[];
|
|
193
|
+
'x-embedded-lines'?: EmbeddedLinesSchema$1[];
|
|
212
194
|
/**
|
|
213
195
|
* Hydra search template describing server-side filterable query params.
|
|
214
196
|
* Present on collection operations in API Platform JSON-LD responses.
|
|
@@ -309,11 +291,11 @@ interface HydraResourceSchema {
|
|
|
309
291
|
*/
|
|
310
292
|
supportedOperations?: string[];
|
|
311
293
|
/** Workflow transitions for auto row actions (nubitio/workflow-bundle). */
|
|
312
|
-
workflow?: WorkflowSchema;
|
|
294
|
+
workflow?: WorkflowSchema$1;
|
|
313
295
|
/** Server-allocated sequence field (nubitio/sequence-bundle). */
|
|
314
296
|
sequence?: SequenceSchema;
|
|
315
297
|
/** Embedded line collections (nubitio/admin-bundle). */
|
|
316
|
-
embeddedLines?: EmbeddedLinesSchema[];
|
|
298
|
+
embeddedLines?: EmbeddedLinesSchema$1[];
|
|
317
299
|
}
|
|
318
300
|
interface OpenApiProperty {
|
|
319
301
|
type?: string;
|
package/dist/index.mjs
CHANGED
|
@@ -4,6 +4,25 @@ import { ResourceSchemaProvider, ResourceStoreProvider, currencyField, datetimeF
|
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
import { useQuery } from "@tanstack/react-query";
|
|
6
6
|
//#region packages/hydra/HydraRemoteDataSource.ts
|
|
7
|
+
const XLSX_MIME_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
8
|
+
const CONTENT_DISPOSITION_FILENAME_EXT = /filename\*\s*=\s*[^']*'[^']*'([^;]+)/i;
|
|
9
|
+
const CONTENT_DISPOSITION_FILENAME = /filename\s*=\s*"([^"]+)"|filename\s*=\s*([^;]+)/i;
|
|
10
|
+
function parseContentDispositionFilename(headers, fallback) {
|
|
11
|
+
const raw = headers.get("content-disposition");
|
|
12
|
+
if (!raw) return fallback;
|
|
13
|
+
const extended = CONTENT_DISPOSITION_FILENAME_EXT.exec(raw)?.[1];
|
|
14
|
+
if (extended) try {
|
|
15
|
+
return sanitizeFilename(decodeURIComponent(extended.trim())) ?? fallback;
|
|
16
|
+
} catch {}
|
|
17
|
+
const match = CONTENT_DISPOSITION_FILENAME.exec(raw);
|
|
18
|
+
const plain = match?.[1] ?? match?.[2];
|
|
19
|
+
return plain && sanitizeFilename(plain.trim()) || fallback;
|
|
20
|
+
}
|
|
21
|
+
/** The server names the file; never let that name escape the download directory. */
|
|
22
|
+
function sanitizeFilename(value) {
|
|
23
|
+
const name = value.replace(/[/\\]/g, "_").trim();
|
|
24
|
+
return name === "" || name === "." || name === ".." ? null : name;
|
|
25
|
+
}
|
|
7
26
|
const defaultHttpClient = createCoreHttpClient({ baseUrl: "" });
|
|
8
27
|
function findPreloadedItem(loadOptions, idField, id) {
|
|
9
28
|
const prependData = Array.isArray(loadOptions.prependData) ? loadOptions.prependData : [];
|
|
@@ -184,6 +203,24 @@ var HydraRemoteDataSource = class {
|
|
|
184
203
|
}
|
|
185
204
|
return this.fetchAll(preparedOptions);
|
|
186
205
|
}
|
|
206
|
+
async export(loadOptions) {
|
|
207
|
+
const preparedOptions = this.prepareLoadOptions({
|
|
208
|
+
...loadOptions,
|
|
209
|
+
skip: void 0,
|
|
210
|
+
take: void 0
|
|
211
|
+
});
|
|
212
|
+
delete preparedOptions.itemsPerPage;
|
|
213
|
+
delete preparedOptions.page;
|
|
214
|
+
const response = await this.httpClient.get(this.config.url, {
|
|
215
|
+
params: stripMergeOnlyParams(preparedOptions),
|
|
216
|
+
headers: { Accept: XLSX_MIME_TYPE },
|
|
217
|
+
responseType: "blob"
|
|
218
|
+
});
|
|
219
|
+
return {
|
|
220
|
+
blob: response.data,
|
|
221
|
+
filename: parseContentDispositionFilename(response.headers, "export.xlsx")
|
|
222
|
+
};
|
|
223
|
+
}
|
|
187
224
|
async byKey(key) {
|
|
188
225
|
const id = typeof key === "object" && key !== null ? key[this.config.idField] : key;
|
|
189
226
|
if (id === void 0) return null;
|
|
@@ -1181,11 +1218,13 @@ function useResourceSchema(apiUrl, options) {
|
|
|
1181
1218
|
error,
|
|
1182
1219
|
supportedOperations: []
|
|
1183
1220
|
};
|
|
1184
|
-
const
|
|
1221
|
+
const resolver = getSchemaResolver(data);
|
|
1222
|
+
const resolved = resolver.resolveResource(apiUrl);
|
|
1185
1223
|
return {
|
|
1186
1224
|
...resolved,
|
|
1187
1225
|
error: resolved.error,
|
|
1188
|
-
isLoading: false
|
|
1226
|
+
isLoading: false,
|
|
1227
|
+
resolveFormDetail: (formDetail) => resolver.resolveFormDetail(apiUrl, formDetail, resolved.embeddedLines)
|
|
1189
1228
|
};
|
|
1190
1229
|
}, [
|
|
1191
1230
|
data,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nubitio/hydra",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.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",
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"files": [
|
|
39
39
|
"dist"
|
|
40
40
|
],
|
|
41
|
+
"sideEffects": false,
|
|
41
42
|
"engines": {
|
|
42
43
|
"node": ">=18.0.0"
|
|
43
44
|
},
|
|
@@ -50,7 +51,7 @@
|
|
|
50
51
|
"react": "^18.2.0 || ^19.0.0",
|
|
51
52
|
"react-dom": "^18.2.0 || ^19.0.0",
|
|
52
53
|
"react-i18next": "^14.0.0",
|
|
53
|
-
"@nubitio/core": "^0.
|
|
54
|
-
"@nubitio/crud": "^0.
|
|
54
|
+
"@nubitio/core": "^0.11.0",
|
|
55
|
+
"@nubitio/crud": "^0.11.0"
|
|
55
56
|
}
|
|
56
57
|
}
|