Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Sergii Stotskyi
    @stalniy
    anyway @ucast/mongo2js will not help you to solve the usecase which you explained in sift's issue. To implement it, you need to use @ucast/mongo and @ucast/js and create a custom interpreter
    Jems
    @J3m5
    I'm mentionned all this because backward compatibility with sift was discussed here crcn/sift.js#204.
    So if replacing sift is not the goal anymore then it's not important.
    But I did some search about serializing functions, and it's technically possible.
    Functions can be stringified with the toString method and then parsed and recreated with the new Function constructor.
    Jems
    @J3m5
    const funcStrings = ["val", "return val > 2"];
    const func = new Function(...funcStrings);
    console.log(func(3))
    // true
    Sergii Stotskyi
    @stalniy
    new Function is almost the same as eval and forbidden in some CSP environments, so this cannot be used universally
    for example in chrome apps you can use new Function. You also cannot use new Function when Content-Secure-Policy doesn't allow to eval - https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP
    Also it's not recommended due to security concerns
    Jems
    @J3m5
    Yep, I said it's technically possible, not that it was secure ;)
    Jems
    @J3m5
    About my issue, I'm a bit lost, I'm looking around in the source code but I don't know what function I need to customize / reimplement...
    Can you give me a hint please ?
    Jems
    @J3m5
    I customized the createInterpreter function in order to get the result and the path but now I need to figure out how to accumulate the results and how to stop the operation while returning a value that is not false.
    6 replies
    The farther I get, the harder you make it, haha ^^
    Jems
    @J3m5
    Hi @stalniy , I'm trying to setup the project but when I runthe build command I get
    src/interpreter.ts:1:43 - error TS2307: Cannot find module '@ucast/core' or its corresponding type declarations.
    
    1 import { createInterpreter, ITSELF } from '@ucast/core';
    I've followed the instructions in the CONTRIBUTING.md file
    Jems
    @J3m5
    Problem solved, I had to run pnpm run build -r
    Sergii Stotskyi
    @stalniy
    yes, pnpm do link all packages as local dependencies that's why you need to build everything first.
    Jems
    @J3m5
    Just sent a PR for that.
    It ain't much but it's honest work
    Sergii Stotskyi
    @stalniy
    Thanks @J3m5 !
    Jems
    @J3m5
    You're welcome
    I'm looking after a bug in getValueByPath right now
    It doesn't handle deeply nested array
      it('returns deeply nested property values from array', () => {
        const object = { items: [{ specs: [{ price: 12 }] }, { specs: [{ price: 14 }] }] }
        expect(getObjectField(object, 'items.specs.price')).to.deep.equal([12, 14])
      })
     AssertionError: expected [ undefined, undefined ] to deeply equal [ 12, 14 ]
      + expected - actual
    
      [
      -  [undefined]
      -  [undefined]
      +  12
      +  14
       ]
    Jems
    @J3m5
    And this is because at some point the items will be
    [ [ { price: 12 } ], [ { price: 14 } ] ]
    Sergii Stotskyi
    @stalniy
    Thanks for testing @J3m5! I'll look into this tomorrow and think what I can do with this
    maybe instead of Array.map we can use Array.reduce + concat
    Jems
    @J3m5
    That's what I'm trying but typescript is complaining about types and I don't know it well enough to make the types right
    I got it working!
    Sergii Stotskyi
    @stalniy
    Cool!
    Jems
    @J3m5
    All current and new tests have passed!
    This change make it unnecessary to check if the value is an array or a projected field in the interpreters, and that's a good news because there were other interpreters like all, in or elemMatch that didn't works with nested arrays.
    I'll submit a PR
    Sergii Stotskyi
    @stalniy
    Awesome news! Waiting for this PR!
    Jems
    @J3m5
    Do you prefer one big commit ot mutlples detailed ones ?
    Jems
    @J3m5
    PR submited, I'll squash those commits if you want.
    Sergii Stotskyi
    @stalniy
    That’s fine. PR is not so big. Thanks for asking :) I'll squash commits during merge, so no worries
    Simon Brunel
    @simonbrunel
    Hi! Thanks again @stalniy for your work on CASL and UCAST :) I'm going to give a try to UCAST in a NestJS project, in an attempt to not use nestjs-query. I'm wondering what is the current status of this project, are you still interested in maintaining it? How do you feel it will evolve?
    Simon Brunel
    @simonbrunel

    For context, my use case is abstracting HTTP queries (at the controller level) and later interpret these queries (at the service level) either as a mongodb query or an Azure Search query, which means:

    • a custom parser to translate HTTP queries to condition AST (I can reuse part of the @ucast/mongodb parser instructions + custom)
    • and a mongodb interpreter (I was hoping this to be built-in, but just found stalniy/ucast#2)
    • an Azure Search interpreter (obviously, I need to write it from scratch, though I could contribute it back if it makes sense)

    So it looks like I would need to write quite a lot of logic, thus the initial question :)

    Sergii Stotskyi
    @stalniy

    Hi @simonbrunel

    Thanks :)

    the project is alive and I do maintain it, it is used by casl and one commercial DAL.
    However I don't have much time to push it forward for now. just busy on my current job
    Simon Brunel
    @simonbrunel
    Thanks @stalniy! I will give it a try and, if conclusive, will contribute the mongodb interpreter. Though, I'm not sure I will have time to make it "clean" enough for a good PR. Will see :)
    Simon Brunel
    @simonbrunel
    Currently the mongo parser accepts any non empty arrays for $and/$or/$nor. Does it make sense to also check that these arrays only contain objects (expressions)?
    Sergii Stotskyi
    @stalniy
    I did quite littke checks just to ensure that query is semy-valid because the rest of validation ts does at build time and other checks are done by nested operators. However Im not sure whether parse validates its input as an object
    but if not it should be easy to add this
    Simon Brunel
    @simonbrunel
    Indeed, parse() doesn't validate its input (i.e. parse("foo") -> {"$and":[{"0":{"$eq":"f"}},{"1":{"$eq":"o"}},{"2":{"$eq":"o"}}]})
    which probably won't happen when the user calls parse() directly because he must validate the input beforehand (TS), however if the input contains $and/$or/$nor with none object array, it's not handled by type checking.
    Sergii Stotskyi
    @stalniy
    right, it needs a bit more validation if we want to use it to parse query from user (http). If you can collect all of such cases, I will add them to ObjectParser
    Simon Brunel
    @simonbrunel
    stalniy/ucast#20 for the logical operators
    carlba
    @carlba
    @stalniy: Any plans to update this to a later version of TypeORM this currently uses 0.2.0 while 0.3.0 is available for a long time.
    @stalniy: I tried to make a fork and upgrade but I don't know how to get a proper build that I can test :)
    Sergii Stotskyi
    @stalniy

    hey guys,

    Currently it's not a priority for me. as you may know we have a war in Ukraine. So, from time to time I look into casl issues but for anything extra (or new) doesn't have time.