diff --git a/src/@types/MetaData.d.ts b/src/@types/MetaData.d.ts index 7d1e713e9..f86328f61 100644 --- a/src/@types/MetaData.d.ts +++ b/src/@types/MetaData.d.ts @@ -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 } diff --git a/src/components/atoms/File.tsx b/src/components/atoms/File.tsx index 4ba38fade..444059422 100644 --- a/src/components/atoms/File.tsx +++ b/src/components/atoms/File.tsx @@ -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 ( diff --git a/src/components/molecules/AssetTeaser.tsx b/src/components/molecules/AssetTeaser.tsx index 1354ec3e5..03f3c1356 100644 --- a/src/components/molecules/AssetTeaser.tsx +++ b/src/components/molecules/AssetTeaser.tsx @@ -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 = ({ diff --git a/src/components/molecules/FilesInput/Info.tsx b/src/components/molecules/FilesInput/Info.tsx index 4bbd29692..35264e1e4 100644 --- a/src/components/molecules/FilesInput/Info.tsx +++ b/src/components/molecules/FilesInput/Info.tsx @@ -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 ( diff --git a/src/components/organisms/AssetActions/Compute.tsx b/src/components/organisms/AssetActions/Compute.tsx index afffb5b0f..243d9cfe6 100644 --- a/src/components/organisms/AssetActions/Compute.tsx +++ b/src/components/organisms/AssetActions/Compute.tsx @@ -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 { diff --git a/src/components/organisms/AssetActions/Consume.tsx b/src/components/organisms/AssetActions/Consume.tsx index 6bae5ed0d..f4ff580ee 100644 --- a/src/components/organisms/AssetActions/Consume.tsx +++ b/src/components/organisms/AssetActions/Consume.tsx @@ -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() diff --git a/src/components/organisms/AssetActions/index.tsx b/src/components/organisms/AssetActions/index.tsx index 543cabe93..10a693ff1 100644 --- a/src/components/organisms/AssetActions/index.tsx +++ b/src/components/organisms/AssetActions/index.tsx @@ -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() diff --git a/src/components/organisms/AssetContent/MetaFull.tsx b/src/components/organisms/AssetContent/MetaFull.tsx index 6a2af5e3b..141c952ce 100644 --- a/src/components/organisms/AssetContent/MetaFull.tsx +++ b/src/components/organisms/AssetContent/MetaFull.tsx @@ -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 diff --git a/src/components/organisms/AssetContent/MetaSecondary.tsx b/src/components/organisms/AssetContent/MetaSecondary.tsx index 8458a92a7..d7587f5db 100644 --- a/src/components/organisms/AssetContent/MetaSecondary.tsx +++ b/src/components/organisms/AssetContent/MetaSecondary.tsx @@ -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 diff --git a/src/components/organisms/AssetContent/index.tsx b/src/components/organisms/AssetContent/index.tsx index b51baabe9..2a8184c3f 100644 --- a/src/components/organisms/AssetContent/index.tsx +++ b/src/components/organisms/AssetContent/index.tsx @@ -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 } diff --git a/src/components/organisms/AssetList.tsx b/src/components/organisms/AssetList.tsx index bd7eb3f82..bc38aef5e 100644 --- a/src/components/organisms/AssetList.tsx +++ b/src/components/organisms/AssetList.tsx @@ -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 = ({ queryResult }) => {
{queryResult && queryResult.totalResults > 0 ? ( queryResult.results.map((ddo: DDO) => { - const { attributes }: MetaDataMarket = ddo.findServiceByType( + const { attributes }: MetadataMarket = ddo.findServiceByType( 'metadata' ) diff --git a/src/components/organisms/ConsumedList.tsx b/src/components/organisms/ConsumedList.tsx index 52f12a9df..d0f1ba573 100644 --- a/src/components/organisms/ConsumedList.tsx +++ b/src/components/organisms/ConsumedList.tsx @@ -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, diff --git a/src/components/organisms/JobsList.tsx b/src/components/organisms/JobsList.tsx index ca210aa6b..2b27ba323 100644 --- a/src/components/organisms/JobsList.tsx +++ b/src/components/organisms/JobsList.tsx @@ -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, diff --git a/src/components/organisms/PublishedList.tsx b/src/components/organisms/PublishedList.tsx index 9a2feff60..aa01085ac 100644 --- a/src/components/organisms/PublishedList.tsx +++ b/src/components/organisms/PublishedList.tsx @@ -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, diff --git a/src/components/pages/Publish/PublishForm.tsx b/src/components/pages/Publish/PublishForm.tsx index 72e1a12fa..3c0aa425a 100644 --- a/src/components/pages/Publish/PublishForm.tsx +++ b/src/components/pages/Publish/PublishForm.tsx @@ -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({ +const validationSchema = Yup.object().shape({ // ---- required fields ---- name: Yup.string().required('Required'), author: Yup.string().required('Required'), price: Yup.string().required('Required'), - files: Yup.array().required('Required').nullable(), + files: Yup.array().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({ // ---- optional fields ---- copyrightHolder: Yup.string(), tags: Yup.string(), - links: Yup.object() + links: Yup.object() }) -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 // ) diff --git a/src/components/pages/Publish/utils.ts b/src/components/pages/Publish/utils.ts index 5c609cf71..8e1142b1d 100644 --- a/src/components/pages/Publish/utils.ts +++ b/src/components/pages/Publish/utils.ts @@ -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, diff --git a/src/models/Asset.ts b/src/models/Asset.ts index 2152993f5..1a082e959 100644 --- a/src/models/Asset.ts +++ b/src/models/Asset.ts @@ -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: { diff --git a/src/pages/asset/index.tsx b/src/pages/asset/index.tsx index 8fd0df130..57e483cd2 100644 --- a/src/pages/asset/index.tsx +++ b/src/pages/asset/index.tsx @@ -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() + const [metadata, setMetadata] = useState() const [title, setTitle] = useState() const [error, setError] = useState() @@ -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 { diff --git a/src/utils/index.ts b/src/utils/index.ts index 67fc353d6..5080fd72c 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -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 { +export async function getFileInfo(url: string): Promise { const response: AxiosResponse = await axios({ method: 'POST', url: '/api/file', @@ -72,7 +72,7 @@ export async function getFileInfo(url: string): Promise { } } -export async function fetchData(url: string): Promise { +export async function fetchData(url: string): Promise { try { const response = await axios(url) diff --git a/tests/unit/AssetModel.test.ts b/tests/unit/AssetModel.test.ts index 54a0c3fee..52cfdfc5e 100644 --- a/tests/unit/AssetModel.test.ts +++ b/tests/unit/AssetModel.test.ts @@ -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' }), diff --git a/tests/unit/__fixtures__/ddo.ts b/tests/unit/__fixtures__/ddo.ts index 0d72b491a..b0ef43cb5 100644 --- a/tests/unit/__fixtures__/ddo.ts +++ b/tests/unit/__fixtures__/ddo.ts @@ -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 = { '@context': 'https://w3id.org/did/v1', @@ -78,9 +81,9 @@ const ddo: Partial = { numVotes: 100, rating: 5 } - } as MetaDataMarket, + } as MetadataMarket, index: 0 - }, + } as ServiceMetadataMarket, { type: 'authorization', serviceEndpoint: 'https://secret-store.pacific.oceanprotocol.com', diff --git a/tests/unit/__fixtures__/testFormData.ts b/tests/unit/__fixtures__/testFormData.ts index 64cd251c2..158dc8a5b 100644 --- a/tests/unit/__fixtures__/testFormData.ts +++ b/tests/unit/__fixtures__/testFormData.ts @@ -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: '', diff --git a/tests/unit/components/PublishForm.test.tsx b/tests/unit/components/PublishForm.test.tsx index 7e08352f5..59f96e096 100644 --- a/tests/unit/components/PublishForm.test.tsx +++ b/tests/unit/components/PublishForm.test.tsx @@ -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()