Skip to content

Commit

Permalink
feat: Validation for labels (#1062)
Browse files Browse the repository at this point in the history
* feat: Validation for labels

* allow only uppercase for colors

* v0.12.17
  • Loading branch information
ChaituVR committed Sep 27, 2024
1 parent 89f9bb4 commit d287c01
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@snapshot-labs/snapshot.js",
"version": "0.12.16",
"version": "0.12.17",
"repository": "snapshot-labs/snapshot.js",
"license": "MIT",
"main": "dist/snapshot.cjs.js",
Expand Down
35 changes: 35 additions & 0 deletions src/schemas/space.json
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,41 @@
"additionalProperties": false
}
},
"labels": {
"type": "array",
"maxItems": 100,
"uniqueItems": true,
"items":{
"type": "object",
"properties": {
"id":{
"type": "string",
"title": "Id",
"minLength": 1,
"maxLength": 8
},
"name": {
"type": "string",
"title": "Name",
"minLength": 1,
"maxLength": 32
},
"description": {
"type": "string",
"title": "Description",
"minLength": 1,
"maxLength": 100
},
"color": {
"type": "string",
"title": "Color",
"format": "color"
}
},
"required": ["id", "name", "description", "color"],
"additionalProperties": false
}
},
"parent": {
"type": "string",
"title": "parent"
Expand Down
7 changes: 7 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ ajv.addFormat('lowercase', {
validate: (value: string) => value === value.toLowerCase()
});

ajv.addFormat('color', {
validate: (value: string) => {
if (!value) return false;
return !!value.match(/^#[0-9A-F]{6}$/);
}
});

ajv.addFormat('ethValue', {
validate: (value: string) => {
if (!value.match(/^([0-9]|[1-9][0-9]+)(\.[0-9]+)?$/)) return false;
Expand Down
18 changes: 16 additions & 2 deletions test/examples/space.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,23 @@
"name": "basic",
"params": {}
},
"voting":{
"voting": {
"delay": 2592000,
"period": 15552000,
"quorum": 100
}
},
"labels": [
{
"id": "4b6a8c88",
"name": "Test 1",
"description": "Test Description 1",
"color": "#48CB0D"
},
{
"id": "893b2f3",
"name": "Test 2",
"description": "Test Description 2",
"color": "#FBE54E"
}
]
}

0 comments on commit d287c01

Please sign in to comment.