mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
added schema tipying and integration to marketprovider
This commit is contained in:
parent
da0c428e59
commit
5b857426d3
316
src/@context/MarketMetadata/_shaclType.ts
Normal file
316
src/@context/MarketMetadata/_shaclType.ts
Normal file
@ -0,0 +1,316 @@
|
|||||||
|
export interface ShaclSchema {
|
||||||
|
chainId: {
|
||||||
|
maxCount: number
|
||||||
|
minCount: number
|
||||||
|
}
|
||||||
|
credentials: {
|
||||||
|
allow: {
|
||||||
|
type: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
minCount: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
values: {
|
||||||
|
maxLength: number
|
||||||
|
minCount: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
deny: {
|
||||||
|
type: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
minCount: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
values: {
|
||||||
|
maxLength: number
|
||||||
|
minCount: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
id: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
minCount: number
|
||||||
|
minLength: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
metadata: {
|
||||||
|
additionalInformation: any
|
||||||
|
algorithm: {
|
||||||
|
consumerParameters: {
|
||||||
|
default: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
minCount: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
description: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
minCount: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
label: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
minCount: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
name: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
minCount: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
options: {
|
||||||
|
maxLength: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
required: {
|
||||||
|
maxCount: number
|
||||||
|
minCount: number
|
||||||
|
}
|
||||||
|
type: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
minCount: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
container: {
|
||||||
|
checksum: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
minCount: number
|
||||||
|
minLength: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
entrypoint: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
minCount: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
image: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
minCount: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
tag: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
minCount: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
language: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
version: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
author: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
minCount: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
categories: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
contentLanguage: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
copyrightHolder: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
description: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
minCount: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
license: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
minCount: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
links: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
name: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
minCount: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
tags: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
type: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
minCount: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
nftAddress: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
minCount: number
|
||||||
|
minLength: number
|
||||||
|
}
|
||||||
|
services: {
|
||||||
|
additionalInformation: any
|
||||||
|
compute: {
|
||||||
|
allowNetworkAccess: {
|
||||||
|
maxCount: number
|
||||||
|
minCount: number
|
||||||
|
}
|
||||||
|
allowRawAlgorithm: {
|
||||||
|
maxCount: number
|
||||||
|
minCount: number
|
||||||
|
}
|
||||||
|
publisherTrustedAlgorithmPublishers: {
|
||||||
|
maxLength: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
publisherTrustedAlgorithms: {
|
||||||
|
containerSectionChecksum: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
minCount: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
did: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
minCount: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
filesChecksum: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
minCount: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
consumerParameters: {
|
||||||
|
default: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
minCount: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
description: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
minCount: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
label: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
minCount: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
name: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
minCount: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
options: {
|
||||||
|
maxLength: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
required: {
|
||||||
|
maxCount: number
|
||||||
|
minCount: number
|
||||||
|
}
|
||||||
|
type: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
minCount: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
datatokenAddress: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
minCount: number
|
||||||
|
minLength: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
description: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
minLength: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
files: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
minCount: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
id: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
minCount: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
name: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
minLength: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
serviceEndpoint: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
minCount: number
|
||||||
|
minLength: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
timeout: {
|
||||||
|
maxCount: number
|
||||||
|
minCount: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
type: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
minCount: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
version: {
|
||||||
|
maxCount: number
|
||||||
|
maxLength: number
|
||||||
|
minCount: number
|
||||||
|
pattern: string
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,7 @@
|
|||||||
|
import { Asset } from '@oceanprotocol/lib'
|
||||||
|
import { CancelToken } from 'axios'
|
||||||
|
import { ShaclSchema } from './_shaclType'
|
||||||
|
|
||||||
export interface OpcFee {
|
export interface OpcFee {
|
||||||
chainId: number
|
chainId: number
|
||||||
swapNotApprovedFee: string
|
swapNotApprovedFee: string
|
||||||
@ -50,4 +54,5 @@ export interface MarketMetadataProviderValue {
|
|||||||
siteContent: SiteContent
|
siteContent: SiteContent
|
||||||
appConfig: AppConfig
|
appConfig: AppConfig
|
||||||
getOpcFeeForToken: (tokenAddress: string, chainId: number) => string
|
getOpcFeeForToken: (tokenAddress: string, chainId: number) => string
|
||||||
|
getShaclSchema: (token?: CancelToken) => Promise<Asset>
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,9 @@ import siteContent from '../../../content/site.json'
|
|||||||
import appConfig from '../../../app.config'
|
import appConfig from '../../../app.config'
|
||||||
import { fetchData, getQueryContext } from '@utils/subgraph'
|
import { fetchData, getQueryContext } from '@utils/subgraph'
|
||||||
import { LoggerInstance } from '@oceanprotocol/lib'
|
import { LoggerInstance } from '@oceanprotocol/lib'
|
||||||
|
import { retrieveShaclSchema } from '@utils/aquarius'
|
||||||
|
import { CancelToken } from 'axios'
|
||||||
|
import { ShaclSchema } from './_shaclType'
|
||||||
|
|
||||||
const MarketMetadataContext = createContext({} as MarketMetadataProviderValue)
|
const MarketMetadataContext = createContext({} as MarketMetadataProviderValue)
|
||||||
|
|
||||||
@ -64,6 +67,12 @@ function MarketMetadataProvider({
|
|||||||
},
|
},
|
||||||
[opcFees]
|
[opcFees]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const getShaclSchema = useCallback(async (token?: CancelToken) => {
|
||||||
|
const schema = await retrieveShaclSchema()
|
||||||
|
return schema
|
||||||
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MarketMetadataContext.Provider
|
<MarketMetadataContext.Provider
|
||||||
value={
|
value={
|
||||||
@ -71,7 +80,8 @@ function MarketMetadataProvider({
|
|||||||
opcFees,
|
opcFees,
|
||||||
siteContent,
|
siteContent,
|
||||||
appConfig,
|
appConfig,
|
||||||
getOpcFeeForToken
|
getOpcFeeForToken,
|
||||||
|
getShaclSchema
|
||||||
} as MarketMetadataProviderValue
|
} as MarketMetadataProviderValue
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
@ -8,6 +8,7 @@ import {
|
|||||||
SortTermOptions
|
SortTermOptions
|
||||||
} from '../@types/aquarius/SearchQuery'
|
} from '../@types/aquarius/SearchQuery'
|
||||||
import { transformAssetToAssetSelection } from './assetConvertor'
|
import { transformAssetToAssetSelection } from './assetConvertor'
|
||||||
|
import { ShaclSchema } from '@context/MarketMetadata/_shaclType'
|
||||||
|
|
||||||
export const MAXIMUM_NUMBER_OF_PAGES_WITH_RESULTS = 476
|
export const MAXIMUM_NUMBER_OF_PAGES_WITH_RESULTS = 476
|
||||||
|
|
||||||
@ -140,13 +141,10 @@ export async function retrieveAsset(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function retrieveShaclSchema(
|
export async function retrieveShaclSchema(): Promise<ShaclSchema> {
|
||||||
cancelToken: CancelToken
|
|
||||||
): Promise<Asset> {
|
|
||||||
try {
|
try {
|
||||||
const response: AxiosResponse<Asset> = await axios.get(
|
const response: AxiosResponse<ShaclSchema> = await axios.get(
|
||||||
`${metadataCacheUri}/api/aquarius/validation/schema`,
|
`${metadataCacheUri}/api/aquarius/validation/schema`
|
||||||
{ cancelToken }
|
|
||||||
)
|
)
|
||||||
if (!response || response.status !== 200 || !response.data) return
|
if (!response || response.status !== 200 || !response.data) return
|
||||||
|
|
||||||
|
@ -1,30 +1,53 @@
|
|||||||
import { MAX_DECIMALS } from '@utils/constants'
|
import { MAX_DECIMALS } from '@utils/constants'
|
||||||
import * as Yup from 'yup'
|
import * as Yup from 'yup'
|
||||||
import { getMaxDecimalsValidation } from '@utils/numbers'
|
import { getMaxDecimalsValidation } from '@utils/numbers'
|
||||||
|
import { retrieveShaclSchema } from '@utils/aquarius'
|
||||||
|
|
||||||
// TODO: conditional validation
|
// TODO: conditional validation
|
||||||
// e.g. when algo is selected, Docker image is required
|
// e.g. when algo is selected, Docker image is required
|
||||||
// hint, hint: https://github.com/jquense/yup#mixedwhenkeys-string--arraystring-builder-object--value-schema-schema-schema
|
// hint, hint: https://github.com/jquense/yup#mixedwhenkeys-string--arraystring-builder-object--value-schema-schema-schema
|
||||||
|
|
||||||
const validationMetadata = {
|
const getValidationMetadata = async () => {
|
||||||
type: Yup.string()
|
const { metadata } = await retrieveShaclSchema()
|
||||||
.matches(/dataset|algorithm/g, { excludeEmptyString: true })
|
console.log(metadata)
|
||||||
.required('Required'),
|
|
||||||
name: Yup.string()
|
return {
|
||||||
.min(4, (param) => `Title must be at least ${param.min} characters`)
|
type: Yup.string()
|
||||||
.required('Required'),
|
.matches(/dataset|algorithm/g, { excludeEmptyString: true })
|
||||||
description: Yup.string()
|
.required('Required'),
|
||||||
.min(10, (param) => `Description must be at least ${param.min} characters`)
|
name: Yup.string()
|
||||||
.max(
|
.min(4, (param) => `Title must be at least ${param.min} characters`)
|
||||||
5000,
|
.max(
|
||||||
(param) => `Description must have maximum ${param.max} characters`
|
metadata.name.maxLength,
|
||||||
)
|
(param) => `Description must have maximum ${param.max} characters`
|
||||||
.required('Required'),
|
)
|
||||||
author: Yup.string().required('Required'),
|
.required('Required'),
|
||||||
tags: Yup.string().nullable(),
|
description: Yup.string()
|
||||||
termsAndConditions: Yup.boolean()
|
.min(
|
||||||
.required('Required')
|
10,
|
||||||
.isTrue('Please agree to the Terms and Conditions.')
|
(param) => `Description must be at least ${param.min} characters`
|
||||||
|
)
|
||||||
|
.max(
|
||||||
|
metadata.description.maxLength,
|
||||||
|
(param) => `Description must have maximum ${param.max} characters`
|
||||||
|
)
|
||||||
|
.required('Required'),
|
||||||
|
author: Yup.string()
|
||||||
|
.max(
|
||||||
|
metadata.author.maxLength,
|
||||||
|
(param) => `Author must have maximum ${param.max} characters`
|
||||||
|
)
|
||||||
|
.required('Required'),
|
||||||
|
tags: Yup.string()
|
||||||
|
.max(
|
||||||
|
metadata.tags.maxLength,
|
||||||
|
(param) => `Tags must have maximum ${param.max} characters`
|
||||||
|
)
|
||||||
|
.nullable(),
|
||||||
|
termsAndConditions: Yup.boolean()
|
||||||
|
.required('Required')
|
||||||
|
.isTrue('Please agree to the Terms and Conditions.')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const validationService = {
|
const validationService = {
|
||||||
@ -91,7 +114,7 @@ export const validationSchema: Yup.SchemaOf<any> = Yup.object().shape({
|
|||||||
chainId: Yup.number().required('Required'),
|
chainId: Yup.number().required('Required'),
|
||||||
accountId: Yup.string().required('Required')
|
accountId: Yup.string().required('Required')
|
||||||
}),
|
}),
|
||||||
metadata: Yup.object().shape(validationMetadata),
|
metadata: Yup.object().shape(getValidationMetadata()),
|
||||||
services: Yup.array().of(Yup.object().shape(validationService)),
|
services: Yup.array().of(Yup.object().shape(validationService)),
|
||||||
pricing: Yup.object().shape(validationPricing)
|
pricing: Yup.object().shape(validationPricing)
|
||||||
})
|
})
|
||||||
|
@ -25,8 +25,7 @@ import { getOceanConfig } from '@utils/ocean'
|
|||||||
import { validationSchema } from './_validation'
|
import { validationSchema } from './_validation'
|
||||||
import { useAbortController } from '@hooks/useAbortController'
|
import { useAbortController } from '@hooks/useAbortController'
|
||||||
import { setNFTMetadataAndTokenURI } from '@utils/nft'
|
import { setNFTMetadataAndTokenURI } from '@utils/nft'
|
||||||
import { retrieveShaclSchema } from '@utils/aquarius'
|
import { useMarketMetadata } from '@context/MarketMetadata'
|
||||||
import { CancelToken } from 'axios'
|
|
||||||
|
|
||||||
// TODO: restore FormikPersist, add back clear form action
|
// TODO: restore FormikPersist, add back clear form action
|
||||||
// const formName = 'ocean-publish-form'
|
// const formName = 'ocean-publish-form'
|
||||||
@ -54,14 +53,6 @@ export default function PublishPage({
|
|||||||
const [ddoEncrypted, setDdoEncrypted] = useState<string>()
|
const [ddoEncrypted, setDdoEncrypted] = useState<string>()
|
||||||
const [did, setDid] = useState<string>()
|
const [did, setDid] = useState<string>()
|
||||||
|
|
||||||
const getShaclSchema = useCallback(async (token?: CancelToken) => {
|
|
||||||
const schema = await retrieveShaclSchema(token)
|
|
||||||
console.log(schema)
|
|
||||||
}, [])
|
|
||||||
useEffect(() => {
|
|
||||||
getShaclSchema()
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
// --------------------------------------------------
|
// --------------------------------------------------
|
||||||
// 1. Create NFT & datatokens & create pricing schema
|
// 1. Create NFT & datatokens & create pricing schema
|
||||||
// --------------------------------------------------
|
// --------------------------------------------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user