Skip to content

Commit b681561

Browse files
authored
Add typegen to example (#413)
* feat: mark mux.videoAsset as document type * feat: add typegen to mux example
1 parent 40dac4d commit b681561

File tree

5 files changed

+1860
-34
lines changed

5 files changed

+1860
-34
lines changed

example/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"start": "next start",
99
"lint": "next lint",
1010
"sanity:graphql": "sanity graphql deploy",
11+
"sanity:schema": "sanity schema extract --enforce-required-fields",
12+
"sanity:typegen": "sanity typegen generate",
1113
"reset-mux-credentials": "sanity documents delete secrets.mux"
1214
},
1315
"dependencies": {

example/sanity.types.ts

Lines changed: 357 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,357 @@
1+
/**
2+
* ---------------------------------------------------------------------------------
3+
* This file has been generated by Sanity TypeGen.
4+
* Command: `sanity typegen generate`
5+
*
6+
* Any modifications made directly to this file will be overwritten the next time
7+
* the TypeScript definitions are generated. Please make changes to the Sanity
8+
* schema definitions and/or GROQ queries if you need to update these types.
9+
*
10+
* For more information on how to use Sanity TypeGen, visit the official documentation:
11+
* https://www.sanity.io/docs/sanity-typegen
12+
* ---------------------------------------------------------------------------------
13+
*/
14+
15+
// Source: schema.json
16+
export type SanityImagePaletteSwatch = {
17+
_type: 'sanity.imagePaletteSwatch'
18+
background?: string
19+
foreground?: string
20+
population?: number
21+
title?: string
22+
}
23+
24+
export type SanityImagePalette = {
25+
_type: 'sanity.imagePalette'
26+
darkMuted?: SanityImagePaletteSwatch
27+
lightVibrant?: SanityImagePaletteSwatch
28+
darkVibrant?: SanityImagePaletteSwatch
29+
vibrant?: SanityImagePaletteSwatch
30+
dominant?: SanityImagePaletteSwatch
31+
lightMuted?: SanityImagePaletteSwatch
32+
muted?: SanityImagePaletteSwatch
33+
}
34+
35+
export type SanityImageDimensions = {
36+
_type: 'sanity.imageDimensions'
37+
height?: number
38+
width?: number
39+
aspectRatio?: number
40+
}
41+
42+
export type SanityFileAsset = {
43+
_id: string
44+
_type: 'sanity.fileAsset'
45+
_createdAt: string
46+
_updatedAt: string
47+
_rev: string
48+
originalFilename?: string
49+
label?: string
50+
title?: string
51+
description?: string
52+
altText?: string
53+
sha1hash?: string
54+
extension?: string
55+
mimeType?: string
56+
size?: number
57+
assetId?: string
58+
uploadId?: string
59+
path?: string
60+
url?: string
61+
source?: SanityAssetSourceData
62+
}
63+
64+
export type Geopoint = {
65+
_type: 'geopoint'
66+
lat?: number
67+
lng?: number
68+
alt?: number
69+
}
70+
71+
export type Post = {
72+
_id: string
73+
_type: 'post'
74+
_createdAt: string
75+
_updatedAt: string
76+
_rev: string
77+
title: string
78+
slug: Slug
79+
video: MuxVideo
80+
body?: Array<
81+
| {
82+
children?: Array<{
83+
marks?: Array<string>
84+
text?: string
85+
_type: 'span'
86+
_key: string
87+
}>
88+
style?: 'normal' | 'h1' | 'h2' | 'h3' | 'h4' | 'blockquote'
89+
listItem?: 'bullet'
90+
markDefs?: Array<{
91+
href?: string
92+
_type: 'link'
93+
_key: string
94+
}>
95+
level?: number
96+
_type: 'block'
97+
_key: string
98+
}
99+
| {
100+
asset?: {
101+
_ref: string
102+
_type: 'reference'
103+
_weak?: boolean
104+
[internalGroqTypeReferenceTo]?: 'sanity.imageAsset'
105+
}
106+
hotspot?: SanityImageHotspot
107+
crop?: SanityImageCrop
108+
_type: 'image'
109+
_key: string
110+
}
111+
>
112+
}
113+
114+
export type SanityImageCrop = {
115+
_type: 'sanity.imageCrop'
116+
top?: number
117+
bottom?: number
118+
left?: number
119+
right?: number
120+
}
121+
122+
export type SanityImageHotspot = {
123+
_type: 'sanity.imageHotspot'
124+
x?: number
125+
y?: number
126+
height?: number
127+
width?: number
128+
}
129+
130+
export type SanityImageAsset = {
131+
_id: string
132+
_type: 'sanity.imageAsset'
133+
_createdAt: string
134+
_updatedAt: string
135+
_rev: string
136+
originalFilename?: string
137+
label?: string
138+
title?: string
139+
description?: string
140+
altText?: string
141+
sha1hash?: string
142+
extension?: string
143+
mimeType?: string
144+
size?: number
145+
assetId?: string
146+
uploadId?: string
147+
path?: string
148+
url?: string
149+
metadata?: SanityImageMetadata
150+
source?: SanityAssetSourceData
151+
}
152+
153+
export type SanityAssetSourceData = {
154+
_type: 'sanity.assetSourceData'
155+
name?: string
156+
id?: string
157+
url?: string
158+
}
159+
160+
export type SanityImageMetadata = {
161+
_type: 'sanity.imageMetadata'
162+
location?: Geopoint
163+
dimensions?: SanityImageDimensions
164+
palette?: SanityImagePalette
165+
lqip?: string
166+
blurHash?: string
167+
hasAlpha?: boolean
168+
isOpaque?: boolean
169+
}
170+
171+
export type Slug = {
172+
_type: 'slug'
173+
current: string
174+
source?: string
175+
}
176+
177+
export type MuxVideo = {
178+
_type: 'mux.video'
179+
asset?: {
180+
_ref: string
181+
_type: 'reference'
182+
_weak?: boolean
183+
[internalGroqTypeReferenceTo]?: 'mux.videoAsset'
184+
}
185+
}
186+
187+
export type MuxVideoAsset = {
188+
_id: string
189+
_type: 'mux.videoAsset'
190+
_createdAt: string
191+
_updatedAt: string
192+
_rev: string
193+
status?: string
194+
assetId?: string
195+
playbackId?: string
196+
filename?: string
197+
thumbTime?: number
198+
data?: MuxAssetData
199+
}
200+
201+
export type MuxAssetData = {
202+
_type: 'mux.assetData'
203+
resolution_tier?: string
204+
upload_id?: string
205+
created_at?: string
206+
id?: string
207+
status?: string
208+
max_stored_resolution?: string
209+
passthrough?: string
210+
encoding_tier?: string
211+
master_access?: string
212+
aspect_ratio?: string
213+
duration?: number
214+
max_stored_frame_rate?: number
215+
mp4_support?: string
216+
max_resolution_tier?: string
217+
tracks?: Array<
218+
{
219+
_key: string
220+
} & MuxTrack
221+
>
222+
playback_ids?: Array<
223+
{
224+
_key: string
225+
} & MuxPlaybackId
226+
>
227+
static_renditions?: MuxStaticRenditions
228+
}
229+
230+
export type MuxStaticRenditions = {
231+
_type: 'mux.staticRenditions'
232+
status?: string
233+
files?: Array<
234+
{
235+
_key: string
236+
} & MuxStaticRenditionFile
237+
>
238+
}
239+
240+
export type MuxStaticRenditionFile = {
241+
_type: 'mux.staticRenditionFile'
242+
ext?: string
243+
name?: string
244+
width?: number
245+
bitrate?: number
246+
filesize?: number
247+
height?: number
248+
}
249+
250+
export type MuxPlaybackId = {
251+
_type: 'mux.playbackId'
252+
id?: string
253+
policy?: string
254+
}
255+
256+
export type MuxTrack = {
257+
_type: 'mux.track'
258+
id?: string
259+
type?: string
260+
max_width?: number
261+
max_frame_rate?: number
262+
duration?: number
263+
max_height?: number
264+
}
265+
266+
export type AllSanitySchemaTypes =
267+
| SanityImagePaletteSwatch
268+
| SanityImagePalette
269+
| SanityImageDimensions
270+
| SanityFileAsset
271+
| Geopoint
272+
| Post
273+
| SanityImageCrop
274+
| SanityImageHotspot
275+
| SanityImageAsset
276+
| SanityAssetSourceData
277+
| SanityImageMetadata
278+
| Slug
279+
| MuxVideo
280+
| MuxVideoAsset
281+
| MuxAssetData
282+
| MuxStaticRenditions
283+
| MuxStaticRenditionFile
284+
| MuxPlaybackId
285+
| MuxTrack
286+
export declare const internalGroqTypeReferenceTo: unique symbol
287+
// Source: ./src/app/page.tsx
288+
// Variable: postsQuery
289+
// Query: *[_type == "post" && defined(slug.current)]{_id,title,slug,}
290+
export type PostsQueryResult = Array<{
291+
_id: string
292+
title: string
293+
slug: Slug
294+
}>
295+
296+
// Source: ./src/app/posts/[[...slug]]/page.tsx
297+
// Variable: postQuery
298+
// Query: *[_type == "post" && slug.current == $slug][0]{...,"va": video.asset,"video": video.asset->{ playbackId}}
299+
export type PostQueryResult = {
300+
_id: string
301+
_type: 'post'
302+
_createdAt: string
303+
_updatedAt: string
304+
_rev: string
305+
title: string
306+
slug: Slug
307+
video: {
308+
playbackId: string | null
309+
} | null
310+
body?: Array<
311+
| {
312+
children?: Array<{
313+
marks?: Array<string>
314+
text?: string
315+
_type: 'span'
316+
_key: string
317+
}>
318+
style?: 'blockquote' | 'h1' | 'h2' | 'h3' | 'h4' | 'normal'
319+
listItem?: 'bullet'
320+
markDefs?: Array<{
321+
href?: string
322+
_type: 'link'
323+
_key: string
324+
}>
325+
level?: number
326+
_type: 'block'
327+
_key: string
328+
}
329+
| {
330+
asset?: {
331+
_ref: string
332+
_type: 'reference'
333+
_weak?: boolean
334+
[internalGroqTypeReferenceTo]?: 'sanity.imageAsset'
335+
}
336+
hotspot?: SanityImageHotspot
337+
crop?: SanityImageCrop
338+
_type: 'image'
339+
_key: string
340+
}
341+
>
342+
va: {
343+
_ref: string
344+
_type: 'reference'
345+
_weak?: boolean
346+
[internalGroqTypeReferenceTo]?: 'mux.videoAsset'
347+
} | null
348+
} | null
349+
350+
// Query TypeMap
351+
import '@sanity/client'
352+
declare module '@sanity/client' {
353+
interface SanityQueries {
354+
'*[_type == "post" && defined(slug.current)]{\n_id,\ntitle,\nslug,\n}': PostsQueryResult
355+
'*[_type == "post" && slug.current == $slug][0]{\n...,\n"va": video.asset,\n"video": video.asset->{\n playbackId\n}\n}': PostQueryResult
356+
}
357+
}

0 commit comments

Comments
 (0)