npm package: @jabberwocky-labs/ts-db
Description: <h1 align="center">Jabberwocky Labs - TypeScript</h1> <p align="center">   <a href="https://www.npmjs.com/package/@jabberwocky-labs/ts-db" target="_blank" >         <img src="https://img.shields.io/npm/v/@jabberwocky-labs/ts-db.svg?color=white&style=for-t
Latest version: 0.0.1

<h1 align="center">Jabberwocky Labs - TypeScript</h1>
<p align="center">
  <a href="https://www.npmjs.com/package/@jabberwocky-labs/ts-db" target="_blank" >
        <img src="https://img.shields.io/npm/v/@jabberwocky-labs/ts-db.svg?color=white&style=for-the-badge" />
  </a>
  <a href="https://github.com/jabberwocky-db/eslint-config/blob/master/LICENSE" target="_blank" >
    <img alt="License: MIT" src="https://img.shields.io/badge/license-MIT-blue.svg?style=for-the-badge"/>
  </a>
  <a href="https://libraries.io/npm/@jabberwocky-labs%2Fts-db" target="_blank" >
    <img alt="License: MIT" src="https://img.shields.io/librariesio/release/npm/@jabberwocky-labs/ts-db?style=for-the-badge" />
  </a>
  <a href="https://www.npmjs.com/package/@jabberwocky-labs/ts-db" target="_blank" >
    <img alt="downloads" src="https://img.shields.io/npm/dm/@jabberwocky-labs/ts-db.svg?color=purple&style=for-the-badge"/>
  </a>
  <a href="https://bundlephobia.com/package/@jabberwocky-labs/ts-db" target="_blank" >
    <img src="https://img.shields.io/bundlephobia/min/@jabberwocky-labs/ts-db?style=for-the-badge&color=teal"/>
  </a>
</p>

> The home of Jabberwocky Labs' TypeScript community code. For now, this codebase will focus on our database product, however, this will be expanded to support additional Jabberwocky Labs products as well as non-product, open-sourced TypeScript projects. 

## ⬇️ Install

Run the following command at the root of your project:

**Yarn**

```sh
yarn add @jabberwocky-labs/ts-db
```

**NPM**

```sh
npm install @jabberwocky-labs/ts-db
```

## 📘  Terminology

### Space
A space can be thought of as an independent timeline of your databases records.
Spaces reference shared locations for the used primitives allowing for non-duplicated values across 
spaces. The value `My awesome string` will only exist once across your spaces. However, in your usage
of spaces, they operate as isolated environments.  In the future, we will be adding extended functionality to allow 
for spaces to branch from, merge together, and stream to one another. 

Example:

You may have both a `production` space and a `development` space to allow you to work locally 
without affecting production data. With this setup, you may periodically clone the `production` space
over the `development`  space so that you can safely test/build with your production data. Because the values of your space
need not be cloned, just the architecture of it, this clone will happen in microseconds.

### Class

A class is a means of classifying your data. Some example classes may be `firstName`, `emailAddress`, or `phoneNumber`.

### Value
A value is a primitive type:
- null
- boolean
- string
- number
- float

### Item

An item is the unique combination of a `class` and `value` within a `space`. An `item` can have sub items 
which you interact with like you would record properties in other databases. The key difference here 
is that an `item` only exists once and using it as a property creates a relationship between data.

## 🔧 Setup

All requests are run through the `JabberwockyDBClient`

```typescript
import { JabberwockyDBClient } from '@jabberwocky-labs/ts-db';

const client = new JabberwockyDBClient();
```

You can authenticate by directly passing your token:

```typescript
const client = new JabberwockyDBClient({ token: 'xxxxxxx' });
```

However, the recommended method is to set the `JW_TOKEN` environment variable using
a tool like [dotenv](https://www.npmjs.com/package/dotenv) or via node directly:
```shell
JW_TOKEN=xxxxxxx node index.js
```

## 🚀 Usage
### Account
#### Initiate Account Client
```typescript
const account = client.account(123456);
```
### Space
#### Initiate Space Client
```typescript
const productionSpace = account.space('production');
```
#### Check Existence
```typescript
const doesExist = await productionSpace.exists();
```
#### Ensure Not Existing
```typescript
await productionSpace.ensureMissing();
```
### Class
#### Initiate Class Client
```typescript
const emailClass = productionSpace.class('email');
```
#### Check Existence
```typescript
const doesExist = await emailClass.exists();
```
#### Ensure Not Existing
```typescript
await emailClass.ensureMissing();
```
### Item
#### Initiate Item Client
```typescript
const zachsEmails = emailClass.item('zach@jabberwockylabs.com');
```
#### Check Existence
```typescript
const doesExist = await zachsEmails.exists();
```
#### Ensure Not Existing
```typescript
await zachsEmails.ensureMissing();
```