# sanity-zodify

> A toolkit to maintain typesafety when working with data from Sanity - intended for use with groq, but not a requirement.

Latest version **0.0.4** (published 2022-09-25) · Apache-3.0 license · 4 weekly downloads

## Install

```sh
npm install sanity-zodify
pnpm add sanity-zodify
yarn add sanity-zodify
bun add sanity-zodify
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2022-09-25 |
| First published | 2022-09-24 |
| Weekly downloads | 4 |
| License | Apache-3.0 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 339.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Ollie Taylor |
| Maintainers | olliejt |
| Keywords | sanity, zod, typescript, schema, validation, codegen, types |

## Links

- npm: https://www.npmjs.com/package/sanity-zodify
- Repository: https://github.com/OllieJT/sanity-zodify
- Homepage: https://github.com/OllieJT/sanity-zodify#readme
- Issues: https://github.com/OllieJT/sanity-zodify/issues
- npm.io page: https://npm.io/package/sanity-zodify

## Alternatives

- [@regle/core](https://npm.io/package/@regle/core.md) — 47.0K weekly downloads
- [typeof-arguments](https://npm.io/package/typeof-arguments.md) — 12.5K weekly downloads
- [@lokalise/projects-engine-contracts](https://npm.io/package/@lokalise/projects-engine-contracts.md) — 978 weekly downloads
- [@osjwnpm/nam-laboriosam-quibusdam](https://npm.io/package/@osjwnpm/nam-laboriosam-quibusdam.md) — 70 weekly downloads
- [@oridune/validator](https://npm.io/package/@oridune/validator.md) — 16 weekly downloads

## Recent versions

- 0.0.4 (latest) — 2022-09-25
- 0.0.3 — 2022-09-25
- 0.0.2 — 2022-09-24
- 0.0.1 — 2022-09-24

## README

# Sanity Zodify

A toolkit to maintain typesafety when working with data from Sanity - intended for use with groq, but not a requirement.

**Now**

This kit includes Zod models to help build your schema faster.

**Next**

I hope to generate models from your Sanity Schema to reduce the time to setup your queries.

## Why not just use Zod types?

You could use Zod types, but you would need to write more boilerplate. This kit aims to codify the proccess of setting up types for your project with convenient transforms of values like date strings into Date objects you can use in your code.

## Installation

```bash
# npm
npm i -D sanity-zodify

# yarn
yarn add -D sanity-zodify

# pnpm
pnpm add -D sanity-zodify

```

## Usage

> Note: This is a work in progress, I'll add better docs later™️

```js
import { z } from 'zod';
import * as S from './src';

const colors = z.union([z.literal('red'), z.literal('green'), z.literal('blue')]);

const Homepage = S.Document.extend({
	title: z.String,
	subtitle: S.String.optional(),
	thumbnail: S.Image,
	colors: z.union([z.literal('red'), z.literal('green'), z.literal('blue')]),
	authors: z.array(S.String),
	publishAt: S.Datetime,
});

// raw_data is NOT type safe.
const awesome_data = Homepage.parse(raw_data);

// awesome_data IS type safe.
console.log(awesome_data.title);
```

---
_Source: https://npm.io/package/sanity-zodify · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
