Merge branch 'pk/ranks' of github.com:web3privacy/explorer-data into pb/fix-tests

This commit is contained in:
Diex5 2024-09-17 10:24:28 +02:00
commit d3cb83a811
4 changed files with 83 additions and 13 deletions

View file

@ -24,10 +24,10 @@ properties:
type: string type: string
pattern: "^[A-Z0-9-]+$" pattern: "^[A-Z0-9-]+$"
ecosystem: ecosystem:
anyOf: [{ type: array }, { type: string }] type: array
items: items:
type: string type: string
pattern: "^[A-Z0-9-]+$" pattern: "^[a-z0-9-]+$"
project_type: project_type:
type: string type: string
description: description:
@ -315,3 +315,8 @@ properties:
type: boolean type: boolean
mainnet: mainnet:
type: boolean type: boolean
usecases:
type: array
items:
type: string
pattern: "^[a-z0-9-]+$"

View file

@ -13,6 +13,10 @@ properties:
type: string type: string
label: label:
type: string type: string
positive:
type: string
negative:
type: string
condition: condition:
type: object type: object
properties: properties:

View file

@ -3,53 +3,73 @@
references: references:
- field: team.teammembers - field: team.teammembers
label: Team label: Team
positive: 'Member'
negative: 'Anonymous'
condition: condition:
minLength: 1 minLength: 1
points: 10 points: 10
- field: links.docs - field: links.docs
label: Documentation label: Documentation
positive: 'Link'
negative: 'Not available'
condition: condition:
exists: true exists: true
points: 10 points: 10
- field: links.github - field: links.github
label: Github label: Github
positive: 'Link'
negative: 'Not available'
condition: condition:
exists: true exists: true
points: 10 points: 10
- field: links.twitter - field: links.twitter
label: Twitter label: Twitter
positive: 'Link'
negative: 'Not available'
condition: condition:
exists: true exists: true
points: 1 points: 1
- field: links.telegram - field: links.telegram
label: Telegram label: Telegram
positive: 'Link'
negative: 'Not available'
condition: condition:
exists: true exists: true
points: 1 points: 1
- field: links.discord - field: links.discord
label: Discord label: Discord
positive: 'Link'
negative: 'Not available'
condition: condition:
exists: true exists: true
points: 1 points: 1
- field: links.lens - field: links.lens
label: Lens label: Lens
positive: 'Link'
negative: 'Not available'
condition: condition:
exists: true exists: true
points: 1 points: 1
- field: links.farcaster - field: links.farcaster
label: Farcaster label: Farcaster
positive: 'Link'
negative: 'Not available'
condition: condition:
exists: true exists: true
points: 1 points: 1
- field: links.whitepaper - field: links.whitepaper
label: Whitepaper label: Whitepaper
positive: 'Link'
negative: 'Not available'
condition: condition:
exists: true exists: true
points: 10 points: 10
- field: team.funding - field: funding.value
label: Funding label: Funding
positive: 'Investment'
negative: 'Not available'
condition: condition:
minLength: 1 exists: true
points: 10 points: 10
- id: technology - id: technology
@ -57,26 +77,36 @@
references: references:
- field: project_status.mainnet - field: project_status.mainnet
label: Mainnet label: Mainnet
positive: 'Yes'
negative: 'No'
condition: condition:
exists: true exists: true
points: 10 points: 10
- field: blockchain_features.opensource - field: blockchain_features.opensource
label: Open Source label: Open Source
positive: 'Yes'
negative: 'No'
condition: condition:
equals: true equals: true
points: 20 points: 20
- field: blockchain_features.asset_custody_type - field: blockchain_features.asset_custody_type
label: Non Custody label: Non Custody
positive: 'None'
negative: 'Custodial'
condition: condition:
equals: non-custody equals: non-custody
points: 10 points: 10
- field: blockchain_features.upgradability.enabled - field: blockchain_features.upgradability.enabled
label: Upgradability label: Upgradability
positive: 'Disabled'
negative: 'Enabled'
condition: condition:
equals: false equals: false
points: 10 points: 10
- field: audits - field: audits
label: Audits label: Audits
positive: 'Audit'
negative: 'None'
condition: condition:
minLength: 1 minLength: 1
points: 10 points: 10
@ -86,21 +116,29 @@
references: references:
- field: privacy_policy.link - field: privacy_policy.link
label: Privacy Policy label: Privacy Policy
positive: 'Link'
negative: 'Not available'
condition: condition:
exists: true exists: true
points: 10 points: 10
- field: traceability.kyc - field: traceability.kyc
label: KYC label: KYC
positive: 'No'
negative: 'Yes'
condition: condition:
equals: false equals: false
points: 10 points: 10
- field: compliance - field: compliance
label: Compliance label: Compliance
positive: 'No'
negative: 'OFAC'
condition: condition:
equals: true equals: true
points: 5 points: 5
- field: default_privacy - field: default_privacy
label: Default Privacy label: Default Privacy
positive: 'YES'
negative: 'No'
condition: condition:
equals: true equals: true
points: 10 points: 10

View file

@ -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 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 yaml from "npm:js-yaml";
import { W3PData } from "./w3pdata.js"; import { W3PData } from "./w3pdata.js";
@ -7,7 +8,7 @@ import { W3PData } from "./w3pdata.js";
const w3pd = new W3PData(); const w3pd = new W3PData();
await w3pd.init(); await w3pd.init();
const ajv = new Ajv({ strict: false }); const ajv = new Ajv({ strict: false, allErrors: true });
addFormats(ajv); addFormats(ajv);
async function loadSchemas() { async function loadSchemas() {
@ -19,6 +20,28 @@ async function loadSchemas() {
return out; 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 = { const matrix = {
categories: "category", categories: "category",
projects: "project", projects: "project",
@ -32,9 +55,9 @@ const matrix = {
const schemaDir = "./schema"; const schemaDir = "./schema";
const schemas = await loadSchemas(); const schemas = await loadSchemas();
schemas.project.properties.categories.items.enum = w3pd.data.categories.map( schemas.rank.properties.references.items.properties.field.enum = getDeepPropertiesKeys(schemas.project);
(c) => c.id 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)) { for (const col of Object.keys(w3pd.data)) {
const validator = ajv.compile(schemas[matrix[col]]); 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) { if (Object.keys(item).length > 1) {
Deno.test(testName + " (schema)", () => { Deno.test(testName + " (schema)", () => {
if (!validator(item)) { if (!validator(item)) {
// throw validator.errors; const betterErrors = betterAjvErrors({ errors: validator.errors });
// log instead of throwing to proceed building all projects throw betterErrors;
console.log(validator.errors); console.log(betterErrors);
} }
}); });
} }