{"id":15632536,"url":"https://github.com/danielroe/sanity-typed-queries","last_synced_at":"2025-05-16T06:05:07.621Z","repository":{"id":37300844,"uuid":"251618828","full_name":"danielroe/sanity-typed-queries","owner":"danielroe","description":"A typed, zero-dependency schema generator and query builder for Sanity.","archived":false,"fork":false,"pushed_at":"2025-05-13T15:49:26.000Z","size":7503,"stargazers_count":176,"open_issues_count":9,"forks_count":6,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-13T16:49:41.875Z","etag":null,"topics":["groq","hacktoberfest","library","query-builder","sanity","schema-builder","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danielroe.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["danielroe"]}},"created_at":"2020-03-31T13:57:50.000Z","updated_at":"2025-05-12T19:37:16.000Z","dependencies_parsed_at":"2024-04-09T18:33:51.594Z","dependency_job_id":"b2567339-238a-4d99-ac62-318efc23ec62","html_url":"https://github.com/danielroe/sanity-typed-queries","commit_stats":{"total_commits":728,"total_committers":8,"mean_commits":91.0,"dds":"0.28708791208791207","last_synced_commit":"265d461066c5e8790b18e4e8df5534927e3003a7"},"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielroe%2Fsanity-typed-queries","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielroe%2Fsanity-typed-queries/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielroe%2Fsanity-typed-queries/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielroe%2Fsanity-typed-queries/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danielroe","download_url":"https://codeload.github.com/danielroe/sanity-typed-queries/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254000826,"owners_count":21997441,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["groq","hacktoberfest","library","query-builder","sanity","schema-builder","typescript"],"created_at":"2024-10-03T10:44:32.963Z","updated_at":"2025-05-16T06:05:07.604Z","avatar_url":"https://github.com/danielroe.png","language":"TypeScript","funding_links":["https://github.com/sponsors/danielroe"],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e🔤 sanity-typed-queries\u003c/h1\u003e\n\u003cp align=\"center\"\u003eA typed query generator for Sanity\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://npmjs.com/package/sanity-typed-queries\"\u003e\n    \u003cimg alt=\"\" src=\"https://img.shields.io/npm/v/sanity-typed-queries/latest.svg?style=flat-square\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://bundlephobia.com/result?p=sanity-typed-queries\"\u003e\n    \u003cimg alt=\"\" src=\"https://img.shields.io/bundlephobia/minzip/sanity-typed-queries?style=flat-square\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://npmjs.com/package/sanity-typed-queries\"\u003e\n    \u003cimg alt=\"\" src=\"https://img.shields.io/npm/dt/sanity-typed-queries.svg?style=flat-square\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://lgtm.com/projects/g/danielroe/sanity-typed-queries\"\u003e\n    \u003cimg alt=\"\" src=\"https://img.shields.io/lgtm/alerts/github/danielroe/sanity-typed-queries?style=flat-square\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://lgtm.com/projects/g/danielroe/sanity-typed-queries\"\u003e\n    \u003cimg alt=\"\" src=\"https://img.shields.io/lgtm/grade/javascript/github/danielroe/sanity-typed-queries?style=flat-square\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://david-dm.org/danielroe/sanity-typed-queries\"\u003e\n    \u003cimg alt=\"\" src=\"https://img.shields.io/david/danielroe/sanity-typed-queries.svg?style=flat-square\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://codecov.io/gh/danielroe/sanity-typed-queries\"\u003e\n    \u003cimg alt=\"\" src=\"https://img.shields.io/codecov/c/github/danielroe/sanity-typed-queries.svg?style=flat-square\"\u003e\n\u003c/a\u003e\n\u003c/p\u003e\n\n\u003e A zero-dependency schema generator and query builder that is fully-typed and works in JavaScript and TypeScript.\n\n## Features\n\n- 📚 **Documentation:** Sanity documentation appears as you type.\n- 💪 **TypeScript**: Written in TypeScript.\n\n## Progress\n\n- [x] Fully typed schema builder\n- [x] Query builder (working with string, boolean, number), ordering, projections\n- [x] Inferred type of arrays\n- [x] Support for object types with subfields\n- [x] Custom mappings (`\"prop\": my.prop`)\n- [x] Resolving image and file types\n- [x] Resolving custom object/document types\n- [ ] Distinguish object/document types within valid field types\n- [ ] Additional query filters\n- [ ] Querying multiple types of document\n\nHelp and contributions are welcome.\n\n## Quick Start\n\nFirst install `sanity-typed-queries`:\n\n```bash\nyarn add sanity-typed-queries\n\n# or npm\n\nnpm install sanity-typed-queries --save\n```\n\n### Schema definition\n\nNow you will need to generate your Sanity schema documents using the schema builder. You will get documentation as you type, and enforced compliance with Sanity's schema builder, such as being able to see validation rules applicable to the type of field you are creating, and so on.\n\n`schema/author.js`:\n\n```ts\nimport { defineDocument } from 'sanity-typed-queries'\n\nconst { document } = defineDocument('author', {\n  name: {\n    type: 'string',\n    validation: Rule =\u003e Rule.required(),\n  },\n  biography: {\n    type: 'text',\n    rows: 4,\n  },\n  yearOfBirth: {\n    type: 'number',\n  },\n})\n\nexport default document\n```\n\nThis is equivalent to defining the following schema:\n\n```ts\nexport default {\n  name: 'author',\n  title: 'Author',\n  type: 'document',\n  fields: [\n    {\n      name: 'name',\n      title: 'Name',\n      type: 'string',\n      validation: Rule =\u003e Rule.required(),\n    },\n    {\n      name: 'biography',\n      title: 'Biography',\n      type: 'text',\n      rows: 4,\n    },\n    {\n      name: 'yearOfBirth',\n      title: 'Year Of Birth',\n      type: 'number',\n    },\n  ],\n}\n```\n\n### Query builder\n\n\u003e For more documentation, see [this GROQ/query builder cheat sheet](https://github.com/danielroe/sanity-typed-queries/blob/master/docs/cheat-sheet.md).\n\nYou can also export a query builder from the same file.\n\n```ts\nimport { defineDocument } from 'sanity-typed-queries'\n\nconst { document, builder } = defineDocument('author', {\n  // ...\n})\n\n// Export your query builder for use elsewhere\nexport { builder }\nexport default document\n```\n\nYou can use this builder elsewhere to generate the appropriate types and GROQ queries. For example:\n\n```ts\nimport { builder as authorBuilder } from './cms/schema/author.js'\n\nconst [query, type] = authorBuilder.pick('name').first().use()\n\n// *[_type == 'author'][0].name\nconst queryString = query\n\n// string\ntype AuthorName = typeof type\n```\n\nIf you're using the Sanity client, you might use it like this:\n\n```ts\nimport sanityClient from '@sanity/client'\nimport { author } from './cms/schema/author.js'\n\nconst [query, type] = author.pick('name').first().use()\n\nconst client = sanityClient(config)\n// Promise\u003cstring\u003e\nconst result = client.fetch\u003ctypeof type\u003e(query)\n```\n\n### Custom types\n\nYou can export utility objects or documents for reference within other schemas.\n\n`schema/tag.js`:\n\n```ts\nimport { defineObject } from 'sanity-typed-queries'\n\nconst { tag, object } = defineObject('tag', {\n  // ...\n})\n\nexport { tag }\nexport default object\n```\n\nThen you can pass that when defining documents that reference it.\n\n`schema/author.js`:\n\n```ts\nimport { defineObject } from 'sanity-typed-queries'\nimport { tag } from './tag'\n\nconst { builder, document } = defineDocument(\n  'author',\n  {\n    tag: {\n      type: 'tag',\n    },\n  },\n  [tag]\n)\n\nexport default document\n```\n\n## Inspirations\n\nProjects I've found helpful are:\n\n- [`sanity-query-helper`](https://github.com/staccx/sanity-query-helper)\n\n## Contributors\n\nThis has been developed to suit my needs but additional use cases and contributions are very welcome.\n\n## License\n\n[MIT License](./LICENSE) - Copyright \u0026copy; Daniel Roe\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielroe%2Fsanity-typed-queries","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanielroe%2Fsanity-typed-queries","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielroe%2Fsanity-typed-queries/lists"}