@adminforth/import-export 1.2.0 → 1.2.1
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/build.log +1 -1
- package/dist/index.js +2 -19
- package/index.ts +1 -19
- package/package.json +1 -1
package/build.log
CHANGED
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { AdminForthPlugin, suggestIfTypo,
|
|
10
|
+
import { AdminForthPlugin, suggestIfTypo, Filters } from "adminforth";
|
|
11
11
|
export default class ImportExport extends AdminForthPlugin {
|
|
12
12
|
constructor(options) {
|
|
13
13
|
super(options, import.meta.url);
|
|
@@ -56,28 +56,11 @@ export default class ImportExport extends AdminForthPlugin {
|
|
|
56
56
|
noAuth: true,
|
|
57
57
|
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body }) {
|
|
58
58
|
const { filters, sort } = body;
|
|
59
|
-
for (const filter of (filters || [])) {
|
|
60
|
-
if (!Object.values(AdminForthFilterOperators).includes(filter.operator)) {
|
|
61
|
-
throw new Error(`Operator '${filter.operator}' is not allowed`);
|
|
62
|
-
}
|
|
63
|
-
if (!this.resourceConfig.columns.some((col) => col.name === filter.field)) {
|
|
64
|
-
throw new Error(`Field '${filter.field}' is not in resource '${this.resourceConfig.resourceId}'. Available fields: ${this.resourceConfig.columns.map((col) => col.name).join(', ')}`);
|
|
65
|
-
}
|
|
66
|
-
if (filter.operator === AdminForthFilterOperators.IN || filter.operator === AdminForthFilterOperators.NIN) {
|
|
67
|
-
if (!Array.isArray(filter.value)) {
|
|
68
|
-
throw new Error(`Value for operator '${filter.operator}' should be an array`);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (filter.operator === AdminForthFilterOperators.IN && filter.value.length === 0) {
|
|
72
|
-
// nonsense
|
|
73
|
-
return { data: [], total: 0 };
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
59
|
const data = yield this.adminforth.connectors[this.resourceConfig.dataSource].getData({
|
|
77
60
|
resource: this.resourceConfig,
|
|
78
61
|
limit: 1e6,
|
|
79
62
|
offset: 0,
|
|
80
|
-
filters,
|
|
63
|
+
filters: this.adminforth.connectors[this.resourceConfig.dataSource].validateAndNormalizeInputFilters(filters),
|
|
81
64
|
sort,
|
|
82
65
|
getTotals: true,
|
|
83
66
|
});
|
package/index.ts
CHANGED
|
@@ -57,29 +57,11 @@ export default class ImportExport extends AdminForthPlugin {
|
|
|
57
57
|
handler: async ({ body }) => {
|
|
58
58
|
const { filters, sort } = body;
|
|
59
59
|
|
|
60
|
-
for (const filter of (filters || [])) {
|
|
61
|
-
if (!Object.values(AdminForthFilterOperators).includes(filter.operator)) {
|
|
62
|
-
throw new Error(`Operator '${filter.operator}' is not allowed`);
|
|
63
|
-
}
|
|
64
|
-
if (!this.resourceConfig.columns.some((col) => col.name === filter.field)) {
|
|
65
|
-
throw new Error(`Field '${filter.field}' is not in resource '${this.resourceConfig.resourceId}'. Available fields: ${this.resourceConfig.columns.map((col) => col.name).join(', ')}`);
|
|
66
|
-
}
|
|
67
|
-
if (filter.operator === AdminForthFilterOperators.IN || filter.operator === AdminForthFilterOperators.NIN) {
|
|
68
|
-
if (!Array.isArray(filter.value)) {
|
|
69
|
-
throw new Error(`Value for operator '${filter.operator}' should be an array`);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
if (filter.operator === AdminForthFilterOperators.IN && filter.value.length === 0) {
|
|
73
|
-
// nonsense
|
|
74
|
-
return { data: [], total: 0 };
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
60
|
const data = await this.adminforth.connectors[this.resourceConfig.dataSource].getData({
|
|
79
61
|
resource: this.resourceConfig,
|
|
80
62
|
limit: 1e6,
|
|
81
63
|
offset: 0,
|
|
82
|
-
filters,
|
|
64
|
+
filters: this.adminforth.connectors[this.resourceConfig.dataSource].validateAndNormalizeInputFilters(filters),
|
|
83
65
|
sort,
|
|
84
66
|
getTotals: true,
|
|
85
67
|
});
|