Skip to content

Commit

Permalink
docs(types): add missing TSDoc release tags
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuslundgard committed Oct 4, 2022
1 parent 8785639 commit 72c4676
Show file tree
Hide file tree
Showing 50 changed files with 363 additions and 30 deletions.
1 change: 1 addition & 0 deletions packages/@sanity/types/src/assets/asserters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {isObject} from '../helpers'
import {isReference} from '../reference'
import type {Image} from './types'

/** @public */
export function isImage(value: unknown): value is Image {
return isObject(value) && isReference(value.asset) && value.asset._ref.startsWith('image-')
}
18 changes: 18 additions & 0 deletions packages/@sanity/types/src/assets/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@ import type {ComponentType} from 'react'
import type {Reference} from '../reference'
import type {SanityDocument} from '../documents'

/** @public */
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface EmptyProps {}

/** @public */
export interface File {
[key: string]: unknown // We allow meta-fields on file
asset: Reference
}

/** @public */
export interface Image {
[key: string]: unknown // We allow meta-fields on image
asset: Reference
crop?: ImageCrop
hotspot?: ImageHotspot
}

/** @public */
export interface Asset extends SanityDocument {
url: string
path: string
Expand All @@ -32,16 +36,19 @@ export interface Asset extends SanityDocument {
source?: AssetSourceSpec
}

/** @public */
export interface ImageAsset extends Asset {
_type: 'sanity.imageAsset'
metadata: ImageMetadata
}

/** @public */
export interface FileAsset extends Asset {
_type: 'sanity.fileAsset'
metadata: Record<string, unknown>
}

/** @public */
export interface ImageMetadata {
[key: string]: unknown
_type: 'sanity.imageMetadata'
Expand All @@ -53,13 +60,15 @@ export interface ImageMetadata {
isOpaque: boolean
}

/** @public */
export interface ImageDimensions {
_type: 'sanity.imageDimensions'
height: number
width: number
aspectRatio: number
}

/** @public */
export interface ImageCrop {
_type?: 'sanity.imageCrop'
left: number
Expand All @@ -68,6 +77,7 @@ export interface ImageCrop {
top: number
}

/** @public */
export interface ImageHotspot {
_type?: 'sanity.imageHotspot'
width: number
Expand All @@ -76,6 +86,7 @@ export interface ImageHotspot {
y: number
}

/** @public */
export interface ImagePalette {
_type: 'sanity.imagePalette'
darkMuted?: ImageSwatch
Expand All @@ -87,6 +98,7 @@ export interface ImagePalette {
vibrant?: ImageSwatch
}

/** @public */
export interface ImageSwatch {
_type: 'sanity.imagePaletteSwatch'
background: string
Expand All @@ -95,6 +107,7 @@ export interface ImageSwatch {
title?: string
}

/** @public */
export type SwatchName =
| 'darkMuted'
| 'darkVibrant'
Expand All @@ -104,18 +117,21 @@ export type SwatchName =
| 'muted'
| 'vibrant'

/** @public */
export interface AssetSourceSpec {
id: string
name: string
url?: string
}

/** @public */
export type AssetFromSource = {
kind: 'assetDocumentId' | 'file' | 'base64' | 'url'
value: string | File
assetDocumentProps?: ImageAsset
}

/** @public */
export interface AssetSourceComponentProps {
assetType?: 'file' | 'image'
selectionType: 'single'
Expand All @@ -125,6 +141,7 @@ export interface AssetSourceComponentProps {
onSelect: (assetFromSource: AssetFromSource[]) => void
}

/** @public */
export type AssetMetadataType =
| 'location'
| 'exif'
Expand All @@ -134,6 +151,7 @@ export type AssetMetadataType =
| 'blurhash'
| 'none'

/** @public */
export interface AssetSource {
name: string
title: string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {isObject} from '../helpers'
import type {CrossDatasetReference} from './types'

/** @beta */
export function isCrossDatasetReference(reference: unknown): reference is CrossDatasetReference {
return (
isObject(reference) &&
Expand Down
8 changes: 7 additions & 1 deletion packages/@sanity/types/src/crossDatasetReference/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {SanityDocument} from '../documents'
import type {ObjectSchemaType, PreviewConfig} from '../schema'
import type {ReferenceFilterOptions} from '../reference'

/** @beta */
export interface CrossDatasetReference {
_type: string
_dataset: string
Expand All @@ -13,31 +14,36 @@ export interface CrossDatasetReference {
_weak?: boolean
}

/** @beta */
export interface WeakCrossDatasetReference extends CrossDatasetReference {
_weak: true
}

/** @beta */
export type CrossDatasetReferenceFilterSearchOptions = {
filter?: string
params?: Record<string, unknown>
tag?: string
}

/** @beta */
export type CrossDatasetReferenceFilterResolver = (options: {
document: SanityDocument
parent?: Record<string, unknown> | Record<string, unknown>[]
parentPath: Path
}) => CrossDatasetReferenceFilterSearchOptions | Promise<CrossDatasetReferenceFilterSearchOptions>

/** @beta */
export interface CrossDatasetType {
type: string
title?: string
icon: ComponentType
preview: PreviewConfig
// eslint-disable-next-line camelcase
/** @alpha */
__experimental_search: ObjectSchemaType['__experimental_search']
}

/** @beta */
export interface CrossDatasetReferenceSchemaType extends Omit<ObjectSchemaType, 'options'> {
jsonType: 'object'
to: CrossDatasetType[]
Expand Down
3 changes: 3 additions & 0 deletions packages/@sanity/types/src/documents/asserters.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import {isObject} from '../helpers'
import type {KeyedObject, SanityDocument, TypedObject} from './types'

/** @public */
export function isSanityDocument(document: unknown): document is SanityDocument {
return (
isObject(document) && typeof document._id === 'string' && typeof document._type === 'string'
)
}

/** @public */
export function isTypedObject(obj: unknown): obj is TypedObject {
return isObject(obj) && typeof obj._type === 'string'
}

/** @public */
export function isKeyedObject(obj: unknown): obj is KeyedObject {
return isObject(obj) && typeof obj._key === 'string'
}
6 changes: 6 additions & 0 deletions packages/@sanity/types/src/documents/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @public */
export interface SanityDocument {
_id: string
_type: string
Expand All @@ -9,7 +10,10 @@ export interface SanityDocument {

/**
* Similar to `SanityDocument` but only requires the `_id` and `_type`
*
* @see SanityDocument
*
* @public
*/
export interface SanityDocumentLike {
_id: string
Expand All @@ -20,11 +24,13 @@ export interface SanityDocumentLike {
[key: string]: unknown
}

/** @public */
export interface TypedObject {
[key: string]: unknown
_type: string
}

/** @public */
export interface KeyedObject {
[key: string]: unknown
_key: string
Expand Down
9 changes: 8 additions & 1 deletion packages/@sanity/types/src/images/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/**
* Note: These are query parameters, so they will eventually be encoded as strings.
* NOTE: These are query parameters, so they will eventually be encoded as strings.
* However, since most/all query parameter encoders will accept numbers and encode
* them as strings, we'll use `string| number` where applicable, as it makes it easier
* to use in places that do calculations and such.
*
* @internal
*/
export interface ImageUrlParams {
bg?: string
Expand Down Expand Up @@ -35,10 +37,13 @@ export interface ImageUrlParams {
border?: string // <width>,<color>
}

/** @internal */
export type ImageUrlFormat = 'jpg' | 'pjpg' | 'png' | 'webp'

/** @internal */
export type ImageUrlFitMode = 'clip' | 'crop' | 'fill' | 'fillmax' | 'max' | 'scale' | 'min'

/** @internal */
export type ImageUrlCropMode =
| 'top'
| 'bottom'
Expand All @@ -48,6 +53,8 @@ export type ImageUrlCropMode =
| 'focalpoint'
| 'entropy' // EXPERIMENTAL

/** @internal */
export type ImageUrlAutoMode = 'format'

/** @internal */
export type ImageUrlOrientation = '0' | '90' | '180' | '270'
3 changes: 3 additions & 0 deletions packages/@sanity/types/src/markers/asserters.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import type {ValidationMarker} from './types'

/** @internal */
export function isValidationErrorMarker(
marker: ValidationMarker
): marker is ValidationMarker & {level: 'error'} {
return marker.level === 'error'
}

/** @internal */
export function isValidationWarningMarker(
marker: ValidationMarker
): marker is ValidationMarker & {level: 'warning'} {
return marker.level === 'warning'
}

/** @internal */
export function isValidationInfoMarker(
marker: ValidationMarker
): marker is ValidationMarker & {level: 'info'} {
Expand Down
1 change: 1 addition & 0 deletions packages/@sanity/types/src/markers/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type {ValidationError} from '../validation'
import type {Path} from '../paths'

/** @public */
export interface ValidationMarker {
level: 'error' | 'warning' | 'info'
item: ValidationError
Expand Down
5 changes: 5 additions & 0 deletions packages/@sanity/types/src/mutations/asserters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,35 @@ import type {
PatchMutation,
} from './types'

/** @internal */
export function isCreateMutation(
mutation: Mutation | TransactionLogMutation
): mutation is CreateMutation {
return 'create' in mutation
}

/** @internal */
export function isCreateIfNotExistsMutation(
mutation: Mutation | TransactionLogMutation
): mutation is CreateIfNotExistsMutation {
return 'createIfNotExists' in mutation
}

/** @internal */
export function isCreateOrReplaceMutation(
mutation: Mutation | TransactionLogMutation
): mutation is CreateOrReplaceMutation {
return 'createOrReplace' in mutation
}

/** @internal */
export function isDeleteMutation(
mutation: Mutation | TransactionLogMutation
): mutation is DeleteMutation {
return 'delete' in mutation
}

/** @internal */
export function isPatchMutation(
mutation: Mutation | TransactionLogMutation
): mutation is PatchMutation {
Expand Down

0 comments on commit 72c4676

Please sign in to comment.