# @datawheel/logiclayer-client

Types and utility classes to communicate with a [LogicLayer](https://github.com/Datawheel/logiclayer) server.

<a href="https://www.datawheel.us"><img src="https://badgen.net/static/_/Datawheel/yellow?icon=https://raw.githubusercontent.com/Datawheel/datawheel/1a83069a6d988a04dbfec7add52bf1cf0ff9f88b/img/logo/icon.svg&label"/></a>
<a href="https://www.npmjs.com/package/@datawheel/logiclayer-client"><img alt="npm package" src="https://img.shields.io/npm/v/@datawheel/logiclayer-client"/></a>
<a href="https://github.com/Datawheel/logiclayer-client/blob/main/LICENSE"><img alt="license" src="https://badgen.net/github/license/datawheel/logiclayer-client"/></a>

## Installation

```sh
npm i @datawheel/logiclayer-client
```

## Usage

The package provides client classes for the [Tesseract](https://github.com/Datawheel/logiclayer#tesseract) and [Complexity](https://github.com/Datawheel/logiclayer#complexity) modules, along with enums, types, and serialization utilities.

```ts
import {TesseractModuleClient} from "@datawheel/logiclayer-client";

const tesseract = new TesseractModuleClient(
  "https://api-v2.oec.world/tesseract",
  {headers: {Authorization: `Bearer ${token}`}},
);

const schema = await tesseract.fetchSchema({locale: "en"});

const data = await tesseract.fetchData(
  {cube: "trade_i_baci_a_92", drilldowns: "Year", measures: "Trade Value"},
  "csv",
);
const text = await data.text();
```

Every `fetch*` method accepts an optional [`RequestInit`](https://developer.mozilla.org/en-US/docs/Web/API/RequestInit) as its last argument. The per-request `init` is **merged** with the client-level `requestConfig`—headers are combined at the individual header level, so per-request headers add to (or override) the defaults rather than replacing them entirely.

```ts
const status = await tesseract.fetchStatus({signal: controller.signal});
```

### Exports

| Category | Exports |
|----------|---------|
| **Clients** | `TesseractModuleClient`, `ComplexityModuleClient` |
| **Enums** | `Aggregator`, `DataType`, `DimensionType`, `Format`, `GeoScale`, `LogicOperator`, `MembershipOperator`, `NullityOperator`, `Order`, `RelationalOperator`, `Restriction`, `TimeScale` |
| **Utilities** | `matchEnumProperty`, `mergeHeaders`, `mergeRequestInit` |
| **Types** | `TesseractCube`, `TesseractDataRequest`, `TesseractCubeRequest`, `TesseractSchemaRequest`, `TesseractMembersRequest`, `TesseractDataResponse`, `TesseractSchemaResponse`, `TesseractStatusResponse`, `TesseractMembersResponse`, `TesseractErrorResponse`, `RcaRequest`, `ComplexityIndexRequest`, `GiniRequest`, `EmissionsRequest`, `OpportunityRequest`, `RelatednessRequest`, `RelativeRelatednessRequest`, `ComplexityStatusResponse`, and dimension/annotation types |
