> For the complete documentation index, see [llms.txt](https://docs.specifyapp.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.specifyapp.com/reference/sdtf-engine/query-api.md).

# Query API

You access each of the query methods over:

```typescript
sdtfEngine.query.[method]
```

### `getTokenState`

Get a tokenState instance from the tokens token tree.

```typescript
function getTokenState(
  path: Array<string>
):
  | { status: "resolved"; tokenState: TokenState<Type> }
  | { status: "unresolvable"; reason: "DOES_NOT_EXIST" };
```

### `getGroupState`

Get a groupState instance from the tokens token tree.

```typescript
function getGroupState(
  path: Array<string>
):
  | { status: "resolved"; groupState: GroupState }
  | { status: "unresolvable"; reason: "DOES_NOT_EXIST" };
```

### `getCollectionState`

Get a collectionState instance from the tokens token tree.

```typescript
function getCollectionState(
  path: Array<string>
):
  | { status: 'resolved'; collectionState: CollectionState }
  | { status: 'unresolvable'; reason: 'DOES_NOT_EXIST' };
```

### `getNearestCollectionState`

Get the collectionState instance enclosing the given path.

```typescript
function getNearestCollectionState(
  path: Array<string>
):     | { status: 'resolved'; collectionState: CollectionState }
  | { status: 'unresolvable'; reason: 'DOES_NOT_EXIST' };
```

### `getAllTokenStates`

Get all tokenState instances from the tokens token tree.

```typescript
function getAllTokenStates(): Array<TokenState>;
```

### `getAllGroupStates`

Get all groupState instances from the tokens token tree.

```typescript
function getAllGroupStates(): Array<GroupState>;
```

### `getAllCollectionStates`

Get all collectionState instances from the tokens token tree.

```typescript
function getAllCollectionStates(): Array<CollectionState>;
```

### `getAllNodeStates`

Get all tokenState, groupState and collectionState instances from the tokens token tree.

```typescript
function getAllNodeStates(): Array<TokenState | GroupState | CollectionState>;
```

### `getTokenChildrenOf`

Get the tokenState instances that are children of the given path.

```typescript
function getTokenChildrenOf(path: Array<string>): Array<TokenState>;
```

### `getGroupChildrenOf`

Get the groupState instances that are children of the given path.

```typescript
function getGroupChildrenOf(path: Array<string>): Array<GroupState>;
```

### `getCollectionChildrenOf`

Get the collectionState instances that are children of the given path.

```typescript
function getCollectionChildrenOf(path: Array<string>): Array<CollectionState>;
```

### `getChildrenOf`

Get the tokenState, groupState and collectionState instances that are children of the given path.

```typescript
function getChildrenOf(path: Array<string>, depth: number): Array<TokenState | GroupState | CollectionState>;
```

### `getParentsOf`

Get the groupState and collectionState instances that are parents of the given path.

```typescript
function getParentsOf(path: Array<string>, depth: number): Array<TokenState | GroupState | CollectionState>;
```

### `getGroupChildren`

Get groupState instances that are direct children of the given path.

```typescript
function getGroupChildren(path: Array<string>): Array<GroupState>;
```

### `getTokenChildren`

Get tokenState instances that are direct children of the given path.

```typescript
function getTokenChildren(path: Array<string>): Array<TokenState>;
```

### `getCollectionChildren`

Get collectionState instances that are direct children of the given path.

```typescript
function getCollectionChildren(path: Array<string>): Array<CollectionState>;
```

### `renderJSONTree`

Get the JSON representation of the tokens token tree.

```typescript
function renderJSONTree(renderOptions: RenderOptions): JSON;
```

### `getAliasReference`

Get the aliasReference instance from given coordinates.

```typescript
function getAliasReference(
  from: AliasReferenceCoordinates
): Result<AliasReference, SDTFError>;
```

### `getAllAliasReferences`

Get all aliasReference instances from the tokens token tree.

```typescript
function getAllAliasReferences(): Array<AliasReference>;
```

### `getAliasReferencesTo`

Get all aliasReference instances that reference the given "to" coordinates.

```typescript
function getAliasReferencesTo(
  to: Partial<AliasReferenceCoordinates>,
  options: AliasReferenceResolvabilityOptions
): Array<AliasReference>;
```

### `getAliasReferencesFrom`

Get all aliasReference instances that reference the given "from" coordinates.

```typescript
function getAliasReferencesFrom(
  from: Partial<AliasReferenceCoordinates>,
  options: AliasReferenceResolvabilityOptions
): Array<AliasReference>;
```

### `getStatefulAliasReference`

Get the statefulAliasReference instance of the given "from" coordinates.

```typescript
function getStatefulAliasReference(
  from: AliasReferenceCoordinates
): Result<StatefulAliasReference, SDTFError>;
```

### `getStatefulAliasReferencesTo`

Get the statefulAliasReference instances that reference the given "to" coordinates.

```typescript
function getStatefulAliasReferencesTo(
  to: Partial<AliasReferenceCoordinates>,
  options: AliasReferenceResolvabilityOptions
): Array<StatefulAliasReference>;
```

### `getStatefulAliasReferencesFrom`

Get the statefulAliasReference instances that reference the given "from" coordinates.

```typescript
function getStatefulAliasReferencesFrom(
  from: Partial<AliasReferenceCoordinates>,
  options: AliasReferenceResolvabilityOptions
): Array<StatefulAliasReference>;
```
