How to use the expression-eval.compileAsync function in expression-eval

To help you get started, we’ve selected a few expression-eval examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github casbin / node-casbin / src / coreEnforcer.ts View on Github external
const expString = this.model.model.get('m')?.get('m')?.value;
    if (!expString) {
      throw new Error('Unable to find matchers in model');
    }

    const effect = this.model.model.get('e')?.get('e')?.value;
    if (!effect) {
      throw new Error('Unable to find policy_effect in model');
    }

    const matcherKey = `${asyncCompile ? 'ASYNC[' : 'SYNC['}${expString}]`;

    let expression = this.matcherMap.get(matcherKey);
    if (!expression) {
      expression = asyncCompile ? compileAsync(expString) : compile(expString);
      this.matcherMap.set(matcherKey, expression);
    }

    let policyEffects: Effect[];
    let matcherResults: number[];

    const p = this.model.model.get('p')?.get('p');
    const policyLen = p?.policy?.length;

    const rTokens = this.model.model.get('r')?.get('r')?.tokens;
    const rTokensLen = rTokens?.length;

    if (policyLen && policyLen !== 0) {
      policyEffects = new Array(policyLen);
      matcherResults = new Array(policyLen);

expression-eval

JavaScript expression parsing and evaluation.

MIT
Latest version published 11 months ago

Package Health Score

56 / 100
Full package analysis