From 1860fddc72e2b83fb1c062f83cf1fd21e9192f45 Mon Sep 17 00:00:00 2001 From: Cody Olsen <81981+stipsan@users.noreply.github.com> Date: Mon, 10 Oct 2022 19:20:11 +0200 Subject: [PATCH] chore: fix TS error --- src/index.tsx | 65 +++++++++++++++++++++++++----------- src/schema/mux.video.ts | 22 ------------ src/schema/mux.videoAsset.ts | 33 ------------------ src/util/asserters.ts | 4 +-- 4 files changed, 47 insertions(+), 77 deletions(-) delete mode 100644 src/schema/mux.video.ts delete mode 100644 src/schema/mux.videoAsset.ts diff --git a/src/index.tsx b/src/index.tsx index a3f35a14..cefb74b5 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -3,31 +3,12 @@ import {createPlugin} from 'sanity' import ErrorBoundaryCard from './components/ErrorBoundaryCard' import {AspectRatioCard, InputFallback} from './components/Input.styled' -import muxVideo from './schema/mux.video' -import videoAsset from './schema/mux.videoAsset' import {isMuxInputPreviewProps, isMuxInputProps} from './util/asserters' import {type Config} from './util/types' const Input = lazy(() => import('./components/Input')) const Preview = lazy(() => import('./components/Preview')) -/* -// @TODO use declaration merging to allow correct typings for userland schemas when they use type: mux.video -declare module 'sanity' { - namespace Schema { - - } -} -// */ - -/* @TODO export validation rules for: required (checks if the video asset is defined), and that it has a ready uploaded file -export const validation = { - required(Rule: Rule) { - return - } -} -// */ - export const defaultConfig: Config = { mp4_support: 'none', } @@ -63,7 +44,51 @@ export const muxInput = createPlugin | void>((userConfig) => { return next(props) }, }, - schema: {types: [muxVideo, videoAsset]}, + schema: { + types: [ + { + name: 'mux.video', + type: 'object', + title: 'Video asset reference', + fields: [ + { + title: 'Video', + name: 'asset', + type: 'reference', + weak: true, + to: [{type: 'mux.videoAsset'}], + }, + ], + }, + { + name: 'mux.videoAsset', + type: 'object', + title: 'Video asset', + fields: [ + { + type: 'string', + name: 'status', + }, + { + type: 'string', + name: 'assetId', + }, + { + type: 'string', + name: 'playbackId', + }, + { + type: 'string', + name: 'filename', + }, + { + type: 'number', + name: 'thumbTime', + }, + ], + }, + ], + }, } }) diff --git a/src/schema/mux.video.ts b/src/schema/mux.video.ts deleted file mode 100644 index a0dda571..00000000 --- a/src/schema/mux.video.ts +++ /dev/null @@ -1,22 +0,0 @@ -import {defineField} from 'sanity' - -import {name as muxVideoAssetType} from './mux.videoAsset' - -export const name = 'mux.video' as const - -const video = defineField({ - name, - type: 'object', - title: 'Video asset reference', - fields: [ - { - title: 'Video', - name: 'asset', - type: 'reference', - weak: true, - to: [{type: muxVideoAssetType}], - }, - ], -}) - -export default video diff --git a/src/schema/mux.videoAsset.ts b/src/schema/mux.videoAsset.ts deleted file mode 100644 index d5564434..00000000 --- a/src/schema/mux.videoAsset.ts +++ /dev/null @@ -1,33 +0,0 @@ -import {defineField} from 'sanity' - -export const name = 'mux.videoAsset' as const - -const videoAsset = defineField({ - name, - type: 'object', - title: 'Video asset', - fields: [ - { - type: 'string', - name: 'status', - }, - { - type: 'string', - name: 'assetId', - }, - { - type: 'string', - name: 'playbackId', - }, - { - type: 'string', - name: 'filename', - }, - { - type: 'number', - name: 'thumbTime', - }, - ], -}) - -export default videoAsset diff --git a/src/util/asserters.ts b/src/util/asserters.ts index a93b976b..bf9c2f78 100644 --- a/src/util/asserters.ts +++ b/src/util/asserters.ts @@ -8,12 +8,12 @@ import { isObjectSchemaType, } from 'sanity' -import {name} from '../schema/mux.video' import type {MuxInputPreviewProps, MuxInputProps} from './types' export function isMuxInputProps(props: InputProps): props is MuxInputProps { return ( - isObjectSchemaType(props.schemaType) && props.schemaType.type?.name === name + isObjectSchemaType(props.schemaType) && + props.schemaType.type?.name === 'mux.video' ) }