mirror of
https://github.com/oceanprotocol/market.git
synced 2024-11-14 17:24:51 +01:00
fix most metadata typings
This commit is contained in:
parent
ff36e07a45
commit
c19cdcd9da
18
src/@types/MetaData.d.ts
vendored
18
src/@types/MetaData.d.ts
vendored
@ -1,21 +1,21 @@
|
||||
import { File, MetaData, AdditionalInformation } from '@oceanprotocol/lib'
|
||||
import { ServiceMetadata } from '@oceanprotocol/lib/dist/node/ddo/Service'
|
||||
import { Metadata } from '@oceanprotocol/lib'
|
||||
import { AdditionalInformation } from '@oceanprotocol/lib/dist/node/ddo/interfaces/AdditionalInformation'
|
||||
import { File } from '@oceanprotocol/lib/dist/node/ddo/interfaces/File'
|
||||
import { ServiceMetadata } from '@oceanprotocol/lib/dist/node/ddo/interfaces/Service'
|
||||
|
||||
export declare type AccessType = 'Download' | 'Compute'
|
||||
|
||||
export interface AdditionalInformationMarket extends AdditionalInformation {
|
||||
description: string
|
||||
links?: File[] // redefine existing key, cause not specific enough in Squid
|
||||
links?: File[]
|
||||
termsAndConditions: boolean
|
||||
dateRange?: [string, string]
|
||||
access: AccessType | string
|
||||
}
|
||||
|
||||
export interface MetaDataMarket extends MetaData {
|
||||
export interface MetadataMarket extends Metadata {
|
||||
additionalInformation: AdditionalInformationMarket
|
||||
}
|
||||
|
||||
export interface MetaDataPublishForm {
|
||||
export interface MetadataPublishForm {
|
||||
// ---- required fields ----
|
||||
name: string
|
||||
description: string
|
||||
@ -31,6 +31,6 @@ export interface MetaDataPublishForm {
|
||||
links?: string | File[]
|
||||
}
|
||||
|
||||
export interface ServiceMetaDataMarket extends ServiceMetadata {
|
||||
attributes: MetaDataMarket
|
||||
export interface ServiceMetadataMarket extends ServiceMetadata {
|
||||
attributes: MetadataMarket
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
import React, { ReactElement } from 'react'
|
||||
import { File as FileMetaData } from '@oceanprotocol/lib'
|
||||
import { File as FileMetadata } from '@oceanprotocol/lib/dist/node/ddo/interfaces/File'
|
||||
import filesize from 'filesize'
|
||||
import cleanupContentType from '../../utils/cleanupContentType'
|
||||
import styles from './File.module.css'
|
||||
|
||||
export default function File({ file }: { file: FileMetaData }): ReactElement {
|
||||
export default function File({ file }: { file: FileMetadata }): ReactElement {
|
||||
if (!file) return null
|
||||
|
||||
return (
|
||||
|
@ -1,13 +1,13 @@
|
||||
import React from 'react'
|
||||
import { Link } from 'gatsby'
|
||||
import Dotdotdot from 'react-dotdotdot'
|
||||
import { MetaDataMarket } from '../../@types/MetaData'
|
||||
import { MetadataMarket } from '../../@types/Metadata'
|
||||
import Price from '../atoms/Price'
|
||||
import styles from './AssetTeaser.module.css'
|
||||
|
||||
declare type AssetTeaserProps = {
|
||||
did: string
|
||||
metadata: MetaDataMarket
|
||||
metadata: MetadataMarket
|
||||
}
|
||||
|
||||
const AssetTeaser: React.FC<AssetTeaserProps> = ({
|
||||
|
@ -1,5 +1,5 @@
|
||||
import React, { ReactElement } from 'react'
|
||||
import { File } from '@oceanprotocol/lib'
|
||||
import { File as FileMetadata } from '@oceanprotocol/lib/dist/node/ddo/interfaces/File'
|
||||
import { prettySize } from '../../../utils'
|
||||
import cleanupContentType from '../../../utils/cleanupContentType'
|
||||
import styles from './Info.module.css'
|
||||
@ -8,7 +8,7 @@ export default function FileInfo({
|
||||
file,
|
||||
removeItem
|
||||
}: {
|
||||
file: File
|
||||
file: FileMetadata
|
||||
removeItem(): void
|
||||
}): ReactElement {
|
||||
return (
|
||||
|
@ -14,7 +14,7 @@ import {
|
||||
import styles from './Compute.module.css'
|
||||
import Button from '../../atoms/Button'
|
||||
import Input from '../../atoms/Input'
|
||||
import { MetaDataMarket } from '../../../@types/MetaData'
|
||||
import { MetadataMarket } from '../../../@types/Metadata'
|
||||
import Alert from '../../atoms/Alert'
|
||||
|
||||
export default function Compute({
|
||||
@ -24,7 +24,7 @@ export default function Compute({
|
||||
ocean
|
||||
}: {
|
||||
did: string
|
||||
metadata: MetaDataMarket
|
||||
metadata: MetadataMarket
|
||||
balance: string | null
|
||||
ocean: Ocean | null
|
||||
}): ReactElement {
|
||||
|
@ -8,14 +8,14 @@ import Web3Feedback from '../../molecules/Wallet/Feedback'
|
||||
import styles from './Consume.module.css'
|
||||
import Loader from '../../atoms/Loader'
|
||||
import { useOcean, useConsume } from '@oceanprotocol/react'
|
||||
import { MetaDataMarket } from '../../../@types/MetaData'
|
||||
import { MetadataMarket } from '../../../@types/Metadata'
|
||||
|
||||
export default function Consume({
|
||||
did,
|
||||
metadata
|
||||
}: {
|
||||
did: string
|
||||
metadata: MetaDataMarket
|
||||
metadata: MetadataMarket
|
||||
}): ReactElement {
|
||||
const { ocean, balanceInOcean } = useOcean()
|
||||
const { consume, consumeStepText, isLoading } = useConsume()
|
||||
|
@ -4,13 +4,13 @@ import styles from './index.module.css'
|
||||
import Compute from './Compute'
|
||||
import Consume from './Consume'
|
||||
import { useOcean } from '@oceanprotocol/react'
|
||||
import { MetaDataMarket } from '../../../@types/MetaData'
|
||||
import { MetadataMarket } from '../../../@types/Metadata'
|
||||
|
||||
export default function AssetActions({
|
||||
metadata,
|
||||
did
|
||||
}: {
|
||||
metadata: MetaDataMarket
|
||||
metadata: MetadataMarket
|
||||
did: string
|
||||
}): ReactElement {
|
||||
// const { ocean, balanceInOcean } = useOcean()
|
||||
|
@ -2,14 +2,14 @@ import React, { ReactElement } from 'react'
|
||||
import Time from '../../atoms/Time'
|
||||
import MetaItem from './MetaItem'
|
||||
import styles from './MetaFull.module.css'
|
||||
import { MetaDataMarket } from '../../../@types/MetaData'
|
||||
import { MetadataMarket } from '../../../@types/Metadata'
|
||||
|
||||
export default function MetaFull({
|
||||
did,
|
||||
metadata
|
||||
}: {
|
||||
did: string
|
||||
metadata: MetaDataMarket
|
||||
metadata: MetadataMarket
|
||||
}): ReactElement {
|
||||
const { dateCreated, datePublished, author, license } = metadata.main
|
||||
const { categories } = metadata.additionalInformation
|
||||
|
@ -3,13 +3,13 @@ import shortid from 'shortid'
|
||||
import { ListItem } from '../../atoms/Lists'
|
||||
import MetaItem from './MetaItem'
|
||||
import styles from './MetaSecondary.module.css'
|
||||
import { MetaDataMarket } from '../../../@types/MetaData'
|
||||
import { MetadataMarket } from '../../../@types/Metadata'
|
||||
import Tags from '../../atoms/Tags'
|
||||
|
||||
export default function MetaSecondary({
|
||||
metadata
|
||||
}: {
|
||||
metadata: MetaDataMarket
|
||||
metadata: MetadataMarket
|
||||
}): ReactElement {
|
||||
const { links, tags } = metadata.additionalInformation
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { MetaDataMarket } from '../../../@types/MetaData'
|
||||
import { MetadataMarket } from '../../../@types/Metadata'
|
||||
import React, { ReactElement } from 'react'
|
||||
import Time from '../../atoms/Time'
|
||||
import { Link } from 'gatsby'
|
||||
@ -9,7 +9,7 @@ import styles from './index.module.css'
|
||||
import AssetActions from '../AssetActions'
|
||||
|
||||
export interface AssetContentProps {
|
||||
metadata: MetaDataMarket
|
||||
metadata: MetadataMarket
|
||||
did: string
|
||||
path?: string
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import { useLocation, useNavigate } from '@reach/router'
|
||||
import Pagination from '../molecules/Pagination'
|
||||
import { updateQueryStringParameter } from '../../utils'
|
||||
import styles from './AssetList.module.css'
|
||||
import { MetaDataMarket } from '../../@types/MetaData'
|
||||
import { MetadataMarket } from '../../@types/Metadata'
|
||||
import { DDO } from '@oceanprotocol/lib'
|
||||
import { useSiteMetadata } from '../../hooks/useSiteMetadata'
|
||||
|
||||
@ -45,7 +45,7 @@ const AssetList: React.FC<AssetListProps> = ({ queryResult }) => {
|
||||
<div className={styles.assetList}>
|
||||
{queryResult && queryResult.totalResults > 0 ? (
|
||||
queryResult.results.map((ddo: DDO) => {
|
||||
const { attributes }: MetaDataMarket = ddo.findServiceByType(
|
||||
const { attributes }: MetadataMarket = ddo.findServiceByType(
|
||||
'metadata'
|
||||
)
|
||||
|
||||
|
@ -10,7 +10,7 @@ import Price from '../atoms/Price'
|
||||
import { fromWei } from 'web3-utils'
|
||||
import DateCell from '../atoms/Table/DateCell'
|
||||
import DdoLinkCell from '../atoms/Table/DdoLinkCell'
|
||||
import { MetaDataMain } from '@oceanprotocol/lib'
|
||||
import { MetadataMain } from '@oceanprotocol/lib'
|
||||
|
||||
const consumedColumns = [
|
||||
{
|
||||
@ -57,7 +57,7 @@ export default function ConsumedList(): ReactElement {
|
||||
|
||||
const data = consumedItems.map((ddo) => {
|
||||
const { attributes } = ddo.findServiceByType('metadata')
|
||||
const { name, price, datePublished } = attributes.main as MetaDataMain
|
||||
const { name, price, datePublished } = attributes.main as MetadataMain
|
||||
return {
|
||||
published: datePublished,
|
||||
name: name,
|
||||
|
@ -11,7 +11,7 @@ import Price from '../atoms/Price'
|
||||
import { fromWei } from 'web3-utils'
|
||||
import Table from '../atoms/Table'
|
||||
import Button from '../atoms/Button'
|
||||
import { MetaDataMain, Logger } from '@oceanprotocol/lib'
|
||||
import { MetadataMain, Logger } from '@oceanprotocol/lib'
|
||||
import DateCell from '../atoms/Table/DateCell'
|
||||
import DdoLinkCell from '../atoms/Table/DdoLinkCell'
|
||||
import shortid from 'shortid'
|
||||
@ -94,7 +94,7 @@ export default function JobsList(): ReactElement {
|
||||
if (!computeItems) return
|
||||
const data = computeItems.map((item) => {
|
||||
const { attributes } = item.ddo.findServiceByType('metadata')
|
||||
const { name, price } = attributes.main as MetaDataMain
|
||||
const { name, price } = attributes.main as MetadataMain
|
||||
return {
|
||||
dateCreated: item.job.dateCreated,
|
||||
dateFinished: item.job.dateFinished,
|
||||
|
@ -1,6 +1,6 @@
|
||||
import React, { useEffect, useState, ReactElement } from 'react'
|
||||
import Loader from '../atoms/Loader'
|
||||
import { MetaDataMain } from '@oceanprotocol/lib'
|
||||
import { MetadataMain } from '@oceanprotocol/lib'
|
||||
import {
|
||||
useOcean,
|
||||
OceanConnectionStatus,
|
||||
@ -72,7 +72,7 @@ export default function PublishedList(): ReactElement {
|
||||
|
||||
const data = publishedItems.results.map((ddo) => {
|
||||
const { attributes } = ddo.findServiceByType('metadata')
|
||||
const { name, price, datePublished } = attributes.main as MetaDataMain
|
||||
const { name, price, datePublished } = attributes.main as MetadataMain
|
||||
return {
|
||||
published: datePublished,
|
||||
name: name,
|
||||
|
@ -7,22 +7,22 @@ import { useOcean } from '@oceanprotocol/react'
|
||||
import {
|
||||
Service,
|
||||
ServiceCompute
|
||||
} from '@oceanprotocol/lib/dist/node/ddo/Service'
|
||||
} from '@oceanprotocol/lib/dist/node/ddo/interfaces/Service'
|
||||
import { Formik, Form as FormFormik, Field } from 'formik'
|
||||
import Input from '../../atoms/Input'
|
||||
import Button from '../../atoms/Button'
|
||||
import { transformPublishFormToMetadata } from './utils'
|
||||
import { FormContent, FormFieldProps } from '../../../@types/Form'
|
||||
import { MetaDataPublishForm } from '../../../@types/MetaData'
|
||||
import { MetadataPublishForm } from '../../../@types/Metadata'
|
||||
import AssetModel from '../../../models/Asset'
|
||||
import { File } from '@oceanprotocol/lib'
|
||||
import { File as FileMetadata } from '@oceanprotocol/lib/dist/node/ddo/interfaces/File'
|
||||
|
||||
const validationSchema = Yup.object().shape<MetaDataPublishForm>({
|
||||
const validationSchema = Yup.object().shape<MetadataPublishForm>({
|
||||
// ---- required fields ----
|
||||
name: Yup.string().required('Required'),
|
||||
author: Yup.string().required('Required'),
|
||||
price: Yup.string().required('Required'),
|
||||
files: Yup.array<File>().required('Required').nullable(),
|
||||
files: Yup.array<FileMetadata>().required('Required').nullable(),
|
||||
description: Yup.string().required('Required'),
|
||||
license: Yup.string().required('Required'),
|
||||
access: Yup.string().min(4).required('Required'),
|
||||
@ -31,10 +31,10 @@ const validationSchema = Yup.object().shape<MetaDataPublishForm>({
|
||||
// ---- optional fields ----
|
||||
copyrightHolder: Yup.string(),
|
||||
tags: Yup.string(),
|
||||
links: Yup.object<File[]>()
|
||||
links: Yup.object<FileMetadata[]>()
|
||||
})
|
||||
|
||||
const initialValues: MetaDataPublishForm = {
|
||||
const initialValues: MetadataPublishForm = {
|
||||
name: undefined,
|
||||
author: undefined,
|
||||
price: undefined,
|
||||
@ -55,7 +55,7 @@ export default function PublishForm({
|
||||
}): ReactElement {
|
||||
const { ocean, account } = useOcean()
|
||||
|
||||
async function handleSubmit(values: MetaDataPublishForm) {
|
||||
async function handleSubmit(values: MetadataPublishForm) {
|
||||
const submittingToast = toast.info('submitting asset')
|
||||
|
||||
console.log(`
|
||||
@ -90,7 +90,7 @@ export default function PublishForm({
|
||||
|
||||
// try {
|
||||
// const asset = await ocean.assets.create(
|
||||
// (metadata as unknown) as MetaData,
|
||||
// (metadata as unknown) as Metadata,
|
||||
// account,
|
||||
// services
|
||||
// )
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { MetaDataMarket, MetaDataPublishForm } from '../../../@types/MetaData'
|
||||
import { MetadataMarket, MetadataPublishForm } from '../../../@types/Metadata'
|
||||
import { toStringNoMS } from '../../../utils'
|
||||
import AssetModel from '../../../models/Asset'
|
||||
import web3Utils from 'web3-utils'
|
||||
|
||||
export function transformPublishFormToMetadata(
|
||||
data: MetaDataPublishForm
|
||||
): MetaDataMarket {
|
||||
data: MetadataPublishForm
|
||||
): MetadataMarket {
|
||||
const currentTime = toStringNoMS(new Date())
|
||||
|
||||
const {
|
||||
@ -22,7 +22,7 @@ export function transformPublishFormToMetadata(
|
||||
access
|
||||
} = data
|
||||
|
||||
const metadata: MetaDataMarket = {
|
||||
const metadata: MetadataMarket = {
|
||||
main: {
|
||||
...AssetModel.main,
|
||||
name,
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { MetaDataMarket } from '../@types/MetaData'
|
||||
import { MetadataMarket } from '../@types/Metadata'
|
||||
|
||||
const AssetModel: MetaDataMarket = {
|
||||
const AssetModel: MetadataMarket = {
|
||||
// OEP-8 Attributes
|
||||
// https://github.com/oceanprotocol/OEPs/tree/master/8
|
||||
main: {
|
||||
|
@ -3,7 +3,7 @@ import { Router } from '@reach/router'
|
||||
import AssetContent from '../../components/organisms/AssetContent'
|
||||
import Layout from '../../components/Layout'
|
||||
import { PageProps } from 'gatsby'
|
||||
import { MetaDataMarket, ServiceMetaDataMarket } from '../../@types/MetaData'
|
||||
import { MetadataMarket, ServiceMetadataMarket } from '../../@types/Metadata'
|
||||
import { MetadataStore, Logger } from '@oceanprotocol/lib'
|
||||
import Alert from '../../components/atoms/Alert'
|
||||
import Loader from '../../components/atoms/Loader'
|
||||
@ -11,7 +11,7 @@ import { useSiteMetadata } from '../../hooks/useSiteMetadata'
|
||||
|
||||
export default function AssetRoute(props: PageProps): ReactElement {
|
||||
const { appConfig } = useSiteMetadata()
|
||||
const [metadata, setMetadata] = useState<MetaDataMarket>()
|
||||
const [metadata, setMetadata] = useState<MetadataMarket>()
|
||||
const [title, setTitle] = useState<string>()
|
||||
const [error, setError] = useState<string>()
|
||||
|
||||
@ -32,7 +32,7 @@ export default function AssetRoute(props: PageProps): ReactElement {
|
||||
return
|
||||
}
|
||||
|
||||
const { attributes }: ServiceMetaDataMarket = ddo.findServiceByType(
|
||||
const { attributes }: ServiceMetadataMarket = ddo.findServiceByType(
|
||||
'metadata'
|
||||
)
|
||||
|
||||
@ -51,7 +51,7 @@ export default function AssetRoute(props: PageProps): ReactElement {
|
||||
<Router basepath="/asset">
|
||||
<AssetContent
|
||||
did={did}
|
||||
metadata={metadata as MetaDataMarket}
|
||||
metadata={metadata as MetadataMarket}
|
||||
path=":did"
|
||||
/>
|
||||
</Router>
|
||||
|
@ -1,6 +1,6 @@
|
||||
import axios, { AxiosResponse } from 'axios'
|
||||
import { toast } from 'react-toastify'
|
||||
import { File } from '@oceanprotocol/lib'
|
||||
import { File as FileMetadata } from '@oceanprotocol/lib/dist/node/ddo/interfaces/File'
|
||||
import numeral from 'numeral'
|
||||
import web3Utils from 'web3-utils'
|
||||
|
||||
@ -51,7 +51,7 @@ export function toStringNoMS(date: Date): string {
|
||||
return date.toISOString().replace(/\.[0-9]{3}Z/, 'Z')
|
||||
}
|
||||
|
||||
export async function getFileInfo(url: string): Promise<File> {
|
||||
export async function getFileInfo(url: string): Promise<FileMetadata> {
|
||||
const response: AxiosResponse = await axios({
|
||||
method: 'POST',
|
||||
url: '/api/file',
|
||||
@ -72,7 +72,7 @@ export async function getFileInfo(url: string): Promise<File> {
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchData(url: string): Promise<any> {
|
||||
export async function fetchData(url: string): Promise<Axios> {
|
||||
try {
|
||||
const response = await axios(url)
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
import AssetModel from '../../src/models/Asset'
|
||||
import { MetaDataMarket } from '../../src/@types/MetaData'
|
||||
import { MetadataMarket } from '../../src/@types/Metadata'
|
||||
|
||||
describe('AssetModel', () => {
|
||||
it('values can be reassigned', () => {
|
||||
const newMeta: MetaDataMarket = {
|
||||
const newMeta: MetadataMarket = {
|
||||
main: Object.assign(AssetModel.main, {
|
||||
name: 'Hello'
|
||||
}),
|
||||
|
@ -1,5 +1,8 @@
|
||||
import { DDO } from '@oceanprotocol/lib'
|
||||
import { MetaDataMarket } from '../../../src/@types/MetaData'
|
||||
import {
|
||||
MetadataMarket,
|
||||
ServiceMetadataMarket
|
||||
} from '../../../src/@types/Metadata'
|
||||
|
||||
const ddo: Partial<DDO> = {
|
||||
'@context': 'https://w3id.org/did/v1',
|
||||
@ -78,9 +81,9 @@ const ddo: Partial<DDO> = {
|
||||
numVotes: 100,
|
||||
rating: 5
|
||||
}
|
||||
} as MetaDataMarket,
|
||||
} as MetadataMarket,
|
||||
index: 0
|
||||
},
|
||||
} as ServiceMetadataMarket,
|
||||
{
|
||||
type: 'authorization',
|
||||
serviceEndpoint: 'https://secret-store.pacific.oceanprotocol.com',
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { MetaDataPublishForm } from '../../../src/@types/MetaData'
|
||||
import { MetadataPublishForm } from '../../../src/@types/Metadata'
|
||||
|
||||
const testFormData: MetaDataPublishForm = {
|
||||
const testFormData: MetadataPublishForm = {
|
||||
author: '',
|
||||
files: [],
|
||||
license: '',
|
||||
|
@ -2,9 +2,9 @@ import React from 'react'
|
||||
import { render } from '@testing-library/react'
|
||||
import { transformPublishFormToMetadata } from '../../../src/components/pages/Publish/utils'
|
||||
import {
|
||||
MetaDataMarket,
|
||||
MetaDataPublishForm
|
||||
} from '../../../src/@types/MetaData'
|
||||
MetadataMarket,
|
||||
MetadataPublishForm
|
||||
} from '../../../src/@types/Metadata'
|
||||
import PublishForm from '../../../src/components/pages/Publish/PublishForm'
|
||||
import publishFormData from '../__fixtures__/testFormData'
|
||||
import content from '../../../content/pages/publish.json'
|
||||
@ -15,9 +15,9 @@ describe('PublishForm', () => {
|
||||
expect(container.firstChild).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('Form data is correctly transformed to asset MetaData', () => {
|
||||
const data: MetaDataPublishForm = publishFormData
|
||||
let metadata: MetaDataMarket = transformPublishFormToMetadata(data)
|
||||
it('Form data is correctly transformed to asset Metadata', () => {
|
||||
const data: MetadataPublishForm = publishFormData
|
||||
let metadata: MetadataMarket = transformPublishFormToMetadata(data)
|
||||
|
||||
expect(metadata.additionalInformation).toBeDefined()
|
||||
expect(metadata.main).toBeDefined()
|
||||
|
Loading…
Reference in New Issue
Block a user