Specify Docs
Specify ↗︎Changelog ↗︎Guide ↗︎
V2
V2
  • Getting started
    • Introduction
    • What is Specify?
    • Pulling your first tokens with the CLI
    • Glossary
  • Collect
    • What is a Source?
    • Available sources
      • Figma Variables & Styles
      • Tokens Studio
  • Distribute
    • What is a Destination?
    • Available destinations
      • GitHub
      • Specify CLI
      • Specify SDK
      • HTTP API
  • Concepts
    • Overview
    • Parsers Engine
    • SDTF Client
      • SDTF Engine
    • Specify Design Token Format
  • Guides
    • Configuration file 101
    • Specify CLI usage 101
      • Getting started
      • Authentication
      • Generate Files
    • Specify SDK usage 101
      • Getting started
      • Retrieving and working with the tokens
      • Updating tokens
      • Converting a token to XXX
      • Executing generation parsers
    • Specify SDK Cheatsheet
    • Manage font files
    • Querying a SDTF graph
  • Reference
    • Parsers Engine
    • Parsers
      • change-case
      • convert-color
      • convert-dimension
      • make-line-height-relative
      • filter
      • register-view
      • select-modes
      • prefix-by
      • suffix-by
      • replace-string
      • to-css-custom-properties
      • to-css-text-style
      • to-css-font-import
      • to-flutter
      • to-javascript
      • to-json
      • to-json-list
      • to-kotlin
      • to-react-native
      • to-scss-mixin-text-style
      • to-scss-map
      • to-sdtf
      • to-style-dictionary
      • to-swift
      • to-tailwind
      • to-typescript
      • svgo
      • svg-to-jsx
      • svg-to-tsx
      • to-svg-file
      • to-bitmap-file
      • to-file
    • Specify SDK
      • SpecifyClient
      • SDTFClient
      • Converters
        • CSS
      • ParsersEngineResults
    • SDTF Engine
      • Query API
      • Mutation API
      • SDTF Query Language
      • SDTF QueryResult
      • TokenState
        • Stateful Value
    • HTTP API
      • POST /parsers-engine-rpc
    • Specify CLI
  • Resources
    • Parser Rules templates
      • CSS Custom Properties
      • Tailwind
      • React Native
      • Flutter
      • SDTF
      • JSON
    • Specify CLI VS Specify SDK
    • Playground
    • Best practices
  • Useful links
    • Discord
    • YouTube
    • Twitter
    • Help Center
    • Canny
Powered by GitBook
On this page
  • Examples
  • Query Language Structure
  • Where Token
  • Where Group
  • Where Collection
  • Recursion
  • Query Result

Was this helpful?

Export as PDF
  1. Reference
  2. SDTF Engine

SDTF Query Language

SDTF Query Langage format API reference

PreviousMutation APINextSDTF QueryResult

Last updated 1 year ago

Was this helpful?

The SDTF Query Language is a JSON structure describing several match criteria used to select nodes - tokens, groups and collections - within the token tree.

Examples

Get a collection exactly named "Colors" and all its children of kind: "token"

{
  "where": {
    "collection": "^Colors$",
    "select": {
      "collection": true,
      "children": {
        "tokens": true
      }
    }
  }
}

Select all tokens of type: "color". See all available types in .

{
  "where": {
    "token": ".*",
    "withTypes": { "include": ["color"] },
    "select": true
  }
}

Select the tokens of type: "color", only within a group named "components" nested in a collection named "Colors".

{
  "where": {
    "collection": "^Colors$",
    "andWhere": {
      "group": "^components$",
      "andWhere": {
        "token": ".*",
        "withTypes": { "include": ["color"] },
        "select": {
          "token": true,
          "parents": true
        }
      }
    }
  }
}

Notice it also selects the containing "components" group and "Colors" collection thanks to select.parents: true.

Query Language Structure

Every SDTFQuery holds a single a where property being:

  • an object: to select one branch of the graph

  • an array of objects: to select many branches of the graph - equivalent to an OR statement.

type SDTFQuery = { where: Where | Array<Where> }

The where property splits in 3 kinds: token, group, collection - offering a dedicated set of options to match against the given kind.

Where Token

type WhereToken = {
  token:
    | string // regex compatible
    | {
      name?: string; // regex compatible
      description?: string; // regex compatible
    };
  select:
    | true
    | {
      token?: boolean;
      parents?:
        | true
        | {
          groups?: true;
          collections?: true;
        };
    };
  withTypes?: {
    include?: Array<TokenTypeName>;
    exclude?: Array<TokenTypeName>;
  };
  withModes?: {
    include?: Array<string>;
    exclude?: Array<string>;
  }
};

Where Group

type WhereGroup = {
  group:
    | string // regex compatible
    | {
      name?: string; // regex compatible
      description?: string; // regex compatible
    };
  select:
    | true
    | {
    group?: boolean;
    parents?:
      | true
      | {
        groups?: true;
        collections?: true;
      };
    children:
      | true
      | {
        groups?: true;
        collections?: true;
        tokens?: true;
      };
  };
};

Where Collection

type WhereCollection = {
  collection:
    | string // regex compatible
    | {
      name?: string; // regex compatible
      description?: string; // regex compatible
    };
  select:
    | true
    | {
      collection?: boolean;
      parents?:
        | true
        | {
          groups?: true;
        };
      children:
        | true
        | {
          groups?: true;
          tokens?: true;
        };
    };
  withModes?: {
    include?: Array<string>;
    exclude?: Array<string>;
  }
};

Recursion

The where property can alternatively holds a andWhere property instead of the select property.

Doing so, the andWhere property can receive any where operator described earlier.

Note: since Collections cannot be nested, we cannot nest a andWhere Collection operator into another where or andWhere Collection

{
  "where": {
    "collection": "^colors$",
    "andWhere": {
      "group": "^base",
      "andWhere": {
        "token": ".*",
        "withTypes": { "include": ["color"] },
        "select": {
          "token": true,
          "parents": true
        }
      }
    }
  }
}

Query Result

Once executed by the engine, the query returns a that helps to work with the matched tree nodes.

QueryResult
Supported types