From 415e9b6ece47d0aacbf902d18875f757c8e4a4bf Mon Sep 17 00:00:00 2001 From: Klein Petr Date: Mon, 16 Sep 2024 19:43:18 +0200 Subject: [PATCH 1/4] fix: rank schema --- src/ranks.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ranks.yaml b/src/ranks.yaml index 8656b12d..3a056c56 100644 --- a/src/ranks.yaml +++ b/src/ranks.yaml @@ -46,10 +46,10 @@ condition: exists: true points: 10 - - field: team.funding + - field: funding.value label: Funding condition: - minLength: 1 + exists: true points: 10 - id: technology From 2cd582717c539fc898c973ef9e56ca92ca6f1f66 Mon Sep 17 00:00:00 2001 From: Klein Petr Date: Mon, 16 Sep 2024 19:43:27 +0200 Subject: [PATCH 2/4] fix: project schema --- schema/project.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/schema/project.yaml b/schema/project.yaml index 1a5e8d1a..f69e48db 100644 --- a/schema/project.yaml +++ b/schema/project.yaml @@ -315,4 +315,9 @@ properties: testnet: type: boolean mainnet: - type: boolean \ No newline at end of file + type: boolean + usecases: + type: array + items: + type: string + pattern: '^[a-z0-9-]+$' \ No newline at end of file From 435304b3c329c5ae1d6eaeaba68859d371b5591f Mon Sep 17 00:00:00 2001 From: Klein Petr Date: Mon, 16 Sep 2024 19:44:53 +0200 Subject: [PATCH 3/4] test: extend schemas with data enums & add betterAvjErrors --- utils/test.js | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/utils/test.js b/utils/test.js index 0403d808..575f6cd2 100644 --- a/utils/test.js +++ b/utils/test.js @@ -1,5 +1,6 @@ -import Ajv from "https://esm.sh/ajv@8.8.1?pin=v58"; +import Ajv from "https://esm.sh/ajv@8.17.1?pin=v58"; import addFormats from "https://esm.sh/ajv-formats@2.1.1"; +import { betterAjvErrors } from 'https://esm.sh/@apideck/better-ajv-errors@0.3.6?pin=v58'; import yaml from "npm:js-yaml"; import { W3PData } from "./w3pdata.js"; @@ -7,7 +8,7 @@ import { W3PData } from "./w3pdata.js"; const w3pd = new W3PData(); await w3pd.init(); -const ajv = new Ajv({ strict: false }); +const ajv = new Ajv({ strict: false, allErrors: true }); addFormats(ajv); async function loadSchemas() { @@ -19,6 +20,28 @@ async function loadSchemas() { return out; } +function getDeepPropertiesKeys(obj, parentKey = '') { + let keys = []; + + if (obj.hasOwnProperty('properties')) { + const properties = obj['properties']; + + for (const key in properties) { + if (properties.hasOwnProperty(key)) { + const newKey = parentKey ? `${parentKey}.${key}` : key; + + if (properties[key].hasOwnProperty('properties')) { + keys = keys.concat(getDeepPropertiesKeys(properties[key], newKey)); + } else { + keys.push(newKey); + } + } + } + } + + return keys; +} + const matrix = { categories: "category", projects: "project", @@ -32,9 +55,9 @@ const matrix = { const schemaDir = "./schema"; const schemas = await loadSchemas(); -schemas.project.properties.categories.items.enum = w3pd.data.categories.map( - (c) => c.id -); +schemas.rank.properties.references.items.properties.field.enum = getDeepPropertiesKeys(schemas.project); +schemas.project.properties.categories.items.enum = w3pd.data.categories.map((c) => c.id); +schemas.project.properties.usecases.items.enum = w3pd.data.usecases.map((c) => c.id); for (const col of Object.keys(w3pd.data)) { const validator = ajv.compile(schemas[matrix[col]]); @@ -61,9 +84,9 @@ for (const col of Object.keys(w3pd.data)) { if (Object.keys(item).length > 1) { Deno.test(testName + " (schema)", () => { if (!validator(item)) { - // throw validator.errors; - // log instead of throwing to proceed building all projects - console.log(validator.errors); + const betterErrors = betterAjvErrors({ errors: validator.errors }); + throw betterErrors; + console.log(betterErrors); } }); } From bb55177ab15438805b5030015340fae70f5ffc0a Mon Sep 17 00:00:00 2001 From: Daniel Klein Date: Mon, 16 Sep 2024 20:53:05 +0200 Subject: [PATCH 4/4] fix(schema): ecosystem type, add rank positive and negative texts --- schema/project.yaml | 6 +++--- schema/rank.yaml | 6 +++++- src/ranks.yaml | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/schema/project.yaml b/schema/project.yaml index f69e48db..f0ea53e6 100644 --- a/schema/project.yaml +++ b/schema/project.yaml @@ -25,10 +25,10 @@ properties: type: string pattern: '^[A-Z0-9-]+$' ecosystem: - anyOf: [{type: array}, {type: string}] + type: array items: type: string - pattern: '^[A-Z0-9-]+$' + pattern: '^[a-z0-9-]+$' project_type: type: string description: @@ -320,4 +320,4 @@ properties: type: array items: type: string - pattern: '^[a-z0-9-]+$' \ No newline at end of file + pattern: '^[a-z0-9-]+$' diff --git a/schema/rank.yaml b/schema/rank.yaml index e34a9e89..d37c1acc 100644 --- a/schema/rank.yaml +++ b/schema/rank.yaml @@ -13,6 +13,10 @@ properties: type: string label: type: string + positive: + type: string + negative: + type: string condition: type: object properties: @@ -38,4 +42,4 @@ required: - id - name - references -additionalProperties: false \ No newline at end of file +additionalProperties: false diff --git a/src/ranks.yaml b/src/ranks.yaml index 3a056c56..1ec1b4a6 100644 --- a/src/ranks.yaml +++ b/src/ranks.yaml @@ -3,51 +3,71 @@ references: - field: team.teammembers label: Team + positive: 'Member' + negative: 'Anonymous' condition: minLength: 1 points: 10 - field: links.docs label: Documentation + positive: 'Link' + negative: 'Not available' condition: exists: true points: 10 - field: links.github label: Github + positive: 'Link' + negative: 'Not available' condition: exists: true points: 10 - field: links.twitter label: Twitter + positive: 'Link' + negative: 'Not available' condition: exists: true points: 1 - field: links.telegram label: Telegram + positive: 'Link' + negative: 'Not available' condition: exists: true points: 1 - field: links.discord label: Discord + positive: 'Link' + negative: 'Not available' condition: exists: true points: 1 - field: links.lens label: Lens + positive: 'Link' + negative: 'Not available' condition: exists: true points: 1 - field: links.farcaster label: Farcaster + positive: 'Link' + negative: 'Not available' condition: exists: true points: 1 - field: links.whitepaper label: Whitepaper + positive: 'Link' + negative: 'Not available' condition: exists: true points: 10 - field: funding.value label: Funding + positive: 'Investment' + negative: 'Not available' condition: exists: true points: 10 @@ -57,26 +77,36 @@ references: - field: project_status.mainnet label: Mainnet + positive: 'Yes' + negative: 'No' condition: exists: true points: 10 - field: blockchain_features.opensource label: Open Source + positive: 'Yes' + negative: 'No' condition: equals: true points: 20 - field: blockchain_features.asset_custody_type label: Non Custody + positive: 'None' + negative: 'Custodial' condition: equals: non-custody points: 10 - field: blockchain_features.upgradability.enabled label: Upgradability + positive: 'Disabled' + negative: 'Enabled' condition: equals: false points: 10 - field: audits label: Audits + positive: 'Audit' + negative: 'None' condition: minLength: 1 points: 10 @@ -86,21 +116,29 @@ references: - field: privacy_policy.link label: Privacy Policy + positive: 'Link' + negative: 'Not available' condition: exists: true points: 10 - field: traceability.kyc label: KYC + positive: 'No' + negative: 'Yes' condition: equals: false points: 10 - field: compliance label: Compliance + positive: 'No' + negative: 'OFAC' condition: equals: true points: 5 - field: default_privacy label: Default Privacy + positive: 'YES' + negative: 'No' condition: equals: true points: 10