MistQL Documentation

website·Indexed 31 days ago

https://www.mistql.com/

A miniature language for performing computations on JSON-like structures. MistQL provides implementations for JavaScript (via npm) and Python (via pip, supporting Python 3.8+), featuring contextualized expressions, core datatypes corresponding to JSON, and support for custom functions in the JS implementation.

Tokens
64.8K
Snippets
673
Records
764
Agent score
49%

What's inside MistQL

  1. Overview of MistQL

    MistQL is a domain-specific expression language designed for performing computations on JSON-like objects. It is built for high readability and is specifically optimized for size-restricted frontends (the NPM implementation is 5.5kB gzipped with 0 dependencies). It is available in both JavaScript and Python, allowing developers to share logic between the client and server.
  2. Understand and use Contextualized Expressions in MistQL

    Contextualized Expressions in MistQL function similarly to lambdas in other languages. Every expression is executed within a specific context, represented by the @ variable. MistQL uses a context stack; functions that modify the context push a new context onto this stack. When a function executes an expression multiple times (e.g., iterating over an array), it pushes the current element to the @ variable for each execution. In documentation, functions that push to the context stack are denoted with the signature @: SomeContextType -> SomeReturnType.
  3. Understand the MistQL Initial Context and @ symbol

    In MistQL, the @ symbol refers to the current context. Initially, this context is set to the data passed into the engine, making @ an identity query that returns the input data exactly as it was provided.
    Query: @
    Data: ["arbitrary", "data"]
    Result: ["arbitrary", "data"]
  4. Understand the MistQL Initial Context and @ symbol

    In MistQL, the @ symbol refers to the current context. Initially, this context is set to the data passed into MistQL, making @ an identity query that returns the input data structure exactly as it was provided.
    Query: @
    Data: ["arbitrary", "data"]
    Result: ["arbitrary", "data"]
  5. Understand the MistQL Initial Context and @ symbol

    In MistQL, the @ symbol refers to the current context. Initially, this context is set to the _data passed into the engine. Therefore, a query consisting only of @ acts as an identity query, returning the input data exactly as it was provided.
    Query: @
    Data: ["arbitrary", "data"]
    Result: ["arbitrary", "data"]
  6. Understand and use Contextualized Expressions in MistQL

    Contextualized Expressions in MistQL act as lambdas. Every expression is executed within a specific context, represented by the @ variable. MistQL uses a context stack; functions that modify the context push new values onto this stack. When a function (like filter or map) iterates over a collection, it pushes the current element to the context stack, making the element's properties available as variables in the expression scope.
  7. Understand the MistQL Initial Context and @ symbol

    The @ symbol refers to the current context. Initially, this context is set to the data passed into MistQL, making @ an identity query that returns the input data exactly as provided.
    Query: @
    Data: ["arbitrary", "data"]
    Result: ["arbitrary", "data"]
  8. Understand the MistQL Initial Context and @ symbol

    In MistQL, the @ symbol refers to the current context. Initially, this context is set to the data passed into the engine. The simplest query @ acts as an identity query, returning the input data exactly as it was provided.
    Query: @
    Data: ["arbitrary", "data"]
    Result: ["arbitrary", "data"]
  9. Understand and use Contextualized Expressions in MistQL

    Contextualized Expressions in MistQL act as lambdas. Every expression is executed within a specific context, and the @ variable refers to the current context at the time of execution. MistQL manages contexts using a stack; functions that modify the context push a new context onto this stack.

    When a function (like filter or map) executes an expression multiple times over a collection, it pushes the current element to the context stack as @. Any properties of the object assigned to @ are automatically populated into the scope, allowing you to reference fields directly by name without explicitly prefixing them with @.

    -- Filter an array for even numbers
    filter (@ % 2 == 0) [1, 2, 3, 4, 5, 6, 7] 
    -- Result: [2, 4, 6]
    
    -- Map over objects, incrementing the 'foo' property of each
    map (foo + 1) [{"foo": 10}, {"foo": 20}] 
    -- Result: [11, 21]
    
    -- Pipeline: filter events by type and map to the email field
    events | filter type == "page_shown" | map email
  10. Install MistQL for JavaScript or Python

    MistQL is a miniature language for performing computations on JSON-like structures. The JavaScript implementation is dependency-free and optimized for client-side browser applications (5.3kB gzipped).
    # For JavaScript
    npm install --save mistql
    
    # For Python
    pip install mistql
  11. Install and use MistQL in JavaScript

    The MistQL JavaScript implementation allows you to execute MistQL queries against JS data structures. Install the package via npm and use the query function to process data.
    npm install mistql
    import {query} from 'mistql';
    
    const len = query('count @', [1, 2, 3]);
    console.log(len);