1
0
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:
Matthias Kretschmann 2020-07-16 13:39:02 +02:00
parent ff36e07a45
commit c19cdcd9da
Signed by: m
GPG Key ID: 606EEEF3C479A91F
23 changed files with 73 additions and 70 deletions

View File

@ -1,21 +1,21 @@
import { File, MetaData, AdditionalInformation } from '@oceanprotocol/lib' import { Metadata } from '@oceanprotocol/lib'
import { ServiceMetadata } from '@oceanprotocol/lib/dist/node/ddo/Service' 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 declare type AccessType = 'Download' | 'Compute'
export interface AdditionalInformationMarket extends AdditionalInformation { export interface AdditionalInformationMarket extends AdditionalInformation {
description: string links?: File[]
links?: File[] // redefine existing key, cause not specific enough in Squid
termsAndConditions: boolean termsAndConditions: boolean
dateRange?: [string, string]
access: AccessType | string access: AccessType | string
} }
export interface MetaDataMarket extends MetaData { export interface MetadataMarket extends Metadata {
additionalInformation: AdditionalInformationMarket additionalInformation: AdditionalInformationMarket
} }
export interface MetaDataPublishForm { export interface MetadataPublishForm {
// ---- required fields ---- // ---- required fields ----
name: string name: string
description: string description: string
@ -31,6 +31,6 @@ export interface MetaDataPublishForm {
links?: string | File[] links?: string | File[]
} }
export interface ServiceMetaDataMarket extends ServiceMetadata { export interface ServiceMetadataMarket extends ServiceMetadata {
attributes: MetaDataMarket attributes: MetadataMarket
} }

View File

@ -1,10 +1,10 @@
import React, { ReactElement } from 'react' 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 filesize from 'filesize'
import cleanupContentType from '../../utils/cleanupContentType' import cleanupContentType from '../../utils/cleanupContentType'
import styles from './File.module.css' 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 if (!file) return null
return ( return (

View File

@ -1,13 +1,13 @@
import React from 'react' import React from 'react'
import { Link } from 'gatsby' import { Link } from 'gatsby'
import Dotdotdot from 'react-dotdotdot' import Dotdotdot from 'react-dotdotdot'
import { MetaDataMarket } from '../../@types/MetaData' import { MetadataMarket } from '../../@types/Metadata'
import Price from '../atoms/Price' import Price from '../atoms/Price'
import styles from './AssetTeaser.module.css' import styles from './AssetTeaser.module.css'
declare type AssetTeaserProps = { declare type AssetTeaserProps = {
did: string did: string
metadata: MetaDataMarket metadata: MetadataMarket
} }
const AssetTeaser: React.FC<AssetTeaserProps> = ({ const AssetTeaser: React.FC<AssetTeaserProps> = ({

View File

@ -1,5 +1,5 @@
import React, { ReactElement } from 'react' 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 { prettySize } from '../../../utils'
import cleanupContentType from '../../../utils/cleanupContentType' import cleanupContentType from '../../../utils/cleanupContentType'
import styles from './Info.module.css' import styles from './Info.module.css'
@ -8,7 +8,7 @@ export default function FileInfo({
file, file,
removeItem removeItem
}: { }: {
file: File file: FileMetadata
removeItem(): void removeItem(): void
}): ReactElement { }): ReactElement {
return ( return (

View File

@ -14,7 +14,7 @@ import {
import styles from './Compute.module.css' import styles from './Compute.module.css'
import Button from '../../atoms/Button' import Button from '../../atoms/Button'
import Input from '../../atoms/Input' import Input from '../../atoms/Input'
import { MetaDataMarket } from '../../../@types/MetaData' import { MetadataMarket } from '../../../@types/Metadata'
import Alert from '../../atoms/Alert' import Alert from '../../atoms/Alert'
export default function Compute({ export default function Compute({
@ -24,7 +24,7 @@ export default function Compute({
ocean ocean
}: { }: {
did: string did: string
metadata: MetaDataMarket metadata: MetadataMarket
balance: string | null balance: string | null
ocean: Ocean | null ocean: Ocean | null
}): ReactElement { }): ReactElement {

View File

@ -8,14 +8,14 @@ import Web3Feedback from '../../molecules/Wallet/Feedback'
import styles from './Consume.module.css' import styles from './Consume.module.css'
import Loader from '../../atoms/Loader' import Loader from '../../atoms/Loader'
import { useOcean, useConsume } from '@oceanprotocol/react' import { useOcean, useConsume } from '@oceanprotocol/react'
import { MetaDataMarket } from '../../../@types/MetaData' import { MetadataMarket } from '../../../@types/Metadata'
export default function Consume({ export default function Consume({
did, did,
metadata metadata
}: { }: {
did: string did: string
metadata: MetaDataMarket metadata: MetadataMarket
}): ReactElement { }): ReactElement {
const { ocean, balanceInOcean } = useOcean() const { ocean, balanceInOcean } = useOcean()
const { consume, consumeStepText, isLoading } = useConsume() const { consume, consumeStepText, isLoading } = useConsume()

View File

@ -4,13 +4,13 @@ import styles from './index.module.css'
import Compute from './Compute' import Compute from './Compute'
import Consume from './Consume' import Consume from './Consume'
import { useOcean } from '@oceanprotocol/react' import { useOcean } from '@oceanprotocol/react'
import { MetaDataMarket } from '../../../@types/MetaData' import { MetadataMarket } from '../../../@types/Metadata'
export default function AssetActions({ export default function AssetActions({
metadata, metadata,
did did
}: { }: {
metadata: MetaDataMarket metadata: MetadataMarket
did: string did: string
}): ReactElement { }): ReactElement {
// const { ocean, balanceInOcean } = useOcean() // const { ocean, balanceInOcean } = useOcean()

View File

@ -2,14 +2,14 @@ import React, { ReactElement } from 'react'
import Time from '../../atoms/Time' import Time from '../../atoms/Time'
import MetaItem from './MetaItem' import MetaItem from './MetaItem'
import styles from './MetaFull.module.css' import styles from './MetaFull.module.css'
import { MetaDataMarket } from '../../../@types/MetaData' import { MetadataMarket } from '../../../@types/Metadata'
export default function MetaFull({ export default function MetaFull({
did, did,
metadata metadata
}: { }: {
did: string did: string
metadata: MetaDataMarket metadata: MetadataMarket
}): ReactElement { }): ReactElement {
const { dateCreated, datePublished, author, license } = metadata.main const { dateCreated, datePublished, author, license } = metadata.main
const { categories } = metadata.additionalInformation const { categories } = metadata.additionalInformation

View File

@ -3,13 +3,13 @@ import shortid from 'shortid'
import { ListItem } from '../../atoms/Lists' import { ListItem } from '../../atoms/Lists'
import MetaItem from './MetaItem' import MetaItem from './MetaItem'
import styles from './MetaSecondary.module.css' import styles from './MetaSecondary.module.css'
import { MetaDataMarket } from '../../../@types/MetaData' import { MetadataMarket } from '../../../@types/Metadata'
import Tags from '../../atoms/Tags' import Tags from '../../atoms/Tags'
export default function MetaSecondary({ export default function MetaSecondary({
metadata metadata
}: { }: {
metadata: MetaDataMarket metadata: MetadataMarket
}): ReactElement { }): ReactElement {
const { links, tags } = metadata.additionalInformation const { links, tags } = metadata.additionalInformation

View File

@ -1,4 +1,4 @@
import { MetaDataMarket } from '../../../@types/MetaData' import { MetadataMarket } from '../../../@types/Metadata'
import React, { ReactElement } from 'react' import React, { ReactElement } from 'react'
import Time from '../../atoms/Time' import Time from '../../atoms/Time'
import { Link } from 'gatsby' import { Link } from 'gatsby'
@ -9,7 +9,7 @@ import styles from './index.module.css'
import AssetActions from '../AssetActions' import AssetActions from '../AssetActions'
export interface AssetContentProps { export interface AssetContentProps {
metadata: MetaDataMarket metadata: MetadataMarket
did: string did: string
path?: string path?: string
} }

View File

@ -5,7 +5,7 @@ import { useLocation, useNavigate } from '@reach/router'
import Pagination from '../molecules/Pagination' import Pagination from '../molecules/Pagination'
import { updateQueryStringParameter } from '../../utils' import { updateQueryStringParameter } from '../../utils'
import styles from './AssetList.module.css' import styles from './AssetList.module.css'
import { MetaDataMarket } from '../../@types/MetaData' import { MetadataMarket } from '../../@types/Metadata'
import { DDO } from '@oceanprotocol/lib' import { DDO } from '@oceanprotocol/lib'
import { useSiteMetadata } from '../../hooks/useSiteMetadata' import { useSiteMetadata } from '../../hooks/useSiteMetadata'
@ -45,7 +45,7 @@ const AssetList: React.FC<AssetListProps> = ({ queryResult }) => {
<div className={styles.assetList}> <div className={styles.assetList}>
{queryResult && queryResult.totalResults > 0 ? ( {queryResult && queryResult.totalResults > 0 ? (
queryResult.results.map((ddo: DDO) => { queryResult.results.map((ddo: DDO) => {
const { attributes }: MetaDataMarket = ddo.findServiceByType( const { attributes }: MetadataMarket = ddo.findServiceByType(
'metadata' 'metadata'
) )

View File

@ -10,7 +10,7 @@ import Price from '../atoms/Price'
import { fromWei } from 'web3-utils' import { fromWei } from 'web3-utils'
import DateCell from '../atoms/Table/DateCell' import DateCell from '../atoms/Table/DateCell'
import DdoLinkCell from '../atoms/Table/DdoLinkCell' import DdoLinkCell from '../atoms/Table/DdoLinkCell'
import { MetaDataMain } from '@oceanprotocol/lib' import { MetadataMain } from '@oceanprotocol/lib'
const consumedColumns = [ const consumedColumns = [
{ {
@ -57,7 +57,7 @@ export default function ConsumedList(): ReactElement {
const data = consumedItems.map((ddo) => { const data = consumedItems.map((ddo) => {
const { attributes } = ddo.findServiceByType('metadata') const { attributes } = ddo.findServiceByType('metadata')
const { name, price, datePublished } = attributes.main as MetaDataMain const { name, price, datePublished } = attributes.main as MetadataMain
return { return {
published: datePublished, published: datePublished,
name: name, name: name,

View File

@ -11,7 +11,7 @@ import Price from '../atoms/Price'
import { fromWei } from 'web3-utils' import { fromWei } from 'web3-utils'
import Table from '../atoms/Table' import Table from '../atoms/Table'
import Button from '../atoms/Button' import Button from '../atoms/Button'
import { MetaDataMain, Logger } from '@oceanprotocol/lib' import { MetadataMain, Logger } from '@oceanprotocol/lib'
import DateCell from '../atoms/Table/DateCell' import DateCell from '../atoms/Table/DateCell'
import DdoLinkCell from '../atoms/Table/DdoLinkCell' import DdoLinkCell from '../atoms/Table/DdoLinkCell'
import shortid from 'shortid' import shortid from 'shortid'
@ -94,7 +94,7 @@ export default function JobsList(): ReactElement {
if (!computeItems) return if (!computeItems) return
const data = computeItems.map((item) => { const data = computeItems.map((item) => {
const { attributes } = item.ddo.findServiceByType('metadata') const { attributes } = item.ddo.findServiceByType('metadata')
const { name, price } = attributes.main as MetaDataMain const { name, price } = attributes.main as MetadataMain
return { return {
dateCreated: item.job.dateCreated, dateCreated: item.job.dateCreated,
dateFinished: item.job.dateFinished, dateFinished: item.job.dateFinished,

View File

@ -1,6 +1,6 @@
import React, { useEffect, useState, ReactElement } from 'react' import React, { useEffect, useState, ReactElement } from 'react'
import Loader from '../atoms/Loader' import Loader from '../atoms/Loader'
import { MetaDataMain } from '@oceanprotocol/lib' import { MetadataMain } from '@oceanprotocol/lib'
import { import {
useOcean, useOcean,
OceanConnectionStatus, OceanConnectionStatus,
@ -72,7 +72,7 @@ export default function PublishedList(): ReactElement {
const data = publishedItems.results.map((ddo) => { const data = publishedItems.results.map((ddo) => {
const { attributes } = ddo.findServiceByType('metadata') const { attributes } = ddo.findServiceByType('metadata')
const { name, price, datePublished } = attributes.main as MetaDataMain const { name, price, datePublished } = attributes.main as MetadataMain
return { return {
published: datePublished, published: datePublished,
name: name, name: name,

View File

@ -7,22 +7,22 @@ import { useOcean } from '@oceanprotocol/react'
import { import {
Service, Service,
ServiceCompute 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 { Formik, Form as FormFormik, Field } from 'formik'
import Input from '../../atoms/Input' import Input from '../../atoms/Input'
import Button from '../../atoms/Button' import Button from '../../atoms/Button'
import { transformPublishFormToMetadata } from './utils' import { transformPublishFormToMetadata } from './utils'
import { FormContent, FormFieldProps } from '../../../@types/Form' import { FormContent, FormFieldProps } from '../../../@types/Form'
import { MetaDataPublishForm } from '../../../@types/MetaData' import { MetadataPublishForm } from '../../../@types/Metadata'
import AssetModel from '../../../models/Asset' 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 ---- // ---- required fields ----
name: Yup.string().required('Required'), name: Yup.string().required('Required'),
author: Yup.string().required('Required'), author: Yup.string().required('Required'),
price: 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'), description: Yup.string().required('Required'),
license: Yup.string().required('Required'), license: Yup.string().required('Required'),
access: Yup.string().min(4).required('Required'), access: Yup.string().min(4).required('Required'),
@ -31,10 +31,10 @@ const validationSchema = Yup.object().shape<MetaDataPublishForm>({
// ---- optional fields ---- // ---- optional fields ----
copyrightHolder: Yup.string(), copyrightHolder: Yup.string(),
tags: Yup.string(), tags: Yup.string(),
links: Yup.object<File[]>() links: Yup.object<FileMetadata[]>()
}) })
const initialValues: MetaDataPublishForm = { const initialValues: MetadataPublishForm = {
name: undefined, name: undefined,
author: undefined, author: undefined,
price: undefined, price: undefined,
@ -55,7 +55,7 @@ export default function PublishForm({
}): ReactElement { }): ReactElement {
const { ocean, account } = useOcean() const { ocean, account } = useOcean()
async function handleSubmit(values: MetaDataPublishForm) { async function handleSubmit(values: MetadataPublishForm) {
const submittingToast = toast.info('submitting asset') const submittingToast = toast.info('submitting asset')
console.log(` console.log(`
@ -90,7 +90,7 @@ export default function PublishForm({
// try { // try {
// const asset = await ocean.assets.create( // const asset = await ocean.assets.create(
// (metadata as unknown) as MetaData, // (metadata as unknown) as Metadata,
// account, // account,
// services // services
// ) // )

View File

@ -1,11 +1,11 @@
import { MetaDataMarket, MetaDataPublishForm } from '../../../@types/MetaData' import { MetadataMarket, MetadataPublishForm } from '../../../@types/Metadata'
import { toStringNoMS } from '../../../utils' import { toStringNoMS } from '../../../utils'
import AssetModel from '../../../models/Asset' import AssetModel from '../../../models/Asset'
import web3Utils from 'web3-utils' import web3Utils from 'web3-utils'
export function transformPublishFormToMetadata( export function transformPublishFormToMetadata(
data: MetaDataPublishForm data: MetadataPublishForm
): MetaDataMarket { ): MetadataMarket {
const currentTime = toStringNoMS(new Date()) const currentTime = toStringNoMS(new Date())
const { const {
@ -22,7 +22,7 @@ export function transformPublishFormToMetadata(
access access
} = data } = data
const metadata: MetaDataMarket = { const metadata: MetadataMarket = {
main: { main: {
...AssetModel.main, ...AssetModel.main,
name, name,

View File

@ -1,6 +1,6 @@
import { MetaDataMarket } from '../@types/MetaData' import { MetadataMarket } from '../@types/Metadata'
const AssetModel: MetaDataMarket = { const AssetModel: MetadataMarket = {
// OEP-8 Attributes // OEP-8 Attributes
// https://github.com/oceanprotocol/OEPs/tree/master/8 // https://github.com/oceanprotocol/OEPs/tree/master/8
main: { main: {

View File

@ -3,7 +3,7 @@ import { Router } from '@reach/router'
import AssetContent from '../../components/organisms/AssetContent' import AssetContent from '../../components/organisms/AssetContent'
import Layout from '../../components/Layout' import Layout from '../../components/Layout'
import { PageProps } from 'gatsby' import { PageProps } from 'gatsby'
import { MetaDataMarket, ServiceMetaDataMarket } from '../../@types/MetaData' import { MetadataMarket, ServiceMetadataMarket } from '../../@types/Metadata'
import { MetadataStore, Logger } from '@oceanprotocol/lib' import { MetadataStore, Logger } from '@oceanprotocol/lib'
import Alert from '../../components/atoms/Alert' import Alert from '../../components/atoms/Alert'
import Loader from '../../components/atoms/Loader' import Loader from '../../components/atoms/Loader'
@ -11,7 +11,7 @@ import { useSiteMetadata } from '../../hooks/useSiteMetadata'
export default function AssetRoute(props: PageProps): ReactElement { export default function AssetRoute(props: PageProps): ReactElement {
const { appConfig } = useSiteMetadata() const { appConfig } = useSiteMetadata()
const [metadata, setMetadata] = useState<MetaDataMarket>() const [metadata, setMetadata] = useState<MetadataMarket>()
const [title, setTitle] = useState<string>() const [title, setTitle] = useState<string>()
const [error, setError] = useState<string>() const [error, setError] = useState<string>()
@ -32,7 +32,7 @@ export default function AssetRoute(props: PageProps): ReactElement {
return return
} }
const { attributes }: ServiceMetaDataMarket = ddo.findServiceByType( const { attributes }: ServiceMetadataMarket = ddo.findServiceByType(
'metadata' 'metadata'
) )
@ -51,7 +51,7 @@ export default function AssetRoute(props: PageProps): ReactElement {
<Router basepath="/asset"> <Router basepath="/asset">
<AssetContent <AssetContent
did={did} did={did}
metadata={metadata as MetaDataMarket} metadata={metadata as MetadataMarket}
path=":did" path=":did"
/> />
</Router> </Router>

View File

@ -1,6 +1,6 @@
import axios, { AxiosResponse } from 'axios' import axios, { AxiosResponse } from 'axios'
import { toast } from 'react-toastify' 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 numeral from 'numeral'
import web3Utils from 'web3-utils' import web3Utils from 'web3-utils'
@ -51,7 +51,7 @@ export function toStringNoMS(date: Date): string {
return date.toISOString().replace(/\.[0-9]{3}Z/, 'Z') 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({ const response: AxiosResponse = await axios({
method: 'POST', method: 'POST',
url: '/api/file', 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 { try {
const response = await axios(url) const response = await axios(url)

View File

@ -1,9 +1,9 @@
import AssetModel from '../../src/models/Asset' import AssetModel from '../../src/models/Asset'
import { MetaDataMarket } from '../../src/@types/MetaData' import { MetadataMarket } from '../../src/@types/Metadata'
describe('AssetModel', () => { describe('AssetModel', () => {
it('values can be reassigned', () => { it('values can be reassigned', () => {
const newMeta: MetaDataMarket = { const newMeta: MetadataMarket = {
main: Object.assign(AssetModel.main, { main: Object.assign(AssetModel.main, {
name: 'Hello' name: 'Hello'
}), }),

View File

@ -1,5 +1,8 @@
import { DDO } from '@oceanprotocol/lib' import { DDO } from '@oceanprotocol/lib'
import { MetaDataMarket } from '../../../src/@types/MetaData' import {
MetadataMarket,
ServiceMetadataMarket
} from '../../../src/@types/Metadata'
const ddo: Partial<DDO> = { const ddo: Partial<DDO> = {
'@context': 'https://w3id.org/did/v1', '@context': 'https://w3id.org/did/v1',
@ -78,9 +81,9 @@ const ddo: Partial<DDO> = {
numVotes: 100, numVotes: 100,
rating: 5 rating: 5
} }
} as MetaDataMarket, } as MetadataMarket,
index: 0 index: 0
}, } as ServiceMetadataMarket,
{ {
type: 'authorization', type: 'authorization',
serviceEndpoint: 'https://secret-store.pacific.oceanprotocol.com', serviceEndpoint: 'https://secret-store.pacific.oceanprotocol.com',

View File

@ -1,6 +1,6 @@
import { MetaDataPublishForm } from '../../../src/@types/MetaData' import { MetadataPublishForm } from '../../../src/@types/Metadata'
const testFormData: MetaDataPublishForm = { const testFormData: MetadataPublishForm = {
author: '', author: '',
files: [], files: [],
license: '', license: '',

View File

@ -2,9 +2,9 @@ import React from 'react'
import { render } from '@testing-library/react' import { render } from '@testing-library/react'
import { transformPublishFormToMetadata } from '../../../src/components/pages/Publish/utils' import { transformPublishFormToMetadata } from '../../../src/components/pages/Publish/utils'
import { import {
MetaDataMarket, MetadataMarket,
MetaDataPublishForm MetadataPublishForm
} from '../../../src/@types/MetaData' } from '../../../src/@types/Metadata'
import PublishForm from '../../../src/components/pages/Publish/PublishForm' import PublishForm from '../../../src/components/pages/Publish/PublishForm'
import publishFormData from '../__fixtures__/testFormData' import publishFormData from '../__fixtures__/testFormData'
import content from '../../../content/pages/publish.json' import content from '../../../content/pages/publish.json'
@ -15,9 +15,9 @@ describe('PublishForm', () => {
expect(container.firstChild).toBeInTheDocument() expect(container.firstChild).toBeInTheDocument()
}) })
it('Form data is correctly transformed to asset MetaData', () => { it('Form data is correctly transformed to asset Metadata', () => {
const data: MetaDataPublishForm = publishFormData const data: MetadataPublishForm = publishFormData
let metadata: MetaDataMarket = transformPublishFormToMetadata(data) let metadata: MetadataMarket = transformPublishFormToMetadata(data)
expect(metadata.additionalInformation).toBeDefined() expect(metadata.additionalInformation).toBeDefined()
expect(metadata.main).toBeDefined() expect(metadata.main).toBeDefined()