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
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:
@ -315,3 +315,8 @@ properties:
type: boolean
mainnet:
type: boolean
usecases:
type: array
items:
type: string
pattern: "^[a-z0-9-]+$"

View file

@ -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
additionalProperties: false

View file

@ -3,53 +3,73 @@
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: team.funding
- field: funding.value
label: Funding
positive: 'Investment'
negative: 'Not available'
condition:
minLength: 1
exists: true
points: 10
- id: technology
@ -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

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 { 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);
}
});
}