Skip to content

Plugin for Pailingual-odata implements support filtering on arrow function based expression

Notifications You must be signed in to change notification settings

genusP/pailingual-odata-filter

Repository files navigation

Pailingual-Odata-Filter

Plugin for Pailingual-OData offering a simple and type-safe filtering expression

Install

npm --save pailingual-odata-filter

Usage

Before create instance ApiContext you must initialize plugin:

import Pailingual from "pailingual-odata";
import FilterPlugin from "pailingual-odata-filter";

Pailingual.use(FilterPlugin);

This plugin add override $filter function for support arrow-function expression. Expression takes 3 parameters:

  1. Filtrable entity
  2. Parameters
  3. List of builtin OData funcs
//simle filter
ctx.Parents.$filter(e=> e.id === 1);

//filter with parameter
let maxId =10;
ctx.Parent.$filter((e, p) => e.id <== p.maxId, { maxId })

//use Odata functions
ctx.Parent.$filter((e, p, f) => f.endsWith( e.stringField, '.txt'))

//lambda funcs
ctx.Parent.$filter(e=>e.childs.any(c=>c.childField === "test"))

AOT

Plugin implement custom tranformation for transform expressions to string. As result not need execute parsing expression on runtime. You can use transform with awesome-typescript-loader or ts-loader

//webpack.config.js
const PailingualFilterTransform = require("pailingual-odata-filter/pailingualFilterTransform").default;
const transform = new PailingualFilterTransform(apiMetdata);
....
rules: [
      {
        test: /\.tsx?$/,
        loader: 'awesome-typescript-loader',
         options: {
            getCustomTransformers: program => ({
                before: argv.mode === "production"
                  ? [ transform.createTransform(program) ]
                  : []
            })
        }

      }
    ]
...
//For notify when transform filed
plugins:[
	trsnsform.notTransfomedError()
]

//app.ts
import Pailingual from "pailingual-odata";

//No need register plugin in production mode, all expression transforms to string
if (process.env.NODE_ENV !== "production")
    Pailingual.use(require("pailingual-odata-filter").default);

About

Plugin for Pailingual-odata implements support filtering on arrow function based expression

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published