1.0.13 • Published 8 months ago

nv-pg-jrow-ir-cond-front v1.0.13

Weekly downloads
-
License
ISC
Repository
-
Last release
8 months ago

nv-pg-jrow-ir-cond-front

install

  • npm install nv-pg-jrow-ir-cond-front

usage

  const { creat_cond_for_back}   = require("nv-pg-jrow-ir-cond-front");

example

            const _parser = require("/mnt/sdb/JS/BUSINESS-LIB_/PG/nv-pg-jrow/pkgs/nv-pg-jrow-front")._parser;
            const _scheme = require("/mnt/sdb/JS/BUSINESS-LIB_/PG/nv-pg-jrow/pkgs/nv-pg-jrow-scheme");

            var jcfg = {                                                               //non_leaf  '': [c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11]
                ss:'text',                                //leaf c0      s                   
                aa:[                                                                      //non_leaf  aa : [c1,c2,c3,c4,c5,c6]
                    'float8',                            //leaf c1      aa.0  
                    'text',                              //leaf c2      aa.1 
                    {                                                                    //non_leaf  a.2: [c3,c4]
                        dina_k0:'text',                  //leaf c3      aa.2.dina_k0 
                        dina_k1:'text',                  //leaf c4      aa.2.dina_k1
                    },
                    'int4',                              //leaf c5      aa.3
                    'json'                               //leaf c6      aa.4
                ],
                dd: {                                                                      //non_leaf d : [c7,c8,c9,c10,c11]
                    k0:'int8',                           //leaf c7      d.k0
                    k1:'buf',                            //leaf c8      d.k1 
                    aind: [                                                               //non_leaf d.aind : [c9,c10,c11]
                        'text',                          //leaf c9      a.aind.0  
                        'text',                          //leaf c10     a.aind.1
                        'json'                           //leaf c11     a.aind.2
                    ]
                }
            }

            console.log("scheme:");
            console.dir(jcfg);

            var scheme = _scheme.creat(jcfg).scheme;
            const {creat_cond_for_back} = require("../index");

            /*
                    var cd = `
                       c22                                        === !666      &&
                       extra.x                                    === 555      &&
                       aa[2].dina_k0                               === "ttxxtt" &&
                       as_json_leaf(dd.aind[2]).x[1]["2"]["x"]    === {m:1,n:2}
                    `





                    var [cond,rslt] = creat_cond_for_back(cd,scheme,_parser);

                    console.dir(
                      [cond,rslt],
                      {depth:null}
                    )
            
                    //[ false, 'c22 is not in scheme' ] 
             

            */

            var cd = `
               ( 
                   extra.x                                    === 555      &&
                   aa[2].dina_k0                               === "ttxxtt" &&
                   as_json_leaf(dd.aind[2]).x[1]["2"]["x"]    === {m:1,n:2}
               ) || (
                   aa[4] !== [1,{m:888},2,[{n:[5,6,7]}]]  ||
                   aa[3] > 8                              ||
                   str_includes(dd.aind[0],"ssss")       ||
                   !aa[0]
               )
            `

            console.log("input where cond_str:",cd)

            var [cond,rslt] = creat_cond_for_back(cd,scheme,_parser);
            console.log("compile to and send to backend: ")
            console.dir(
              JSON.parse(JSON.stringify([cond,rslt])),
              {depth:null}
            )


            /*

                    scheme:
                    
                    
                    {
                      ss: 'text',
                      aa: [
                        'float8',
                        'text',
                        { dina_k0: 'text', dina_k1: 'text' },
                        'int4',
                        'json'
                      ],
                      dd: { k0: 'int8', k1: 'buf', aind: [ 'text', 'text', 'json' ] }
                    }
                    
                    
                    
                    input where cond_str:
                    
                       (
                           extra.x                                    === 555      &&
                           aa[2].dina_k0                               === "ttxxtt" &&
                           as_json_leaf(dd.aind[2]).x[1]["2"]["x"]    === {m:1,n:2}
                       ) || (
                           aa[4] !== [1,{m:888},2,[{n:[5,6,7]}]]  ||
                           aa[3] > 8                              ||
                           str_includes(dd.aind[0],"ssss")       ||
                           !aa[0]
                       )

                    compile to and send to backend:
                    
                    
                    [
                      true,
                      {
                        cd: 'JPL0 === 555 && c3 === "ttxxtt" && JPL1 === JLIT0 || c6 !== JLIT1 || c5 > 8 || str_includes(c9, "ssss") || !c1',
                        hint: {
                          jpl: { JPL0: [ 'extra', 'x' ], JPL1: [ 'c11', 'x', 1, '2', 'x' ] },
                          jlit: {
                            JLIT0: '{"m":1,"n":2}',
                            JLIT1: '[1,{"m":888},2,[{"n":[5,6,7]}]]'
                          }
                        }
                      }
                    ]
            */

