Breeze / breeze-client

Breeze for JavaScript clients
MIT License
38 stars 16 forks source link

Add extendFuncMap to Predicate #37

Closed tschettler closed 3 years ago

tschettler commented 3 years ago

Adding a function to extend the funcMap defined in FnExpr within the Predicate scope. This function is modeled after extendBinaryPredicateFn, This will allow adding functions that are available in OData 4, but that breeze does not have defined.

For example, adding a date function to the funcMap:

Predicate.extendFuncMap({date: {fn: (date: Date) => new Date(date).setHours(0, 0, 0), dataType: DataType.DateTimeOffset }});

Afterwards, we can employ the OData 4 date function in the predicate:

let predicate = new breeze.Predicate("date(startDate)", "eq", dateValue);

The workaround for this would be to use a pass-thru predicate:

let predicate = new breeze.Predicate("date(startDate) eq " + dateValue);

Original PR Breeze/breeze.js#202

steveschmitt commented 3 years ago

Cool, thanks.

Out of curiosity, what's your server setup for testing with OData 4?

tschettler commented 3 years ago

@steveschmitt Thanks! I use Microsoft.AspNet.Odata and also test against the public APIs referenced on XOData. I've authored a breeze-odata4 package that is basically an OData 4 shim for breeze, but haven't updated it to use breeze-client 2.x yet.