Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ucast/core

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ucast/core

git@github.com:stalniy/ucast.git

  • 1.10.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
399K
decreased by-16.44%
Maintainers
1
Weekly downloads
 
Created
Source

Universal Conditions AST

@ucast/core NPM version UCAST join the chat

This package contains classes and functions that helps to create parsers, conditions AST, interpreters and translators.

Installation

npm i @ucast/core
# or
yarn add @ucast/core
# or
pnpm add @ucast/core

Getting Started

Parser

Parser is a function that translates conditions from any language into conditions AST. For example, MongoQueryParser parses MongoQuery into AST which then can be interpreted by JavaScriptInterpreter that returns a boolean value based on passed in object.

Conditions AST

Abstract Syntax Tree of any condition. What is condition? x > 4 is a condition, x === 4 is a condition as well, { x: { $eq: 4 } } is a MongoQuery condition.

There are few types of AST nodes that allow us to represent any condition:

  • FieldCondition.
    Depends on a field, operator and its value. For example, in condition x > 4, x is a field, 4 is a value and > is operator
  • DocumentCondition.
    Any condition that test a document (or a row) as whole (e.g., in MongoDB Query, it's $where operator and in SQL it's EXISTS).
  • CompoundCondition.
    Combines other conditions using logical operations like "and", "or", "not".

Interpreter

An interpreter is a function that interprets conditions AST in a specific way. For example, it can:

  • interpret conditions in JavaScript runtime to return a boolean result
  • or it can convert conditions into SQL WHERE statement
  • or MongoDB query,
  • or HTTP/REST query
  • or GraphQL input
  • or anything else you can imagine

Translator

Combines Parser and Interpreter and returns a factory function:

const parse = (query) => /* to conditions AST */
const interpreter = createInterpreter({ /* condition interpreters */ });
const translate = (query, ...args) => interpreter.bind(null, parse(query));

Want to help?

Want to file a bug, contribute some code, or improve documentation? Excellent! Read up on guidelines for contributing

License

Apache License, Version 2.0

Keywords

FAQs

Package last updated on 15 Feb 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc