Specify SDK Cheatsheet

On this page you'll find a lot of common actions you'll probably want to perform when using the SDK

Creating Specify and SDTF clients

You will first create a Specify client, then authenticate, then create a SDTF client by fetching the repository token tree.

import { createSpecifyClient } from "@specifyapp/sdk";

const specifyClient = createSpecifyClient();
await specifyClient.authenticate("<YOUR_PERSONAL_ACCESS_TOKEN_VAR>");

const sdtfClient = 
  await specifyClient.getSDTFClientByRepositoryName("<YOUR_SPECIFY_REPO_NAME>");
  
  console.log('Repository name',sdtfClient.repository.name)

Updating tokens

The following example is only an overview, if you need more details you can have a look here.

import { updaters } from '@specifyapp/sdk'

sdtfClient.update(
  updaters.color({ toFormat: 'hex' }, { where: { token: '^color-' }}),
);

Convert a token to XXX

The following example is only an overview, if you need more details you can have a look here.

Execute a parser

The following example is only an overview, if you need more details you can have a look here.

Retrieving data

Get a specific token

Get all the tokens

Map over all the tokens

Get a specific group

Get all the groups

Map over all the groups

Get a specific collection

Get all collections

Map over all the collections

Filtering data

Keeping a sub-graph from a path

If you only want a specific portion of the graph, you can cherry-pick using the pick function:

Keeping the children of a path

If you only want the children of a specific portion of the graph you can use the pick function this way:

Query a specific set of data

You can use the query method of the SDTFClient to create a copy of the current SDTF with only the tokens that'll match your query:

You can find all the details about querying the data here.

Remove tokens from the SDTF

You can use the remove method to delete tokens based on a query:

Renaming tokens

Rename a node

By not specifying any type, the method will rename any node as long as the path is valid.

Rename a collection

By specifying the type, the method will rename only a collection node.

Rename a group

By specifying the type, the method will rename only a group node.

Rename a token

By specifying the type, the method will rename only a token node.

Last updated

Was this helpful?