another

        scheme:
        {
          ss: 'text',
          aa: [
            'float8',
            'text',
            { dina_k0: 'text', dina_k1: 'text' },
            'int4',
            'json'
          ],
          dd: { k0: 'int8', k1: 'buf', aind: [ 'text', 'text', 'json' ] }
        }
        input where cond_str:
           (
               extra.x                                    === 555       &&
               to_i64(extra.y)                            === 77        &&
               aa[2].dina_k0                               === "ttxxtt"  &&
               as_json_leaf(dd.aind[2]).x[1]["2"]["x"]    === {m:1,n:2} &&
               to_i64(as_json_leaf(dd.aind[2]).int)       === 100
           ) || (
               aa[4] !== [1,{m:888},2,[{n:[5,6,7]}]]     ||
               aa[3] > 8                                 ||
               str_includes(dd.aind[0],"ssss")          ||
               !aa[0]                                    ||
               str_includes(to_str(dd.aind[0]),"ssss")
           )

        compile to and send to backend:
        [
          true,
          {
            cd: 'JPL0 === 555 && to_i64(JPL1) === 77 && c3 === "ttxxtt" && JPL2 === JLIT0 && to_i64(JPL3) === 100 || c6 !== JLIT1 || c5 > 8 || str_includes(c9, "ssss") || !c1 || str_includes(to_str(c9), "ssss")',
            hint: {
              jpl: {
                JPL0: [ 'extra', 'x' ],
                JPL1: [ 'extra', 'y' ],
                JPL2: [ 'c11', 'x', 1, '2', 'x' ],
                JPL3: [ 'c11', 'int' ]
              },
              jlit: {
                JLIT0: '{"m":1,"n":2}',
                JLIT1: '[1,{"m":888},2,[{"n":[5,6,7]}]]'
              }
            }
          }
        ]

METHODS

APIS

            {
              _agg: {
                ERRD: {
                  MemberExpression: {
                    computed_prop_must_be: 'computed prop must be: StringLiteral OR NumericLiteral',
                    dot_prop_must_be: 'dot prop must be Identifier',
                    obj_must_be: 'obj must be Identifier OR MemberExpression OR CallExpression',
                    call_expr_as_obj: 'if using call_expr as obj, callee must be Identifier:as_json_leaf',
                    fst_obj_must_be: 'fst obj must be Identifier'
                  }
                },
                vali_and_get_prop: [Function: vali_and_get_prop],
                agg_pl_to_c_if_pl_exist: [Function: agg_pl_to_c_if_pl_exist],
                vali_and_handle_mem_expr: [Function: vali_and_handle_mem_expr]
              },
              _vali: {
                ERRD: {
                  MemberExpression: {
                    jpl_must_begin_with_colnm: 'jpl_must_begin_with_colnm:c[0-9]+'
                  }
                },
                is_nd_safe: [Function: is_nd_safe]
              },
              creat_cond_for_back: [Function: creat_cond_for_back]
            }

LICENSE

  • ISC
1.0.13

8 months ago

1.0.12

9 months ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago