Skip to content

Commit

Permalink
feat(schema): mark required image/file asset fields, add isAnimated
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Sep 26, 2024
1 parent 7b9b556 commit 92fbcd7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
11 changes: 11 additions & 0 deletions packages/sanity/src/core/schema/types/fileAsset.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {type SanityDocument} from '@sanity/client'
import {type Rule} from '@sanity/types'

export default {
name: 'sanity.fileAsset',
Expand Down Expand Up @@ -44,35 +45,43 @@ export default {
title: 'SHA1 hash',
readOnly: true,
fieldset: 'system',
validation: (Rule: Rule): Rule => Rule.required(),
},
{
name: 'extension',
type: 'string',
title: 'File extension',
readOnly: true,
fieldset: 'system',
validation: (Rule: Rule): Rule => Rule.required(),
},
{
name: 'mimeType',
type: 'string',
title: 'Mime type',
readOnly: true,
fieldset: 'system',
validation: (Rule: Rule): Rule => Rule.required(),
},
{
name: 'size',
type: 'number',
title: 'File size in bytes',
readOnly: true,
fieldset: 'system',
validation: (Rule: Rule): Rule => Rule.required(),
},
{
name: 'assetId',
type: 'string',
title: 'Asset ID',
readOnly: true,
fieldset: 'system',
validation: (Rule: Rule): Rule => Rule.required(),
},
/**
* Added in 2020, so not "required" because of backwards compatibility
*/
{
name: 'uploadId',
type: 'string',
Expand All @@ -86,13 +95,15 @@ export default {
title: 'Path',
readOnly: true,
fieldset: 'system',
validation: (Rule: Rule): Rule => Rule.required(),
},
{
name: 'url',
type: 'string',
title: 'Url',
readOnly: true,
fieldset: 'system',
validation: (Rule: Rule): Rule => Rule.required(),
},
{
name: 'source',
Expand Down
13 changes: 12 additions & 1 deletion packages/sanity/src/core/schema/types/imageAsset.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {type SanityDocument} from '@sanity/types'
import {type Rule, type SanityDocument} from '@sanity/types'

export default {
name: 'sanity.imageAsset',
Expand Down Expand Up @@ -44,35 +44,43 @@ export default {
title: 'SHA1 hash',
readOnly: true,
fieldset: 'system',
validation: (Rule: Rule): Rule => Rule.required(),
},
{
name: 'extension',
type: 'string',
readOnly: true,
title: 'File extension',
fieldset: 'system',
validation: (Rule: Rule): Rule => Rule.required(),
},
{
name: 'mimeType',
type: 'string',
readOnly: true,
title: 'Mime type',
fieldset: 'system',
validation: (Rule: Rule): Rule => Rule.required(),
},
{
name: 'size',
type: 'number',
title: 'File size in bytes',
readOnly: true,
fieldset: 'system',
validation: (Rule: Rule): Rule => Rule.required(),
},
{
name: 'assetId',
type: 'string',
title: 'Asset ID',
readOnly: true,
fieldset: 'system',
validation: (Rule: Rule): Rule => Rule.required(),
},
/**
* Added in 2020, so not "required" because of backwards compatibility
*/
{
name: 'uploadId',
type: 'string',
Expand All @@ -86,18 +94,21 @@ export default {
title: 'Path',
readOnly: true,
fieldset: 'system',
validation: (Rule: Rule): Rule => Rule.required(),
},
{
name: 'url',
type: 'string',
title: 'Url',
readOnly: true,
fieldset: 'system',
validation: (Rule: Rule): Rule => Rule.required(),
},
{
name: 'metadata',
type: 'sanity.imageMetadata',
title: 'Metadata',
validation: (Rule: Rule): Rule => Rule.required(),
},
{
name: 'source',
Expand Down
14 changes: 14 additions & 0 deletions packages/sanity/src/core/schema/types/imageMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {type Rule} from '@sanity/types'

export default {
name: 'sanity.imageMetadata',
title: 'Image metadata',
Expand All @@ -21,6 +23,7 @@ export default {
title: 'Dimensions',
type: 'sanity.imageDimensions',
fieldset: 'extra',
validation: (Rule: Rule): Rule => Rule.required(),
},
{
name: 'palette',
Expand All @@ -45,12 +48,23 @@ export default {
title: 'Has alpha channel',
type: 'boolean',
readOnly: true,
validation: (Rule: Rule): Rule => Rule.required(),
},
{
name: 'isOpaque',
title: 'Is opaque',
type: 'boolean',
readOnly: true,
validation: (Rule: Rule): Rule => Rule.required(),
},
/**
* Added in 2024, so not "required" because of backwards compatibility
*/
{
name: 'isAnimated',
title: 'Is animated',
type: 'boolean',
readOnly: true,
},
],
}

0 comments on commit 92fbcd7

Please sign in to comment.