@forestadmin/datasource-customizer
Advanced tools
Comparing version 1.56.0 to 1.57.0
@@ -8,3 +8,5 @@ import { Caller, CollectionDecorator, CollectionSchema, PaginatedFilter } from '@forestadmin/datasource-toolkit'; | ||
refineFilter(caller: Caller, filter?: PaginatedFilter): Promise<PaginatedFilter>; | ||
private refineFilterSegment; | ||
private refineFilterLiveQuerySegment; | ||
} | ||
//# sourceMappingURL=collection.d.ts.map |
@@ -27,3 +27,11 @@ "use strict"; | ||
} | ||
let { conditionTree, segment } = filter; | ||
const trees = await Promise.all([ | ||
this.refineFilterSegment(caller, filter), | ||
this.refineFilterLiveQuerySegment(filter), | ||
]); | ||
const conditionTree = datasource_toolkit_1.ConditionTreeFactory.intersect(filter.conditionTree, ...trees); | ||
return filter.override({ conditionTree, segment: null, liveQuerySegment: null }); | ||
} | ||
async refineFilterSegment(caller, filter) { | ||
const { segment } = filter; | ||
if (segment && this.segments[segment]) { | ||
@@ -34,11 +42,27 @@ const definition = this.segments[segment]; | ||
: await definition; | ||
const conditionTreeSegment = result instanceof datasource_toolkit_1.ConditionTree ? result : datasource_toolkit_1.ConditionTreeFactory.fromPlainObject(result); | ||
datasource_toolkit_1.ConditionTreeValidator.validate(conditionTreeSegment, this); | ||
conditionTree = datasource_toolkit_1.ConditionTreeFactory.intersect(conditionTree, conditionTreeSegment); | ||
segment = null; | ||
const conditionTree = result instanceof datasource_toolkit_1.ConditionTree ? result : datasource_toolkit_1.ConditionTreeFactory.fromPlainObject(result); | ||
datasource_toolkit_1.ConditionTreeValidator.validate(conditionTree, this); | ||
return conditionTree; | ||
} | ||
return filter.override({ conditionTree, segment }); | ||
return null; | ||
} | ||
async refineFilterLiveQuerySegment(filter) { | ||
const { liveQuerySegment } = filter; | ||
if (liveQuerySegment) { | ||
const { query, connectionName } = liveQuerySegment; | ||
try { | ||
const result = (await this.dataSource.executeNativeQuery(connectionName, query, {})); | ||
const [primaryKey] = datasource_toolkit_1.SchemaUtils.getPrimaryKeys(this.childCollection.schema); | ||
const conditionTree = new datasource_toolkit_1.ConditionTreeLeaf(primaryKey, 'In', result.map(row => row[primaryKey])); | ||
datasource_toolkit_1.ConditionTreeValidator.validate(conditionTree, this); | ||
return conditionTree; | ||
} | ||
catch (error) { | ||
throw new datasource_toolkit_1.BusinessError(`An error occurred during the execution of the segment query - ${error.message}`, error); | ||
} | ||
} | ||
return null; | ||
} | ||
} | ||
exports.default = SegmentCollectionDecorator; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29sbGVjdGlvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9kZWNvcmF0b3JzL3NlZ21lbnQvY29sbGVjdGlvbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLHdFQVF5QztBQUd6QywwRkFBOEU7QUFFOUUsTUFBcUIsMEJBQTJCLFNBQVEsd0NBQW1CO0lBQTNFOztRQUNVLGFBQVEsR0FBMEMsRUFBRSxDQUFDO0lBMEMvRCxDQUFDO0lBeENDLFVBQVUsQ0FBQyxXQUFtQixFQUFFLFVBQTZCO1FBQzNELElBQUksQ0FBQyxRQUFRLENBQUMsV0FBVyxDQUFDLEdBQUcsVUFBVSxDQUFDO1FBQ3hDLElBQUksQ0FBQyxpQkFBaUIsRUFBRSxDQUFDO0lBQzNCLENBQUM7SUFFa0IsWUFBWSxDQUFDLFNBQTJCO1FBQ3pELE9BQU87WUFDTCxHQUFHLFNBQVM7WUFDWixRQUFRLEVBQUUsQ0FBQyxHQUFHLFNBQVMsQ0FBQyxRQUFRLEVBQUUsR0FBRyxNQUFNLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxRQUFRLENBQUMsQ0FBQztTQUNqRSxDQUFDO0lBQ0osQ0FBQztJQUVlLEtBQUssQ0FBQyxZQUFZLENBQ2hDLE1BQWMsRUFDZCxNQUF3QjtRQUV4QixJQUFJLENBQUMsTUFBTSxFQUF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tBQUssRUFBRSxjQUFjLEVBQUUsR0FBRyxnQkFBZ0IsQ0FBQztZQUVuRCxJQUFJO2dCQUNGLE1BQU0sTUFBTSxHQUFHLENBQUMsTUFBTSxJQUFJLENBQUMsVUFBVSxDQUFDLGtCQUFrQixDQUN0RCxjQUFjLEVBQ2QsS0FBSyxFQUNMLEVBQUUsQ0FDSCxDQUE4QixDQUFDO2dCQUVoQyxNQUFNLENBQUMsVUFBVSxDQUFDLEdBQUcsZ0NBQVcsQ0FBQyxjQUFjLENBQUMsSUFBSSxDQUFDLGVBQWUsQ0FBQyxNQUFNLENBQUMsQ0FBQztnQkFFN0UsTUFBTSxhQUFhLEdBQUcsSUFBSSxzQ0FBaUIsQ0FDekMsVUFBVSxFQUNWLElBQUksRUFDSixNQUFNLENBQUMsR0FBRyxDQUFDLEdBQUcsQ0FBQyxFQUFFLENBQUMsR0FBRyxDQUFDLFVBQVUsQ0FBQyxDQUFDLENBQ25DLENBQUM7Z0JBRUYsMkNBQXNCLENBQUMsUUFBUSxDQUFDLGFBQWEsRUFBRSxJQUFJLENBQUMsQ0FBQztnQkFFckQsT0FBTyxhQUFhLENBQUM7YUFDdEI7WUFBQyxPQUFPLEtBQUssRUFBRTtnQkFDZCxNQUFNLElBQUksa0NBQWEsQ0FDckIsaUVBQWlFLEtBQUssQ0FBQyxPQUFPLEVBQUUsRUFDaEYsS0FBSyxDQUNOLENBQUM7YUFDSDtTQUNGO1FBRUQsT0FBTyxJQUFJLENBQUM7SUFDZCxDQUFDO0NBQ0Y7QUF4RkQsNkNBd0ZDIn0= |
{ | ||
"name": "@forestadmin/datasource-customizer", | ||
"version": "1.56.0", | ||
"version": "1.57.0", | ||
"main": "dist/index.js", | ||
@@ -32,3 +32,3 @@ "license": "GPL-3.0", | ||
"dependencies": { | ||
"@forestadmin/datasource-toolkit": "1.44.0", | ||
"@forestadmin/datasource-toolkit": "1.45.0", | ||
"antlr4": "^4.13.1-patch-1", | ||
@@ -35,0 +35,0 @@ "file-type": "^16.5.4", |
724670
8574
+ Added@forestadmin/datasource-toolkit@1.45.0(transitive)
- Removed@forestadmin/datasource-toolkit@1.44.0(transitive)