Gathering detailed insights and metrics for @freighter-studio/sanity-typed-queries
Gathering detailed insights and metrics for @freighter-studio/sanity-typed-queries
Gathering detailed insights and metrics for @freighter-studio/sanity-typed-queries
Gathering detailed insights and metrics for @freighter-studio/sanity-typed-queries
A typed, zero-dependency schema generator and query builder for Sanity.
npm install @freighter-studio/sanity-typed-queries
Typescript
Module System
Node Version
NPM Version
TypeScript (98.12%)
JavaScript (1.88%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
270 Commits
1 Watchers
8 Branches
1 Contributors
Updated on Aug 27, 2021
Latest Version
0.8.3
Package Id
@freighter-studio/sanity-typed-queries@0.8.3
Unpacked Size
61.04 kB
Size
15.08 kB
File Count
7
NPM Version
6.14.14
Node Version
14.17.5
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
28
A typed query generator for Sanity
A zero-dependency schema generator and query builder that is fully-typed and works in JavaScript and TypeScript.
"prop": my.prop
)Help and contributions are welcome.
First install sanity-typed-queries
:
1yarn add sanity-typed-queries 2 3# or npm 4 5npm install sanity-typed-queries --save
Now 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.
schema/author.js
:
1import { defineDocument } from 'sanity-typed-queries' 2 3const { document } = defineDocument('author', { 4 name: { 5 type: 'string', 6 validation: Rule => Rule.required(), 7 }, 8 biography: { 9 type: 'text', 10 rows: 4, 11 }, 12 yearOfBirth: { 13 type: 'number', 14 }, 15}) 16 17export default document
This is equivalent to defining the following schema:
1export default { 2 name: 'author', 3 title: 'Author', 4 type: 'document', 5 fields: [ 6 { 7 name: 'name', 8 title: 'Name', 9 type: 'string', 10 validation: Rule => Rule.required(), 11 }, 12 { 13 name: 'biography', 14 title: 'Biography', 15 type: 'text', 16 rows: 4, 17 }, 18 { 19 name: 'yearOfBirth', 20 title: 'Year Of Birth', 21 type: 'number', 22 }, 23 ], 24}
For more documentation, see this GROQ/query builder cheat sheet.
You can also export a query builder from the same file.
1import { defineDocument } from 'sanity-typed-queries' 2 3const { document, builder } = defineDocument('author', { 4 ... 5}) 6 7// Export your query builder for use elsewhere 8export { builder } 9export default document
You can use this builder elsewhere to generate the appropriate types and GROQ queries. For example:
1import { builder as authorBuilder } from './cms/schema/author.js' 2 3const [query, type] = authorBuilder.pick('name').first().use() 4 5// *[_type == 'author'][0].name 6const queryString = query 7 8// string 9type AuthorName = typeof type
If you're using the Sanity client, you might use it like this:
1import sanityClient from '@sanity/client' 2import { author } from './cms/schema/author.js' 3 4const [query, type] = author.pick('name').first().use() 5 6const client = sanityClient(config) 7// Promise<string> 8const result = client.fetch<typeof type>(query)
You can export utility objects or documents for reference within other schemas.
schema/tag.js
:
1import { defineObject } from 'sanity-typed-queries' 2 3const { tag, object } = defineObject('tag', { 4 ... 5}) 6 7export { tag } 8export default object
Then you can pass that when defining documents that reference it.
schema/author.js
:
1import { defineObject } from 'sanity-typed-queries' 2import { tag } from './tag' 3 4const { builder, document } = defineDocument( 5 'author', 6 { 7 tag: { 8 type: 'tag', 9 }, 10 }, 11 [tag] 12) 13 14export default document
Projects I've found helpful are:
This has been developed to suit my needs but additional use cases and contributions are very welcome.
MIT License - Copyright © Daniel Roe
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
no SAST tool detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
60 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More